/* 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.camunda.bpm.engine.test.api.history;

import org.camunda.bpm.engine.ProcessEngine;
import org.camunda.bpm.engine.ProcessEngineConfiguration;
import org.camunda.bpm.engine.ProcessEngines;
import org.camunda.bpm.engine.test.RequiredHistoryLevel;
import org.junit.Test;

import static org.junit.Assert.assertNotNull;

/**
 * @author Nikola Koevski
 */
@RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_ACTIVITY)
public class HistoryCleanupOnConsecutiveEngineBootstrap {

  private static final String FIRST_ENGINE_NAME = "engineWithoutHistoryCleanupBatchWindow";
  private static final String SECOND_ENGINE_NAME = "engineWithHistoryCleanupBatchWindow";

  @Test
  public void testConsecutiveEngineBootstrapHistoryCleanupJobReconfiguration() {

    ProcessEngineConfiguration processEngineConfiguration = ProcessEngineConfiguration
      .createProcessEngineConfigurationFromResource("org/camunda/bpm/engine/test/history/no-batchwindow.camunda.cfg.xml");
    processEngineConfiguration.setProcessEngineName(FIRST_ENGINE_NAME);
    ProcessEngine processEngine1 = processEngineConfiguration.buildProcessEngine();
    processEngine1.close();

    processEngineConfiguration = ProcessEngineConfiguration
      .createProcessEngineConfigurationFromResource("org/camunda/bpm/engine/test/history/batchwindow.camunda.cfg.xml");
    processEngineConfiguration.setProcessEngineName(SECOND_ENGINE_NAME);
    ProcessEngine processEngine2 = processEngineConfiguration.buildProcessEngine();

    assertNotNull(ProcessEngines.getProcessEngine(SECOND_ENGINE_NAME));

    processEngine2.close();
  }
}

@@ -1075,107 +1075,8 @@
 ing 
-FIRST_ENGINE_NAME = %22engineWithoutHistoryCleanupBatchWindow%22;%0A  private static final String SECOND_
 ENGI
@@ -1223,63 +1223,54 @@
     
-ProcessEngineConfiguration processEngineConfiguration =
+// given%0A    // create history cleanup job%0A   
  Pro
@@ -1386,11 +1386,8 @@
 ory/
-no-
 batc
@@ -1403,39 +1403,46 @@
 amunda.cfg.xml%22)
-;
 %0A    
-p
+  .buildP
 rocessEngineConf
@@ -1441,152 +1441,241 @@
 gine
-Configuration.setProcessEngineName(FIRST_ENGINE_NAME);%0A    ProcessEngine processEngine1 = processEngineConfiguration.buildProcessEngine();%0A    p
+()%0A      .close();%0A%0A    // when%0A    // suspend history cleanup job%0A    ProcessEngineConfiguration%0A      .createProcessEngineConfigurationFromResource(%22org/camunda/bpm/engine/test/history/no-batchwindow.camunda.cfg.xml%22)%0A      .buildP
 roce
@@ -1686,9 +1686,17 @@
 gine
-1
+()%0A      
 .clo
@@ -1698,32 +1698,110 @@
  .close();%0A%0A    
+// then%0A    // reconfigure history cleanup job%0A    ProcessEngineConfiguration 
 processEngineCon
@@ -2012,23 +2012,16 @@
 ineName(
-SECOND_
 ENGINE_N
@@ -2057,17 +2057,16 @@
 ssEngine
-2
  = proce
@@ -2164,15 +2164,8 @@
 ine(
-SECOND_
 ENGI
@@ -2193,17 +2193,16 @@
 ssEngine
-2
 .close()

add additional step in historycleanupjob reconf test case