Search in sources :

Example 11 with JiraServerConfigurationEntity

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

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

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

the class JiraServerGlobalConfigAccessorTest method getByConfigurationNameTest.

@Test
void getByConfigurationNameTest() throws AlertConfigurationException {
    UUID id = UUID.randomUUID();
    JiraServerConfigurationEntity entity = createEntity(id);
    Mockito.when(jiraServerConfigurationRepository.findByName(AlertRestConstants.DEFAULT_CONFIGURATION_NAME)).thenReturn(Optional.of(entity));
    JiraServerGlobalConfigModel configModel = jiraServerGlobalConfigAccessor.getConfigurationByName(AlertRestConstants.DEFAULT_CONFIGURATION_NAME).orElseThrow(() -> new AlertConfigurationException("Cannot find expected configuration"));
    assertEquals(id.toString(), configModel.getId());
    assertEquals(TEST_URL, configModel.getUrl());
    assertEquals(TEST_USERNAME, configModel.getUserName());
    assertTrue(configModel.getIsPasswordSet().orElse(Boolean.FALSE));
    assertEquals(TEST_PASSWORD, configModel.getPassword().orElse(null));
    assertTrue(configModel.getDisablePluginCheck().orElse(Boolean.FALSE));
}
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) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException) Test(org.junit.jupiter.api.Test)

Example 14 with JiraServerConfigurationEntity

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

the class JiraServerGlobalConfigAccessorTest method getPageTest.

@Test
void getPageTest() {
    UUID id = UUID.randomUUID();
    JiraServerConfigurationEntity entity = createEntity(id);
    Page<JiraServerConfigurationEntity> jiraConfigurations = new PageImpl<>(List.of(entity));
    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());
    assertNotNull(pagedModel.getModels());
    assertEquals(1, 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 15 with JiraServerConfigurationEntity

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

the class JiraServerGlobalConfigAccessorTest method createConfigurationModelNullTest.

@Test
void createConfigurationModelNullTest() throws AlertConfigurationException {
    UUID id = UUID.randomUUID();
    JiraServerConfigurationEntity entity = createEntity(id, OffsetDateTime.now(), OffsetDateTime.now());
    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.save(Mockito.any())).thenReturn(null);
    JiraServerGlobalConfigModel createdModel = jiraServerGlobalConfigAccessor.createConfiguration(model);
    assertNull(createdModel.getId());
    assertNull(createdModel.getUrl());
    assertNull(createdModel.getUserName());
    assertTrue(createdModel.getIsPasswordSet().isEmpty());
    assertTrue(createdModel.getPassword().isEmpty());
    assertTrue(createdModel.getDisablePluginCheck().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)

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