Search in sources :

Example 21 with ValidationActionResponse

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());
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel) IntegrationException(com.synopsys.integration.exception.IntegrationException) DistributionChannelTestAction(com.synopsys.integration.alert.common.channel.DistributionChannelTestAction) AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) FrequencyType(com.synopsys.integration.alert.common.enumeration.FrequencyType) HttpUrl(com.synopsys.integration.rest.HttpUrl) ConfigurationFieldModelConverter(com.synopsys.integration.alert.common.persistence.util.ConfigurationFieldModelConverter) GlobalConfigurationFieldModelValidator(com.synopsys.integration.alert.common.descriptor.validator.GlobalConfigurationFieldModelValidator) JobAccessor(com.synopsys.integration.alert.common.persistence.accessor.JobAccessor) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) Map(java.util.Map) AlertRuntimeException(com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException) JobPagedModel(com.synopsys.integration.alert.common.rest.model.JobPagedModel) Set(java.util.Set) UUID(java.util.UUID) AlertPagedModel(com.synopsys.integration.alert.common.rest.model.AlertPagedModel) Test(org.junit.jupiter.api.Test) FieldUtility(com.synopsys.integration.alert.common.persistence.accessor.FieldUtility) RegisteredDescriptorModel(com.synopsys.integration.alert.common.persistence.model.RegisteredDescriptorModel) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) OffsetDateTime(java.time.OffsetDateTime) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) FieldModelProcessor(com.synopsys.integration.alert.common.rest.FieldModelProcessor) Optional(java.util.Optional) JobFieldStatuses(com.synopsys.integration.alert.common.rest.model.JobFieldStatuses) Descriptor(com.synopsys.integration.alert.common.descriptor.Descriptor) AlertFieldException(com.synopsys.integration.alert.common.exception.AlertFieldException) MessageResult(com.synopsys.integration.alert.common.message.model.MessageResult) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) DescriptorAccessor(com.synopsys.integration.alert.common.persistence.accessor.DescriptorAccessor) ConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor) HashMap(java.util.HashMap) DistributionConfigurationValidator(com.synopsys.integration.alert.common.descriptor.validator.DistributionConfigurationValidator) Supplier(java.util.function.Supplier) PKIXErrorResponseFactory(com.synopsys.integration.alert.component.certificates.web.PKIXErrorResponseFactory) DescriptorMap(com.synopsys.integration.alert.common.descriptor.DescriptorMap) HttpMethod(com.synopsys.integration.rest.HttpMethod) ProcessingType(com.synopsys.integration.alert.common.enumeration.ProcessingType) DescriptorType(com.synopsys.integration.alert.common.enumeration.DescriptorType) ProviderDescriptor(com.synopsys.integration.alert.api.provider.ProviderDescriptor) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) JobIdsRequestModel(com.synopsys.integration.alert.common.rest.model.JobIdsRequestModel) JobFieldModel(com.synopsys.integration.alert.common.rest.model.JobFieldModel) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) ChannelDescriptor(com.synopsys.integration.alert.common.descriptor.ChannelDescriptor) ConfigContextEnum(com.synopsys.integration.alert.common.enumeration.ConfigContextEnum) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) MSTeamsJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.MSTeamsJobDetailsModel) Mockito(org.mockito.Mockito) HttpStatus(org.springframework.http.HttpStatus) IntegrationRestException(com.synopsys.integration.rest.exception.IntegrationRestException) DescriptorProcessor(com.synopsys.integration.alert.common.descriptor.DescriptorProcessor) GlobalConfigExistsValidator(com.synopsys.integration.alert.common.descriptor.config.GlobalConfigExistsValidator) FieldModelTestAction(com.synopsys.integration.alert.common.action.FieldModelTestAction) FieldValueModel(com.synopsys.integration.alert.common.rest.model.FieldValueModel) ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) DescriptorMap(com.synopsys.integration.alert.common.descriptor.DescriptorMap) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) Descriptor(com.synopsys.integration.alert.common.descriptor.Descriptor) ProviderDescriptor(com.synopsys.integration.alert.api.provider.ProviderDescriptor) ChannelDescriptor(com.synopsys.integration.alert.common.descriptor.ChannelDescriptor) AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus) Test(org.junit.jupiter.api.Test)

Example 22 with ValidationActionResponse

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());
}
Also used : ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus) AlertFieldException(com.synopsys.integration.alert.common.exception.AlertFieldException) Test(org.junit.jupiter.api.Test)

Example 23 with ValidationActionResponse

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());
}
Also used : ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) Test(org.junit.jupiter.api.Test)

Example 24 with ValidationActionResponse

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);
}
Also used : ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) FieldModelTestAction(com.synopsys.integration.alert.common.action.FieldModelTestAction) IntegrationRestException(com.synopsys.integration.rest.exception.IntegrationRestException) IntegrationException(com.synopsys.integration.exception.IntegrationException) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) AlertFieldException(com.synopsys.integration.alert.common.exception.AlertFieldException) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) MultiFieldModel(com.synopsys.integration.alert.common.rest.model.MultiFieldModel) FieldUtility(com.synopsys.integration.alert.common.persistence.accessor.FieldUtility) AlertFieldException(com.synopsys.integration.alert.common.exception.AlertFieldException) IntegrationException(com.synopsys.integration.exception.IntegrationException) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) IntegrationRestException(com.synopsys.integration.rest.exception.IntegrationRestException)

Example 25 with ValidationActionResponse

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);
}
Also used : ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus)

Aggregations

ValidationActionResponse (com.synopsys.integration.alert.common.action.ValidationActionResponse)44 ValidationResponseModel (com.synopsys.integration.alert.common.rest.model.ValidationResponseModel)33 Test (org.junit.jupiter.api.Test)28 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)15 AuthorizationManager (com.synopsys.integration.alert.common.security.authorization.AuthorizationManager)13 AlertFieldStatus (com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus)10 ActionResponse (com.synopsys.integration.alert.common.action.ActionResponse)9 PermissionKey (com.synopsys.integration.alert.common.persistence.model.PermissionKey)9 PermissionMatrixModel (com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel)8 ChannelKey (com.synopsys.integration.alert.descriptor.api.model.ChannelKey)8 AuthenticationTestUtils (com.synopsys.integration.alert.test.common.AuthenticationTestUtils)8 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)7 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)7 AlertFieldException (com.synopsys.integration.alert.common.exception.AlertFieldException)7 FieldModel (com.synopsys.integration.alert.common.rest.model.FieldModel)7 FieldModelTestAction (com.synopsys.integration.alert.common.action.FieldModelTestAction)6 FieldUtility (com.synopsys.integration.alert.common.persistence.accessor.FieldUtility)6 ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)6 IntegrationException (com.synopsys.integration.exception.IntegrationException)6 IntegrationRestException (com.synopsys.integration.rest.exception.IntegrationRestException)6