Search in sources :

Example 81 with ConfigurationModel

use of com.synopsys.integration.alert.common.persistence.model.ConfigurationModel 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 82 with ConfigurationModel

use of com.synopsys.integration.alert.common.persistence.model.ConfigurationModel in project hub-alert by blackducksoftware.

the class JiraServerGlobalConfigurationModelSaveActionsTest method createInvalidConversionTest.

@Test
void createInvalidConversionTest() {
    AtomicReference<JiraServerConfigurationEntity> savedEntity = new AtomicReference<>();
    JiraServerConfigurationRepository jiraConfigurationRepository = Mockito.mock(JiraServerConfigurationRepository.class);
    Mockito.when(jiraConfigurationRepository.save(Mockito.any(JiraServerConfigurationEntity.class))).thenAnswer(invocation -> {
        savedEntity.set(invocation.getArgument(0));
        return savedEntity.get();
    });
    JiraServerGlobalConfigAccessor configurationAccessor = new JiraServerGlobalConfigAccessor(encryptionUtility, jiraConfigurationRepository);
    JiraServerGlobalCrudActions crudActions = new JiraServerGlobalCrudActions(authorizationManager, configurationAccessor, validator);
    JiraServerGlobalConfigurationModelSaveActions saveActions = new JiraServerGlobalConfigurationModelSaveActions(converter, crudActions, configurationAccessor);
    ConfigurationModel configurationModel = createDefaultConfigurationModel();
    updateField(configurationModel, JiraServerGlobalConfigurationModelConverter.URL_KEY, "      ");
    saveActions.createConcreteModel(configurationModel);
    JiraServerConfigurationEntity actualEntity = savedEntity.get();
    assertNull(actualEntity);
}
Also used : JiraServerConfigurationRepository(com.synopsys.integration.alert.channel.jira.server.database.configuration.JiraServerConfigurationRepository) ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) JiraServerConfigurationEntity(com.synopsys.integration.alert.channel.jira.server.database.configuration.JiraServerConfigurationEntity) AtomicReference(java.util.concurrent.atomic.AtomicReference) JiraServerGlobalConfigAccessor(com.synopsys.integration.alert.channel.jira.server.database.accessor.JiraServerGlobalConfigAccessor) JiraServerGlobalCrudActions(com.synopsys.integration.alert.channel.jira.server.action.JiraServerGlobalCrudActions) Test(org.junit.jupiter.api.Test)

Example 83 with ConfigurationModel

use of com.synopsys.integration.alert.common.persistence.model.ConfigurationModel in project hub-alert by blackducksoftware.

the class JiraServerGlobalConfigurationModelSaveActionsTest method updateItemNotFoundUpdateTest.

