Search in sources :

Example 1 with JiraServerConfigurationEntity

use of com.synopsys.integration.alert.channel.jira.server.database.configuration.JiraServerConfigurationEntity in project hub-alert by blackducksoftware.

the class JiraServerGlobalConfigurationModelSaveActionsTest method updateTest.

@Test
void updateTest() {
    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.ofNullable(savedEntity.get()));
    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);
    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 2 with JiraServerConfigurationEntity

use of com.synopsys.integration.alert.channel.jira.server.database.configuration.JiraServerConfigurationEntity in project hub-alert by blackducksoftware.

the class JiraServerGlobalConfigurationModelSaveActionsTest method deleteTest.

@Test
void deleteTest() {
    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.ofNullable(savedEntity.get()));
    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);
    Mockito.doAnswer(invocation -> {
        savedEntity.set(null);
        return null;
    }).when(jiraConfigurationRepository).deleteById(Mockito.any());
    JiraServerGlobalConfigAccessor configurationAccessor = new JiraServerGlobalConfigAccessor(encryptionUtility, jiraConfigurationRepository);
    JiraServerGlobalCrudActions crudActions = new JiraServerGlobalCrudActions(authorizationManager, configurationAccessor, validator);
    JiraServerGlobalConfigurationModelSaveActions saveActions = new JiraServerGlobalConfigurationModelSaveActions(converter, crudActions, configurationAccessor);
    ConfigurationModel configurationModel = createDefaultConfigurationModel();
    saveActions.createConcreteModel(configurationModel);
    JiraServerConfigurationEntity actualEntity = savedEntity.get();
    assertNotNull(actualEntity);
    saveActions.deleteConcreteModel(configurationModel);
    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) 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 3 with JiraServerConfigurationEntity

use of com.synopsys.integration.alert.channel.jira.server.database.configuration.JiraServerConfigurationEntity in project hub-alert by blackducksoftware.

the class JiraServerGlobalConfigurationModelSaveActionsTest method createTest.

@Test
void createTest() {
    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);
    saveActions.createConcreteModel(createDefaultConfigurationModel());
    JiraServerConfigurationEntity actualEntity = savedEntity.get();
    assertEquals(TEST_URL, actualEntity.getUrl());
    assertEquals(TEST_USERNAME, actualEntity.getUsername());
    assertEquals(TEST_PASSWORD, encryptionUtility.decrypt(actualEntity.getPassword()));
    assertTrue(actualEntity.getDisablePluginCheck());
}
Also used : JiraServerConfigurationRepository(com.synopsys.integration.alert.channel.jira.server.database.configuration.JiraServerConfigurationRepository) 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 4 with JiraServerConfigurationEntity

use of com.synopsys.integration.alert.channel.jira.server.database.configuration.JiraServerConfigurationEntity in project hub-alert by blackducksoftware.

the class JiraServerGlobalConfigurationModelSaveActionsTest method updateInvalidConversionTest.

@Test
void updateInvalidConversionTest() {
    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.ofNullable(savedEntity.get()));
    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 invalidUrl = "      \t\r\n       ";
    ConfigurationModel configurationModel = createDefaultConfigurationModel();
    saveActions.createConcreteModel(configurationModel);
    updateField(configurationModel, JiraServerGlobalConfigurationModelConverter.URL_KEY, invalidUrl);
    updateField(configurationModel, JiraServerGlobalConfigurationModelConverter.PASSWORD_KEY, newPassword);
    saveActions.updateConcreteModel(configurationModel);
    // make sure the values are not the updated values
    JiraServerConfigurationEntity actualEntity = savedEntity.get();
    assertEquals(TEST_URL, actualEntity.getUrl());
    assertEquals(TEST_USERNAME, actualEntity.getUsername());
    assertEquals(TEST_PASSWORD, 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 5 with JiraServerConfigurationEntity

use of com.synopsys.integration.alert.channel.jira.server.database.configuration.JiraServerConfigurationEntity in project hub-alert by blackducksoftware.

the class JiraServerGlobalConfigAccessorTest method updateConfigurationTest.

@Test
void updateConfigurationTest() throws AlertConfigurationException {
    UUID id = UUID.randomUUID();
    String updatedName = "updatedName";
    String newUrl = "https://updated.example.com";
    JiraServerConfigurationEntity entity = createEntity(id, OffsetDateTime.now(), OffsetDateTime.now());
    JiraServerConfigurationEntity updatedEntity = new JiraServerConfigurationEntity(entity.getConfigurationId(), updatedName, entity.getCreatedAt(), entity.getLastUpdated(), newUrl, entity.getUsername(), entity.getPassword(), entity.getDisablePluginCheck());
    JiraServerGlobalConfigModel model = new JiraServerGlobalConfigModel(null, AlertRestConstants.DEFAULT_CONFIGURATION_NAME, DateUtils.formatDate(entity.getCreatedAt(), DateUtils.UTC_DATE_FORMAT_TO_MINUTE), DateUtils.formatDate(entity.getLastUpdated(), DateUtils.UTC_DATE_FORMAT_TO_MINUTE), TEST_URL, TEST_USERNAME, TEST_PASSWORD, false, true);
    Mockito.when(jiraServerConfigurationRepository.findById(id)).thenReturn(Optional.of(entity));
    Mockito.when(jiraServerConfigurationRepository.save(Mockito.any())).thenReturn(updatedEntity);
    JiraServerGlobalConfigModel updatedModel = jiraServerGlobalConfigAccessor.updateConfiguration(id, model);
    assertEquals(updatedEntity.getConfigurationId().toString(), updatedModel.getId());
    assertEquals(updatedEntity.getUrl(), updatedModel.getUrl());
    assertEquals(updatedEntity.getUsername(), updatedModel.getUserName());
    assertTrue(updatedModel.getIsPasswordSet().orElse(Boolean.FALSE));
    assertEquals(TEST_PASSWORD, updatedModel.getPassword().orElse(null));
    assertEquals(updatedEntity.getDisablePluginCheck(), updatedModel.getDisablePluginCheck().orElse(null));
}
Also used : JiraServerGlobalConfigModel(com.synopsys.integration.alert.channel.jira.server.model.JiraServerGlobalConfigModel) JiraServerConfigurationEntity(com.synopsys.integration.alert.channel.jira.server.database.configuration.JiraServerConfigurationEntity) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Aggregations

JiraServerConfigurationEntity (com.synopsys.integration.alert.channel.jira.server.database.configuration.JiraServerConfigurationEntity)18 Test (org.junit.jupiter.api.Test)16 UUID (java.util.UUID)14 JiraServerGlobalConfigModel (com.synopsys.integration.alert.channel.jira.server.model.JiraServerGlobalConfigModel)10 JiraServerGlobalCrudActions (com.synopsys.integration.alert.channel.jira.server.action.JiraServerGlobalCrudActions)6 JiraServerGlobalConfigAccessor (com.synopsys.integration.alert.channel.jira.server.database.accessor.JiraServerGlobalConfigAccessor)6 JiraServerConfigurationRepository (com.synopsys.integration.alert.channel.jira.server.database.configuration.JiraServerConfigurationRepository)6 AtomicReference (java.util.concurrent.atomic.AtomicReference)6 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)5 AlertConfigurationException (com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)4 PageImpl (org.springframework.data.domain.PageImpl)2 PageRequest (org.springframework.data.domain.PageRequest)2 OffsetDateTime (java.time.OffsetDateTime)1 Transactional (org.springframework.transaction.annotation.Transactional)1