Search in sources :

Example 11 with JobFieldModel

use of com.synopsys.integration.alert.common.rest.model.JobFieldModel 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 12 with JobFieldModel

use of com.synopsys.integration.alert.common.rest.model.JobFieldModel in project hub-alert by blackducksoftware.

the class JobConfigActionsTest method createServerErrorTest.

@Test
public void createServerErrorTest() throws Exception {
    Mockito.doThrow(new AlertException("Exception for test")).when(mockedFieldModelProcessor).performBeforeSaveAction(Mockito.any());
    ActionResponse<JobFieldModel> jobFieldModelActionResponse = defaultJobConfigActions.create(jobFieldModel);
    assertTrue(jobFieldModelActionResponse.isError());
    assertFalse(jobFieldModelActionResponse.hasContent());
    assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, jobFieldModelActionResponse.getHttpStatus());
}
Also used : JobFieldModel(com.synopsys.integration.alert.common.rest.model.JobFieldModel) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) Test(org.junit.jupiter.api.Test)

Example 13 with JobFieldModel

use of com.synopsys.integration.alert.common.rest.model.JobFieldModel in project hub-alert by blackducksoftware.

the class JobConfigActionsTest method updateServerErrorTest.

@Test
public void updateServerErrorTest() throws Exception {
    Mockito.when(mockedJobAccessor.getJobById(jobId)).thenReturn(Optional.of(distributionJobModel));
    Mockito.doThrow(new AlertConfigurationException("Exception for Alert test")).when(mockedFieldModelProcessor).performBeforeUpdateAction(Mockito.any());
    ActionResponse<JobFieldModel> jobFieldModelActionResponse = defaultJobConfigActions.update(jobId, jobFieldModel);
    assertTrue(jobFieldModelActionResponse.isError());
    assertFalse(jobFieldModelActionResponse.hasContent());
    assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, jobFieldModelActionResponse.getHttpStatus());
}
Also used : JobFieldModel(com.synopsys.integration.alert.common.rest.model.JobFieldModel) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException) Test(org.junit.jupiter.api.Test)

Example 14 with JobFieldModel

use of com.synopsys.integration.alert.common.rest.model.JobFieldModel in project hub-alert by blackducksoftware.

the class JobConfigActionsTest method getOneErrorTest.

@Test
public void getOneErrorTest() throws Exception {
    Mockito.doThrow(new AlertException("Exception for Alert")).when(mockedFieldModelProcessor).performAfterReadAction(Mockito.any());
    ActionResponse<JobFieldModel> jobFieldModelActionResponse = defaultJobConfigActions.getOne(jobId);
    assertTrue(jobFieldModelActionResponse.isError());
    assertFalse(jobFieldModelActionResponse.hasContent());
    assertEquals(HttpStatus.NOT_FOUND, jobFieldModelActionResponse.getHttpStatus());
}
Also used : JobFieldModel(com.synopsys.integration.alert.common.rest.model.JobFieldModel) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) Test(org.junit.jupiter.api.Test)

Example 15 with JobFieldModel

use of com.synopsys.integration.alert.common.rest.model.JobFieldModel in project hub-alert by blackducksoftware.

the class JobConfigActionsTest method init.

