diff --git a/wise-webapp/src/test/java/com/wisemapping/test/rest/RestLabelITCase.java b/wise-webapp/src/test/java/com/wisemapping/test/rest/RestLabelITCase.java index 90a2f222..fecd783a 100644 --- a/wise-webapp/src/test/java/com/wisemapping/test/rest/RestLabelITCase.java +++ b/wise-webapp/src/test/java/com/wisemapping/test/rest/RestLabelITCase.java @@ -4,7 +4,6 @@ package com.wisemapping.test.rest; import com.wisemapping.exceptions.WiseMappingException; import com.wisemapping.rest.model.RestLabel; import com.wisemapping.rest.model.RestLabelList; -import org.apache.http.HttpException; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.springframework.http.HttpEntity; @@ -14,6 +13,7 @@ import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.client.HttpClientErrorException; import org.springframework.web.client.RestTemplate; +import org.testng.Assert; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -51,13 +51,11 @@ public class RestLabelITCase { final String title2 = "Label 2 - " + mediaType.toString(); addNewLabel(requestHeaders, template, title2, COLOR); - // Check that the map has been created ... - final HttpEntity findMapEntity = new HttpEntity(requestHeaders); - final ResponseEntity response = template.exchange(BASE_REST_URL + "/labels/", HttpMethod.GET, findMapEntity, RestLabelList.class); + // Check that the label has been created ... + final RestLabelList restLabelList = getLabels(requestHeaders, template); // Validate that the two maps are there ... - final RestLabelList body = response.getBody(); - final List labels = body.getLabels(); + final List labels = restLabelList.getLabels(); boolean found1 = false; boolean found2 = false; @@ -73,13 +71,17 @@ public class RestLabelITCase { } + private RestLabelList getLabels(HttpHeaders requestHeaders, RestTemplate template) { + final HttpEntity findLabelEntity = new HttpEntity(requestHeaders); + final ResponseEntity response = template.exchange(BASE_REST_URL + "/labels", HttpMethod.GET, findLabelEntity, RestLabelList.class); + return response.getBody(); + } + @Test(dataProviderClass = RestHelper.class, dataProvider="ContentType-Provider-Function") - public void createLabelWithoutTitleOrColor(final @NotNull MediaType mediaType) throws IOException, WiseMappingException { + public void createLabelWithoutRequiredField(final @NotNull MediaType mediaType) throws IOException, WiseMappingException { final HttpHeaders requestHeaders = RestHelper.createHeaders(mediaType); final RestTemplate template = RestHelper.createTemplate( userEmail + ":" + "admin"); - // Create a new label - try { addNewLabel(requestHeaders, template, null, COLOR); fail("Wrong response"); @@ -95,10 +97,27 @@ public class RestLabelITCase { final String responseBodyAsString = e.getResponseBodyAsString(); assert (responseBodyAsString.contains("Required field cannot be left blank")); } - - } + @Test(dataProviderClass = RestHelper.class, dataProvider="ContentType-Provider-Function") + public void deleteLabel(final @NotNull MediaType mediaType) throws IOException, WiseMappingException { + final HttpHeaders requestHeaders = RestHelper.createHeaders(mediaType); + final RestTemplate template = RestHelper.createTemplate( userEmail + ":" + "admin"); + + final String title = "title to delete"; + final URI resourceUri = addNewLabel(requestHeaders, template, title, COLOR); + + // Now remove it ... + template.delete(RestHelper.HOST_PORT + resourceUri.toString()); + final RestLabelList restLabelList = getLabels(requestHeaders, template); + + for (RestLabel restLabel : restLabelList.getLabels()) { + if (title.equals(restLabel.getTitle())) { + Assert.fail("Label could not be removed:" + resourceUri); + } + } + + } static URI addNewLabel(@NotNull HttpHeaders requestHeaders, @NotNull RestTemplate template, @Nullable String title, @Nullable String color ) throws IOException, WiseMappingException { final RestLabel restLabel = new RestLabel();