Skip to content

Commit

Permalink
delete deployment via REST
Browse files Browse the repository at this point in the history
  • Loading branch information
ingorichtsmeier authored and Stefan Hentschel committed Oct 2, 2014
1 parent 5a90785 commit bd2de51
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,26 @@
package org.camunda.bpm.engine.rest.sub.repository;

import org.camunda.bpm.engine.rest.dto.repository.DeploymentDto;
import org.camunda.bpm.engine.rest.dto.repository.DeploymentResourceDto;

import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import java.io.InputStream;
import java.util.List;
import javax.ws.rs.core.UriInfo;

public interface DeploymentResource {

public static final String CASCADE = "cascade";

@GET
@Produces(MediaType.APPLICATION_JSON)
DeploymentDto getDeployment();

@Path("/resources")
DeploymentResourcesResource getDeploymentResources();

@DELETE
void deleteDeployment(@PathParam("id") String deploymentId, @Context UriInfo uriInfo);
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
package org.camunda.bpm.engine.rest.sub.repository.impl;

import javax.ws.rs.core.Response.Status;
import javax.ws.rs.core.UriInfo;

import org.camunda.bpm.engine.ProcessEngine;
import org.camunda.bpm.engine.RepositoryService;
Expand Down Expand Up @@ -46,4 +47,21 @@ public DeploymentDto getDeployment() {
public DeploymentResourcesResource getDeploymentResources() {
return new DeploymentResourcesResourceImpl(engine, deploymentId);
}

@Override
public void deleteDeployment(String deploymentId, UriInfo uriInfo) {
RepositoryService repositoryService = engine.getRepositoryService();
Deployment deployment = repositoryService.createDeploymentQuery().deploymentId(deploymentId).singleResult();

if (deployment == null) {
throw new InvalidRequestException(Status.NOT_FOUND, "Deployment with id '" + deploymentId + "' do not exist");
}
boolean cascade = false;
if (uriInfo.getQueryParameters().containsKey(CASCADE)
&& (uriInfo.getQueryParameters().get(CASCADE).size() > 0)
&& "true".equals(uriInfo.getQueryParameters().get(CASCADE).get(0))) {
cascade = true;
}
repositoryService.deleteDeployment(deploymentId, cascade);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import com.jayway.restassured.path.json.JsonPath;
import com.jayway.restassured.response.Response;

import org.camunda.bpm.engine.RepositoryService;
import org.camunda.bpm.engine.impl.calendar.DateTimeUtil;
import org.camunda.bpm.engine.impl.util.ReflectUtil;
Expand All @@ -27,6 +28,7 @@

import javax.ws.rs.HttpMethod;
import javax.ws.rs.core.Response.Status;

import java.io.InputStream;
import java.util.*;

Expand All @@ -47,6 +49,7 @@ public abstract class AbstractDeploymentRestServiceInteractionTest extends Abstr
protected static final String SINGLE_RESOURCE_DATA_URL = SINGLE_RESOURCE_URL + "/data";
protected static final String CREATE_DEPLOYMENT_URL = TEST_RESOURCE_ROOT_PATH + "/deployment/create";

protected RepositoryService mockRepositoryService;
protected Deployment mockDeployment;
protected List<Resource> mockDeploymentResources;
protected Resource mockDeploymentResource;
Expand All @@ -56,24 +59,24 @@ public abstract class AbstractDeploymentRestServiceInteractionTest extends Abstr

@Before
public void setUpRuntimeData() {
RepositoryService repositoryServiceMock = mock(RepositoryService.class);
when(processEngine.getRepositoryService()).thenReturn(repositoryServiceMock);
mockRepositoryService = mock(RepositoryService.class);
when(processEngine.getRepositoryService()).thenReturn(mockRepositoryService);

mockDeployment = MockProvider.createMockDeployment();
mockDeploymentQuery = mock(DeploymentQuery.class);
when(mockDeploymentQuery.deploymentId(EXAMPLE_DEPLOYMENT_ID)).thenReturn(mockDeploymentQuery);
when(mockDeploymentQuery.singleResult()).thenReturn(mockDeployment);
when(repositoryServiceMock.createDeploymentQuery()).thenReturn(mockDeploymentQuery);
when(mockRepositoryService.createDeploymentQuery()).thenReturn(mockDeploymentQuery);

mockDeploymentResources = MockProvider.createMockDeploymentResources();
when(repositoryServiceMock.getDeploymentResources(eq(EXAMPLE_DEPLOYMENT_ID))).thenReturn(mockDeploymentResources);
when(mockRepositoryService.getDeploymentResources(eq(EXAMPLE_DEPLOYMENT_ID))).thenReturn(mockDeploymentResources);

mockDeploymentResource = MockProvider.createMockDeploymentResource();

when(repositoryServiceMock.getResourceAsStreamById(eq(EXAMPLE_DEPLOYMENT_ID), eq(EXAMPLE_DEPLOYMENT_RESOURCE_ID))).thenReturn(createMockDeploymentResourceBpmnData());
when(mockRepositoryService.getResourceAsStreamById(eq(EXAMPLE_DEPLOYMENT_ID), eq(EXAMPLE_DEPLOYMENT_RESOURCE_ID))).thenReturn(createMockDeploymentResourceBpmnData());

mockDeploymentBuilder = mock(DeploymentBuilder.class);
when(repositoryServiceMock.createDeployment()).thenReturn(mockDeploymentBuilder);
when(mockRepositoryService.createDeployment()).thenReturn(mockDeploymentBuilder);
when(mockDeploymentBuilder.addInputStream(anyString(), any(InputStream.class))).thenReturn(mockDeploymentBuilder);
when(mockDeploymentBuilder.getResourceNames()).thenReturn(resourceNames);
when(mockDeploymentBuilder.deploy()).thenReturn(mockDeployment);
Expand Down Expand Up @@ -321,6 +324,76 @@ public void testCreateDeploymentWithoutBytes() throws Exception {
.post(CREATE_DEPLOYMENT_URL);

}

@Test
public void testDeleteDeployment() {

given()
.pathParam("id", MockProvider.EXAMPLE_DEPLOYMENT_ID)
.expect()
.statusCode(Status.NO_CONTENT.getStatusCode())
.when()
.delete(DEPLOYMENT_URL);

verify(mockRepositoryService).deleteDeployment(MockProvider.EXAMPLE_DEPLOYMENT_ID, false);
}

@Test
public void testDeleteDeploymentCascade() {

given()
.pathParam("id", MockProvider.EXAMPLE_DEPLOYMENT_ID)
.queryParam("cascade", true)
.expect()
.statusCode(Status.NO_CONTENT.getStatusCode())
.when()
.delete(DEPLOYMENT_URL);

verify(mockRepositoryService).deleteDeployment(MockProvider.EXAMPLE_DEPLOYMENT_ID, true);
}

@Test
public void testDeleteDeploymentCascadeNonsense() {

given()
.pathParam("id", MockProvider.EXAMPLE_DEPLOYMENT_ID)
.queryParam("cascade", "bla")
.expect()
.statusCode(Status.NO_CONTENT.getStatusCode())
.when()
.delete(DEPLOYMENT_URL);

verify(mockRepositoryService).deleteDeployment(MockProvider.EXAMPLE_DEPLOYMENT_ID, false);
}

@Test
public void testDeleteDeploymentCascadeFalse() {

given()
.pathParam("id", MockProvider.EXAMPLE_DEPLOYMENT_ID)
.queryParam("cascade", false)
.expect()
.statusCode(Status.NO_CONTENT.getStatusCode())
.when()
.delete(DEPLOYMENT_URL);

verify(mockRepositoryService).deleteDeployment(MockProvider.EXAMPLE_DEPLOYMENT_ID, false);
}

@Test
public void testDeleteNonExistingDeployment() {

when(mockDeploymentQuery.deploymentId(NON_EXISTING_DEPLOYMENT_ID)).thenReturn(mockDeploymentQuery);
when(mockDeploymentQuery.singleResult()).thenReturn(null);

given()
.pathParam("id", NON_EXISTING_DEPLOYMENT_ID)
.expect()
.statusCode(Status.NOT_FOUND.getStatusCode())
.body(containsString("Deployment with id '" + NON_EXISTING_DEPLOYMENT_ID + "' do not exist"))
.when()
.delete(DEPLOYMENT_URL);
}

private void verifyDeployment(Deployment mockDeployment, Response response) {
String content = response.asString();
Expand Down

0 comments on commit bd2de51

Please sign in to comment.