Workflow name validation 65/60865/1
authorayalaben <ayala.benzvi@amdocs.com>
Thu, 16 Aug 2018 08:08:21 +0000 (11:08 +0300)
committerayalaben <ayala.benzvi@amdocs.com>
Thu, 16 Aug 2018 08:08:21 +0000 (11:08 +0300)
Change-Id: I6ff7175b84f32deb5e66ce9a3597bb2e32c12e70
Issue-ID: SDC-1654
Signed-off-by: ayalaben <ayala.benzvi@amdocs.com>
workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ParameterEntity.java
workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/types/Workflow.java
workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/WorkflowControllerTest.java

index c7f7d17..bc813f2 100644 (file)
@@ -16,6 +16,7 @@
 
 package org.onap.sdc.workflow.persistence.types;
 
+import javax.validation.constraints.NotBlank;
 import javax.validation.constraints.NotNull;
 import javax.validation.constraints.Pattern;
 import lombok.Data;
@@ -24,7 +25,7 @@ import lombok.Data;
 public class ParameterEntity {
 
     private String id;
-    @NotNull(message = "Parameter name may not be null")
+    @NotBlank(message = "Parameter Name may not be blank")
     @Pattern(regexp = "[A-Za-z0-9_ ]+", message = "Parameter name must contain only letters, digits and underscores")
     private String name;
     @NotNull
index dde708d..f312f7b 100644 (file)
@@ -19,7 +19,7 @@ package org.onap.sdc.workflow.services.types;
 
 import java.util.Collection;
 import java.util.Set;
-import javax.validation.constraints.NotNull;
+import javax.validation.constraints.NotBlank;
 import javax.validation.constraints.Pattern;
 import javax.validation.constraints.Size;
 import lombok.Data;
@@ -29,9 +29,9 @@ import lombok.Data;
 public class Workflow {
 
     private String id;
-    @NotNull(message = "Workflow name may not be null")
+    @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")
+    @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;
index a748dd5..da45212 100644 (file)
@@ -201,6 +201,36 @@ public class WorkflowControllerTest {
                 jsonPath("$.message", is("Workflow name must contain only letters, digits and underscores")));
     }
 
+    @Test
+    public void shouldThrowExceptionWhenWorkflowNameBlank() 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()).andExpect(
+                jsonPath("$.message", is("Workflow name may not be blank")));
+    }
+
+    @Test
+    public void shouldThrowExceptionWhenWorkflowNameNull() throws Exception {
+        Workflow reqWorkflow = new Workflow();
+        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")));
+    }
+
+    @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()).andExpect(
+                jsonPath("$.message", is("Workflow name may not be blank")));
+    }
+
     private void mockManagerList3() {
         doReturn(new Page<>(Arrays.asList(createWorkflow(1, true), createWorkflow(2, true), createWorkflow(3, true)),
                 new PagingRequest(DEFAULT_OFFSET, DEFAULT_LIMIT), 3)).when(workflowManagerMock).list(any(), any());