use of com.synopsys.integration.alert.common.descriptor.DescriptorMap in project hub-alert by blackducksoftware.
the class PhoneHomeTest method runTest.
@Test
public void runTest() {
RestApiAuditAccessor auditAccessor = Mockito.mock(RestApiAuditAccessor.class);
Mockito.when(auditAccessor.findFirstByJobId(Mockito.any())).thenReturn(Optional.empty());
TaskScheduler taskScheduler = Mockito.mock(TaskScheduler.class);
ProxyManager proxyManager = Mockito.mock(ProxyManager.class);
Mockito.when(proxyManager.createProxyInfoForHost(Mockito.anyString())).thenReturn(ProxyInfo.NO_PROXY_INFO);
AboutReader aboutReader = Mockito.mock(AboutReader.class);
Mockito.when(aboutReader.getProductVersion()).thenReturn(TEST_VERSION);
JobAccessor jobAccessor = Mockito.mock(JobAccessor.class);
// FIXME implement mocks
DefaultConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(DefaultConfigurationModelConfigurationAccessor.class);
ConfigurationModel config = Mockito.mock(ConfigurationModel.class);
Mockito.when(configurationModelConfigurationAccessor.getConfigurationsByDescriptorKey(Mockito.any(DescriptorKey.class))).thenReturn(List.of(config));
DescriptorMap descriptorMap = Mockito.mock(DescriptorMap.class);
Descriptor descriptor = Mockito.mock(Descriptor.class);
DescriptorKey descriptorKey = Mockito.mock(DescriptorKey.class);
Mockito.when(descriptorKey.getUniversalKey()).thenReturn(TEST_DESCRIPTOR_NAME);
Mockito.when(descriptorMap.getDescriptorMap()).thenReturn(Collections.singletonMap(descriptorKey, descriptor));
List<ProviderPhoneHomeHandler> providerHandlers = List.of();
ProviderKey providerKey = new BlackDuckProviderKey();
PhoneHomeTask phoneHomeTask = new PhoneHomeTask(taskScheduler, aboutReader, jobAccessor, configurationModelConfigurationAccessor, null, proxyManager, new Gson(), auditAccessor, providerHandlers, providerKey);
try {
phoneHomeTask.run();
} catch (Exception e) {
fail("Unexpected exception");
}
}
use of com.synopsys.integration.alert.common.descriptor.DescriptorMap 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.descriptor.DescriptorMap 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);
}
use of com.synopsys.integration.alert.common.descriptor.DescriptorMap in project hub-alert by blackducksoftware.
the class GlobalConfigurationModelToConcreteConversionServiceTest method deleteDescriptorFoundTest.
@Test
void deleteDescriptorFoundTest() {
TestSaveActions saveActions = new TestSaveActions(testDescriptorKey);
DescriptorMap descriptorMap = new DescriptorMap(List.of(testDescriptorKey), List.of());
List<GlobalConfigurationModelToConcreteSaveActions> fieldModelSaveActions = List.of(saveActions);
String timestamp = DateUtils.createCurrentDateString(DateUtils.UTC_DATE_FORMAT_TO_MINUTE);
ConfigurationModel configurationModel = new ConfigurationModel(1L, 1L, timestamp, timestamp, ConfigContextEnum.GLOBAL, Map.of());
GlobalConfigurationModelToConcreteConversionService conversionService = new GlobalConfigurationModelToConcreteConversionService(fieldModelSaveActions, descriptorMap);
conversionService.deleteDefaultConcreteModel(TEST_DESCRIPTOR_KEY, configurationModel);
assertTrue(saveActions.wasDeleteCalled());
}
use of com.synopsys.integration.alert.common.descriptor.DescriptorMap in project hub-alert by blackducksoftware.
the class GlobalConfigurationModelToConcreteConversionServiceTest method createdDescriptorFoundTest.
@Test
void createdDescriptorFoundTest() {
TestSaveActions saveActions = new TestSaveActions(testDescriptorKey);
DescriptorMap descriptorMap = new DescriptorMap(List.of(testDescriptorKey), List.of());
List<GlobalConfigurationModelToConcreteSaveActions> fieldModelSaveActions = List.of(saveActions);
String timestamp = DateUtils.createCurrentDateString(DateUtils.UTC_DATE_FORMAT_TO_MINUTE);
ConfigurationModel configurationModel = new ConfigurationModel(1L, 1L, timestamp, timestamp, ConfigContextEnum.GLOBAL, Map.of());
GlobalConfigurationModelToConcreteConversionService conversionService = new GlobalConfigurationModelToConcreteConversionService(fieldModelSaveActions, descriptorMap);
conversionService.createDefaultConcreteModel(TEST_DESCRIPTOR_KEY, configurationModel);
assertTrue(saveActions.wasCreatedCalled());
}
Aggregations