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));
}
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());
}
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());
}
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());
}
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);
}
Aggregations