content: /*
   * Copyright 2017-2025 Hyland Software, Inc. and its affiliates.
   *
   * Licensed 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.activiti.cloud.services.core.utils;
  
  import org.activiti.engine.ManagementService;
  import org.activiti.engine.ProcessEngine;
  import org.activiti.engine.ProcessEngineConfiguration;
  import org.activiti.engine.RepositoryService;
  import org.activiti.engine.RuntimeService;
  import org.activiti.engine.TaskService;
  import org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl;
  import org.activiti.image.ProcessDiagramGenerator;
  import org.activiti.image.impl.DefaultProcessDiagramGenerator;
  import org.activiti.validation.ProcessValidator;
  import org.activiti.validation.ProcessValidatorImpl;
  import org.activiti.validation.validator.ValidatorSetFactory;
  import org.springframework.boot.test.context.TestConfiguration;
  import org.springframework.cloud.stream.binder.test.TestChannelBinderConfiguration;
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.Import;
  import org.springframework.messaging.MessageChannel;
  import org.springframework.messaging.SubscribableChannel;
  import org.springframework.security.core.userdetails.UserDetailsService;
  import org.springframework.security.provisioning.InMemoryUserDetailsManager;
  
  /**
   * Test context configuration for integration tests over Activiti process engine
   */
  @TestConfiguration
  @Import(TestChannelBinderConfiguration.class)
  public class TestProcessEngineConfiguration {
  
      @Bean
      public TestProcessEngine testProcessEngine(ProcessEngine processEngine) {
          return new TestProcessEngine(processEngine);
      }
  
      @Bean
      public MockMessageChannel mockMessageChannel() {
          return new MockMessageChannel();
      }
  
      @Bean
      public MockProcessEngineChannels mockProcessEngineChannels() {
          return new MockProcessEngineChannels();
      }
  
      @Bean
      public SubscribableChannel commandConsumer() {
          return new MockSubscribableChannel();
      }
  
      @Bean
      public ProcessEngine processEngine() {
          return ProcessEngineConfiguration
              .createStandaloneInMemProcessEngineConfiguration()
              .setDatabaseSchemaUpdate(ProcessEngineConfigurationImpl.DB_SCHEMA_UPDATE_DROP_CREATE)
              .buildProcessEngine();
      }
  
      @Bean
      public RuntimeService runtimeService(ProcessEngine processEngine) {
          return processEngine.getRuntimeService();
      }
  
      @Bean
      public ManagementService managementService(ProcessEngine processEngine) {
          return processEngine.getManagementService();
      }
  
      @Bean
      public RepositoryService repositoryService(ProcessEngine processEngine) {
          return processEngine.getRepositoryService();
      }
  
      @Bean
      public TaskService taskService(ProcessEngine processEngine) {
          return processEngine.getTaskService();
      }
  
      @Bean
      public ProcessDiagramGenerator processDiagramGenerator() {
          return new DefaultProcessDiagramGenerator();
      }
  
      @Bean
      public ProcessValidator processValidator() {
          ProcessValidatorImpl processValidator = new ProcessValidatorImpl();
          processValidator.addValidatorSet(new ValidatorSetFactory().createActivitiExecutableProcessValidatorSet());
          return processValidator;
      }
  
      @Bean
      public MessageChannel commandResults() {
          return new MockSubscribableChannel();
      }
  
      @Bean
      public UserDetailsService myUserDetailsService() {
          return new InMemoryUserDetailsManager();
      }
  }
  