mirror of
https://bitbucket.org/wisemapping/wisemapping-open-source.git
synced 2024-11-25 15:37:56 +01:00
new tests added
This commit is contained in:
parent
83e51a6501
commit
1d6e3ec4bf
@ -4,7 +4,6 @@ package com.wisemapping.test.rest;
|
|||||||
import com.wisemapping.exceptions.WiseMappingException;
|
import com.wisemapping.exceptions.WiseMappingException;
|
||||||
import com.wisemapping.rest.model.RestLabel;
|
import com.wisemapping.rest.model.RestLabel;
|
||||||
import com.wisemapping.rest.model.RestLabelList;
|
import com.wisemapping.rest.model.RestLabelList;
|
||||||
import org.apache.http.HttpException;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.springframework.http.HttpEntity;
|
import org.springframework.http.HttpEntity;
|
||||||
@ -14,6 +13,7 @@ import org.springframework.http.MediaType;
|
|||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.client.HttpClientErrorException;
|
import org.springframework.web.client.HttpClientErrorException;
|
||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
import org.testng.Assert;
|
||||||
import org.testng.annotations.BeforeClass;
|
import org.testng.annotations.BeforeClass;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
@ -51,13 +51,11 @@ public class RestLabelITCase {
|
|||||||
final String title2 = "Label 2 - " + mediaType.toString();
|
final String title2 = "Label 2 - " + mediaType.toString();
|
||||||
addNewLabel(requestHeaders, template, title2, COLOR);
|
addNewLabel(requestHeaders, template, title2, COLOR);
|
||||||
|
|
||||||
// Check that the map has been created ...
|
// Check that the label has been created ...
|
||||||
final HttpEntity findMapEntity = new HttpEntity(requestHeaders);
|
final RestLabelList restLabelList = getLabels(requestHeaders, template);
|
||||||
final ResponseEntity<RestLabelList> response = template.exchange(BASE_REST_URL + "/labels/", HttpMethod.GET, findMapEntity, RestLabelList.class);
|
|
||||||
|
|
||||||
// Validate that the two maps are there ...
|
// Validate that the two maps are there ...
|
||||||
final RestLabelList body = response.getBody();
|
final List<RestLabel> labels = restLabelList.getLabels();
|
||||||
final List<RestLabel> labels = body.getLabels();
|
|
||||||
|
|
||||||
boolean found1 = false;
|
boolean found1 = false;
|
||||||
boolean found2 = 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<RestLabelList> response = template.exchange(BASE_REST_URL + "/labels", HttpMethod.GET, findLabelEntity, RestLabelList.class);
|
||||||
|
return response.getBody();
|
||||||
|
}
|
||||||
|
|
||||||
@Test(dataProviderClass = RestHelper.class, dataProvider="ContentType-Provider-Function")
|
@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 HttpHeaders requestHeaders = RestHelper.createHeaders(mediaType);
|
||||||
final RestTemplate template = RestHelper.createTemplate( userEmail + ":" + "admin");
|
final RestTemplate template = RestHelper.createTemplate( userEmail + ":" + "admin");
|
||||||
|
|
||||||
// Create a new label
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
addNewLabel(requestHeaders, template, null, COLOR);
|
addNewLabel(requestHeaders, template, null, COLOR);
|
||||||
fail("Wrong response");
|
fail("Wrong response");
|
||||||
@ -95,10 +97,27 @@ public class RestLabelITCase {
|
|||||||
final String responseBodyAsString = e.getResponseBodyAsString();
|
final String responseBodyAsString = e.getResponseBodyAsString();
|
||||||
assert (responseBodyAsString.contains("Required field cannot be left blank"));
|
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 {
|
static URI addNewLabel(@NotNull HttpHeaders requestHeaders, @NotNull RestTemplate template, @Nullable String title, @Nullable String color ) throws IOException, WiseMappingException {
|
||||||
final RestLabel restLabel = new RestLabel();
|
final RestLabel restLabel = new RestLabel();
|
||||||
|
Loading…
Reference in New Issue
Block a user