Search in sources :

Example 1 with ValidationError

use of com.netflix.conductor.common.validation.ValidationError in project conductor by Netflix.

the class AbstractHttpEndToEndTest method testUpdateWorkflowDefNameNull.

@Test(expected = ConductorClientException.class)
public void testUpdateWorkflowDefNameNull() {
    WorkflowDef workflowDef = new WorkflowDef();
    List<WorkflowDef> list = new ArrayList<>();
    list.add(workflowDef);
    try {
        metadataClient.updateWorkflowDefs(list);
    } catch (ConductorClientException e) {
        assertEquals(3, e.getValidationErrors().size());
        assertEquals(400, e.getStatus());
        assertEquals("Validation failed, check below errors for detail.", e.getMessage());
        assertFalse(e.isRetryable());
        List<ValidationError> errors = e.getValidationErrors();
        List<String> errorMessages = errors.stream().map(ValidationError::getMessage).collect(Collectors.toList());
        assertTrue(errorMessages.contains("WorkflowDef name cannot be null or empty"));
        assertTrue(errorMessages.contains("WorkflowTask list cannot be empty"));
        assertTrue(errorMessages.contains("ownerEmail cannot be empty"));
        throw e;
    }
}
Also used : WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ValidationError(com.netflix.conductor.common.validation.ValidationError) ConductorClientException(com.netflix.conductor.client.exceptions.ConductorClientException) Test(org.junit.Test)

Example 2 with ValidationError

use of com.netflix.conductor.common.validation.ValidationError in project conductor by Netflix.

the class AbstractHttpEndToEndTest method testEmptyCreateWorkflowDef.

@Test(expected = ConductorClientException.class)
public void testEmptyCreateWorkflowDef() {
    try {
        WorkflowDef workflowDef = new WorkflowDef();
        metadataClient.registerWorkflowDef(workflowDef);
    } catch (ConductorClientException e) {
        assertEquals(400, e.getStatus());
        assertEquals("Validation failed, check below errors for detail.", e.getMessage());
        assertFalse(e.isRetryable());
        List<ValidationError> errors = e.getValidationErrors();
        List<String> errorMessages = errors.stream().map(ValidationError::getMessage).collect(Collectors.toList());
        assertTrue(errorMessages.contains("WorkflowDef name cannot be null or empty"));
        assertTrue(errorMessages.contains("WorkflowTask list cannot be empty"));
        throw e;
    }
}
Also used : WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) ArrayList(java.util.ArrayList) List(java.util.List) ValidationError(com.netflix.conductor.common.validation.ValidationError) ConductorClientException(com.netflix.conductor.client.exceptions.ConductorClientException) Test(org.junit.Test)

Example 3 with ValidationError

use of com.netflix.conductor.common.validation.ValidationError in project conductor by Netflix.

the class AbstractHttpEndToEndTest method testCreateInvalidWorkflowDef.

@Test(expected = ConductorClientException.class)
public void testCreateInvalidWorkflowDef() {
    try {
        WorkflowDef workflowDef = new WorkflowDef();
        List<WorkflowDef> workflowDefList = new ArrayList<>();
        workflowDefList.add(workflowDef);
        metadataClient.registerWorkflowDef(workflowDef);
    } catch (ConductorClientException e) {
        assertEquals(3, e.getValidationErrors().size());
        assertEquals(400, e.getStatus());
        assertEquals("Validation failed, check below errors for detail.", e.getMessage());
        assertFalse(e.isRetryable());
        List<ValidationError> errors = e.getValidationErrors();
        List<String> errorMessages = errors.stream().map(ValidationError::getMessage).collect(Collectors.toList());
        assertTrue(errorMessages.contains("WorkflowDef name cannot be null or empty"));
        assertTrue(errorMessages.contains("WorkflowTask list cannot be empty"));
        assertTrue(errorMessages.contains("ownerEmail cannot be empty"));
        throw e;
    }
}
Also used : WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ValidationError(com.netflix.conductor.common.validation.ValidationError) ConductorClientException(com.netflix.conductor.client.exceptions.ConductorClientException) Test(org.junit.Test)

Example 4 with ValidationError

use of com.netflix.conductor.common.validation.ValidationError in project conductor by Netflix.

the class AbstractHttpEndToEndTest method testUpdateWorkflowDef.

@Test(expected = ConductorClientException.class)
public void testUpdateWorkflowDef() {
    try {
        WorkflowDef workflowDef = new WorkflowDef();
        List<WorkflowDef> workflowDefList = new ArrayList<>();
        workflowDefList.add(workflowDef);
        metadataClient.updateWorkflowDefs(workflowDefList);
    } catch (ConductorClientException e) {
        assertEquals(400, e.getStatus());
        assertEquals("Validation failed, check below errors for detail.", e.getMessage());
        assertFalse(e.isRetryable());
        List<ValidationError> errors = e.getValidationErrors();
        List<String> errorMessages = errors.stream().map(ValidationError::getMessage).collect(Collectors.toList());
        assertEquals(3, errors.size());
        assertTrue(errorMessages.contains("WorkflowTask list cannot be empty"));
        assertTrue(errorMessages.contains("WorkflowDef name cannot be null or empty"));
        assertTrue(errorMessages.contains("ownerEmail cannot be empty"));
        throw e;
    }
}
Also used : WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ValidationError(com.netflix.conductor.common.validation.ValidationError) ConductorClientException(com.netflix.conductor.client.exceptions.ConductorClientException) Test(org.junit.Test)

Example 5 with ValidationError

use of com.netflix.conductor.common.validation.ValidationError in project conductor by Netflix.

the class ValidationExceptionMapper method constraintViolationExceptionToErrorResponse.

private static ErrorResponse constraintViolationExceptionToErrorResponse(ConstraintViolationException exception) {
    ErrorResponse errorResponse = new ErrorResponse();
    errorResponse.setStatus(Response.Status.BAD_REQUEST.getStatusCode());
    errorResponse.setMessage("Validation failed, check below errors for detail.");
    List<ValidationError> validationErrors = new ArrayList<>();
    exception.getConstraintViolations().forEach(e -> validationErrors.add(new ValidationError(getViolationPath(e), e.getMessage(), getViolationInvalidValue(e.getInvalidValue()))));
    errorResponse.setValidationErrors(validationErrors);
    return errorResponse;
}
Also used : ArrayList(java.util.ArrayList) ValidationError(com.netflix.conductor.common.validation.ValidationError) ErrorResponse(com.netflix.conductor.common.validation.ErrorResponse)

Aggregations

ValidationError (com.netflix.conductor.common.validation.ValidationError)5 ArrayList (java.util.ArrayList)5 ConductorClientException (com.netflix.conductor.client.exceptions.ConductorClientException)4 WorkflowDef (com.netflix.conductor.common.metadata.workflow.WorkflowDef)4 List (java.util.List)4 Test (org.junit.Test)4 ErrorResponse (com.netflix.conductor.common.validation.ErrorResponse)1