Search in sources :

Example 86 with ValidationResponseModel

use of com.synopsys.integration.alert.api.common.model.ValidationResponseModel in project blackduck-alert by blackducksoftware.

the class JobConfigActionsTest method validateBadRequestWithFieldStatusTest.

@Test
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) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) AlertFieldStatus(com.synopsys.integration.alert.api.common.model.errors.AlertFieldStatus) 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) 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) ValidationResponseModel(com.synopsys.integration.alert.api.common.model.ValidationResponseModel) 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.api.common.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.api.common.model.errors.AlertFieldStatus) Test(org.junit.jupiter.api.Test)

Example 87 with ValidationResponseModel

use of com.synopsys.integration.alert.api.common.model.ValidationResponseModel in project hub-alert by blackducksoftware.

the class SettingsProxyTestActionTestIT method testWithPermissionCheckTest.

@Test
void testWithPermissionCheckTest() {
    SettingsProxyModel settingsProxyModel = createSettingsProxyModel(testProperties);
    AuthorizationManager authorizationManager = createAuthorizationManager(AuthenticationTestUtils.FULL_PERMISSIONS);
    settingsProxyTestAction = new SettingsProxyTestAction(authorizationManager, settingsProxyValidator, settingsDescriptorKey, proxyTestService, settingsProxyConfigAccessor);
    ActionResponse<ValidationResponseModel> testResult = settingsProxyTestAction.testWithPermissionCheck(validTargetUrl, settingsProxyModel);
    assertTrue(testResult.isSuccessful());
    assertTrue(testResult.getContent().isPresent());
    ValidationResponseModel validationResponseModel = testResult.getContent().get();
    assertFalse(validationResponseModel.hasErrors());
}
Also used : ValidationResponseModel(com.synopsys.integration.alert.api.common.model.ValidationResponseModel) SettingsProxyTestAction(com.synopsys.integration.alert.component.settings.proxy.action.SettingsProxyTestAction) SettingsProxyModel(com.synopsys.integration.alert.common.rest.model.SettingsProxyModel) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 88 with ValidationResponseModel

use of com.synopsys.integration.alert.api.common.model.ValidationResponseModel in project hub-alert by blackducksoftware.

the class SettingsProxyTestActionTestIT method testWithoutPermissionsCheckTest.

@Test
void testWithoutPermissionsCheckTest() {
    SettingsProxyModel settingsProxyModel = createSettingsProxyModel(testProperties);
    AuthorizationManager authorizationManager = createAuthorizationManager(AuthenticationTestUtils.NO_PERMISSIONS);
    settingsProxyTestAction = new SettingsProxyTestAction(authorizationManager, settingsProxyValidator, settingsDescriptorKey, proxyTestService, settingsProxyConfigAccessor);
    ActionResponse<ValidationResponseModel> testResult = settingsProxyTestAction.testWithPermissionCheck(validTargetUrl, settingsProxyModel);
    assertTrue(testResult.isError());
    assertTrue(testResult.getContent().isPresent());
    ValidationResponseModel validationResponseModel = testResult.getContent().get();
    assertTrue(validationResponseModel.hasErrors());
}
Also used : ValidationResponseModel(com.synopsys.integration.alert.api.common.model.ValidationResponseModel) SettingsProxyTestAction(com.synopsys.integration.alert.component.settings.proxy.action.SettingsProxyTestAction) SettingsProxyModel(com.synopsys.integration.alert.common.rest.model.SettingsProxyModel) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 89 with ValidationResponseModel

use of com.synopsys.integration.alert.api.common.model.ValidationResponseModel in project hub-alert by blackducksoftware.

the class SettingsProxyTestActionTestIT method testValidationFailureTest.

