Search in sources :

Example 31 with JiraServerGlobalConfigModel

use of com.synopsys.integration.alert.channel.jira.server.model.JiraServerGlobalConfigModel 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 32 with JiraServerGlobalConfigModel

use of com.synopsys.integration.alert.channel.jira.server.model.JiraServerGlobalConfigModel 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)

Example 33 with JiraServerGlobalConfigModel

use of com.synopsys.integration.alert.channel.jira.server.model.JiraServerGlobalConfigModel in project hub-alert by blackducksoftware.

the class JiraServerGlobalConfigAccessorTest method createConfigurationTest.

@Test
void createConfigurationTest() 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(entity);
    JiraServerGlobalConfigModel createdModel = jiraServerGlobalConfigAccessor.createConfiguration(model);
    assertEquals(entity.getConfigurationId().toString(), createdModel.getId());
    assertEquals(entity.getUrl(), createdModel.getUrl());
    assertEquals(entity.getUsername(), createdModel.getUserName());
    assertTrue(createdModel.getIsPasswordSet().orElse(Boolean.FALSE));
    assertEquals(TEST_PASSWORD, createdModel.getPassword().orElse(null));
    assertEquals(entity.getDisablePluginCheck(), createdModel.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 34 with JiraServerGlobalConfigModel

use of com.synopsys.integration.alert.channel.jira.server.model.JiraServerGlobalConfigModel in project hub-alert by blackducksoftware.

the class JiraServerGlobalConfigAccessorTest method getByConfigurationIdTest.

@Test
void getByConfigurationIdTest() throws AlertConfigurationException {
    UUID id = UUID.randomUUID();
    JiraServerConfigurationEntity entity = createEntity(id);
    Mockito.when(jiraServerConfigurationRepository.findById(id)).thenReturn(Optional.of(entity));
    JiraServerGlobalConfigModel configModel = jiraServerGlobalConfigAccessor.getConfiguration(id).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 35 with JiraServerGlobalConfigModel

use of com.synopsys.integration.alert.channel.jira.server.model.JiraServerGlobalConfigModel in project hub-alert by blackducksoftware.

the class JiraServerGlobalConfigAccessorTest method updateConfigurationNotFoundTest.

@Test
void updateConfigurationNotFoundTest() {
    UUID id = UUID.randomUUID();
    String updatedName = "updatedName";
    String newUrl = "https://updated.example.com";
    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.findById(id)).thenReturn(Optional.empty());
    try {
        jiraServerGlobalConfigAccessor.updateConfiguration(id, model);
        fail("Exception expected because id not found");
    } catch (AlertConfigurationException ex) {
    // expected to get here
    }
}
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)

Aggregations

JiraServerGlobalConfigModel (com.synopsys.integration.alert.channel.jira.server.model.JiraServerGlobalConfigModel)44 Test (org.junit.jupiter.api.Test)40 UUID (java.util.UUID)17 AlertIntegrationTest (com.synopsys.integration.alert.util.AlertIntegrationTest)14 JiraServerConfigurationEntity (com.synopsys.integration.alert.channel.jira.server.database.configuration.JiraServerConfigurationEntity)10 WithMockUser (org.springframework.security.test.context.support.WithMockUser)7 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)7 JiraServerGlobalConfigAccessor (com.synopsys.integration.alert.channel.jira.server.database.accessor.JiraServerGlobalConfigAccessor)6 AlertFieldStatus (com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus)5 ValidationResponseModel (com.synopsys.integration.alert.common.rest.model.ValidationResponseModel)5 AlertConfigurationException (com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)4 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)4 ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)3 EnvironmentProcessingResult (com.synopsys.integration.alert.environment.EnvironmentProcessingResult)2 PageImpl (org.springframework.data.domain.PageImpl)2 PageRequest (org.springframework.data.domain.PageRequest)2 JiraServerEnvironmentVariableHandlerFactory (com.synopsys.integration.alert.channel.jira.server.environment.JiraServerEnvironmentVariableHandlerFactory)1 JiraServerGlobalConfigurationValidator (com.synopsys.integration.alert.channel.jira.server.validator.JiraServerGlobalConfigurationValidator)1 IssueTrackerException (com.synopsys.integration.alert.common.channel.issuetracker.exception.IssueTrackerException)1 ConfigurationTestResult (com.synopsys.integration.alert.common.message.model.ConfigurationTestResult)1