mirror of
https://bitbucket.org/wisemapping/wisemapping-open-source.git
synced 2024-11-21 21:57:56 +01:00
attributes nullable
This commit is contained in:
parent
1a31e5ee99
commit
b110d338af
@ -31,7 +31,7 @@ public class Label {
|
||||
return creator;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Nullable
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
@ -44,6 +44,7 @@ public class RestLabel {
|
||||
return this.label.getParent();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getTitle() {
|
||||
return this.label.getTitle();
|
||||
}
|
||||
@ -64,7 +65,7 @@ public class RestLabel {
|
||||
label.setColor(color);
|
||||
}
|
||||
|
||||
@NotNull public String getColor() {
|
||||
@Nullable public String getColor() {
|
||||
return label.getColor();
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@ package com.wisemapping.test.rest;
|
||||
import com.wisemapping.exceptions.WiseMappingException;
|
||||
import com.wisemapping.rest.model.RestLabel;
|
||||
import com.wisemapping.rest.model.RestLabelList;
|
||||
import org.apache.http.HttpException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.springframework.http.HttpEntity;
|
||||
@ -11,6 +12,7 @@ import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.client.HttpClientErrorException;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
@ -21,11 +23,13 @@ import java.util.List;
|
||||
|
||||
import static com.wisemapping.test.rest.RestHelper.BASE_REST_URL;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
import static org.testng.AssertJUnit.fail;
|
||||
|
||||
@Test
|
||||
public class RestMindmapLabelITCase {
|
||||
public class RestLabelITCase {
|
||||
|
||||
private String userEmail;
|
||||
private static final String COLOR = "#000000";
|
||||
|
||||
@BeforeClass
|
||||
void createUser() {
|
||||
@ -41,11 +45,11 @@ public class RestMindmapLabelITCase {
|
||||
|
||||
// Create a new label
|
||||
final String title1 = "Label 1 - " + mediaType.toString();
|
||||
addNewLabel(requestHeaders, template, title1);
|
||||
addNewLabel(requestHeaders, template, title1, COLOR);
|
||||
|
||||
// Create a new label
|
||||
final String title2 = "Label 2 - " + mediaType.toString();
|
||||
addNewLabel(requestHeaders,template,title2);
|
||||
addNewLabel(requestHeaders, template, title2, COLOR);
|
||||
|
||||
// Check that the map has been created ...
|
||||
final HttpEntity findMapEntity = new HttpEntity(requestHeaders);
|
||||
@ -58,10 +62,10 @@ public class RestMindmapLabelITCase {
|
||||
boolean found1 = false;
|
||||
boolean found2 = false;
|
||||
for (RestLabel label : labels) {
|
||||
if (label.getTitle().equals(title1)) {
|
||||
if (title1.equals(label.getTitle())) {
|
||||
found1 = true;
|
||||
}
|
||||
if (label.getTitle().equals(title2)) {
|
||||
if (title2.equals(label.getTitle())) {
|
||||
found2 = true;
|
||||
}
|
||||
}
|
||||
@ -69,17 +73,44 @@ public class RestMindmapLabelITCase {
|
||||
|
||||
}
|
||||
|
||||
static URI addNewLabel(@NotNull HttpHeaders requestHeaders, @NotNull RestTemplate template, @NotNull String title, @Nullable String xml) throws IOException, WiseMappingException {
|
||||
@Test(dataProviderClass = RestHelper.class, dataProvider="ContentType-Provider-Function")
|
||||
public void createLabelWithoutTitleOrColor(final @NotNull MediaType mediaType) throws IOException, WiseMappingException {
|
||||
final HttpHeaders requestHeaders = RestHelper.createHeaders(mediaType);
|
||||
final RestTemplate template = RestHelper.createTemplate( userEmail + ":" + "admin");
|
||||
|
||||
// Create a new label
|
||||
|
||||
try {
|
||||
addNewLabel(requestHeaders, template, null, COLOR);
|
||||
fail("Wrong response");
|
||||
} catch (HttpClientErrorException e) {
|
||||
final String responseBodyAsString = e.getResponseBodyAsString();
|
||||
assertTrue (responseBodyAsString.contains("Required field cannot be left blank"));
|
||||
}
|
||||
|
||||
try {
|
||||
addNewLabel(requestHeaders, template, "title12345", null);
|
||||
fail("Wrong response");
|
||||
} catch (HttpClientErrorException e) {
|
||||
final String responseBodyAsString = e.getResponseBodyAsString();
|
||||
assert (responseBodyAsString.contains("Required field cannot be left blank"));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
static URI addNewLabel(@NotNull HttpHeaders requestHeaders, @NotNull RestTemplate template, @Nullable String title, @Nullable String color ) throws IOException, WiseMappingException {
|
||||
final RestLabel restLabel = new RestLabel();
|
||||
restLabel.setTitle(title);
|
||||
restLabel.setColor("#666666");
|
||||
if (title != null) {
|
||||
restLabel.setTitle(title);
|
||||
}
|
||||
if (color != null) {
|
||||
restLabel.setColor(color);
|
||||
}
|
||||
|
||||
// Create a new label ...
|
||||
HttpEntity<RestLabel> createUserEntity = new HttpEntity<RestLabel>(restLabel, requestHeaders);
|
||||
return template.postForLocation(BASE_REST_URL + "/labels", createUserEntity);
|
||||
}
|
||||
|
||||
static URI addNewLabel(@NotNull HttpHeaders requestHeaders, @NotNull RestTemplate template, @NotNull String title) throws IOException, WiseMappingException {
|
||||
return addNewLabel(requestHeaders, template, title, null);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user