use of com.synopsys.integration.alert.common.action.ValidationActionResponse in project hub-alert by blackducksoftware.
the class JobConfigActionsTest method validateBadRequestWithFieldStatusTest.
@Test
public void validateBadRequestWithFieldStatusTest() {
AlertFieldStatus alertFieldStatus = AlertFieldStatus.error("fieldNameTest", "Alert Error Message");
Descriptor mockDescriptor = Mockito.mock(Descriptor.class);
Mockito.when(mockDescriptor.getDistributionValidator()).thenReturn(Optional.of(ignoredJobFieldModel -> Set.of(alertFieldStatus)));
DescriptorMap mockDescriptorMap = Mockito.mock(DescriptorMap.class);
Mockito.when(mockDescriptorMap.getDescriptorKey(Mockito.anyString())).thenReturn(Optional.of(descriptorKey));
Mockito.when(mockDescriptorMap.getDescriptor(descriptorKey)).thenReturn(Optional.of(mockDescriptor));
JobConfigActions testJobConfigActions = new JobConfigActions(mockedAuthorizationManager, null, null, mockedJobAccessor, null, null, null, null, null, mockDescriptorMap, null, List.of(), null);
ValidationActionResponse validationActionResponse = testJobConfigActions.validate(jobFieldModel);
assertTrue(validationActionResponse.isSuccessful());
assertEquals(HttpStatus.OK, validationActionResponse.getHttpStatus());
assertTrue(validationActionResponse.hasContent());
ValidationResponseModel validationResponseModel = validationActionResponse.getContent().get();
assertTrue(validationResponseModel.hasErrors());
}
use of com.synopsys.integration.alert.common.action.ValidationActionResponse in project hub-alert by blackducksoftware.
the class JobConfigActionsTest method testAlertFieldExceptionTest.
@Test
public void testAlertFieldExceptionTest() throws Exception {
Mockito.when(mockedDescriptorProcessor.retrieveDescriptor(Mockito.any())).thenReturn(Optional.of(descriptor));
AlertFieldStatus alertFieldStatus = AlertFieldStatus.error("fieldNameTest", "Alert Error Message");
Mockito.doThrow(new AlertFieldException("AlertFieldException for Alert test", List.of(alertFieldStatus))).when(mockedFieldModelProcessor).createCustomMessageFieldModel(Mockito.any());
ValidationActionResponse validationActionResponse = defaultJobConfigActions.test(jobFieldModel);
assertTrue(validationActionResponse.isSuccessful());
assertEquals(HttpStatus.OK, validationActionResponse.getHttpStatus());
assertTrue(validationActionResponse.hasContent());
ValidationResponseModel validationResponseModel = validationActionResponse.getContent().get();
assertTrue(validationResponseModel.hasErrors());
}
use of com.synopsys.integration.alert.common.action.ValidationActionResponse in project hub-alert by blackducksoftware.
the class JobConfigActionsTest method testExceptionTest.
@Test
public void testExceptionTest() throws Exception {
Mockito.when(mockedDescriptorProcessor.retrieveDescriptor(Mockito.any())).thenReturn(Optional.of(descriptor));
Mockito.doThrow(new NullPointerException("RuntimeException for Alert test")).when(mockedFieldModelProcessor).createCustomMessageFieldModel(Mockito.any());
ValidationActionResponse validationActionResponse = defaultJobConfigActions.test(jobFieldModel);
assertTrue(validationActionResponse.isSuccessful());
assertEquals(HttpStatus.OK, validationActionResponse.getHttpStatus());
assertTrue(validationActionResponse.hasContent());
ValidationResponseModel validationResponseModel = validationActionResponse.getContent().get();
assertTrue(validationResponseModel.hasErrors());
}
use of com.synopsys.integration.alert.common.action.ValidationActionResponse in project hub-alert by blackducksoftware.
the class ConfigActions method testWithoutChecks.
@Override
protected ValidationActionResponse testWithoutChecks(FieldModel resource) {
Optional<FieldModelTestAction> testActionOptional = descriptorProcessor.retrieveTestAction(resource);
ValidationResponseModel responseModel;
if (testActionOptional.isPresent()) {
try {
FieldModel upToDateFieldModel = fieldModelProcessor.createCustomMessageFieldModel(resource);
FieldUtility fieldUtility = modelConverter.convertToFieldAccessor(upToDateFieldModel);
FieldModelTestAction fieldModelTestAction = testActionOptional.get();
// TODO return the message from the result of testAction.testConfig(...)
fieldModelTestAction.testConfig(upToDateFieldModel.getId(), upToDateFieldModel, fieldUtility);
responseModel = ValidationResponseModel.success("Successfully sent test message.");
return new ValidationActionResponse(HttpStatus.OK, responseModel);
} catch (IntegrationRestException e) {
logger.error(e.getMessage(), e);
return ValidationActionResponse.createResponseFromIntegrationRestException(e);
} catch (AlertFieldException e) {
logger.error("Test Error with field Errors", e);
responseModel = ValidationResponseModel.fromStatusCollection(e.getMessage(), e.getFieldErrors());
return new ValidationActionResponse(HttpStatus.OK, responseModel);
} catch (IntegrationException e) {
// FIXME there are definitely other possibilities than this
responseModel = pkixErrorResponseFactory.createSSLExceptionResponse(e).orElse(ValidationResponseModel.generalError(e.getMessage()));
return new ValidationActionResponse(HttpStatus.OK, responseModel);
} catch (Exception e) {
logger.error(e.getMessage(), e);
responseModel = pkixErrorResponseFactory.createSSLExceptionResponse(e).orElse(ValidationResponseModel.generalError(e.getMessage()));
return new ValidationActionResponse(HttpStatus.OK, responseModel);
}
}
String descriptorName = resource.getDescriptorName();
responseModel = ValidationResponseModel.generalError("Test functionality not implemented for " + descriptorName);
return new ValidationActionResponse(HttpStatus.NOT_IMPLEMENTED, responseModel);
}
use of com.synopsys.integration.alert.common.action.ValidationActionResponse in project hub-alert by blackducksoftware.
the class RoleActions method validateWithoutChecks.
@Override
protected ValidationActionResponse validateWithoutChecks(RolePermissionModel resource) {
ValidationResponseModel responseModel;
List<AlertFieldStatus> alertFieldStatus = fullyValidateRoleNameField(resource);
if (alertFieldStatus.isEmpty()) {
responseModel = ValidationResponseModel.success("The role name is valid");
return new ValidationActionResponse(HttpStatus.OK, responseModel);
}
responseModel = ValidationResponseModel.fromStatusCollection("There were problems with the role configuration", alertFieldStatus);
return new ValidationActionResponse(HttpStatus.BAD_REQUEST, responseModel);
}
Aggregations