@BeforeEach
public void init() {
    this.descriptorKey = new DescriptorKey(DESCRIPTOR_KEY_STRING, "Universal Key") {
    };
    this.descriptor = createDescriptor(Optional::empty, Optional::empty);
    this.descriptorMap = new DescriptorMap(List.of(descriptorKey), List.of(descriptor));
    this.fieldModel = createFieldModel();
    this.distributionJobModel = createDistributionJobModel();
    this.jobId = distributionJobModel.getJobId();
    this.jobFieldModel = new JobFieldModel(UUID.randomUUID().toString(), Set.of(fieldModel), List.of());
    this.configurationFieldModel = ConfigurationFieldModel.create(ProviderDescriptor.KEY_PROVIDER_CONFIG_NAME);
    this.configurationFieldModel.setFieldValue(FIELD_VALUE);
    mockedAuthorizationManager = Mockito.mock(AuthorizationManager.class);
    mockedDescriptorAccessor = Mockito.mock(DescriptorAccessor.class);
    mockedConfigurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
    mockedJobAccessor = Mockito.mock(JobAccessor.class);
    mockedFieldModelProcessor = Mockito.mock(FieldModelProcessor.class);
    mockedDescriptorProcessor = Mockito.mock(DescriptorProcessor.class);
    mockedConfigurationFieldModelConverter = Mockito.mock(ConfigurationFieldModelConverter.class);
    mockedGlobalConfigExistsValidator = Mockito.mock(GlobalConfigExistsValidator.class);
    mockedPkixErrorResponseFactory = Mockito.mock(PKIXErrorResponseFactory.class);
    mockedJobModelExtractor = Mockito.mock(DistributionJobModelExtractor.class);
    Mockito.when(mockedJobModelExtractor.convertToJobModel(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.anyList())).thenReturn(distributionJobModel);
    defaultJobConfigActions = createJobConfigActions(descriptorMap, List.of());
    Mockito.when(mockedAuthorizationManager.hasCreatePermission(Mockito.any(ConfigContextEnum.class), Mockito.eq(descriptorKey))).thenReturn(true);
    Mockito.when(mockedAuthorizationManager.hasReadPermission(Mockito.any(ConfigContextEnum.class), Mockito.eq(descriptorKey))).thenReturn(true);
    Mockito.when(mockedAuthorizationManager.anyReadPermission(Mockito.any(), Mockito.any())).thenReturn(true);
    Mockito.when(mockedAuthorizationManager.hasWritePermission(Mockito.any(ConfigContextEnum.class), Mockito.eq(descriptorKey))).thenReturn(true);
    Mockito.when(mockedAuthorizationManager.hasDeletePermission(Mockito.any(ConfigContextEnum.class), Mockito.eq(descriptorKey))).thenReturn(true);
    Mockito.when(mockedAuthorizationManager.hasExecutePermission(Mockito.any(ConfigContextEnum.class), Mockito.eq(descriptorKey))).thenReturn(true);
    Mockito.when(mockedAuthorizationManager.hasCreatePermission(Mockito.anyString(), Mockito.anyString())).thenReturn(true);
    Mockito.when(mockedAuthorizationManager.hasReadPermission(Mockito.anyString(), Mockito.anyString())).thenReturn(true);
    Mockito.when(mockedAuthorizationManager.hasWritePermission(Mockito.anyString(), Mockito.anyString())).thenReturn(true);
    Mockito.when(mockedAuthorizationManager.hasDeletePermission(Mockito.anyString(), Mockito.anyString())).thenReturn(true);
    Mockito.when(mockedAuthorizationManager.hasExecutePermission(Mockito.anyString(), Mockito.anyString())).thenReturn(true);
}
Also used : FieldModelProcessor(com.synopsys.integration.alert.common.rest.FieldModelProcessor) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) JobFieldModel(com.synopsys.integration.alert.common.rest.model.JobFieldModel) DescriptorAccessor(com.synopsys.integration.alert.common.persistence.accessor.DescriptorAccessor) ConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor) ConfigurationFieldModelConverter(com.synopsys.integration.alert.common.persistence.util.ConfigurationFieldModelConverter) GlobalConfigExistsValidator(com.synopsys.integration.alert.common.descriptor.config.GlobalConfigExistsValidator) PKIXErrorResponseFactory(com.synopsys.integration.alert.component.certificates.web.PKIXErrorResponseFactory) DescriptorMap(com.synopsys.integration.alert.common.descriptor.DescriptorMap) JobAccessor(com.synopsys.integration.alert.common.persistence.accessor.JobAccessor) DescriptorProcessor(com.synopsys.integration.alert.common.descriptor.DescriptorProcessor) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) ConfigContextEnum(com.synopsys.integration.alert.common.enumeration.ConfigContextEnum) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

JobFieldModel (com.synopsys.integration.alert.common.rest.model.JobFieldModel)32 ActionResponse (com.synopsys.integration.alert.common.action.ActionResponse)13 ValidationActionResponse (com.synopsys.integration.alert.common.action.ValidationActionResponse)13 DistributionJobModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel)12 FieldModel (com.synopsys.integration.alert.common.rest.model.FieldModel)12 JobProviderProjectFieldModel (com.synopsys.integration.alert.common.rest.model.JobProviderProjectFieldModel)12 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)11 Test (org.junit.jupiter.api.Test)11 AlertFieldStatus (com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus)9 ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)8 FieldValueModel (com.synopsys.integration.alert.common.rest.model.FieldValueModel)7 JobPagedModel (com.synopsys.integration.alert.common.rest.model.JobPagedModel)7 HashMap (java.util.HashMap)7 Set (java.util.Set)7 DescriptorMap (com.synopsys.integration.alert.common.descriptor.DescriptorMap)6 DescriptorProcessor (com.synopsys.integration.alert.common.descriptor.DescriptorProcessor)6 GlobalConfigExistsValidator (com.synopsys.integration.alert.common.descriptor.config.GlobalConfigExistsValidator)6 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)6 ConfigurationModelConfigurationAccessor (com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor)6 DescriptorAccessor (com.synopsys.integration.alert.common.persistence.accessor.DescriptorAccessor)6