mirror of
https://bitbucket.org/wisemapping/wisemapping-open-source.git
synced 2024-11-25 15:37:56 +01:00
adding new suite test
This commit is contained in:
parent
c81439cae8
commit
147a4ec06a
@ -39,7 +39,7 @@ public class LabelController extends BaseController {
|
|||||||
private LabelService labelService;
|
private LabelService labelService;
|
||||||
|
|
||||||
|
|
||||||
@RequestMapping(method = RequestMethod.POST, value = "/labels", consumes = {"application/json"})
|
@RequestMapping(method = RequestMethod.POST, value = "/labels", consumes = {"application/json", "application/xml"})
|
||||||
@ResponseStatus(value = HttpStatus.CREATED)
|
@ResponseStatus(value = HttpStatus.CREATED)
|
||||||
public void createLabel(@RequestBody RestLabel restLabel, @NotNull HttpServletResponse response, @RequestParam(required = false) String title) throws WiseMappingException {
|
public void createLabel(@RequestBody RestLabel restLabel, @NotNull HttpServletResponse response, @RequestParam(required = false) String title) throws WiseMappingException {
|
||||||
// Overwrite title if it was specified by parameter.
|
// Overwrite title if it was specified by parameter.
|
||||||
@ -56,7 +56,7 @@ public class LabelController extends BaseController {
|
|||||||
response.setHeader("ResourceId", Integer.toString(label.getId()));
|
response.setHeader("ResourceId", Integer.toString(label.getId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(method = RequestMethod.GET, value = "/labels", produces = {"application/json"})
|
@RequestMapping(method = RequestMethod.GET, value = "/labels", produces = {"application/json", "application/xml"})
|
||||||
public RestLabelList retrieveList() {
|
public RestLabelList retrieveList() {
|
||||||
final User user = Utils.getUser();
|
final User user = Utils.getUser();
|
||||||
assert user != null;
|
assert user != null;
|
||||||
|
@ -1,16 +1,30 @@
|
|||||||
package com.wisemapping.rest.model;
|
package com.wisemapping.rest.model;
|
||||||
|
|
||||||
import com.wisemapping.model.Label;
|
import com.wisemapping.model.Label;
|
||||||
|
import org.codehaus.jackson.annotate.JsonAutoDetect;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import javax.xml.bind.annotation.XmlAccessType;
|
||||||
|
import javax.xml.bind.annotation.XmlAccessorType;
|
||||||
import javax.xml.bind.annotation.XmlElement;
|
import javax.xml.bind.annotation.XmlElement;
|
||||||
|
import javax.xml.bind.annotation.XmlRootElement;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@XmlRootElement(name = "labels")
|
||||||
|
@XmlAccessorType(XmlAccessType.PROPERTY)
|
||||||
|
@JsonAutoDetect(
|
||||||
|
fieldVisibility = JsonAutoDetect.Visibility.NONE,
|
||||||
|
getterVisibility = JsonAutoDetect.Visibility.PUBLIC_ONLY,
|
||||||
|
isGetterVisibility = JsonAutoDetect.Visibility.PUBLIC_ONLY)
|
||||||
public class RestLabelList {
|
public class RestLabelList {
|
||||||
|
|
||||||
@NotNull private final List<RestLabel> restLabels;
|
@NotNull private final List<RestLabel> restLabels;
|
||||||
|
|
||||||
|
public RestLabelList(){
|
||||||
|
this.restLabels = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
public RestLabelList(@NotNull final List<Label> labels) {
|
public RestLabelList(@NotNull final List<Label> labels) {
|
||||||
this.restLabels = new ArrayList<>(labels.size());
|
this.restLabels = new ArrayList<>(labels.size());
|
||||||
for (Label label : labels) {
|
for (Label label : labels) {
|
||||||
|
@ -45,6 +45,7 @@
|
|||||||
<value>com.wisemapping.rest.model.RestLogItem</value>
|
<value>com.wisemapping.rest.model.RestLogItem</value>
|
||||||
<value>com.wisemapping.rest.model.RestLockInfo</value>
|
<value>com.wisemapping.rest.model.RestLockInfo</value>
|
||||||
<value>com.wisemapping.rest.model.RestLabel</value>
|
<value>com.wisemapping.rest.model.RestLabel</value>
|
||||||
|
<value>com.wisemapping.rest.model.RestLabelList</value>
|
||||||
</list>
|
</list>
|
||||||
</property>
|
</property>
|
||||||
</bean>
|
</bean>
|
||||||
|
@ -0,0 +1,128 @@
|
|||||||
|
package com.wisemapping.test.rest;
|
||||||
|
|
||||||
|
|
||||||
|
import com.wisemapping.exceptions.WiseMappingException;
|
||||||
|
import com.wisemapping.rest.model.RestLabel;
|
||||||
|
import com.wisemapping.rest.model.RestMindmap;
|
||||||
|
import com.wisemapping.rest.model.RestMindmapInfo;
|
||||||
|
import com.wisemapping.rest.model.RestMindmapList;
|
||||||
|
import com.wisemapping.rest.model.RestLabelList;
|
||||||
|
import com.wisemapping.rest.model.RestUser;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.springframework.http.HttpEntity;
|
||||||
|
import org.springframework.http.HttpHeaders;
|
||||||
|
import org.springframework.http.HttpMethod;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.http.client.SimpleClientHttpRequestFactory;
|
||||||
|
import org.springframework.security.crypto.codec.Base64;
|
||||||
|
import org.springframework.web.client.HttpClientErrorException;
|
||||||
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
import org.testng.SkipException;
|
||||||
|
import org.testng.annotations.BeforeClass;
|
||||||
|
import org.testng.annotations.DataProvider;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.testng.Assert.assertEquals;
|
||||||
|
import static org.testng.Assert.assertTrue;
|
||||||
|
import static org.testng.Assert.fail;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public class RestMindmapLabelTCase {
|
||||||
|
|
||||||
|
private String userEmail = "admin@wisemapping.com";
|
||||||
|
private static final String HOST_PORT = "http://localhost:8080";
|
||||||
|
private static final String BASE_REST_URL = HOST_PORT + "/service";
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
void createUser() {
|
||||||
|
|
||||||
|
final RestAdminITCase restAdminITCase = new RestAdminITCase();
|
||||||
|
userEmail = restAdminITCase.createNewUser(MediaType.APPLICATION_JSON);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(dataProvider = "ContentType-Provider-Function")
|
||||||
|
public void createLabel(final @NotNull MediaType mediaType) throws IOException, WiseMappingException { // Configure media types ...
|
||||||
|
final HttpHeaders requestHeaders = createHeaders(mediaType);
|
||||||
|
final RestTemplate template = createTemplate();
|
||||||
|
|
||||||
|
// Create a new label
|
||||||
|
final String title1 = "Label 1 - " + mediaType.toString();
|
||||||
|
addNewLabel(requestHeaders,template,title1);
|
||||||
|
|
||||||
|
// Create a new label
|
||||||
|
final String title2 = "Label 2 - " + mediaType.toString();
|
||||||
|
addNewLabel(requestHeaders,template,title2);
|
||||||
|
|
||||||
|
// Check that the map has been created ...
|
||||||
|
final HttpEntity findMapEntity = new HttpEntity(requestHeaders);
|
||||||
|
final ResponseEntity<RestLabelList> response = template.exchange(BASE_REST_URL + "/labels/", HttpMethod.GET, findMapEntity, RestLabelList.class);
|
||||||
|
|
||||||
|
// Validate that the two maps are there ...
|
||||||
|
final RestLabelList body = response.getBody();
|
||||||
|
final List<RestLabel> labels = body.getLabels();
|
||||||
|
|
||||||
|
boolean found1 = false;
|
||||||
|
boolean found2 = false;
|
||||||
|
for (RestLabel label : labels) {
|
||||||
|
if (label.getTitle().equals(title1)) {
|
||||||
|
found1 = true;
|
||||||
|
}
|
||||||
|
if (label.getTitle().equals(title2)) {
|
||||||
|
found2 = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assertTrue(found1 && found2, "Labels could not be found");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private URI addNewLabel(@NotNull HttpHeaders requestHeaders, @NotNull RestTemplate template, @NotNull String title, @Nullable String xml) throws IOException, WiseMappingException {
|
||||||
|
final RestLabel restLabel = new RestLabel();
|
||||||
|
restLabel.setTitle(title);
|
||||||
|
restLabel.setColor("#666666");
|
||||||
|
|
||||||
|
// Create a new label ...
|
||||||
|
HttpEntity<RestLabel> createUserEntity = new HttpEntity<RestLabel>(restLabel, requestHeaders);
|
||||||
|
return template.postForLocation(BASE_REST_URL + "/labels", createUserEntity);
|
||||||
|
}
|
||||||
|
|
||||||
|
private URI addNewLabel(@NotNull HttpHeaders requestHeaders, @NotNull RestTemplate template, @NotNull String title) throws IOException, WiseMappingException {
|
||||||
|
return addNewLabel(requestHeaders, template, title, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private HttpHeaders createHeaders(@NotNull MediaType mediaType) {
|
||||||
|
List<MediaType> acceptableMediaTypes = new ArrayList<MediaType>();
|
||||||
|
acceptableMediaTypes.add(mediaType);
|
||||||
|
final HttpHeaders requestHeaders = new HttpHeaders();
|
||||||
|
requestHeaders.setAccept(acceptableMediaTypes);
|
||||||
|
requestHeaders.setContentType(mediaType);
|
||||||
|
return requestHeaders;
|
||||||
|
}
|
||||||
|
|
||||||
|
private RestTemplate createTemplate() {
|
||||||
|
SimpleClientHttpRequestFactory s = new SimpleClientHttpRequestFactory() {
|
||||||
|
@Override
|
||||||
|
protected void prepareConnection(HttpURLConnection connection, String httpMethod) throws IOException {
|
||||||
|
super.prepareConnection(connection, httpMethod);
|
||||||
|
|
||||||
|
//Basic Authentication for Police API
|
||||||
|
String authorization = userEmail + ":" + "admin";
|
||||||
|
byte[] encodedAuthorisation = Base64.encode(authorization.getBytes());
|
||||||
|
connection.setRequestProperty("Authorization", "Basic " + new String(encodedAuthorisation));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return new RestTemplate(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
@DataProvider(name = "ContentType-Provider-Function")
|
||||||
|
public Object[][] contentTypes() {
|
||||||
|
return new Object[][]{{MediaType.APPLICATION_XML}, {MediaType.APPLICATION_JSON}};
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user