<commit_before>/*
 *  Licensed to the Apache Software Foundation (ASF) under one
 *  or more contributor license agreements.  See the NOTICE file
 *  distributed with this work for additional information
 *  regarding copyright ownership.  The ASF licenses this file
 *  to you under the Apache License, Version 2.0 (the
 *  "License"); you may not use this file except in compliance
 *  with the License.  You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing,
 *  software distributed under the License is distributed on an
 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 *  KIND, either express or implied.  See the License for the
 *  specific language governing permissions and limitations
 *  under the License.
 */
package org.apache.isis.testing.integtestsupport.applib;

import javax.inject.Inject;

import org.springframework.context.event.EventListener;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Service;

import org.apache.isis.applib.annotation.OrderPrecedence;
import org.apache.isis.applib.services.command.Command;
import org.apache.isis.applib.services.command.CommandContext;
import org.apache.isis.applib.services.factory.FactoryService;
import org.apache.isis.applib.services.metamodel.MetaModelService;
import org.apache.isis.applib.services.registry.ServiceRegistry;
import org.apache.isis.applib.services.repository.RepositoryService;
import org.apache.isis.applib.services.sessmgmt.SessionManagementService;
import org.apache.isis.applib.services.user.UserService;
import org.apache.isis.applib.services.wrapper.WrapperFactory;
import org.apache.isis.applib.services.xactn.TransactionService;
import org.apache.isis.core.runtime.persistence.transaction.events.TransactionAfterBeginEvent;

/**
 * Convenient base class to extend for integration tests. 
 *  
 * @since 2.0
 */
public abstract class IsisIntegrationTestAbstract {

    @Service
    @Order(OrderPrecedence.MIDPOINT)
    public static class CommandSupport {

        private final CommandContext commandContext;

        @Inject
        public CommandSupport(final CommandContext commandContext) {
            this.commandContext = commandContext;
        }

        @EventListener
        public void on(final TransactionAfterBeginEvent event) {
            final Command command = commandContext.getCommand();
            if(command == null) {
                return;
            }
            final Command.Executor executor = command.getExecutor();
            if(executor != Command.Executor.OTHER) {
                return;
            }

            command.internal().setExecutor(Command.Executor.USER);
        }
    }<commit_msg>ISIS-2062: updates javadoc for IsisIntegrationTestAbstract.CommandSupport service<commit_after>/*
 *  Licensed to the Apache Software Foundation (ASF) under one
 *  or more contributor license agreements.  See the NOTICE file
 *  distributed with this work for additional information
 *  regarding copyright ownership.  The ASF licenses this file
 *  to you under the Apache License, Version 2.0 (the
 *  "License"); you may not use this file except in compliance
 *  with the License.  You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing,
 *  software distributed under the License is distributed on an
 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 *  KIND, either express or implied.  See the License for the
 *  specific language governing permissions and limitations
 *  under the License.
 */
package org.apache.isis.testing.integtestsupport.applib;

import javax.inject.Inject;

import org.springframework.context.event.EventListener;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Service;

import org.apache.isis.applib.annotation.Action;
import org.apache.isis.applib.annotation.CommandReification;
import org.apache.isis.applib.annotation.OrderPrecedence;
import org.apache.isis.applib.services.command.Command;
import org.apache.isis.applib.services.command.CommandContext;
import org.apache.isis.applib.services.factory.FactoryService;
import org.apache.isis.applib.services.metamodel.MetaModelService;
import org.apache.isis.applib.services.registry.ServiceRegistry;
import org.apache.isis.applib.services.repository.RepositoryService;
import org.apache.isis.applib.services.sessmgmt.SessionManagementService;
import org.apache.isis.applib.services.user.UserService;
import org.apache.isis.applib.services.wrapper.WrapperFactory;
import org.apache.isis.applib.services.xactn.TransactionService;
import org.apache.isis.core.runtime.persistence.transaction.events.TransactionAfterBeginEvent;

/**
 * Convenient base class to extend for integration tests. 
 *  
 * @since 2.0
 */
public abstract class IsisIntegrationTestAbstract {

    /**
     * If included as a service, then ensures that any {@link Command}s created (eg as a result of
     * {@link Action#command()} set to {@link CommandReification#ENABLED}) will be appear to be created as
     * user initiatied.
     *
     * <p>
     *     Most integration tests won't be concerned with such details, but tests that verify the interaction with the
     *     {@link org.apache.isis.applib.services.command.spi.CommandService} implementations may require this
     *     behaviour.
     * </p>
     */
    @Service
    @Order(OrderPrecedence.MIDPOINT)
    public static class CommandSupport {

        private final CommandContext commandContext;

        @Inject
        public CommandSupport(final CommandContext commandContext) {
            this.commandContext = commandContext;
        }

        @EventListener
        public void on(final TransactionAfterBeginEvent event) {
            final Command command = commandContext.getCommand();
            if(command == null) {
                return;
            }
            final Command.Executor executor = command.getExecutor();
            if(executor != Command.Executor.OTHER) {
                return;
            }

            command.internal().setExecutor(Command.Executor.USER);
        }
    }
{'fraction_non_alphanumeric': 0.08274984086569065, 'fraction_numerical': 0.002546148949713558, 'mean_word_length': 3.492494639027877, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7256141', 'n_tokens_mistral': 1689, 'n_tokens_neox': 1647, 'n_words': 465}