use of com.synopsys.integration.alert.common.persistence.util.ConfigurationFieldModelConverter in project hub-alert by blackducksoftware.
the class EmailConfigActionTestIT method updatePasswordEmailGlobalConfigTest.
@Test
void updatePasswordEmailGlobalConfigTest() throws AlertConfigurationException {
AuthorizationManager authorizationManager = createEmailAuthorizationManager();
EmailGlobalCrudActions emailGlobalCrudActions = createEmailCrudActions(authorizationManager);
GlobalConfigurationModelToConcreteConversionService globalConfigurationModelToConcreteConversionService = createConversionService(emailGlobalCrudActions);
ConfigActions configActions = new ConfigActions(authorizationManager, descriptorAccessor, configurationModelConfigurationAccessor, fieldModelProcessor, descriptorProcessor, configurationFieldModelConverter, descriptorMap, pkixErrorResponseFactory, encryptionUtility, settingsDescriptorKey, globalConfigurationModelToConcreteConversionService);
FieldModel fieldModel = createEmailFieldModel();
fieldModel = configActions.create(fieldModel).getContent().orElseThrow(() -> new AlertConfigurationException("Couldn't create configuration"));
String updatedHost = "updated." + TEST_SMTP_HOST;
String updatedPassword = "updatedPassword";
fieldModel.putField(EmailPropertyKeys.JAVAMAIL_HOST_KEY.getPropertyKey(), new FieldValueModel(List.of(updatedHost), false));
fieldModel.putField(EmailPropertyKeys.JAVAMAIL_PASSWORD_KEY.getPropertyKey(), new FieldValueModel(List.of(updatedPassword), false));
configActions.update(Long.valueOf(fieldModel.getId()), fieldModel);
Optional<EmailGlobalConfigModel> staticEmailConfig = emailGlobalConfigAccessor.getConfiguration();
assertTrue(staticEmailConfig.isPresent());
EmailGlobalConfigModel staticModel = staticEmailConfig.get();
assertEquals(Boolean.TRUE, staticModel.getSmtpAuth().orElse(null));
assertEquals(TEST_AUTH_USER, staticModel.getSmtpUsername().orElse(null));
assertEquals(updatedPassword, staticModel.getSmtpPassword().orElse(null));
assertEquals(updatedHost, staticModel.getSmtpHost().orElse(null));
assertEquals(Integer.valueOf(TEST_SMTP_PORT), staticModel.getSmtpPort().orElse(null));
assertEquals(TEST_FROM, staticModel.getSmtpFrom().orElse(null));
String propertyValue = staticModel.getAdditionalJavaMailProperties().map(map -> map.get(EmailPropertyKeys.JAVAMAIL_EHLO_KEY.getPropertyKey())).orElse(null);
assertEquals("true", propertyValue);
}
use of com.synopsys.integration.alert.common.persistence.util.ConfigurationFieldModelConverter in project hub-alert by blackducksoftware.
the class DefaultDescriptorGlobalConfigUtilityTest method testUpdateNoExistingConfig.
@Test
public void testUpdateNoExistingConfig() throws Exception {
DescriptorKey descriptorKey = createDescriptorKey();
FieldModel fieldModel = new FieldModel(descriptorKey.getUniversalKey(), ConfigContextEnum.GLOBAL.name(), Map.of());
Map<String, ConfigurationFieldModel> configurationFieldModelCollection = Map.of();
ConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
ConfigurationFieldModelConverter converter = Mockito.mock(ConfigurationFieldModelConverter.class);
ConfigurationModel configurationModel = Mockito.mock(ConfigurationModel.class);
ApiAction apiAction = Mockito.mock(ApiAction.class);
Mockito.when(configurationModelConfigurationAccessor.createConfiguration(Mockito.eq(descriptorKey), Mockito.any(ConfigContextEnum.class), Mockito.anyCollection())).thenReturn(configurationModel);
Mockito.when(converter.convertToConfigurationFieldModelMap(Mockito.eq(fieldModel))).thenReturn(configurationFieldModelCollection);
Mockito.when(converter.convertToFieldModel(Mockito.any())).thenReturn(fieldModel);
Mockito.when(apiAction.beforeUpdateAction(Mockito.eq(fieldModel))).thenReturn(fieldModel);
Mockito.when(apiAction.afterUpdateAction(Mockito.eq(fieldModel), Mockito.eq(fieldModel))).thenReturn(fieldModel);
DefaultDescriptorGlobalConfigUtility configUtility = new DefaultDescriptorGlobalConfigUtility(descriptorKey, configurationModelConfigurationAccessor, apiAction, converter);
FieldModel savedModel = configUtility.update(1L, fieldModel);
assertEquals(fieldModel, savedModel);
}
use of com.synopsys.integration.alert.common.persistence.util.ConfigurationFieldModelConverter in project hub-alert by blackducksoftware.
the class DefaultDescriptorGlobalConfigUtilityTest method testUpdate.
@Test
public void testUpdate() throws Exception {
DescriptorKey descriptorKey = createDescriptorKey();
FieldModel fieldModel = new FieldModel(descriptorKey.getUniversalKey(), ConfigContextEnum.GLOBAL.name(), Map.of());
Map<String, ConfigurationFieldModel> configurationFieldModelCollection = Map.of();
ConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
ConfigurationFieldModelConverter converter = Mockito.mock(ConfigurationFieldModelConverter.class);
ConfigurationModel configurationModel = Mockito.mock(ConfigurationModel.class);
ApiAction apiAction = Mockito.mock(ApiAction.class);
Mockito.when(configurationModelConfigurationAccessor.getConfigurationById(Mockito.anyLong())).thenReturn(Optional.of(configurationModel));
Mockito.when(configurationModelConfigurationAccessor.createConfiguration(Mockito.eq(descriptorKey), Mockito.any(ConfigContextEnum.class), Mockito.anyCollection())).thenReturn(configurationModel);
Mockito.when(converter.convertToConfigurationFieldModelMap(Mockito.eq(fieldModel))).thenReturn(configurationFieldModelCollection);
Mockito.when(converter.convertToFieldModel(Mockito.any())).thenReturn(fieldModel);
Mockito.when(apiAction.beforeUpdateAction(Mockito.eq(fieldModel))).thenReturn(fieldModel);
Mockito.when(apiAction.afterUpdateAction(Mockito.eq(fieldModel), Mockito.eq(fieldModel))).thenReturn(fieldModel);
DefaultDescriptorGlobalConfigUtility configUtility = new DefaultDescriptorGlobalConfigUtility(descriptorKey, configurationModelConfigurationAccessor, apiAction, converter);
FieldModel savedModel = configUtility.update(1L, fieldModel);
assertEquals(fieldModel, savedModel);
Mockito.verify(configurationModelConfigurationAccessor).updateConfiguration(Mockito.anyLong(), Mockito.anyCollection());
}
use of com.synopsys.integration.alert.common.persistence.util.ConfigurationFieldModelConverter in project hub-alert by blackducksoftware.
the class DefaultDescriptorGlobalConfigUtilityTest method testSave.
@Test
public void testSave() throws Exception {
DescriptorKey descriptorKey = createDescriptorKey();
FieldModel fieldModel = new FieldModel(descriptorKey.getUniversalKey(), ConfigContextEnum.GLOBAL.name(), Map.of());
Map<String, ConfigurationFieldModel> configurationFieldModelCollection = Map.of();
ConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
ConfigurationFieldModelConverter converter = Mockito.mock(ConfigurationFieldModelConverter.class);
ConfigurationModel configurationModel = Mockito.mock(ConfigurationModel.class);
ApiAction apiAction = Mockito.mock(ApiAction.class);
Mockito.when(configurationModelConfigurationAccessor.createConfiguration(Mockito.eq(descriptorKey), Mockito.any(ConfigContextEnum.class), Mockito.anyCollection())).thenReturn(configurationModel);
Mockito.when(converter.convertToConfigurationFieldModelMap(Mockito.eq(fieldModel))).thenReturn(configurationFieldModelCollection);
Mockito.when(converter.convertToFieldModel(Mockito.any())).thenReturn(fieldModel);
Mockito.when(apiAction.beforeSaveAction(Mockito.eq(fieldModel))).thenReturn(fieldModel);
Mockito.when(apiAction.afterSaveAction(Mockito.eq(fieldModel))).thenReturn(fieldModel);
DefaultDescriptorGlobalConfigUtility configUtility = new DefaultDescriptorGlobalConfigUtility(descriptorKey, configurationModelConfigurationAccessor, apiAction, converter);
FieldModel savedModel = configUtility.save(fieldModel);
assertEquals(fieldModel, savedModel);
Mockito.verify(configurationModelConfigurationAccessor).createConfiguration(Mockito.eq(descriptorKey), Mockito.eq(ConfigContextEnum.GLOBAL), Mockito.anyCollection());
}
use of com.synopsys.integration.alert.common.persistence.util.ConfigurationFieldModelConverter in project hub-alert by blackducksoftware.
the class DefaultDescriptorGlobalConfigUtilityTest method testGetFieldModel.
@Test
public void testGetFieldModel() throws Exception {
DescriptorKey descriptorKey = createDescriptorKey();
FieldModel fieldModel = new FieldModel(descriptorKey.getUniversalKey(), ConfigContextEnum.GLOBAL.name(), Map.of());
ConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
ConfigurationFieldModelConverter converter = Mockito.mock(ConfigurationFieldModelConverter.class);
ConfigurationModel configurationModel = Mockito.mock(ConfigurationModel.class);
ApiAction apiAction = Mockito.mock(ApiAction.class);
Mockito.when(configurationModelConfigurationAccessor.getConfigurationsByDescriptorKeyAndContext(Mockito.any(DescriptorKey.class), Mockito.any(ConfigContextEnum.class))).thenReturn(List.of(configurationModel));
Mockito.when(converter.convertToFieldModel(Mockito.any())).thenReturn(fieldModel);
Mockito.when(apiAction.afterGetAction(Mockito.eq(fieldModel))).thenReturn(fieldModel);
DefaultDescriptorGlobalConfigUtility configUtility = new DefaultDescriptorGlobalConfigUtility(descriptorKey, configurationModelConfigurationAccessor, apiAction, converter);
FieldModel actualFieldModel = configUtility.getFieldModel().orElse(null);
assertEquals(fieldModel, actualFieldModel);
}
Aggregations