Search in sources :

Example 6 with JiraServerConfigurationEntity

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

the class JiraServerGlobalConfigAccessorTest method updateConfigurationPasswordSavedTest.

@Test
void updateConfigurationPasswordSavedTest() 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, null, true, 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)

Example 7 with JiraServerConfigurationEntity

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

the class JiraServerGlobalConfigAccessorTest method getByConfigurationIdNotFoundTest.

@Test
void getByConfigurationIdNotFoundTest() {
    UUID id = UUID.randomUUID();
    JiraServerConfigurationEntity entity = createEntity(id);
    Mockito.when(jiraServerConfigurationRepository.findById(id)).thenReturn(Optional.of(entity));
    Optional<JiraServerGlobalConfigModel> configModel = jiraServerGlobalConfigAccessor.getConfiguration(UUID.randomUUID());
    assertTrue(configModel.isEmpty());
}
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)

Example 8 with JiraServerConfigurationEntity

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

the class JiraServerGlobalConfigAccessorTest method getPageEmptyTest.

@Test
void getPageEmptyTest() {
    UUID id = UUID.randomUUID();
    Page<JiraServerConfigurationEntity> jiraConfigurations = new PageImpl<>(List.of());
    Mockito.when(jiraServerConfigurationRepository.findAll(Mockito.any(PageRequest.class))).thenReturn(jiraConfigurations);
    AlertPagedModel<JiraServerGlobalConfigModel> pagedModel = jiraServerGlobalConfigAccessor.getConfigurationPage(0, 10);
    assertEquals(0, pagedModel.getCurrentPage());
    assertEquals(1, pagedModel.getTotalPages());
    assertEquals(0, pagedModel.getModels().size());
}
Also used : PageImpl(org.springframework.data.domain.PageImpl) PageRequest(org.springframework.data.domain.PageRequest) 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)

Example 9 with JiraServerConfigurationEntity

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

the class JiraServerGlobalConfigAccessor method updateConfiguration.

@Override
@Transactional(propagation = Propagation.REQUIRED)
public JiraServerGlobalConfigModel updateConfiguration(UUID configurationId, JiraServerGlobalConfigModel configuration) throws AlertConfigurationException {
    JiraServerConfigurationEntity configurationEntity = jiraServerConfigurationRepository.findById(configurationId).orElseThrow(() -> new AlertConfigurationException(String.format("Config with id '%s' did not exist", configurationId.toString())));
    if (BooleanUtils.toBoolean(configuration.getIsPasswordSet().orElse(Boolean.FALSE)) && configuration.getPassword().isEmpty()) {
        String decryptedPassword = encryptionUtility.decrypt(configurationEntity.getPassword());
        configuration.setPassword(decryptedPassword);
    }
    return populateConfiguration(configurationId, configuration, configurationEntity.getCreatedAt());
}
Also used : JiraServerConfigurationEntity(com.synopsys.integration.alert.channel.jira.server.database.configuration.JiraServerConfigurationEntity) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 10 with JiraServerConfigurationEntity

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

the class JiraServerGlobalConfigAccessor method populateConfiguration.

private JiraServerGlobalConfigModel populateConfiguration(UUID configurationId, JiraServerGlobalConfigModel configuration, OffsetDateTime createdAt) {
    OffsetDateTime currentTime = DateUtils.createCurrentDateTimestamp();
    JiraServerConfigurationEntity configurationToSave = toEntity(configurationId, configuration, createdAt, currentTime);
    JiraServerConfigurationEntity savedEmailConfig = jiraServerConfigurationRepository.save(configurationToSave);
    return createConfigModel(savedEmailConfig);
}
Also used : OffsetDateTime(java.time.OffsetDateTime) JiraServerConfigurationEntity(com.synopsys.integration.alert.channel.jira.server.database.configuration.JiraServerConfigurationEntity)

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