diff --git a/wise-webapp/src/main/java/com/wisemapping/rest/MindmapController.java b/wise-webapp/src/main/java/com/wisemapping/rest/MindmapController.java index 6302f064..02f066d3 100644 --- a/wise-webapp/src/main/java/com/wisemapping/rest/MindmapController.java +++ b/wise-webapp/src/main/java/com/wisemapping/rest/MindmapController.java @@ -636,7 +636,7 @@ public class MindmapController extends BaseController { mindmapService.removeLabel(mindmap, delegated); } - @RequestMapping(method = RequestMethod.POST, value = "/labels/maps", consumes = {"application/json"}) + @RequestMapping(method = RequestMethod.POST, value = "/labels/maps", consumes = { "application/xml","application/json"}) @ResponseStatus(value = HttpStatus.OK) public void addLabel(@RequestBody RestLabel restLabel, @RequestParam(required = true) String ids) throws WiseMappingException { int labelId = restLabel.getId(); diff --git a/wise-webapp/src/test/java/com/wisemapping/test/rest/RestHelper.java b/wise-webapp/src/test/java/com/wisemapping/test/rest/RestHelper.java index a9ed4ee4..dda90f1d 100644 --- a/wise-webapp/src/test/java/com/wisemapping/test/rest/RestHelper.java +++ b/wise-webapp/src/test/java/com/wisemapping/test/rest/RestHelper.java @@ -18,6 +18,7 @@ public class RestHelper { public static final String HOST_PORT = "http://localhost:8080"; public static final String BASE_REST_URL = HOST_PORT + "/service"; public static final String ADMIN_CREDENTIALS = "admin@wisemapping.org" + ":" + "admin"; + public static final String COLOR = "#000000"; static HttpHeaders createHeaders(@NotNull MediaType mediaType) { List acceptableMediaTypes = new ArrayList(); 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 fecd783a..00d7ffcc 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 @@ -54,7 +54,7 @@ public class RestLabelITCase { // Check that the label has been created ... final RestLabelList restLabelList = getLabels(requestHeaders, template); - // Validate that the two maps are there ... + // Validate that the two labels are there ... final List labels = restLabelList.getLabels(); boolean found1 = false; @@ -71,7 +71,7 @@ public class RestLabelITCase { } - private RestLabelList getLabels(HttpHeaders requestHeaders, RestTemplate template) { + static 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(); diff --git a/wise-webapp/src/test/java/com/wisemapping/test/rest/RestMindmapITCase.java b/wise-webapp/src/test/java/com/wisemapping/test/rest/RestMindmapITCase.java index 83c962db..b083feb2 100644 --- a/wise-webapp/src/test/java/com/wisemapping/test/rest/RestMindmapITCase.java +++ b/wise-webapp/src/test/java/com/wisemapping/test/rest/RestMindmapITCase.java @@ -2,6 +2,10 @@ package com.wisemapping.test.rest; import com.wisemapping.exceptions.WiseMappingException; +import com.wisemapping.model.Label; +import com.wisemapping.model.User; +import com.wisemapping.rest.model.RestLabel; +import com.wisemapping.rest.model.RestLabelList; import com.wisemapping.rest.model.RestMindmap; import com.wisemapping.rest.model.RestMindmapInfo; import com.wisemapping.rest.model.RestMindmapList; @@ -24,6 +28,7 @@ import java.net.URI; import java.util.List; import static com.wisemapping.test.rest.RestHelper.BASE_REST_URL; +import static com.wisemapping.test.rest.RestHelper.COLOR; import static com.wisemapping.test.rest.RestHelper.HOST_PORT; import static com.wisemapping.test.rest.RestHelper.createHeaders; import static com.wisemapping.test.rest.RestHelper.createTemplate; @@ -239,6 +244,35 @@ public class RestMindmapITCase { assertEquals(response.getBody().getProperties(), mapToUpdate.getProperties()); } + @Test(dataProviderClass = RestHelper.class, dataProvider="ContentType-Provider-Function") + public void addLabelToMindmap(final @NotNull MediaType mediaType) throws IOException, WiseMappingException { // Configure media types ... + final HttpHeaders requestHeaders = createHeaders(mediaType); + final RestTemplate template = createTemplate(userEmail); + + // Create a new label + final String titleLabel = "Label 1 - " + mediaType.toString(); + final URI labelUri = RestLabelITCase.addNewLabel(requestHeaders, template, titleLabel, COLOR); + + // Create a sample map ... + final String mapTitle = "Maps 1 - " + mediaType.toString(); + final URI mindmapUri = addNewMap(requestHeaders, template, mapTitle); + final String mapId = mindmapUri.getPath().replace("/service/maps/", ""); + + final RestLabel restLabel = new RestLabel(); + restLabel.setColor(COLOR); + String labelId = labelUri.getPath().replace("/service/labels/", ""); + restLabel.setId(Integer.parseInt(labelId)); + restLabel.setTitle(titleLabel); + + HttpEntity labelEntity = new HttpEntity<>(restLabel, requestHeaders); + template.postForLocation(BASE_REST_URL + "/labels/maps?ids=" + mapId, labelEntity); + + // Load map again .. + final RestMindmap withLabel = findMap(requestHeaders, template, mindmapUri); + +// assertTrue(withLabel.getDelegated().getLabels().size() == 1); + } + private RestMindmap findMap(HttpHeaders requestHeaders, RestTemplate template, URI resourceUri) { final HttpEntity findMapEntity = new HttpEntity(requestHeaders); final ResponseEntity response = template.exchange(HOST_PORT + resourceUri.toString(), HttpMethod.GET, findMapEntity, RestMindmap.class);