@Test
void updateItemNotFoundUpdateTest() {
    AtomicReference<JiraServerConfigurationEntity> savedEntity = new AtomicReference<>();
    JiraServerConfigurationRepository jiraConfigurationRepository = Mockito.mock(JiraServerConfigurationRepository.class);
    Mockito.when(jiraConfigurationRepository.save(Mockito.any(JiraServerConfigurationEntity.class))).thenAnswer(invocation -> {
        savedEntity.set(invocation.getArgument(0));
        return savedEntity.get();
    });
    Mockito.when(jiraConfigurationRepository.findByName(Mockito.anyString())).thenAnswer(invocation -> Optional.empty());
    Mockito.when(jiraConfigurationRepository.findById(Mockito.any())).thenAnswer(invocation -> Optional.ofNullable(savedEntity.get()));
    Mockito.when(jiraConfigurationRepository.existsByConfigurationId(Mockito.any(UUID.class))).thenAnswer(invocation -> savedEntity.get() != null);
    JiraServerGlobalConfigAccessor configurationAccessor = new JiraServerGlobalConfigAccessor(encryptionUtility, jiraConfigurationRepository);
    JiraServerGlobalCrudActions crudActions = new JiraServerGlobalCrudActions(authorizationManager, configurationAccessor, validator);
    JiraServerGlobalConfigurationModelSaveActions saveActions = new JiraServerGlobalConfigurationModelSaveActions(converter, crudActions, configurationAccessor);
    String newPassword = "updatedPassword";
    String newUrl = "https://updated.jira.example.com";
    ConfigurationModel configurationModel = createDefaultConfigurationModel();
    saveActions.createConcreteModel(configurationModel);
    updateField(configurationModel, JiraServerGlobalConfigurationModelConverter.URL_KEY, newUrl);
    updateField(configurationModel, JiraServerGlobalConfigurationModelConverter.PASSWORD_KEY, newPassword);
    saveActions.updateConcreteModel(configurationModel);
    // make sure the values are not the updated values
    JiraServerConfigurationEntity actualEntity = savedEntity.get();
    assertEquals(newUrl, actualEntity.getUrl());
    assertEquals(TEST_USERNAME, actualEntity.getUsername());
    assertEquals(newPassword, encryptionUtility.decrypt(actualEntity.getPassword()));
    assertTrue(actualEntity.getDisablePluginCheck());
}
Also used : JiraServerConfigurationRepository(com.synopsys.integration.alert.channel.jira.server.database.configuration.JiraServerConfigurationRepository) ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) JiraServerConfigurationEntity(com.synopsys.integration.alert.channel.jira.server.database.configuration.JiraServerConfigurationEntity) AtomicReference(java.util.concurrent.atomic.AtomicReference) UUID(java.util.UUID) JiraServerGlobalConfigAccessor(com.synopsys.integration.alert.channel.jira.server.database.accessor.JiraServerGlobalConfigAccessor) JiraServerGlobalCrudActions(com.synopsys.integration.alert.channel.jira.server.action.JiraServerGlobalCrudActions) Test(org.junit.jupiter.api.Test)

Example 84 with ConfigurationModel

use of com.synopsys.integration.alert.common.persistence.model.ConfigurationModel 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 85 with ConfigurationModel

use of com.synopsys.integration.alert.common.persistence.model.ConfigurationModel in project hub-alert by blackducksoftware.

the class JiraServerGlobalConfigurationModelConverterTest method validConversionTest.

@Test
void validConversionTest() {
    ConfigurationModel configurationModel = createDefaultConfigurationModel();
    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());
    assertEquals(TEST_PASSWORD, jiraModel.getPassword().orElse("Password value is missing"));
    assertTrue(jiraModel.getDisablePluginCheck().orElse(Boolean.FALSE));
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) JiraServerGlobalConfigModel(com.synopsys.integration.alert.channel.jira.server.model.JiraServerGlobalConfigModel) Test(org.junit.jupiter.api.Test)

Aggregations

ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)140 Test (org.junit.jupiter.api.Test)89 ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)49 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)33 ConfigurationModelConfigurationAccessor (com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor)31 FieldModel (com.synopsys.integration.alert.common.rest.model.FieldModel)22 List (java.util.List)15 AtomicReference (java.util.concurrent.atomic.AtomicReference)14 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)13 DescriptorMap (com.synopsys.integration.alert.common.descriptor.DescriptorMap)13 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)13 HashMap (java.util.HashMap)13 AlertConfigurationException (com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)11 NotificationContentRepository (com.synopsys.integration.alert.database.notification.NotificationContentRepository)11 NotificationEntity (com.synopsys.integration.alert.database.notification.NotificationEntity)11 DescriptorConfigEntity (com.synopsys.integration.alert.database.configuration.DescriptorConfigEntity)10 BlackDuckServicesFactory (com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)10 ArrayList (java.util.ArrayList)10 AlertNotificationModel (com.synopsys.integration.alert.common.rest.model.AlertNotificationModel)9 AlertIntegrationTest (com.synopsys.integration.alert.util.AlertIntegrationTest)9