From 1059643b0f38540dbe1670b4c73e080f82384d52 Mon Sep 17 00:00:00 2001 From: Paulo Gustavo Veiga Date: Tue, 23 Jan 2024 22:31:46 -0800 Subject: [PATCH] Fix label test. --- .../main/java/com/wisemapping/model/Label.java | 2 +- .../com/wisemapping/rest/model/RestLabel.java | 2 +- .../wisemapping/validator/LabelValidator.java | 17 ++++++----------- .../test/rest/RestLabelControllerTest.java | 4 ++-- 4 files changed, 10 insertions(+), 15 deletions(-) diff --git a/wise-webapp/src/main/java/com/wisemapping/model/Label.java b/wise-webapp/src/main/java/com/wisemapping/model/Label.java index fcc82e94..bb460318 100644 --- a/wise-webapp/src/main/java/com/wisemapping/model/Label.java +++ b/wise-webapp/src/main/java/com/wisemapping/model/Label.java @@ -90,7 +90,7 @@ public class Label implements Serializable { return color; } - public void setColor(@NotNull String color) { + public void setColor(String color) { this.color = color; } diff --git a/wise-webapp/src/main/java/com/wisemapping/rest/model/RestLabel.java b/wise-webapp/src/main/java/com/wisemapping/rest/model/RestLabel.java index 2bf5c365..5a49fd38 100644 --- a/wise-webapp/src/main/java/com/wisemapping/rest/model/RestLabel.java +++ b/wise-webapp/src/main/java/com/wisemapping/rest/model/RestLabel.java @@ -56,7 +56,7 @@ public class RestLabel { label.setTitle(title); } - public void setColor(@NotNull final String color) { + public void setColor(final String color) { label.setColor(color); } diff --git a/wise-webapp/src/main/java/com/wisemapping/validator/LabelValidator.java b/wise-webapp/src/main/java/com/wisemapping/validator/LabelValidator.java index de6cbac8..2639ef5e 100644 --- a/wise-webapp/src/main/java/com/wisemapping/validator/LabelValidator.java +++ b/wise-webapp/src/main/java/com/wisemapping/validator/LabelValidator.java @@ -63,18 +63,13 @@ public class LabelValidator implements Validator { title, Constants.MAX_LABEL_NAME_LENGTH); - ValidatorUtils.rejectIfEmptyOrWhitespace( - errors, - "title", - "Label title can not be empty", - title); - final User user = com.wisemapping.security.Utils.getUser(); - assert user != null; - - final Label foundLabel = service.getLabelByTitle(title, user); - if (foundLabel != null) { - errors.rejectValue("title", Messages.LABEL_TITLE_ALREADY_EXISTS); + if (user != null && title != null) { + final Label foundLabel = service.getLabelByTitle(title, user); + if (foundLabel != null) { + errors.rejectValue("title", Messages.LABEL_TITLE_ALREADY_EXISTS); + } } + } } diff --git a/wise-webapp/src/test/java/com/wisemapping/test/rest/RestLabelControllerTest.java b/wise-webapp/src/test/java/com/wisemapping/test/rest/RestLabelControllerTest.java index d9a0dd77..c694a86c 100644 --- a/wise-webapp/src/test/java/com/wisemapping/test/rest/RestLabelControllerTest.java +++ b/wise-webapp/src/test/java/com/wisemapping/test/rest/RestLabelControllerTest.java @@ -94,14 +94,14 @@ public class RestLabelControllerTest { addNewLabel(requestHeaders, restTemplate, null, COLOR); fail("Wrong response"); } catch (IllegalStateException e) { - assertTrue(e.getMessage().contains("Required field cannot be left blank")); + assertTrue(e.getMessage().contains("Required field cannot be left blank"), e.getMessage()); } try { addNewLabel(requestHeaders, restTemplate, "title12345", null); fail("Wrong response"); } catch (IllegalStateException e) { - assertTrue(e.getMessage().contains("Required field cannot be left blank")); + assertTrue(e.getMessage().contains("Required field cannot be left blank"), e.getMessage()); } }