@Test
public void testGitHubConnectionCRUD() throws Exception {
Connection tmpConnection = new Connection.Builder()
.alias("Nodeable GitHub")
.description("Nodeable's GitHub instance.")
.credentials(new ConnectionCredentials("fakeusername", "fakepassword"))
.provider(connectionProviderFactory.connectionProviderFromId(ProviderIdConstants.GITHUB_PROVIDER_ID))
.user(testUser)
.authType(AuthType.USERNAME_PASSWORD)
.build();
/* Test creating an invalid connection (invalid credentials) */
try {
connectionService.createConnection(tmpConnection);
fail("Should not be able to create a Jira connection with invalid credentials.");
} catch (InvalidCredentialsException e) {
// Expected
}
tmpConnection.setCredentials(new ConnectionCredentials(gitHubProperties.getString("nodeable.github.username"),
gitHubProperties.getString("nodeable.github.password")));
/* Test creating a valid connection */
Connection connection = connectionService.createConnection(tmpConnection);
assertNotNull(connection.getId());
/* Verify the projects returned look like what we expect. (This is fragile and depends on us knowing
the projects the GitHub user we're testing with watches, owns and has access to as part of an org.
*/
validateGitHubProjectHostingInventoryItems(connection);
pollForProjectHostingActivity(connection);
/* Test reading a connection (invalid id) */
try {
connectionService.getConnection(new ObjectId());
fail("Should not be able to find a GitHub connection with an invalid id.");
} catch (ConnectionNotFoundException e) {
// Expected
}
/* Test reading a connection */
connection = connectionService.getConnection(connection.getId());
assertNotNull(connection);
/* Test reading all GitHub connections */
assertEquals(1, connectionService.getConnections(ProjectHostingProvider.TYPE, testUser).size());
/* Test updating a connection (invalid credentials) */
connection.setCredentials(new ConnectionCredentials("fakeusername", "fakepassword"));
try {
connectionService.createConnection(connection);
fail("Should not be able to create a GitHub connection with invalid credentials.");
} catch (InvalidCredentialsException e) {
// Expected
}
/* Test updating a connection */
connection.setCredentials(new ConnectionCredentials(gitHubProperties.getString("nodeable.github.username"),
gitHubProperties.getString("nodeable.github.password")));
connection.setDescription("Updated description.");
connection = connectionService.updateConnection(connection);