use of com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel in project hub-alert by blackducksoftware.
the class JiraServerGlobalConfigurationModelSaveActionsTest method createDefaultConfigurationModel.
private ConfigurationModel createDefaultConfigurationModel() {
Map<String, ConfigurationFieldModel> fieldValuesMap = new HashMap<>();
ConfigurationFieldModel urlField = ConfigurationFieldModel.create(JiraServerGlobalConfigurationModelConverter.URL_KEY);
ConfigurationFieldModel userField = ConfigurationFieldModel.create(JiraServerGlobalConfigurationModelConverter.USERNAME_KEY);
ConfigurationFieldModel passwordField = ConfigurationFieldModel.create(JiraServerGlobalConfigurationModelConverter.PASSWORD_KEY);
ConfigurationFieldModel disableCheckField = ConfigurationFieldModel.create(JiraServerGlobalConfigurationModelConverter.DISABLE_PLUGIN_CHECK_KEY);
urlField.setFieldValue(TEST_URL);
passwordField.setFieldValue(TEST_PASSWORD);
userField.setFieldValue(TEST_USERNAME);
disableCheckField.setFieldValue(TEST_DISABLE_PLUGIN_CHECK);
fieldValuesMap.put(JiraServerGlobalConfigurationModelConverter.URL_KEY, urlField);
fieldValuesMap.put(JiraServerGlobalConfigurationModelConverter.PASSWORD_KEY, passwordField);
fieldValuesMap.put(JiraServerGlobalConfigurationModelConverter.USERNAME_KEY, userField);
fieldValuesMap.put(JiraServerGlobalConfigurationModelConverter.DISABLE_PLUGIN_CHECK_KEY, disableCheckField);
return new ConfigurationModel(1L, 1L, "", "", ConfigContextEnum.GLOBAL, fieldValuesMap);
}
use of com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel in project hub-alert by blackducksoftware.
the class JiraServerGlobalConfigurationModelConverterTest method invalidPropertyKeysTest.
@Test
void invalidPropertyKeysTest() {
String invalidFieldKey = "invalid.jira.field";
ConfigurationFieldModel invalidField = ConfigurationFieldModel.create(invalidFieldKey);
Map<String, ConfigurationFieldModel> fieldValues = Map.of(invalidFieldKey, invalidField);
ConfigurationModel configurationModel = new ConfigurationModel(1L, 1L, "", "", ConfigContextEnum.GLOBAL, fieldValues);
JiraServerGlobalConfigurationModelConverter converter = new JiraServerGlobalConfigurationModelConverter();
Optional<JiraServerGlobalConfigModel> model = converter.convert(configurationModel);
assertTrue(model.isEmpty());
}
use of com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel in project hub-alert by blackducksoftware.
the class JiraServerGlobalConfigurationModelConverterTest method validConversionMissingOptionalFieldsTest.
@Test
void validConversionMissingOptionalFieldsTest() {
ConfigurationModel configurationModel = createDefaultConfigurationModel();
Map<String, ConfigurationFieldModel> fields = configurationModel.getCopyOfKeyToFieldMap();
fields.remove(JiraServerGlobalConfigurationModelConverter.PASSWORD_KEY);
fields.remove(JiraServerGlobalConfigurationModelConverter.DISABLE_PLUGIN_CHECK_KEY);
configurationModel = new ConfigurationModel(1L, 1L, "", "", ConfigContextEnum.GLOBAL, fields);
JiraServerGlobalConfigurationModelConverter converter = new JiraServerGlobalConfigurationModelConverter();
Optional<JiraServerGlobalConfigModel> model = converter.convert(configurationModel);
assertTrue(model.isPresent());
JiraServerGlobalConfigModel jiraModel = model.get();
assertNull(jiraModel.getId());
assertEquals(TEST_URL, jiraModel.getUrl());
assertEquals(TEST_USERNAME, jiraModel.getUserName());
assertTrue(jiraModel.getPassword().isEmpty());
assertTrue(jiraModel.getDisablePluginCheck().isEmpty());
}
use of com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel in project hub-alert by blackducksoftware.
the class JiraServerGlobalConfigurationModelConverterTest method createDefaultConfigurationModel.
private ConfigurationModel createDefaultConfigurationModel() {
Map<String, ConfigurationFieldModel> fieldValuesMap = new HashMap<>();
ConfigurationFieldModel urlField = ConfigurationFieldModel.create(JiraServerGlobalConfigurationModelConverter.URL_KEY);
ConfigurationFieldModel userField = ConfigurationFieldModel.create(JiraServerGlobalConfigurationModelConverter.USERNAME_KEY);
ConfigurationFieldModel passwordField = ConfigurationFieldModel.create(JiraServerGlobalConfigurationModelConverter.PASSWORD_KEY);
ConfigurationFieldModel disableCheckField = ConfigurationFieldModel.create(JiraServerGlobalConfigurationModelConverter.DISABLE_PLUGIN_CHECK_KEY);
urlField.setFieldValue(TEST_URL);
passwordField.setFieldValue(TEST_PASSWORD);
userField.setFieldValue(TEST_USERNAME);
disableCheckField.setFieldValue(TEST_DISABLE_PLUGIN_CHECK);
fieldValuesMap.put(JiraServerGlobalConfigurationModelConverter.URL_KEY, urlField);
fieldValuesMap.put(JiraServerGlobalConfigurationModelConverter.PASSWORD_KEY, passwordField);
fieldValuesMap.put(JiraServerGlobalConfigurationModelConverter.USERNAME_KEY, userField);
fieldValuesMap.put(JiraServerGlobalConfigurationModelConverter.DISABLE_PLUGIN_CHECK_KEY, disableCheckField);
return new ConfigurationModel(1L, 1L, "", "", ConfigContextEnum.GLOBAL, fieldValuesMap);
}
use of com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel in project hub-alert by blackducksoftware.
the class JiraServerGlobalConfigurationModelConverter method convert.
@Override
public Optional<JiraServerGlobalConfigModel> convert(ConfigurationModel globalConfigurationModel) {
String url = globalConfigurationModel.getField(URL_KEY).flatMap(ConfigurationFieldModel::getFieldValue).orElse(null);
if (StringUtils.isBlank(url)) {
return Optional.empty();
}
String username = globalConfigurationModel.getField(USERNAME_KEY).flatMap(ConfigurationFieldModel::getFieldValue).orElse(null);
String password = globalConfigurationModel.getField(PASSWORD_KEY).flatMap(ConfigurationFieldModel::getFieldValue).orElse(null);
JiraServerGlobalConfigModel model = new JiraServerGlobalConfigModel(null, AlertRestConstants.DEFAULT_CONFIGURATION_NAME, url, username, password);
globalConfigurationModel.getField(DISABLE_PLUGIN_CHECK_KEY).flatMap(ConfigurationFieldModel::getFieldValue).map(Boolean::valueOf).ifPresent(model::setDisablePluginCheck);
return Optional.of(model);
}
Aggregations