Workflow name validation test 29/61229/4
authorayalaben <ayala.benzvi@amdocs.com>
Mon, 20 Aug 2018 08:05:16 +0000 (11:05 +0300)
committerayalaben <ayala.benzvi@amdocs.com>
Mon, 20 Aug 2018 08:53:48 +0000 (11:53 +0300)
Change-Id: Ib1601649fdea065b8a3d43b39342fa6c01c58f91
Issue-ID: SDC-1654
Signed-off-by: ayalaben <ayala.benzvi@amdocs.com>
workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/types/Workflow.java
workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/types/WorkflowValidationConstants.java [new file with mode: 0644]
workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/WorkflowControllerTest.java

index f312f7b..f7df447 100644 (file)
@@ -17,6 +17,9 @@
 package org.onap.sdc.workflow.services.types;
 
 
+import static org.onap.sdc.workflow.services.types.WorkflowValidationConstants.MAX_LENGTH;
+import static org.onap.sdc.workflow.services.types.WorkflowValidationConstants.MIN_LENGTH;
+
 import java.util.Collection;
 import java.util.Set;
 import javax.validation.constraints.NotBlank;
@@ -29,9 +32,9 @@ import lombok.Data;
 public class Workflow {
 
     private String id;
-    @NotBlank(message = "Workflow name may not be blank")
-    @Size(max = 80, message = "Workflow name must be less than 80 characters")
-    @Pattern(regexp = "[A-Za-z0-9_ ]+", message = "Workflow name must contain only letters, digits and underscores")
+    @NotBlank(message = "Workflow name may not be blank.")
+    @Size(min = MIN_LENGTH, max = MAX_LENGTH, message = "Workflow name must be at least " + MIN_LENGTH + " characters, and no more than " + MAX_LENGTH +" characters.")
+    @Pattern(regexp = "[A-Za-z0-9_ ]+", message = "Workflow name must contain only letters, digits and underscores.")
     private String name;
     private String description;
     private Set<WorkflowVersionState> versionStates;
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/types/WorkflowValidationConstants.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/types/WorkflowValidationConstants.java
new file mode 100644 (file)
index 0000000..c88f36c
--- /dev/null
@@ -0,0 +1,7 @@
+package org.onap.sdc.workflow.services.types;
+
+public class WorkflowValidationConstants {
+
+    public static final int MAX_LENGTH = 80;
+    public static final int MIN_LENGTH = 6;
+}
index da45212..f8f86f1 100644 (file)
@@ -10,6 +10,8 @@ import static org.onap.sdc.workflow.TestUtil.createWorkflow;
 import static org.onap.sdc.workflow.api.RestParams.USER_ID_HEADER;
 import static org.onap.sdc.workflow.services.types.PagingConstants.DEFAULT_LIMIT;
 import static org.onap.sdc.workflow.services.types.PagingConstants.DEFAULT_OFFSET;
+import static org.onap.sdc.workflow.services.types.WorkflowValidationConstants.MAX_LENGTH;
+import static org.onap.sdc.workflow.services.types.WorkflowValidationConstants.MIN_LENGTH;
 import static org.springframework.http.MediaType.APPLICATION_JSON;
 import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
 import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
@@ -198,7 +200,7 @@ public class WorkflowControllerTest {
         mockMvc.perform(post(RestPath.getWorkflowsPath()).header(USER_ID_HEADER, USER_ID).contentType(APPLICATION_JSON)
                                 .content(JsonUtil.object2Json(reqWorkflow))).andDo(print())
                 .andExpect(status().isBadRequest()).andExpect(
-                jsonPath("$.message", is("Workflow name must contain only letters, digits and underscores")));
+                jsonPath("$.message", is("Workflow name must contain only letters, digits and underscores.")));
     }
 
     @Test
@@ -207,8 +209,7 @@ public class WorkflowControllerTest {
         reqWorkflow.setName("  ");
         mockMvc.perform(post(RestPath.getWorkflowsPath()).header(USER_ID_HEADER, USER_ID).contentType(APPLICATION_JSON)
                                                          .content(JsonUtil.object2Json(reqWorkflow))).andDo(print())
-               .andExpect(status().isBadRequest()).andExpect(
-                jsonPath("$.message", is("Workflow name may not be blank")));
+               .andExpect(status().isBadRequest());
     }
 
     @Test
@@ -217,18 +218,36 @@ public class WorkflowControllerTest {
         reqWorkflow.setName(null);
         mockMvc.perform(post(RestPath.getWorkflowsPath()).header(USER_ID_HEADER, USER_ID).contentType(APPLICATION_JSON)
                                                          .content(JsonUtil.object2Json(reqWorkflow))).andDo(print())
-               .andExpect(status().isBadRequest()).andExpect(
-                jsonPath("$.message", is("Workflow name may not be blank")));
+               .andExpect(status().isBadRequest());
     }
 
     @Test
     public void shouldThrowExceptionWhenWorkflowNameEmptyString() throws Exception {
         Workflow reqWorkflow = new Workflow();
         reqWorkflow.setName("");
+        mockMvc.perform(post(RestPath.getWorkflowsPath()).header(USER_ID_HEADER, USER_ID).contentType(APPLICATION_JSON)
+                                                         .content(JsonUtil.object2Json(reqWorkflow))).andDo(print())
+               .andExpect(status().isBadRequest());
+    }
+
+    @Test
+    public void shouldThrowExceptionWhenWorkflowNameMoreThanMax() throws Exception {
+        Workflow reqWorkflow = new Workflow();
+        reqWorkflow.setName("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
+        mockMvc.perform(post(RestPath.getWorkflowsPath()).header(USER_ID_HEADER, USER_ID).contentType(APPLICATION_JSON)
+                                                         .content(JsonUtil.object2Json(reqWorkflow))).andDo(print())
+               .andExpect(status().isBadRequest()).andExpect(
+                jsonPath("$.message", is("Workflow name must be at least " + MIN_LENGTH + " characters, and no more than " + MAX_LENGTH + " characters.")));
+    }
+
+    @Test
+    public void shouldThrowExceptionWhenWorkflowNameLessThanMin() throws Exception {
+        Workflow reqWorkflow = new Workflow();
+        reqWorkflow.setName("AAA");
         mockMvc.perform(post(RestPath.getWorkflowsPath()).header(USER_ID_HEADER, USER_ID).contentType(APPLICATION_JSON)
                                                          .content(JsonUtil.object2Json(reqWorkflow))).andDo(print())
                .andExpect(status().isBadRequest()).andExpect(
-                jsonPath("$.message", is("Workflow name may not be blank")));
+                jsonPath("$.message", is("Workflow name must be at least " + MIN_LENGTH + " characters, and no more than " + MAX_LENGTH + " characters.")));
     }
 
     private void mockManagerList3() {