Validator init binder fix 59/57659/3
authorayalaben <ayala.benzvi@amdocs.com>
Thu, 26 Jul 2018 08:10:49 +0000 (11:10 +0300)
committerayalaben <ayala.benzvi@amdocs.com>
Thu, 26 Jul 2018 09:17:32 +0000 (12:17 +0300)
Change-Id: I98ac7b42512a4f7b1323e29ed5059553479b24e0
Issue-ID: SDC-1518
Signed-off-by: ayalaben <ayala.benzvi@amdocs.com>
workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/WorkflowVersionController.java
workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/Workflow.java
workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/WorkflowControllerTest.java

index 91995bd..34ecb89 100644 (file)
@@ -59,7 +59,7 @@ public class WorkflowVersionController {
     private final WorkflowVersionManager workflowVersionManager;
     private Validator validator;
 
-    @InitBinder
+    @InitBinder("WorkflowVersion")
     private void initBinder(WebDataBinder binder) {
         binder.addValidators(validator);
     }
index 72e6277..b2fc6f5 100644 (file)
@@ -30,8 +30,8 @@ public class Workflow {
 
     private String id;
     @NotNull(message = "Workflow name may not be null")
-    @Size(min = 6, max = 30, message = "The field must be at least 6 characters, and less than 30 characters")
-    @Pattern(regexp = "[A-Za-z0-9_]*", message = "The field must contain only letters, digits and underscores")
+    @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")
     private String name;
     private String description;
     private Set<WorkflowVersionState> versionStates;
index 5e7df48..337fea7 100644 (file)
@@ -257,6 +257,18 @@ public class WorkflowControllerTest {
         verify(workflowManagerMock).create(reqWorkflow);
     }
 
+    @Test
+    public void shouldThrowExceptionWhenWorkflowNameInvalid() throws Exception {
+
+        Workflow reqWorkflow = new Workflow();
+        reqWorkflow.setName("Invalid workflow name %");
+        MockHttpServletResponse response = mockMvc.perform(
+                post(RestPath.getWorkflowsPath()).header(USER_ID_HEADER_PARAM, USER_ID).contentType(APPLICATION_JSON)
+                                                 .content(GSON.toJson(reqWorkflow))).andDo(print())
+                                                  .andExpect(status().isBadRequest()).andReturn().getResponse();
+        assertEquals("Workflow name must contain only letters, digits and underscores", response.getContentAsString());
+    }
+
     private List<Workflow> createWorkflows(int numOfWorkflows) {
         List<Workflow> workflowList = new ArrayList<>(numOfWorkflows);
         for (int i = 0; i < numOfWorkflows; i++) {