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());
}
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());
}
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());
}
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());
}
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);
}
Aggregations