use of com.synopsys.integration.alert.common.persistence.model.ConfigurationModel in project hub-alert by blackducksoftware.
the class ProxyConfigurationModelConverterTest method validConversionTest.
@Test
void validConversionTest() {
ConfigurationModel configurationModel = createDefaultConfigurationModel();
ProxyConfigurationModelConverter converter = new ProxyConfigurationModelConverter();
Optional<SettingsProxyModel> model = converter.convert(configurationModel);
assertTrue(model.isPresent());
SettingsProxyModel proxyModel = model.get();
assertEquals(TEST_AUTH_USER, proxyModel.getProxyUsername().orElse(null));
assertEquals(TEST_AUTH_PASSWORD, proxyModel.getProxyPassword().orElse(null));
assertEquals(TEST_SMTP_HOST, proxyModel.getProxyHost().orElse(null));
assertEquals(Integer.valueOf(TEST_SMTP_PORT), proxyModel.getProxyPort().orElse(null));
assertEquals(TEST_NON_PROXY_HOSTS, proxyModel.getNonProxyHosts().orElse(null));
}
use of com.synopsys.integration.alert.common.persistence.model.ConfigurationModel in project hub-alert by blackducksoftware.
the class BlackDuckProviderDataAccessor method findFirstUserByEmailAddress.
@Override
public Optional<ProviderUserModel> findFirstUserByEmailAddress(Long providerConfigId, String emailAddress) {
Optional<ConfigurationModel> providerConfigOptional = configurationModelConfigurationAccessor.getConfigurationById(providerConfigId);
if (providerConfigOptional.isPresent()) {
try {
BlackDuckServicesFactory blackDuckServicesFactory = createBlackDuckServicesFactory(providerConfigOptional.get());
UserService userService = blackDuckServicesFactory.createUserService();
return userService.findUsersByEmail(emailAddress, new BlackDuckPageDefinition(1, 0)).getItems().stream().map(userView -> new ProviderUserModel(userView.getEmail(), false)).findFirst();
} catch (IntegrationException e) {
logger.errorAndDebug(createProjectNotFoundString(providerConfigId, e.getMessage()), e);
}
}
return Optional.empty();
}
use of com.synopsys.integration.alert.common.persistence.model.ConfigurationModel in project hub-alert by blackducksoftware.
the class BlackDuckProviderDataAccessor method getEmailAddressesByProvider.
private List<ProviderUserModel> getEmailAddressesByProvider(ConfigurationModel blackDuckConfiguration) throws IntegrationException {
BlackDuckServicesFactory blackDuckServicesFactory = createBlackDuckServicesFactory(blackDuckConfiguration);
BlackDuckApiClient blackDuckService = blackDuckServicesFactory.getBlackDuckApiClient();
ApiDiscovery apiDiscovery = blackDuckServicesFactory.getApiDiscovery();
Set<String> allActiveBlackDuckEmailAddresses = getAllActiveBlackDuckEmailAddresses(blackDuckService, apiDiscovery);
return allActiveBlackDuckEmailAddresses.stream().map(email -> new ProviderUserModel(email, false)).collect(Collectors.toList());
}
use of com.synopsys.integration.alert.common.persistence.model.ConfigurationModel in project hub-alert by blackducksoftware.
the class EmailGlobalConfigurationModelSaveActionsTest method updateTest.
@Test
void updateTest() {
AtomicReference<EmailConfigurationEntity> savedEntity = new AtomicReference<>();
AtomicReference<EmailConfigurationsPropertyEntity> savedProperty = new AtomicReference<>();
EmailConfigurationRepository emailConfigurationRepository = Mockito.mock(EmailConfigurationRepository.class);
EmailConfigurationPropertiesRepository emailConfigurationPropertiesRepository = Mockito.mock(EmailConfigurationPropertiesRepository.class);
Mockito.when(emailConfigurationRepository.save(Mockito.any(EmailConfigurationEntity.class))).thenAnswer(invocation -> {
savedEntity.set(invocation.getArgument(0));
return savedEntity.get();
});
Mockito.when(emailConfigurationRepository.findByName(Mockito.anyString())).thenAnswer(invocation -> Optional.ofNullable(savedEntity.get()));
Mockito.when(emailConfigurationRepository.findById(Mockito.any())).thenAnswer(invocation -> Optional.ofNullable(savedEntity.get()));
Mockito.when(emailConfigurationRepository.existsByName(Mockito.any())).thenAnswer(invocation -> savedEntity.get() != null);
// Mockito.when(emailConfigurationRepository.existsByName(Mockito.anyString())).thenReturn(true);
Mockito.when(emailConfigurationPropertiesRepository.saveAll(Mockito.any(List.class))).thenAnswer(invocation -> {
Iterable<EmailConfigurationsPropertyEntity> iterable = invocation.getArgument(0);
for (EmailConfigurationsPropertyEntity entity : iterable) {
savedProperty.set(entity);
}
return List.of(savedProperty.get());
});
EmailGlobalConfigAccessor configurationAccessor = new EmailGlobalConfigAccessor(encryptionUtility, emailConfigurationRepository, emailConfigurationPropertiesRepository);
EmailGlobalCrudActions crudActions = new EmailGlobalCrudActions(authorizationManager, configurationAccessor, validator);
EmailGlobalConfigurationModelSaveActions saveActions = new EmailGlobalConfigurationModelSaveActions(converter, crudActions, configurationAccessor);
String newPassword = "updatedPassword";
String newHost = "updated." + TEST_SMTP_HOST;
ConfigurationModel configurationModel = createDefaultConfigurationModel();
saveActions.createConcreteModel(configurationModel);
updateField(configurationModel, EmailPropertyKeys.JAVAMAIL_HOST_KEY.getPropertyKey(), newHost);
updateField(configurationModel, EmailPropertyKeys.JAVAMAIL_PASSWORD_KEY.getPropertyKey(), newPassword);
updateField(configurationModel, EmailPropertyKeys.JAVAMAIL_EHLO_KEY.getPropertyKey(), "false");
saveActions.updateConcreteModel(configurationModel);
EmailConfigurationEntity actualEntity = savedEntity.get();
assertEquals(ChannelKeys.EMAIL, saveActions.getDescriptorKey());
assertEquals(Boolean.TRUE, actualEntity.getAuthRequired());
assertEquals(TEST_AUTH_USER, actualEntity.getAuthUsername());
assertEquals(newPassword, encryptionUtility.decrypt(actualEntity.getAuthPassword()));
assertEquals(newHost, actualEntity.getSmtpHost());
assertEquals(Integer.valueOf(TEST_SMTP_PORT), actualEntity.getSmtpPort());
assertEquals(TEST_FROM, actualEntity.getSmtpFrom());
EmailConfigurationsPropertyEntity emailProperty = savedProperty.get();
assertNotNull(emailProperty);
assertEquals(EmailPropertyKeys.JAVAMAIL_EHLO_KEY.getPropertyKey(), emailProperty.getPropertyKey());
assertEquals("false", emailProperty.getPropertyValue());
}
use of com.synopsys.integration.alert.common.persistence.model.ConfigurationModel in project hub-alert by blackducksoftware.
the class EmailGlobalConfigurationModelSaveActionsTest method updateInvalidConversionTest.
@Test
void updateInvalidConversionTest() {
AtomicReference<EmailConfigurationEntity> savedEntity = new AtomicReference<>();
AtomicReference<EmailConfigurationsPropertyEntity> savedProperty = new AtomicReference<>();
EmailConfigurationRepository emailConfigurationRepository = Mockito.mock(EmailConfigurationRepository.class);
EmailConfigurationPropertiesRepository emailConfigurationPropertiesRepository = Mockito.mock(EmailConfigurationPropertiesRepository.class);
Mockito.when(emailConfigurationRepository.save(Mockito.any(EmailConfigurationEntity.class))).thenAnswer(invocation -> {
savedEntity.set(invocation.getArgument(0));
return savedEntity.get();
});
Mockito.when(emailConfigurationRepository.findByName(Mockito.anyString())).thenAnswer(invocation -> Optional.ofNullable(savedEntity.get()));
Mockito.when(emailConfigurationRepository.findById(Mockito.any())).thenAnswer(invocation -> Optional.ofNullable(savedEntity.get()));
Mockito.when(emailConfigurationPropertiesRepository.saveAll(Mockito.any(List.class))).thenAnswer(invocation -> {
Iterable<EmailConfigurationsPropertyEntity> iterable = invocation.getArgument(0);
for (EmailConfigurationsPropertyEntity entity : iterable) {
savedProperty.set(entity);
}
return List.of(savedProperty.get());
});
EmailGlobalConfigAccessor configurationAccessor = new EmailGlobalConfigAccessor(encryptionUtility, emailConfigurationRepository, emailConfigurationPropertiesRepository);
EmailGlobalCrudActions crudActions = new EmailGlobalCrudActions(authorizationManager, configurationAccessor, validator);
EmailGlobalConfigurationModelSaveActions saveActions = new EmailGlobalConfigurationModelSaveActions(converter, crudActions, configurationAccessor);
String newPassword = "updatedPassword";
String newHost = "updated." + TEST_SMTP_HOST;
ConfigurationModel configurationModel = createDefaultConfigurationModel();
saveActions.createConcreteModel(configurationModel);
updateField(configurationModel, EmailPropertyKeys.JAVAMAIL_PORT_KEY.getPropertyKey(), "badport");
updateField(configurationModel, EmailPropertyKeys.JAVAMAIL_HOST_KEY.getPropertyKey(), newHost);
updateField(configurationModel, EmailPropertyKeys.JAVAMAIL_PORT_KEY.getPropertyKey(), newPassword);
updateField(configurationModel, EmailPropertyKeys.JAVAMAIL_EHLO_KEY.getPropertyKey(), "false");
saveActions.updateConcreteModel(configurationModel);
// make sure the values are not the updated values
EmailConfigurationEntity actualEntity = savedEntity.get();
assertEquals(TEST_AUTH_PASSWORD, encryptionUtility.decrypt(actualEntity.getAuthPassword()));
assertEquals(TEST_SMTP_HOST, actualEntity.getSmtpHost());
assertEquals(Integer.valueOf(TEST_SMTP_PORT), actualEntity.getSmtpPort());
}
Aggregations