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