// this test verifies that a process application is able to register a deployment from the @PostDeploy callback:
AbstractApplicationContext applicationContext = new ClassPathXmlApplicationContext("org/camunda/bpm/engine/spring/test/application/PostDeployRegistrationPaTest-context.xml");
applicationContext.start();
ProcessEngine processEngine = BpmPlatform.getDefaultProcessEngine();
// create a manual deployment:
Deployment deployment = processEngine.getRepositoryService()
.createDeployment()
.addClasspathResource("org/camunda/bpm/engine/spring/test/application/process.bpmn20.xml")
.deploy();
// lookup the process application spring bean:
PostDeployRegistrationPa processApplication = applicationContext.getBean("customProcessApplicaiton", PostDeployRegistrationPa.class);
Assert.assertFalse(processApplication.isPostDeployInvoked());
processApplication.deploy();
Assert.assertTrue(processApplication.isPostDeployInvoked());
// the process application was not invoked
Assert.assertFalse(processApplication.isInvoked());
// start process instance:
processEngine.getRuntimeService()
.startProcessInstanceByKey("startToEnd");
// now the process application was invoked:
Assert.assertTrue(processApplication.isInvoked());
// undeploy PA
Assert.assertFalse(processApplication.isPreUndeployInvoked());
processApplication.undeploy();
Assert.assertTrue(processApplication.isPreUndeployInvoked());
// manually undeploy the process
processEngine.getRepositoryService()
.deleteDeployment(deployment.getId(), true);
applicationContext.close();
}