Search in sources :

Example 56 with ConfigurationFieldModel

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);
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) HashMap(java.util.HashMap)

Example 57 with ConfigurationFieldModel

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());
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) JiraServerGlobalConfigModel(com.synopsys.integration.alert.channel.jira.server.model.JiraServerGlobalConfigModel) Test(org.junit.jupiter.api.Test)

Example 58 with ConfigurationFieldModel

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());
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) JiraServerGlobalConfigModel(com.synopsys.integration.alert.channel.jira.server.model.JiraServerGlobalConfigModel) Test(org.junit.jupiter.api.Test)

Example 59 with ConfigurationFieldModel

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);
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) HashMap(java.util.HashMap)

Example 60 with ConfigurationFieldModel

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);
}
Also used : ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) JiraServerGlobalConfigModel(com.synopsys.integration.alert.channel.jira.server.model.JiraServerGlobalConfigModel)

Aggregations

ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)105 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)47 Test (org.junit.jupiter.api.Test)32 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)27 FieldModel (com.synopsys.integration.alert.common.rest.model.FieldModel)23 HashMap (java.util.HashMap)20 ConfigurationFieldModelConverter (com.synopsys.integration.alert.common.persistence.util.ConfigurationFieldModelConverter)14 ArrayList (java.util.ArrayList)13 ConfigurationModelConfigurationAccessor (com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor)12 FieldValueModel (com.synopsys.integration.alert.common.rest.model.FieldValueModel)12 DescriptorAccessor (com.synopsys.integration.alert.common.persistence.accessor.DescriptorAccessor)11 DefinedFieldModel (com.synopsys.integration.alert.common.persistence.model.DefinedFieldModel)11 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)10 BlackDuckProviderKey (com.synopsys.integration.alert.descriptor.api.BlackDuckProviderKey)10 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)9 AlertIntegrationTest (com.synopsys.integration.alert.util.AlertIntegrationTest)9 ConfigurationModelMutable (com.synopsys.integration.alert.common.persistence.model.mutable.ConfigurationModelMutable)8 EncryptionUtility (com.synopsys.integration.alert.common.security.EncryptionUtility)8 BeforeEach (org.junit.jupiter.api.BeforeEach)8 FieldUtility (com.synopsys.integration.alert.common.persistence.accessor.FieldUtility)7