use of com.synopsys.integration.alert.common.rest.model.FieldModel in project hub-alert by blackducksoftware.
the class EmailGlobalFieldModelTestActionTest method testConfigInvalidDestinationTest.
@Test
public void testConfigInvalidDestinationTest() {
EmailGlobalFieldModelTestAction emailGlobalFieldModelTestAction = new EmailGlobalFieldModelTestAction(null, null);
FieldModel validFieldModel = createFieldModelToTest("not a valid email address");
try {
emailGlobalFieldModelTestAction.testConfig("0", validFieldModel, new FieldUtility(Map.of()));
fail("Expected an exception to be thrown");
} catch (AlertException e) {
// Pass
}
}
use of com.synopsys.integration.alert.common.rest.model.FieldModel in project hub-alert by blackducksoftware.
the class JobConfigControllerTestIT method testUpdateConfig.
@Test
@WithMockUser(roles = AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)
public void testUpdateConfig() throws Exception {
ConfigurationModel providerGlobalConfig = addGlobalConfiguration(blackDuckProviderKey, Map.of(ProviderDescriptor.KEY_PROVIDER_CONFIG_NAME, List.of(DEFAULT_BLACK_DUCK_CONFIG), BlackDuckDescriptor.KEY_BLACKDUCK_URL, List.of(testProperties.getBlackDuckURL()), BlackDuckDescriptor.KEY_BLACKDUCK_API_KEY, List.of(testProperties.getBlackDuckAPIToken())));
JobFieldModel fieldModel = createTestJobFieldModel("1", "2", providerGlobalConfig);
Map<String, Collection<String>> fieldValueModels = new HashMap<>();
for (FieldModel newFieldModel : fieldModel.getFieldModels()) {
fieldValueModels.putAll(newFieldModel.getKeyToValues().entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue().getValues())));
}
DistributionJobRequestModel jobRequestModel = createDistributionJobRequestModel(providerGlobalConfig.getConfigurationId());
DistributionJobModel distributionJobModel = addDistributionJob(jobRequestModel);
String configId = String.valueOf(distributionJobModel.getJobId());
String urlPath = REQUEST_URL + "/" + configId;
MockHttpServletRequestBuilder request = MockMvcRequestBuilders.put(urlPath).with(SecurityMockMvcRequestPostProcessors.user("admin").roles(AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)).with(SecurityMockMvcRequestPostProcessors.csrf());
fieldModel.setJobId(configId);
request.content(gson.toJson(fieldModel));
request.contentType(MEDIA_TYPE);
mockMvc.perform(request).andExpect(MockMvcResultMatchers.status().isNoContent());
}
use of com.synopsys.integration.alert.common.rest.model.FieldModel in project hub-alert by blackducksoftware.
the class JobConfigControllerTestIT method createTestJobFieldModel.
private JobFieldModel createTestJobFieldModel(String channelId, String providerId, ConfigurationModel providerGlobalConfig) {
String descriptorName = ChannelKeys.SLACK.getUniversalKey();
String context = ConfigContextEnum.DISTRIBUTION.name();
FieldValueModel providerConfigField = new FieldValueModel(List.of(providerGlobalConfig.getConfigurationId().toString()), true);
FieldValueModel slackChannelName = new FieldValueModel(List.of("channelName"), true);
FieldValueModel frequency = new FieldValueModel(List.of(FrequencyType.DAILY.name()), true);
FieldValueModel name = new FieldValueModel(List.of("name"), true);
FieldValueModel provider = new FieldValueModel(List.of(blackDuckProviderKey.getUniversalKey()), true);
FieldValueModel channel = new FieldValueModel(List.of("channel_slack"), true);
FieldValueModel webhook = new FieldValueModel(List.of("http://slack_webhook_url"), true);
Map<String, FieldValueModel> fields = Map.of(SlackDescriptor.KEY_CHANNEL_NAME, slackChannelName, SlackDescriptor.KEY_WEBHOOK, webhook, ChannelDescriptor.KEY_NAME, name, ChannelDescriptor.KEY_PROVIDER_TYPE, provider, ProviderDescriptor.KEY_PROVIDER_CONFIG_ID, providerConfigField, ChannelDescriptor.KEY_CHANNEL_NAME, channel, ChannelDescriptor.KEY_FREQUENCY, frequency);
FieldModel fieldModel = new FieldModel(descriptorName, context, fields);
if (StringUtils.isNotBlank(channelId)) {
fieldModel.setId(channelId);
}
String bdDescriptorName = blackDuckProviderKey.getUniversalKey();
String bdContext = ConfigContextEnum.DISTRIBUTION.name();
FieldValueModel notificationType = new FieldValueModel(List.of("vulnerability"), true);
FieldValueModel formatType = new FieldValueModel(List.of(ProcessingType.DEFAULT.name()), true);
FieldValueModel filterByProject = new FieldValueModel(List.of("false"), true);
FieldValueModel projectNames = new FieldValueModel(List.of("project"), true);
Map<String, FieldValueModel> bdFields = Map.of(ProviderDescriptor.KEY_NOTIFICATION_TYPES, notificationType, ProviderDescriptor.KEY_PROVIDER_CONFIG_ID, providerConfigField, ProviderDescriptor.KEY_PROCESSING_TYPE, formatType, ProviderDescriptor.KEY_FILTER_BY_PROJECT, filterByProject, ProviderDescriptor.KEY_CONFIGURED_PROJECT, projectNames);
FieldModel bdFieldModel = new FieldModel(bdDescriptorName, bdContext, bdFields);
if (StringUtils.isNotBlank(providerId)) {
bdFieldModel.setId(providerId);
}
return new JobFieldModel(UUID.randomUUID().toString(), Set.of(fieldModel, bdFieldModel), List.of(new JobProviderProjectFieldModel("project", "href", false)));
}
use of com.synopsys.integration.alert.common.rest.model.FieldModel 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.rest.model.FieldModel in project hub-alert by blackducksoftware.
the class EmailConfigActionTestIT method createEmailFieldModel.
private FieldModel createEmailFieldModel() {
Map<String, FieldValueModel> fieldValuesMap = new HashMap<>();
fieldValuesMap.put(EmailPropertyKeys.JAVAMAIL_FROM_KEY.getPropertyKey(), new FieldValueModel(List.of(TEST_FROM), false));
fieldValuesMap.put(EmailPropertyKeys.JAVAMAIL_HOST_KEY.getPropertyKey(), new FieldValueModel(List.of(TEST_SMTP_HOST), false));
fieldValuesMap.put(EmailPropertyKeys.JAVAMAIL_PORT_KEY.getPropertyKey(), new FieldValueModel(List.of(TEST_SMTP_PORT), false));
fieldValuesMap.put(EmailPropertyKeys.JAVAMAIL_AUTH_KEY.getPropertyKey(), new FieldValueModel(List.of(TEST_AUTH_REQUIRED), false));
fieldValuesMap.put(EmailPropertyKeys.JAVAMAIL_PASSWORD_KEY.getPropertyKey(), new FieldValueModel(List.of(TEST_AUTH_PASSWORD), false));
fieldValuesMap.put(EmailPropertyKeys.JAVAMAIL_USER_KEY.getPropertyKey(), new FieldValueModel(List.of(TEST_AUTH_USER), false));
fieldValuesMap.put(EmailPropertyKeys.JAVAMAIL_EHLO_KEY.getPropertyKey(), new FieldValueModel(List.of("true"), false));
return new FieldModel(ChannelKeys.EMAIL.getUniversalKey(), ConfigContextEnum.GLOBAL.name(), fieldValuesMap);
}
Aggregations