Add mindmap list test.

This commit is contained in:
Paulo Gustavo Veiga 2012-03-15 00:29:22 -03:00
parent 6a1484b49d
commit b52da56739
3 changed files with 59 additions and 29 deletions

View File

@ -205,7 +205,6 @@
<img src="images/logo-small.png"/> <img src="images/logo-small.png"/>
</div> </div>
<div id="dragTextNode" class="textNode">Text Node !!</div> <div id="dragTextNode" class="textNode">Text Node !!</div>
</div> </div>
<div id="mindplot"></div> <div id="mindplot"></div>

View File

@ -5,6 +5,7 @@ import com.wisemapping.model.MindMap;
import org.codehaus.jackson.annotate.JsonAutoDetect; import org.codehaus.jackson.annotate.JsonAutoDetect;
import org.codehaus.jackson.annotate.JsonIgnore; import org.codehaus.jackson.annotate.JsonIgnore;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.springframework.util.CollectionUtils;
import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAccessorType;
@ -12,6 +13,7 @@ import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
@XmlRootElement(name = "maps") @XmlRootElement(name = "maps")
@ -25,7 +27,7 @@ public class RestMindmapList {
private List<RestMindmap> mindmaps; private List<RestMindmap> mindmaps;
public RestMindmapList() { public RestMindmapList() {
this(null); this(Collections.<MindMap>emptyList());
} }
public RestMindmapList(@NotNull List<MindMap> mindmaps) { public RestMindmapList(@NotNull List<MindMap> mindmaps) {

View File

@ -2,6 +2,7 @@ package com.wisemapping.test.rest;
import com.wisemapping.rest.model.RestMindmap; import com.wisemapping.rest.model.RestMindmap;
import com.wisemapping.rest.model.RestMindmapList;
import com.wisemapping.rest.model.RestUser; import com.wisemapping.rest.model.RestUser;
import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -21,6 +22,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail; import static org.testng.Assert.fail;
@ -28,7 +30,7 @@ import static org.testng.Assert.fail;
public class RestMindmapTCase { public class RestMindmapTCase {
private String userEmail = "admin@wisemapping.com"; private String userEmail = "admin@wisemapping.com";
private static final String HOST_PORT = "http://localhost:8080"; private static final String HOST_PORT = "http://127.0.0.1:8080";
private static final String BASE_REST_URL = HOST_PORT + "/service"; private static final String BASE_REST_URL = HOST_PORT + "/service";
@BeforeClass @BeforeClass
@ -38,42 +40,75 @@ public class RestMindmapTCase {
userEmail = restAdminITCase.createNewUser(MediaType.APPLICATION_JSON); userEmail = restAdminITCase.createNewUser(MediaType.APPLICATION_JSON);
} }
@Test(dataProvider = "ContentType-Provider-Function")
public void listMaps(final @NotNull MediaType mediaType) { // Configure media types ...
final HttpHeaders requestHeaders = createHeaders(mediaType);
final RestTemplate templateRest = createTemplate();
// Create a sample map ...
final String title1 = "List Maps 1 - " + mediaType.toString();
addNewMap(requestHeaders, templateRest, title1);
final String title2 = "List Maps 2 - " + mediaType.toString();
addNewMap(requestHeaders, templateRest, title2);
// Check that the map has been created ...
final HttpEntity findMapEntity = new HttpEntity(requestHeaders);
final ResponseEntity<RestMindmapList> response = templateRest.exchange(BASE_REST_URL + "/maps", HttpMethod.GET, findMapEntity, RestMindmapList.class);
// Validate that the two maps are there ...
final RestMindmapList body = response.getBody();
final List<RestMindmap> mindmaps = body.getMindmaps();
boolean found1 = false;
boolean found2 = false;
for (RestMindmap mindmap : mindmaps) {
if (mindmap.getTitle().equals(title1)) {
found1 = true;
}
if (mindmap.getTitle().equals(title2)) {
found2 = true;
}
}
assertTrue(found1 && found2, "Map could not be found");
}
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") @Test(dataProvider = "ContentType-Provider-Function")
public void createMap(final @NotNull MediaType mediaType) { // Configure media types ... public void createMap(final @NotNull MediaType mediaType) { // Configure media types ...
final HttpHeaders requestHeaders = createHeaders(mediaType); final HttpHeaders requestHeaders = createHeaders(mediaType);
final RestTemplate templateRest = createTemplate(); final RestTemplate templateRest = createTemplate();
// Create a sample map ... // Create a sample map ...
final RestMindmap restMindmap = new RestMindmap();
final String title = "My Map " + mediaType.toString(); final String title = "My Map " + mediaType.toString();
restMindmap.setTitle(title); final URI resourceLocation = addNewMap(requestHeaders, templateRest, title);
restMindmap.setDescription("My Map Desc");
// Create a new map ...
HttpEntity<RestMindmap> createUserEntity = new HttpEntity<RestMindmap>(restMindmap, requestHeaders);
final URI resourceLocation = templateRest.postForLocation(BASE_REST_URL + "/maps", createUserEntity);
// Check that the map has been created ... // Check that the map has been created ...
HttpEntity<RestUser> findUserEntity = new HttpEntity<RestUser>(requestHeaders); final HttpEntity findMapEntity = new HttpEntity(requestHeaders);
final ResponseEntity<RestMindmap> response = templateRest.exchange(HOST_PORT + resourceLocation.toString(), HttpMethod.GET, findUserEntity, RestMindmap.class); final ResponseEntity<RestMindmap> response = templateRest.exchange(HOST_PORT + resourceLocation.toString(), HttpMethod.GET, findMapEntity, RestMindmap.class);
assertEquals(response.getBody().getTitle(), title); assertEquals(response.getBody().getTitle(), title);
} }
@Test(dataProvider = "ContentType-Provider-Function") @Test(dataProvider = "ContentType-Provider-Function")
public void updateMapXml(final @NotNull MediaType mediaType) throws IOException { // Configure media types ... public void updateMapXml(final @NotNull MediaType mediaType) throws IOException { // Configure media types ...
final HttpHeaders requestHeaders = createHeaders(mediaType); final HttpHeaders requestHeaders = createHeaders(mediaType);
final RestTemplate templateRest = createTemplate(); final RestTemplate templateRest = createTemplate();
// Create a sample map ... // Create a sample map ...
final RestMindmap restMindmap = new RestMindmap();
final String title = "Update XML sample " + mediaType.toString(); final String title = "Update XML sample " + mediaType.toString();
restMindmap.setTitle(title); final URI resourceLocation = addNewMap(requestHeaders, templateRest, title);
restMindmap.setDescription("My Map Desc");
// Create a new map ...
HttpEntity<RestMindmap> createUserEntity = new HttpEntity<RestMindmap>(restMindmap, requestHeaders);
final URI resourceLocation = templateRest.postForLocation(BASE_REST_URL + "/maps", createUserEntity);
// Update map xml content ... // Update map xml content ...
final String resourceUrl = HOST_PORT + resourceLocation.toString(); final String resourceUrl = HOST_PORT + resourceLocation.toString();
@ -83,8 +118,8 @@ public class RestMindmapTCase {
templateRest.put(resourceUrl + "/xml", updateEntity); templateRest.put(resourceUrl + "/xml", updateEntity);
// Check that the map has been updated ... // Check that the map has been updated ...
HttpEntity<RestUser> findUserEntity = new HttpEntity<RestUser>(requestHeaders); final HttpEntity findMapEntity = new HttpEntity(requestHeaders);
final ResponseEntity<RestMindmap> response = templateRest.exchange(HOST_PORT + resourceLocation.toString(), HttpMethod.GET, findUserEntity, RestMindmap.class); final ResponseEntity<RestMindmap> response = templateRest.exchange(HOST_PORT + resourceLocation.toString(), HttpMethod.GET, findMapEntity, RestMindmap.class);
assertEquals(response.getBody().getXml(), newXmlContent); assertEquals(response.getBody().getXml(), newXmlContent);
} }
@ -95,14 +130,8 @@ public class RestMindmapTCase {
final RestTemplate templateRest = createTemplate(); final RestTemplate templateRest = createTemplate();
// Create a sample map ... // Create a sample map ...
final RestMindmap newRestMindmap = new RestMindmap();
final String title = "Update sample " + mediaType.toString(); final String title = "Update sample " + mediaType.toString();
newRestMindmap.setTitle(title); final URI resourceLocation = addNewMap(requestHeaders, templateRest, title);
newRestMindmap.setDescription("My Map Desc");
// Create a new map ...
final HttpEntity<RestMindmap> createUserEntity = new HttpEntity<RestMindmap>(newRestMindmap, requestHeaders);
final URI resourceLocation = templateRest.postForLocation(BASE_REST_URL + "/maps", createUserEntity);
// Build map to update ... // Build map to update ...
final RestMindmap mapToUpdate = new RestMindmap(); final RestMindmap mapToUpdate = new RestMindmap();