attributes nullable

This commit is contained in:
Ezequiel Bergamaschi 2014-02-10 00:58:19 -03:00
parent 1a31e5ee99
commit b110d338af
3 changed files with 46 additions and 14 deletions

View File

@ -31,7 +31,7 @@ public class Label {
return creator; return creator;
} }
@NotNull @Nullable
public String getTitle() { public String getTitle() {
return title; return title;
} }

View File

@ -44,6 +44,7 @@ public class RestLabel {
return this.label.getParent(); return this.label.getParent();
} }
@Nullable
public String getTitle() { public String getTitle() {
return this.label.getTitle(); return this.label.getTitle();
} }
@ -64,7 +65,7 @@ public class RestLabel {
label.setColor(color); label.setColor(color);
} }
@NotNull public String getColor() { @Nullable public String getColor() {
return label.getColor(); return label.getColor();
} }

View File

@ -4,6 +4,7 @@ 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;
@ -11,6 +12,7 @@ import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod; import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType; 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.RestTemplate; import org.springframework.web.client.RestTemplate;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; 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 com.wisemapping.test.rest.RestHelper.BASE_REST_URL;
import static org.testng.Assert.assertTrue; import static org.testng.Assert.assertTrue;
import static org.testng.AssertJUnit.fail;
@Test @Test
public class RestMindmapLabelITCase { public class RestLabelITCase {
private String userEmail; private String userEmail;
private static final String COLOR = "#000000";
@BeforeClass @BeforeClass
void createUser() { void createUser() {
@ -41,11 +45,11 @@ public class RestMindmapLabelITCase {
// Create a new label // Create a new label
final String title1 = "Label 1 - " + mediaType.toString(); final String title1 = "Label 1 - " + mediaType.toString();
addNewLabel(requestHeaders, template, title1); addNewLabel(requestHeaders, template, title1, COLOR);
// Create a new label // Create a new label
final String title2 = "Label 2 - " + mediaType.toString(); final String title2 = "Label 2 - " + mediaType.toString();
addNewLabel(requestHeaders,template,title2); addNewLabel(requestHeaders, template, title2, COLOR);
// Check that the map has been created ... // Check that the map has been created ...
final HttpEntity findMapEntity = new HttpEntity(requestHeaders); final HttpEntity findMapEntity = new HttpEntity(requestHeaders);
@ -58,10 +62,10 @@ public class RestMindmapLabelITCase {
boolean found1 = false; boolean found1 = false;
boolean found2 = false; boolean found2 = false;
for (RestLabel label : labels) { for (RestLabel label : labels) {
if (label.getTitle().equals(title1)) { if (title1.equals(label.getTitle())) {
found1 = true; found1 = true;
} }
if (label.getTitle().equals(title2)) { if (title2.equals(label.getTitle())) {
found2 = true; 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(); final RestLabel restLabel = new RestLabel();
restLabel.setTitle(title); if (title != null) {
restLabel.setColor("#666666"); restLabel.setTitle(title);
}
if (color != null) {
restLabel.setColor(color);
}
// Create a new label ... // Create a new label ...
HttpEntity<RestLabel> createUserEntity = new HttpEntity<RestLabel>(restLabel, requestHeaders); HttpEntity<RestLabel> createUserEntity = new HttpEntity<RestLabel>(restLabel, requestHeaders);
return template.postForLocation(BASE_REST_URL + "/labels", createUserEntity); 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);
}
} }