Add delete map rest operation.
This commit is contained in:
@@ -2,8 +2,8 @@ package com.wisemapping.test.model;
|
||||
|
||||
|
||||
import com.wisemapping.rest.model.RestMindmap;
|
||||
import com.wisemapping.rest.model.RestMindmapInfo;
|
||||
import com.wisemapping.rest.model.RestUser;
|
||||
import org.codehaus.jackson.map.DeserializationConfig;
|
||||
import org.codehaus.jackson.map.ObjectMapper;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
@@ -20,8 +20,5 @@ public class JsonTest {
|
||||
|
||||
String userJson = "{\"username\":\"admin\",\"email\":\"admin@wisemapping.org\",\"tags\":[],\"creationDate\":1329706800000,\"firstname\":\"Wise\",\"lastname\":\"test\",\"password\":\"test\"}";
|
||||
final RestUser restUser = mapper.readValue(userJson, RestUser.class);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -1,17 +1,16 @@
|
||||
package com.wisemapping.test.rest;
|
||||
|
||||
|
||||
import com.wisemapping.rest.model.RestMindmapInfo;
|
||||
import com.wisemapping.rest.model.RestMindmap;
|
||||
import com.wisemapping.rest.model.RestMindmapList;
|
||||
import com.wisemapping.rest.model.RestUser;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.http.*;
|
||||
import org.springframework.http.client.SimpleClientHttpRequestFactory;
|
||||
import org.springframework.security.crypto.codec.Base64;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.BeforeSuite;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
@@ -25,12 +24,11 @@ import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
import static org.testng.Assert.fail;
|
||||
|
||||
|
||||
@Test
|
||||
public class RestMindmapTCase {
|
||||
|
||||
private String userEmail = "admin@wisemapping.com";
|
||||
private static final String HOST_PORT = "http://127.0.0.1:8080";
|
||||
private static final String HOST_PORT = "http://localhost:8080";
|
||||
private static final String BASE_REST_URL = HOST_PORT + "/service";
|
||||
|
||||
@BeforeClass
|
||||
@@ -58,11 +56,11 @@ public class RestMindmapTCase {
|
||||
|
||||
// Validate that the two maps are there ...
|
||||
final RestMindmapList body = response.getBody();
|
||||
final List<RestMindmap> mindmaps = body.getMindmaps();
|
||||
final List<RestMindmapInfo> mindmaps = body.getMindmapsInfo();
|
||||
|
||||
boolean found1 = false;
|
||||
boolean found2 = false;
|
||||
for (RestMindmap mindmap : mindmaps) {
|
||||
for (RestMindmapInfo mindmap : mindmaps) {
|
||||
if (mindmap.getTitle().equals(title1)) {
|
||||
found1 = true;
|
||||
}
|
||||
@@ -74,31 +72,50 @@ public class RestMindmapTCase {
|
||||
|
||||
}
|
||||
|
||||
private URI addNewMap(HttpHeaders requestHeaders, RestTemplate templateRest, String title) {
|
||||
final RestMindmap restMindmap = new RestMindmap();
|
||||
restMindmap.setTitle(title);
|
||||
restMindmap.setDescription("My Map Desc");
|
||||
// Create a new map ...
|
||||
HttpEntity<RestMindmap> createUserEntity = new HttpEntity<RestMindmap>(restMindmap, requestHeaders);
|
||||
return templateRest.postForLocation(BASE_REST_URL + "/maps", createUserEntity);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test(dataProvider = "ContentType-Provider-Function")
|
||||
public void createMap(final @NotNull MediaType mediaType) { // Configure media types ...
|
||||
public void deleteMap(final @NotNull MediaType mediaType) { // Configure media types ...
|
||||
final HttpHeaders requestHeaders = createHeaders(mediaType);
|
||||
final RestTemplate templateRest = createTemplate();
|
||||
|
||||
// Create a sample map ...
|
||||
final String title = "My Map " + mediaType.toString();
|
||||
final String title1 = "Map to delete - " + mediaType.toString();
|
||||
final URI resourceLocation = addNewMap(requestHeaders, templateRest, title1);
|
||||
|
||||
// Now remove it ...
|
||||
templateRest.delete(HOST_PORT + resourceLocation.toString());
|
||||
|
||||
// Check that has been removed ...
|
||||
try {
|
||||
findMap(requestHeaders, templateRest, resourceLocation);
|
||||
fail("Map could not be removed:" + resourceLocation);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
private URI addNewMap(HttpHeaders requestHeaders, RestTemplate templateRest, String title) {
|
||||
final RestMindmapInfo restMindmap = new RestMindmapInfo();
|
||||
restMindmap.setTitle(title);
|
||||
restMindmap.setDescription("My Map Desc");
|
||||
|
||||
// Create a new map ...
|
||||
HttpEntity<RestMindmapInfo> createUserEntity = new HttpEntity<RestMindmapInfo>(restMindmap, requestHeaders);
|
||||
return templateRest.postForLocation(BASE_REST_URL + "/maps", createUserEntity);
|
||||
}
|
||||
|
||||
@Test(dataProvider = "ContentType-Provider-Function")
|
||||
public void discardChange(final @NotNull MediaType mediaType) { // Configure media types ...
|
||||
final HttpHeaders requestHeaders = createHeaders(mediaType);
|
||||
final RestTemplate templateRest = createTemplate();
|
||||
|
||||
// Create a sample map ...
|
||||
final String title = "Add map to discard " + mediaType.toString();
|
||||
final URI resourceLocation = addNewMap(requestHeaders, templateRest, title);
|
||||
|
||||
// Check that the map has been created ...
|
||||
final HttpEntity findMapEntity = new HttpEntity(requestHeaders);
|
||||
final ResponseEntity<RestMindmap> response = templateRest.exchange(HOST_PORT + resourceLocation.toString(), HttpMethod.GET, findMapEntity, RestMindmap.class);
|
||||
assertEquals(response.getBody().getTitle(), title);
|
||||
// Update with "minor" flag ...
|
||||
|
||||
// Revert the change ...
|
||||
|
||||
// Check that the map is the
|
||||
}
|
||||
|
||||
@Test(dataProvider = "ContentType-Provider-Function")
|
||||
@@ -118,11 +135,15 @@ public class RestMindmapTCase {
|
||||
templateRest.put(resourceUrl + "/xml", updateEntity);
|
||||
|
||||
// Check that the map has been updated ...
|
||||
final HttpEntity findMapEntity = new HttpEntity(requestHeaders);
|
||||
final ResponseEntity<RestMindmap> response = templateRest.exchange(HOST_PORT + resourceLocation.toString(), HttpMethod.GET, findMapEntity, RestMindmap.class);
|
||||
assertEquals(response.getBody().getXml(), newXmlContent);
|
||||
final RestMindmap response = findMap(requestHeaders, templateRest, resourceLocation);
|
||||
assertEquals(response.getXml(), newXmlContent);
|
||||
}
|
||||
|
||||
private RestMindmap findMap(HttpHeaders requestHeaders, RestTemplate templateRest, URI resourceLocation) {
|
||||
final HttpEntity findMapEntity = new HttpEntity(requestHeaders);
|
||||
final ResponseEntity<RestMindmap> response = templateRest.exchange(HOST_PORT + resourceLocation.toString(), HttpMethod.GET, findMapEntity, RestMindmap.class);
|
||||
return response.getBody();
|
||||
}
|
||||
|
||||
@Test(dataProvider = "ContentType-Provider-Function")
|
||||
public void updateMap(final @NotNull MediaType mediaType) throws IOException { // Configure media types ...
|
||||
|
Reference in New Issue
Block a user