@Autowired
ConnectionProviderFactory connectionProviderFactory;
@Test
public void testJiraConnectionCRUD() throws Exception {
Connection tmpConnection = new Connection.Builder()
.alias("Nodeable Jira")
.description("Nodeable's Jira instance.")
.credentials(new ConnectionCredentials(jiraProperties.getString("nodeable.jira.username"),
jiraProperties.getString("nodeable.jira.password")))
.provider(connectionProviderFactory.connectionProviderFromId(ProviderIdConstants.JIRA_PROVIDER_ID))
.url(jiraProperties.getString("nodeable.jira.url"))
.authType(AuthType.USERNAME_PASSWORD)
.user(testUser)
.build();
Connection connection = connectionService.createConnection(tmpConnection);
// Set lastActivity
HashMap<String, String> metadata = new HashMap<>();
metadata.put("last_activity_poll", Long.toString(System.currentTimeMillis()));
connection.setMetadata(metadata);
assertNotNull(connection.getId());
/* Verify the projects returned look like what we expect. (This is fragile and depends on us knowing
the projects the Jira user we're testing with has access to.
*/
validateJiraProjectHostingInventoryItems(connection);
pollForProjectHostingActivity(connection);
/* Test reading back the connection */
connection = connectionService.getConnection(connection.getId());
assertNotNull(connection);
/* Test reading all Jira connections */
assertEquals(1, connectionService.getConnections(ProjectHostingProvider.TYPE, testUser).size());
/* Test updating a connection */
connection.setCredentials(new ConnectionCredentials(jiraProperties.getString("nodeable.jira.username"),
jiraProperties.getString("nodeable.jira.password")));
connection.setDescription("Updated description.");
connection = connectionService.updateConnection(connection);
assertEquals("Updated description.", connectionService.getConnection(connection.getId()).getDescription());
/* Test deleting a connection */
connectionService.deleteConnection(connection);
try {
connectionService.getConnection(connection.getId());
fail("Should not be able to find a Jira connection with a deleted id.");
} catch (ConnectionNotFoundException e) {
// Expected
}
}