public DeploymentWithDefinitions deploy(DeploymentBuilder deploymentBuilder) { DeploymentWithDefinitions deployment = deploymentBuilder.deployWithResult(); processEngineRule.manageDeployment(deployment); return deployment; }
public DeploymentWithDefinitionsDto createDeployment(UriInfo uriInfo, MultipartFormData payload) { DeploymentBuilder deploymentBuilder = extractDeploymentInformation(payload); if(!deploymentBuilder.getResourceNames().isEmpty()) { DeploymentWithDefinitions deployment = deploymentBuilder.deployWithResult(); DeploymentWithDefinitionsDto deploymentDto = DeploymentWithDefinitionsDto.fromDeployment(deployment); URI uri = uriInfo.getBaseUriBuilder() .path(relativeRootResourcePath) .path(DeploymentRestService.PATH) .path(deployment.getId()) .build(); // GET deploymentDto.addReflexiveLink(uri, HttpMethod.GET, "self"); return deploymentDto; } else { throw new InvalidRequestException(Status.BAD_REQUEST, "No deployment resources contained in the form upload."); } }
public DeploymentWithDefinitionsDto createDeployment(UriInfo uriInfo, MultipartFormData payload) { DeploymentBuilder deploymentBuilder = extractDeploymentInformation(payload); if(!deploymentBuilder.getResourceNames().isEmpty()) { DeploymentWithDefinitions deployment = deploymentBuilder.deployWithResult(); DeploymentWithDefinitionsDto deploymentDto = DeploymentWithDefinitionsDto.fromDeployment(deployment); URI uri = uriInfo.getBaseUriBuilder() .path(relativeRootResourcePath) .path(DeploymentRestService.PATH) .path(deployment.getId()) .build(); // GET deploymentDto.addReflexiveLink(uri, HttpMethod.GET, "self"); return deploymentDto; } else { throw new InvalidRequestException(Status.BAD_REQUEST, "No deployment resources contained in the form upload."); } }
@Test public void testRedeployDeploymentWithoutRequestBody() { Response response = given() .pathParam("id", MockProvider.EXAMPLE_DEPLOYMENT_ID) .contentType(POST_JSON_CONTENT_TYPE) .expect() .statusCode(Status.OK.getStatusCode()) .contentType(ContentType.JSON) .when() .post(REDEPLOY_DEPLOYMENT_URL); verify(mockDeploymentBuilder).addDeploymentResources(eq(MockProvider.EXAMPLE_DEPLOYMENT_ID)); verify(mockDeploymentBuilder).nameFromDeployment(eq(MockProvider.EXAMPLE_DEPLOYMENT_ID)); verify(mockDeploymentBuilder, never()).addDeploymentResourceById(anyString(), anyString()); verify(mockDeploymentBuilder, never()).addDeploymentResourcesById(anyString(), anyListOf(String.class)); verify(mockDeploymentBuilder, never()).addDeploymentResourceByName(anyString(), anyString()); verify(mockDeploymentBuilder, never()).addDeploymentResourcesByName(anyString(), anyListOf(String.class)); verify(mockDeploymentBuilder, never()).source(anyString()); verify(mockDeploymentBuilder).deployWithResult(); verifyDeployment(mockDeployment, response); }
@Test public void testRedeployDeploymentEmptyRequestBody() { Response response = given() .pathParam("id", MockProvider.EXAMPLE_DEPLOYMENT_ID) .contentType(POST_JSON_CONTENT_TYPE) .body("{}") .expect() .statusCode(Status.OK.getStatusCode()) .contentType(ContentType.JSON) .when() .post(REDEPLOY_DEPLOYMENT_URL); verify(mockDeploymentBuilder).addDeploymentResources(eq(MockProvider.EXAMPLE_DEPLOYMENT_ID)); verify(mockDeploymentBuilder).nameFromDeployment(eq(MockProvider.EXAMPLE_DEPLOYMENT_ID)); verify(mockDeploymentBuilder, never()).addDeploymentResourceById(anyString(), anyString()); verify(mockDeploymentBuilder, never()).addDeploymentResourcesById(eq(MockProvider.EXAMPLE_DEPLOYMENT_ID), anyListOf(String.class)); verify(mockDeploymentBuilder, never()).addDeploymentResourceByName(anyString(), anyString()); verify(mockDeploymentBuilder, never()).addDeploymentResourcesByName(eq(MockProvider.EXAMPLE_DEPLOYMENT_ID), anyListOf(String.class)); verify(mockDeploymentBuilder).source(null); verify(mockDeploymentBuilder).deployWithResult(); verifyDeployment(mockDeployment, response); }
@Test public void testRedeployDeploymentWithoutTenantId() { when(mockDeployment.getTenantId()).thenReturn(null); Response response = given() .pathParam("id", MockProvider.EXAMPLE_DEPLOYMENT_ID) .contentType(POST_JSON_CONTENT_TYPE) .expect() .statusCode(Status.OK.getStatusCode()) .contentType(ContentType.JSON) .when() .post(REDEPLOY_DEPLOYMENT_URL); verify(mockDeploymentBuilder).addDeploymentResources(eq(MockProvider.EXAMPLE_DEPLOYMENT_ID)); verify(mockDeploymentBuilder, never()).tenantId(any(String.class)); verify(mockDeploymentBuilder).deployWithResult(); verifyDeployment(mockDeployment, response); }
@Test public void testRedeployThrowsProcessEngineException() { String message = "something went wrong"; doThrow(new ProcessEngineException(message)).when(mockDeploymentBuilder).deployWithResult(); given() .pathParam("id", MockProvider.EXAMPLE_DEPLOYMENT_ID) .contentType(POST_JSON_CONTENT_TYPE) .expect() .statusCode(Status.INTERNAL_SERVER_ERROR.getStatusCode()) .body("type", is(ProcessEngineException.class.getSimpleName())) .body("message", is(message)) .when() .post(REDEPLOY_DEPLOYMENT_URL); }
@Test public void testRedeployThrowsAuthorizationException() { String message = "missing authorization"; doThrow(new AuthorizationException(message)).when(mockDeploymentBuilder).deployWithResult(); given() .pathParam("id", MockProvider.EXAMPLE_DEPLOYMENT_ID) .contentType(POST_JSON_CONTENT_TYPE) .expect() .statusCode(Status.FORBIDDEN.getStatusCode()) .body("type", is(AuthorizationException.class.getSimpleName())) .body("message", is(message)) .when() .post(REDEPLOY_DEPLOYMENT_URL); }
@Test public void testRedeployThrowsNotValidException() { String message = "not valid"; doThrow(new NotValidException(message)).when(mockDeploymentBuilder).deployWithResult(); String expected = "Cannot redeploy deployment '" + MockProvider.EXAMPLE_DEPLOYMENT_ID + "': " + message; given() .pathParam("id", MockProvider.EXAMPLE_DEPLOYMENT_ID) .contentType(POST_JSON_CONTENT_TYPE) .expect() .statusCode(Status.BAD_REQUEST.getStatusCode()) .body("type", is(InvalidRequestException.class.getSimpleName())) .body("message", is(expected)) .when() .post(REDEPLOY_DEPLOYMENT_URL); }
@Test public void testRedeployDeploymentWithTenantId() { when(mockDeployment.getTenantId()).thenReturn(MockProvider.EXAMPLE_TENANT_ID); Response response = given() .pathParam("id", MockProvider.EXAMPLE_DEPLOYMENT_ID) .contentType(POST_JSON_CONTENT_TYPE) .expect() .statusCode(Status.OK.getStatusCode()) .contentType(ContentType.JSON) .when() .post(REDEPLOY_DEPLOYMENT_URL); verify(mockDeploymentBuilder).addDeploymentResources(eq(MockProvider.EXAMPLE_DEPLOYMENT_ID)); verify(mockDeploymentBuilder).tenantId(eq(MockProvider.EXAMPLE_TENANT_ID)); verify(mockDeploymentBuilder).deployWithResult(); verifyDeployment(mockDeployment, response); }
@Test public void testRedeployThrowsNotFoundException() { String message = "deployment not found"; doThrow(new NotFoundException(message)).when(mockDeploymentBuilder).deployWithResult(); String expected = "Cannot redeploy deployment '" + MockProvider.EXAMPLE_DEPLOYMENT_ID + "': " + message; given() .pathParam("id", MockProvider.EXAMPLE_DEPLOYMENT_ID) .contentType(POST_JSON_CONTENT_TYPE) .expect() .statusCode(Status.NOT_FOUND.getStatusCode()) .body("type", is(InvalidRequestException.class.getSimpleName())) .body("message", is(expected)) .when() .post(REDEPLOY_DEPLOYMENT_URL); }
protected DeploymentWithDefinitions tryToRedeploy(RedeploymentDto redeployment) { RepositoryService repositoryService = getProcessEngine().getRepositoryService(); DeploymentBuilder builder = repositoryService.createDeployment(); builder.nameFromDeployment(deploymentId); String tenantId = getDeployment().getTenantId(); if (tenantId != null) { builder.tenantId(tenantId); } if (redeployment != null) { builder = addRedeploymentResources(builder, redeployment); } else { builder.addDeploymentResources(deploymentId); } return builder.deployWithResult(); }
protected DeploymentWithDefinitions tryToRedeploy(RedeploymentDto redeployment) { RepositoryService repositoryService = getProcessEngine().getRepositoryService(); DeploymentBuilder builder = repositoryService.createDeployment(); builder.nameFromDeployment(deploymentId); String tenantId = getDeployment().getTenantId(); if (tenantId != null) { builder.tenantId(tenantId); } if (redeployment != null) { builder = addRedeploymentResources(builder, redeployment); } else { builder.addDeploymentResources(deploymentId); } return builder.deployWithResult(); }
@Test public void testCreateDeploymentThrowsAuthorizationException() { String message = "expected exception"; when(mockDeploymentBuilder.deployWithResult()).thenThrow(new AuthorizationException(message)); resourceNames.addAll( Arrays.asList("data", "more-data") ); given() .multiPart("data", "unspecified", createMockDeploymentResourceByteData()) .multiPart("more-data", "unspecified", createMockDeploymentResourceBpmnData()) .multiPart("deployment-name", MockProvider.EXAMPLE_DEPLOYMENT_ID) .multiPart("enable-duplicate-filtering", "true") .then().expect() .statusCode(Status.FORBIDDEN.getStatusCode()) .body("type", is(AuthorizationException.class.getSimpleName())) .body("message", is(message)) .when() .post(CREATE_DEPLOYMENT_URL); }
@Test public void testCreateCompleteDrdDeployment() throws Exception { // given DeploymentWithDefinitions mockDeployment = MockProvider.createMockDeploymentWithDefinitions(); when(mockDeployment.getDeployedCaseDefinitions()).thenReturn(null); when(mockDeployment.getDeployedProcessDefinitions()).thenReturn(null); when(mockDeploymentBuilder.deployWithResult()).thenReturn(mockDeployment); // when resourceNames.addAll(Arrays.asList("data", "more-data")); Response response = given() .multiPart("data", "unspecified", createMockDeploymentResourceByteData()) .multiPart("more-data", "unspecified", createMockDeploymentResourceBpmnData()) .multiPart("deployment-name", MockProvider.EXAMPLE_DEPLOYMENT_ID) .multiPart("enable-duplicate-filtering", "true") .expect() .statusCode(Status.OK.getStatusCode()) .when() .post(CREATE_DEPLOYMENT_URL); // then verifyCreatedDrdDeployment(mockDeployment, response); verify(mockDeploymentBuilder).name(MockProvider.EXAMPLE_DEPLOYMENT_ID); verify(mockDeploymentBuilder).enableDuplicateFiltering(false); }
public void testDeployAndGetCaseDefinition() throws Exception { // given case model final CmmnModelInstance modelInstance = createCmmnModelInstance(); // when case model is deployed DeploymentWithDefinitions deployment = repositoryService.createDeployment() .addModelInstance("foo.cmmn", modelInstance).deployWithResult(); deploymentIds.add(deployment.getId()); // then deployment contains deployed case definition List<CaseDefinition> deployedCaseDefinitions = deployment.getDeployedCaseDefinitions(); assertEquals(1, deployedCaseDefinitions.size()); assertNull(deployment.getDeployedProcessDefinitions()); assertNull(deployment.getDeployedDecisionDefinitions()); assertNull(deployment.getDeployedDecisionRequirementsDefinitions()); // and persisted case definition is equal to deployed case definition CaseDefinition persistedCaseDefinition = repositoryService.createCaseDefinitionQuery().caseDefinitionResourceName("foo.cmmn").singleResult(); assertEquals(persistedCaseDefinition.getId(), deployedCaseDefinitions.get(0).getId()); }
public void testDeployEmptyCaseDefinition() throws Exception { // given empty case model final CmmnModelInstance modelInstance = Cmmn.createEmptyModel(); org.camunda.bpm.model.cmmn.instance.Definitions definitions = modelInstance.newInstance(org.camunda.bpm.model.cmmn.instance.Definitions.class); definitions.setTargetNamespace("http://camunda.org/examples"); modelInstance.setDefinitions(definitions); // when case model is deployed DeploymentWithDefinitions deployment = repositoryService.createDeployment() .addModelInstance("foo.cmmn", modelInstance).deployWithResult(); deploymentIds.add(deployment.getId()); // then no case definition is deployed assertNull(deployment.getDeployedCaseDefinitions()); // and there exist not persisted case definition assertNull(repositoryService.createCaseDefinitionQuery().caseDefinitionResourceName("foo.cmmn").singleResult()); }
public void testDeployNonExecutableProcess() throws Exception { // given non executable process definition final BpmnModelInstance modelInstance = Bpmn.createProcess("foo").startEvent().userTask().endEvent().done(); // when process model is deployed DeploymentWithDefinitions deployment = repositoryService.createDeployment() .addModelInstance("foo.bpmn", modelInstance).deployWithResult(); deploymentIds.add(deployment.getId()); // then deployment contains no deployed process definition assertNull(deployment.getDeployedProcessDefinitions()); // and there exist no persisted process definitions assertNull(repositoryService.createProcessDefinitionQuery() .processDefinitionResourceName("foo.bpmn") .singleResult()); }
public void testDeployAndGetProcessDefinition() throws Exception { // given process model final BpmnModelInstance modelInstance = Bpmn.createExecutableProcess("foo").startEvent().userTask().endEvent().done(); // when process model is deployed DeploymentWithDefinitions deployment = repositoryService.createDeployment() .addModelInstance("foo.bpmn", modelInstance).deployWithResult(); deploymentIds.add(deployment.getId()); // then deployment contains deployed process definitions List<ProcessDefinition> deployedProcessDefinitions = deployment.getDeployedProcessDefinitions(); assertEquals(1, deployedProcessDefinitions.size()); assertNull(deployment.getDeployedCaseDefinitions()); assertNull(deployment.getDeployedDecisionDefinitions()); assertNull(deployment.getDeployedDecisionRequirementsDefinitions()); // and persisted process definition is equal to deployed process definition ProcessDefinition persistedProcDef = repositoryService.createProcessDefinitionQuery() .processDefinitionResourceName("foo.bpmn") .singleResult(); assertEquals(persistedProcDef.getId(), deployedProcessDefinitions.get(0).getId()); }
@Test public void shouldDeleteDeployment() { BpmnModelInstance instance = Bpmn.createExecutableProcess("process").startEvent().endEvent().done(); DeploymentWithDefinitions deployment = engineRule.getRepositoryService() .createDeployment() .addModelInstance("foo.bpmn", instance) .deployWithResult(); engineRule.getRepositoryService().deleteDeployment(deployment.getId(), true); long count = engineRule.getRepositoryService().createDeploymentQuery().count(); assertEquals(0, count); }