Search in sources :

Example 6 with JiraServerConfigurationRepository

use of com.synopsys.integration.alert.channel.jira.server.database.configuration.JiraServerConfigurationRepository 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)

Aggregations

JiraServerGlobalCrudActions (com.synopsys.integration.alert.channel.jira.server.action.JiraServerGlobalCrudActions)6 JiraServerGlobalConfigAccessor (com.synopsys.integration.alert.channel.jira.server.database.accessor.JiraServerGlobalConfigAccessor)6 JiraServerConfigurationEntity (com.synopsys.integration.alert.channel.jira.server.database.configuration.JiraServerConfigurationEntity)6 JiraServerConfigurationRepository (com.synopsys.integration.alert.channel.jira.server.database.configuration.JiraServerConfigurationRepository)6 AtomicReference (java.util.concurrent.atomic.AtomicReference)6 Test (org.junit.jupiter.api.Test)6 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)5 UUID (java.util.UUID)4