[Test]   public virtual void testProcessApplicationDeploymentResumePreviousVersionsByDeploymentNameNoResume()
        {
            IBpmnModelInstance process1 = ESS.FW.Bpm.Model.Bpmn.Bpmn.CreateExecutableProcess("process1").Done();
            var deployment = repositoryService.CreateDeployment(processApplication.Reference).Name("deployment").AddModelInstance("process1.bpmn", process1).Deploy();

            AssertThatOneProcessIsDeployed();

            IProcessApplicationDeployment deployment2 = repositoryService.CreateDeployment(processApplication.Reference).ResumePreviousVersions()
                                                        .ResumePreviousVersionsBy(ResumePreviousBy.ResumeByDeploymentName).Name("anotherDeployment")
                                                        .AddModelInstance("process2.bpmn", process1).Deploy() as IProcessApplicationDeployment;

            IList <IProcessDefinition> processDefinitions = repositoryService.CreateProcessDefinitionQuery()
                                                            //.OrderByProcessDefinitionVersion()/*.Asc()*/
                                                            .ToList();

            // there is a new version of the process
            Assert.AreEqual(1, processDefinitions[0].Version);
            Assert.AreEqual(2, processDefinitions[1].Version);

            // but the old deployment was not resumed
            var            registration  = deployment2.ProcessApplicationRegistration;
            IList <string> deploymentIds = registration.DeploymentIds;

            Assert.AreEqual(1, deploymentIds.Count);
            Assert.AreEqual(deployment2.Id, deploymentIds.GetEnumerator().MoveNext());
            Assert.AreEqual(ProcessEngine.Name, registration.ProcessEngineName);

            deleteDeployments(deployment, deployment2);
        }
        [Test]   public virtual void testProcessApplicationDeploymentResumePreviousVersionsByDeploymentNameDeployDifferentProcesses()
        {
            IBpmnModelInstance process1 = ESS.FW.Bpm.Model.Bpmn.Bpmn.CreateExecutableProcess("process1").Done();
            IBpmnModelInstance process2 = ESS.FW.Bpm.Model.Bpmn.Bpmn.CreateExecutableProcess("process2").Done();
            var deployment = repositoryService.CreateDeployment(processApplication.Reference).Name("deployment").AddModelInstance("process1.bpmn", process1).Deploy();

            AssertThatOneProcessIsDeployed();

            IProcessApplicationDeployment deployment2 = repositoryService.CreateDeployment(processApplication.Reference)
                                                        .ResumePreviousVersions().ResumePreviousVersionsBy(ResumePreviousBy.ResumeByDeploymentName).Name("deployment").AddModelInstance("process2.bpmn", process2).Deploy() as IProcessApplicationDeployment;

            IList <IProcessDefinition> processDefinitions = repositoryService.CreateProcessDefinitionQuery().ToList();   //.OrderByProcessDefinitionVersion()/*.Asc()*/.ToList();

            // now there are 2 process definitions deployed but both with version 1
            Assert.AreEqual(1, processDefinitions[0].Version);
            Assert.AreEqual(1, processDefinitions[1].Version);

            // old deployment was resumed
            var            registration  = deployment2.ProcessApplicationRegistration;
            IList <string> deploymentIds = registration.DeploymentIds;

            Assert.AreEqual(2, deploymentIds.Count);
            Assert.AreEqual(ProcessEngine.Name, registration.ProcessEngineName);

            deleteDeployments(deployment, deployment2);
        }
        [Test]   public virtual void testProcessApplicationDeploymentResumePreviousVersionsByDeploymentName()
        {
            // create initial deployment
            var deployment1 = repositoryService.CreateDeployment(processApplication.Reference).Name("deployment").AddClasspathResource("resources/api/repository/version1.bpmn20.xml").Deploy();

            AssertThatOneProcessIsDeployed();

            // deploy update with changes:
            IProcessApplicationDeployment deployment2 = repositoryService.CreateDeployment(processApplication.Reference)
                                                        //.ResumePreviousVersions()
                                                        .ResumePreviousVersionsBy(ResumePreviousBy.ResumeByDeploymentName).ResumePreviousVersions()
                                                        .Name("deployment")
                                                        .EnableDuplicateFiltering(false)
                                                        .AddClasspathResource("resources/api/repository/version2.bpmn20.xml").Deploy() as IProcessApplicationDeployment;

            IList <IProcessDefinition> processDefinitions = repositoryService.CreateProcessDefinitionQuery().ToList();   //.OrderByProcessDefinitionVersion()/*.Asc()*/.ToList();

            // now there are 2 process definitions deployed
            Assert.AreEqual(1, processDefinitions[0].Version);
            Assert.AreEqual(2, processDefinitions[1].Version);

            // old deployment was resumed
            var            registration  = deployment2.ProcessApplicationRegistration;
            IList <string> deploymentIds = registration.DeploymentIds;

            Assert.AreEqual(2, deploymentIds.Count);
            Assert.AreEqual(ProcessEngine.Name, registration.ProcessEngineName);

            deleteDeployments(deployment1, deployment2);
        }
        [Test]   public virtual void testProcessApplicationDeploymentResumePreviousVersionsDifferentKeys()
        {
            // create initial deployment
            var deployment1 = repositoryService.CreateDeployment(processApplication.Reference).Name("deployment").AddClasspathResource("resources/api/repository/version1.bpmn20.xml").Deploy();

            AssertThatOneProcessIsDeployed();

            // deploy update with changes:
            IProcessApplicationDeployment deployment2 = repositoryService.CreateDeployment(processApplication.Reference)
                                                        .ResumePreviousVersions().Name("deployment")
                                                        .AddClasspathResource("resources/api/oneTaskProcess.bpmn20.xml").Deploy() as IProcessApplicationDeployment;

            IList <IProcessDefinition> processDefinitions = repositoryService.CreateProcessDefinitionQuery().ToList();   //.OrderByProcessDefinitionVersion()/*.Asc()*/.ToList();

            // now there are 2 process definitions deployed
            Assert.AreEqual(1, processDefinitions[0].Version);
            Assert.AreEqual(1, processDefinitions[1].Version);

            // and the old deployment was not resumed
            var            registration  = deployment2.ProcessApplicationRegistration;
            IList <string> deploymentIds = registration.DeploymentIds;

            Assert.AreEqual(1, deploymentIds.Count);
            Assert.AreEqual(deployment2.Id, deploymentIds.GetEnumerator().MoveNext());
            Assert.AreEqual(ProcessEngine.Name, registration.ProcessEngineName);

            deleteDeployments(deployment1, deployment2);
        }
        /// <summary>
        /// Test re-deployment of only those resources that have actually changed
        /// </summary>
        [Test]   public virtual void testPartialChangesDeployChangedOnly()
        {
            IBpmnModelInstance model1 = ESS.FW.Bpm.Model.Bpmn.Bpmn.CreateExecutableProcess("process1").Done();
            IBpmnModelInstance model2 = ESS.FW.Bpm.Model.Bpmn.Bpmn.CreateExecutableProcess("process2").Done();

            // create initial deployment
            var deployment1 = repositoryService.CreateDeployment(processApplication.Reference).Name("deployment").AddModelInstance("process1.bpmn20.xml", model1).AddModelInstance("process2.bpmn20.xml", model2).Deploy();

            IBpmnModelInstance changedModel2 = ESS.FW.Bpm.Model.Bpmn.Bpmn.CreateExecutableProcess("process2").StartEvent().Done();

            // second deployment with partial changes:
            IProcessApplicationDeployment deployment2 = repositoryService.CreateDeployment(processApplication.Reference).ResumePreviousVersions().Name("deployment").EnableDuplicateFiltering(true)
                                                        .AddModelInstance("process1.bpmn20.xml", model1).AddModelInstance("process2.bpmn20.xml", changedModel2)
                                                        .Deploy() as IProcessApplicationDeployment;

            Assert.AreEqual(3, repositoryService.CreateProcessDefinitionQuery().Count());

            // there is one version of process1 deployed
            IProcessDefinition processDefinitionModel1 = repositoryService.CreateProcessDefinitionQuery(c => c.Key == "process1").First();

            Assert.NotNull(processDefinitionModel1);
            Assert.AreEqual(1, processDefinitionModel1.Version);
            Assert.AreEqual(deployment1.Id, processDefinitionModel1.DeploymentId);

            // there are two versions of process2 deployed
            IList <IProcessDefinition> processDefinitionsModel2 = repositoryService.CreateProcessDefinitionQuery(c => c.Key == "process2").ToList(); //.OrderByProcessDefinitionVersion()/*.Asc()*/.ToList();

            Assert.AreEqual(2, processDefinitionsModel2.Count);
            Assert.AreEqual(1, processDefinitionsModel2[0].Version);
            Assert.AreEqual(2, processDefinitionsModel2[1].Version);

            // old deployment was resumed
            var            registration  = deployment2.ProcessApplicationRegistration;
            IList <string> deploymentIds = registration.DeploymentIds;

            Assert.AreEqual(2, deploymentIds.Count);

            IBpmnModelInstance anotherChangedModel2 = ESS.FW.Bpm.Model.Bpmn.Bpmn.CreateExecutableProcess("process2").StartEvent().EndEvent().Done();

            // testing with a third deployment to ensure the change check is not only performed against
            // the last version of the deployment
            IProcessApplicationDeployment deployment3 = repositoryService.CreateDeployment(processApplication.Reference).ResumePreviousVersions()
                                                        .EnableDuplicateFiltering(true).AddModelInstance("process1.bpmn20.xml", model1)
                                                        .AddModelInstance("process2.bpmn20.xml", anotherChangedModel2).Name("deployment")
                                                        .Deploy() as IProcessApplicationDeployment;

            // there should still be one version of process 1
            Assert.AreEqual(1, repositoryService.CreateProcessDefinitionQuery(c => c.Key == "process1").Count());

            // there should be three versions of process 2
            Assert.AreEqual(3, repositoryService.CreateProcessDefinitionQuery(c => c.Key == "process2").Count());

            // old deployments are resumed
            registration  = deployment3.ProcessApplicationRegistration;
            deploymentIds = registration.DeploymentIds;
            Assert.AreEqual(3, deploymentIds.Count);

            deleteDeployments(deployment1, deployment2, deployment3);
        }
        [Test]   public virtual void testPartialChangesDeployAll()
        {
            IBpmnModelInstance model1 = ESS.FW.Bpm.Model.Bpmn.Bpmn.CreateExecutableProcess("process1").Done();
            IBpmnModelInstance model2 = ESS.FW.Bpm.Model.Bpmn.Bpmn.CreateExecutableProcess("process2").Done();

            // create initial deployment
            var deployment1 = repositoryService.CreateDeployment(processApplication.Reference).Name("deployment").AddModelInstance("process1.bpmn20.xml", model1).AddModelInstance("process2.bpmn20.xml", model2).Deploy();

            IBpmnModelInstance changedModel2 = ESS.FW.Bpm.Model.Bpmn.Bpmn.CreateExecutableProcess("process2").StartEvent().Done();

            // second deployment with partial changes:
            IProcessApplicationDeployment deployment2 = repositoryService.CreateDeployment(processApplication.Reference).ResumePreviousVersions().Name("deployment").EnableDuplicateFiltering(false)
                                                        .AddModelInstance("process1.bpmn20.xml", model1).AddModelInstance("process2.bpmn20.xml", changedModel2)
                                                        .Deploy() as IProcessApplicationDeployment;

            Assert.AreEqual(4, repositoryService.CreateProcessDefinitionQuery().Count());

            IList <IProcessDefinition> processDefinitionsModel1 = repositoryService.CreateProcessDefinitionQuery()
                                                                  //.ProcessDefinitionKey("process1")
                                                                  //.OrderByProcessDefinitionVersion()
                                                                  /*.Asc()*/
                                                                  .ToList();

            // now there are two versions of process1 deployed
            Assert.AreEqual(2, processDefinitionsModel1.Count);
            Assert.AreEqual(1, processDefinitionsModel1[0].Version);
            Assert.AreEqual(2, processDefinitionsModel1[1].Version);

            // now there are two versions of process2 deployed
            IList <IProcessDefinition> processDefinitionsModel2 = repositoryService.CreateProcessDefinitionQuery(c => c.Key == "process1").ToList(); //.OrderByProcessDefinitionVersion()/*.Asc()*/.ToList();

            Assert.AreEqual(2, processDefinitionsModel2.Count);
            Assert.AreEqual(1, processDefinitionsModel2[0].Version);
            Assert.AreEqual(2, processDefinitionsModel2[1].Version);

            // old deployment was resumed
            var            registration  = deployment2.ProcessApplicationRegistration;
            IList <string> deploymentIds = registration.DeploymentIds;

            Assert.AreEqual(2, deploymentIds.Count);
            Assert.AreEqual(ProcessEngine.Name, registration.ProcessEngineName);

            deleteDeployments(deployment1, deployment2);
        }
        [Test]   public virtual void testPartialChangesResumePreviousVersionByDeploymentName()
        {
            IBpmnModelInstance model1 = ESS.FW.Bpm.Model.Bpmn.Bpmn.CreateExecutableProcess("process1").Done();
            IBpmnModelInstance model2 = ESS.FW.Bpm.Model.Bpmn.Bpmn.CreateExecutableProcess("process2").Done();

            // create initial deployment
            var deployment1 = repositoryService.CreateDeployment(processApplication.Reference).Name("deployment").AddModelInstance("process1.bpmn20.xml", model1).Deploy();

            IProcessApplicationDeployment deployment2 = repositoryService.CreateDeployment(processApplication.Reference)
                                                        .ResumePreviousVersions().ResumePreviousVersionsBy(ResumePreviousBy.ResumeByDeploymentName)
                                                        .Name("deployment").EnableDuplicateFiltering(true).AddModelInstance("process1.bpmn20.xml", model1)
                                                        .AddModelInstance("process2.bpmn20.xml", model2).Deploy() as IProcessApplicationDeployment;

            var registration = deployment2.ProcessApplicationRegistration;

            Assert.AreEqual(2, registration.DeploymentIds.Count);

            deleteDeployments(deployment1, deployment2);
        }
        [Test]   public virtual void testProcessApplicationDeploymentNoChanges()
        {
            // create initial deployment
            IProcessApplicationDeployment deployment = repositoryService.CreateDeployment(processApplication.Reference).Name("deployment").AddClasspathResource("resources/api/repository/version1.bpmn20.xml").Deploy() as IProcessApplicationDeployment;

            AssertThatOneProcessIsDeployed();

            // deploy update with no changes:
            deployment = repositoryService.CreateDeployment(processApplication.Reference).Name("deployment").EnableDuplicateFiltering(false).AddClasspathResource("resources/api/repository/version1.bpmn20.xml").Deploy() as IProcessApplicationDeployment;

            // no changes
            AssertThatOneProcessIsDeployed();
            var            registration  = deployment.ProcessApplicationRegistration;
            IList <string> deploymentIds = registration.DeploymentIds;

            Assert.AreEqual(1, deploymentIds.Count);
            Assert.AreEqual(ProcessEngine.Name, registration.ProcessEngineName);

            deleteDeployments(deployment);
        }