Search in sources :

Example 1 with DescriptorMap

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");
    }
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) BlackDuckProviderKey(com.synopsys.integration.alert.descriptor.api.BlackDuckProviderKey) PhoneHomeTask(com.synopsys.integration.alert.task.PhoneHomeTask) ProxyManager(com.synopsys.integration.alert.common.rest.proxy.ProxyManager) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) Gson(com.google.gson.Gson) TaskScheduler(org.springframework.scheduling.TaskScheduler) ProviderPhoneHomeHandler(com.synopsys.integration.alert.api.provider.ProviderPhoneHomeHandler) AboutReader(com.synopsys.integration.alert.web.api.about.AboutReader) JobAccessor(com.synopsys.integration.alert.common.persistence.accessor.JobAccessor) DescriptorMap(com.synopsys.integration.alert.common.descriptor.DescriptorMap) ProviderKey(com.synopsys.integration.alert.descriptor.api.model.ProviderKey) BlackDuckProviderKey(com.synopsys.integration.alert.descriptor.api.BlackDuckProviderKey) Descriptor(com.synopsys.integration.alert.common.descriptor.Descriptor) RestApiAuditAccessor(com.synopsys.integration.alert.common.persistence.accessor.RestApiAuditAccessor) DefaultConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.database.api.DefaultConfigurationModelConfigurationAccessor) Test(org.junit.jupiter.api.Test)

Example 2 with DescriptorMap

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());
}
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 3 with DescriptorMap

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

Example 4 with DescriptorMap

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());
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) DescriptorMap(com.synopsys.integration.alert.common.descriptor.DescriptorMap) GlobalConfigurationModelToConcreteSaveActions(com.synopsys.integration.alert.common.action.api.GlobalConfigurationModelToConcreteSaveActions) Test(org.junit.jupiter.api.Test)

Example 5 with DescriptorMap

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());
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) DescriptorMap(com.synopsys.integration.alert.common.descriptor.DescriptorMap) GlobalConfigurationModelToConcreteSaveActions(com.synopsys.integration.alert.common.action.api.GlobalConfigurationModelToConcreteSaveActions) Test(org.junit.jupiter.api.Test)

Aggregations

DescriptorMap (com.synopsys.integration.alert.common.descriptor.DescriptorMap)21 Test (org.junit.jupiter.api.Test)20 GlobalConfigurationModelToConcreteSaveActions (com.synopsys.integration.alert.common.action.api.GlobalConfigurationModelToConcreteSaveActions)12 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)12 DescriptorProcessor (com.synopsys.integration.alert.common.descriptor.DescriptorProcessor)11 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)11 ConfigurationModelConfigurationAccessor (com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor)11 DescriptorAccessor (com.synopsys.integration.alert.common.persistence.accessor.DescriptorAccessor)11 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)11 ConfigurationFieldModelConverter (com.synopsys.integration.alert.common.persistence.util.ConfigurationFieldModelConverter)11 FieldModelProcessor (com.synopsys.integration.alert.common.rest.FieldModelProcessor)11 Descriptor (com.synopsys.integration.alert.common.descriptor.Descriptor)7 EncryptionUtility (com.synopsys.integration.alert.common.security.EncryptionUtility)7 AuthorizationManager (com.synopsys.integration.alert.common.security.authorization.AuthorizationManager)7 PKIXErrorResponseFactory (com.synopsys.integration.alert.component.certificates.web.PKIXErrorResponseFactory)7 SettingsDescriptorKey (com.synopsys.integration.alert.component.settings.descriptor.SettingsDescriptorKey)7 BeforeEach (org.junit.jupiter.api.BeforeEach)7 AlertConfigurationException (com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)6 ChannelDescriptor (com.synopsys.integration.alert.common.descriptor.ChannelDescriptor)6 FieldModel (com.synopsys.integration.alert.common.rest.model.FieldModel)6