@Test
void testValidationFailureTest() {
    SettingsProxyModel settingsProxyModel = new SettingsProxyModel();
    AuthorizationManager authorizationManager = createAuthorizationManager(AuthenticationTestUtils.FULL_PERMISSIONS);
    settingsProxyTestAction = new SettingsProxyTestAction(authorizationManager, settingsProxyValidator, settingsDescriptorKey, proxyTestService, settingsProxyConfigAccessor);
    ActionResponse<ValidationResponseModel> testResult = settingsProxyTestAction.testWithPermissionCheck(validTargetUrl, settingsProxyModel);
    assertTrue(testResult.isSuccessful());
    assertTrue(testResult.getContent().isPresent());
    ValidationResponseModel validationResponseModel = testResult.getContent().get();
    assertTrue(validationResponseModel.hasErrors());
}
Also used : ValidationResponseModel(com.synopsys.integration.alert.api.common.model.ValidationResponseModel) SettingsProxyTestAction(com.synopsys.integration.alert.component.settings.proxy.action.SettingsProxyTestAction) SettingsProxyModel(com.synopsys.integration.alert.common.rest.model.SettingsProxyModel) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 90 with ValidationResponseModel

use of com.synopsys.integration.alert.api.common.model.ValidationResponseModel in project hub-alert by blackducksoftware.

the class SettingsProxyTestActionTestIT method testConfigurationWithPasswordSaved.

@Test
void testConfigurationWithPasswordSaved() throws AlertConfigurationException {
    SettingsProxyModel settingsProxyModel = createSettingsProxyModel(testProperties);
    settingsProxyConfigAccessor.createConfiguration(createSettingsProxyModel(testProperties));
    settingsProxyModel.setProxyPassword(null);
    settingsProxyModel.setIsProxyPasswordSet(true);
    AuthorizationManager authorizationManager = createAuthorizationManager(AuthenticationTestUtils.FULL_PERMISSIONS);
    settingsProxyTestAction = new SettingsProxyTestAction(authorizationManager, settingsProxyValidator, settingsDescriptorKey, proxyTestService, settingsProxyConfigAccessor);
    ActionResponse<ValidationResponseModel> testResult = settingsProxyTestAction.testWithPermissionCheck(validTargetUrl, settingsProxyModel);
    assertTrue(testResult.isSuccessful());
    assertTrue(testResult.getContent().isPresent());
    ValidationResponseModel validationResponseModel = testResult.getContent().get();
    assertFalse(validationResponseModel.hasErrors());
}
Also used : ValidationResponseModel(com.synopsys.integration.alert.api.common.model.ValidationResponseModel) SettingsProxyTestAction(com.synopsys.integration.alert.component.settings.proxy.action.SettingsProxyTestAction) SettingsProxyModel(com.synopsys.integration.alert.common.rest.model.SettingsProxyModel) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

ValidationResponseModel (com.synopsys.integration.alert.api.common.model.ValidationResponseModel)179 Test (org.junit.jupiter.api.Test)139 ValidationActionResponse (com.synopsys.integration.alert.common.action.ValidationActionResponse)66 AlertFieldStatus (com.synopsys.integration.alert.api.common.model.errors.AlertFieldStatus)54 AuthorizationManager (com.synopsys.integration.alert.common.security.authorization.AuthorizationManager)50 SettingsProxyModel (com.synopsys.integration.alert.common.rest.model.SettingsProxyModel)36 EmailGlobalConfigModel (com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel)29 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)26 JiraServerGlobalConfigAccessor (com.synopsys.integration.alert.channel.jira.server.database.accessor.JiraServerGlobalConfigAccessor)20 ActionResponse (com.synopsys.integration.alert.common.action.ActionResponse)18 SettingsProxyTestAction (com.synopsys.integration.alert.component.settings.proxy.action.SettingsProxyTestAction)18 IntegrationException (com.synopsys.integration.exception.IntegrationException)16 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)14 EmailGlobalConfigurationValidator (com.synopsys.integration.alert.channel.email.validator.EmailGlobalConfigurationValidator)14 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)14 AlertFieldException (com.synopsys.integration.alert.common.exception.AlertFieldException)14 PermissionKey (com.synopsys.integration.alert.common.persistence.model.PermissionKey)14 AlertIntegrationTest (com.synopsys.integration.alert.util.AlertIntegrationTest)14 IntegrationRestException (com.synopsys.integration.rest.exception.IntegrationRestException)14 AlertConfigurationException (com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)12