Search in sources :

Example 1 with JiraServerGlobalConfigAccessor

use of com.synopsys.integration.alert.channel.jira.server.database.accessor.JiraServerGlobalConfigAccessor 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 JiraServerGlobalConfigAccessor

use of com.synopsys.integration.alert.channel.jira.server.database.accessor.JiraServerGlobalConfigAccessor 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 JiraServerGlobalConfigAccessor

use of com.synopsys.integration.alert.channel.jira.server.database.accessor.JiraServerGlobalConfigAccessor 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 JiraServerGlobalConfigAccessor

use of com.synopsys.integration.alert.channel.jira.server.database.accessor.JiraServerGlobalConfigAccessor 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 JiraServerGlobalConfigAccessor

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

the class JiraServerExternalConnectionTest method sendJiraServerMessageTest.

// This test is @Disabled since it requires a running Jira Server instance. In order to run this test, you must deploy a Jira Server and
// add the Jira Server environment values into test.properties
@Test
@Disabled
public void sendJiraServerMessageTest() throws AlertException {
    Gson gson = new Gson();
    JiraMessageFormatter jiraMessageFormatter = new JiraMessageFormatter();
    JiraServerChannelKey jiraServerChannelKey = new JiraServerChannelKey();
    JiraServerGlobalConfigAccessor jiraServerGlobalConfigAccessor = Mockito.mock(JiraServerGlobalConfigAccessor.class);
    Mockito.when(jiraServerGlobalConfigAccessor.getConfigurationByName(Mockito.anyString())).thenReturn(Optional.of(createJiraServerConfigModel()));
    ProxyManager proxyManager = Mockito.mock(ProxyManager.class);
    Mockito.when(proxyManager.createProxyInfoForHost(Mockito.anyString())).thenReturn(null);
    JobAccessor jobAccessor = Mockito.mock(JobAccessor.class);
    Mockito.when(jobAccessor.getJobById(Mockito.any())).thenReturn(Optional.of(createDistributionJobModel()));
    JiraServerPropertiesFactory jiraServerPropertiesFactory = new JiraServerPropertiesFactory(proxyManager, jiraServerGlobalConfigAccessor, jobAccessor);
    IssueTrackerCallbackInfoCreator issueTrackerCallbackInfoCreator = new IssueTrackerCallbackInfoCreator();
    IssueCategoryRetriever issueCategoryRetriever = new IssueCategoryRetriever();
    JiraServerMessageSenderFactory jiraServerMessageSenderFactory = new JiraServerMessageSenderFactory(gson, jiraServerChannelKey, jiraServerPropertiesFactory, issueTrackerCallbackInfoCreator, issueCategoryRetriever);
    ProjectMessageToIssueModelTransformer modelTransformer = new ProjectMessageToIssueModelTransformer();
    JiraServerProcessorFactory jiraServerProcessorFactory = new JiraServerProcessorFactory(gson, jiraMessageFormatter, jiraServerPropertiesFactory, jiraServerMessageSenderFactory, modelTransformer, issueCategoryRetriever);
    IssueTrackerProcessor<String> processor = jiraServerProcessorFactory.createProcessor(createDistributionDetails());
    IssueTrackerResponse<String> response = processor.processMessages(createMessage(), "jobName");
    assertEquals("Success", response.getStatusMessage());
}
Also used : JiraServerChannelKey(com.synopsys.integration.alert.descriptor.api.JiraServerChannelKey) IssueTrackerCallbackInfoCreator(com.synopsys.integration.alert.api.channel.issue.callback.IssueTrackerCallbackInfoCreator) ProxyManager(com.synopsys.integration.alert.common.rest.proxy.ProxyManager) Gson(com.google.gson.Gson) JiraServerGlobalConfigAccessor(com.synopsys.integration.alert.channel.jira.server.database.accessor.JiraServerGlobalConfigAccessor) JiraServerProcessorFactory(com.synopsys.integration.alert.channel.jira.server.distribution.JiraServerProcessorFactory) JobAccessor(com.synopsys.integration.alert.common.persistence.accessor.JobAccessor) JiraMessageFormatter(com.synopsys.integration.alert.api.channel.jira.distribution.JiraMessageFormatter) JiraServerMessageSenderFactory(com.synopsys.integration.alert.channel.jira.server.distribution.JiraServerMessageSenderFactory) ProjectMessageToIssueModelTransformer(com.synopsys.integration.alert.api.channel.issue.convert.ProjectMessageToIssueModelTransformer) IssueCategoryRetriever(com.synopsys.integration.alert.api.channel.issue.search.IssueCategoryRetriever) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Aggregations

JiraServerGlobalConfigAccessor (com.synopsys.integration.alert.channel.jira.server.database.accessor.JiraServerGlobalConfigAccessor)18 Test (org.junit.jupiter.api.Test)18 JiraServerGlobalCrudActions (com.synopsys.integration.alert.channel.jira.server.action.JiraServerGlobalCrudActions)6 JiraServerConfigurationEntity (com.synopsys.integration.alert.channel.jira.server.database.configuration.JiraServerConfigurationEntity)6 JiraServerConfigurationRepository (com.synopsys.integration.alert.channel.jira.server.database.configuration.JiraServerConfigurationRepository)6 JiraServerGlobalConfigModel (com.synopsys.integration.alert.channel.jira.server.model.JiraServerGlobalConfigModel)6 AtomicReference (java.util.concurrent.atomic.AtomicReference)6 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)5 EnvironmentProcessingResult (com.synopsys.integration.alert.environment.EnvironmentProcessingResult)5 EnvironmentVariableHandler (com.synopsys.integration.alert.environment.EnvironmentVariableHandler)5 EnvironmentVariableHandlerFactory (com.synopsys.integration.alert.environment.EnvironmentVariableHandlerFactory)5 EnvironmentVariableUtility (com.synopsys.integration.alert.environment.EnvironmentVariableUtility)5 Environment (org.springframework.core.env.Environment)5 UUID (java.util.UUID)4 AlertConstants (com.synopsys.integration.alert.api.common.model.AlertConstants)3 ChannelKeys (com.synopsys.integration.alert.descriptor.api.model.ChannelKeys)3 EnvironmentVariableMockingUtil (com.synopsys.integration.alert.test.common.EnvironmentVariableMockingUtil)3 Set (java.util.Set)3 Predicate (java.util.function.Predicate)3 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)3