Search in sources :

Example 1 with GlobalHipChatConfigEntity

use of com.blackducksoftware.integration.hub.alert.channel.hipchat.repository.global.GlobalHipChatConfigEntity in project hub-alert by blackducksoftware.

the class HipChatChannelTest method testGlobalConfigNullTest.

@Test
public void testGlobalConfigNullTest() throws Exception {
    final ChannelRestConnectionFactory restFactory = Mockito.mock(ChannelRestConnectionFactory.class);
    final HipChatChannel hipChatChannel = new HipChatChannel(null, null, null, null, null, restFactory);
    Mockito.when(restFactory.createUnauthenticatedRestConnection(Mockito.anyString())).thenReturn(null);
    final String nullEntityMessage = hipChatChannel.testGlobalConfig(null);
    assertEquals("The provided entity was null.", nullEntityMessage);
    hipChatMockUtil.setApiKey("apiKey");
    final GlobalHipChatConfigEntity entityWithKey = hipChatMockUtil.createGlobalEntity();
    final String restConnectionNullMessage = hipChatChannel.testGlobalConfig(entityWithKey);
    assertEquals("Connection error: see logs for more information.", restConnectionNullMessage);
}
Also used : ChannelRestConnectionFactory(com.blackducksoftware.integration.hub.alert.channel.rest.ChannelRestConnectionFactory) GlobalHipChatConfigEntity(com.blackducksoftware.integration.hub.alert.channel.hipchat.repository.global.GlobalHipChatConfigEntity) ExternalConnectionTest(com.blackducksoftware.integration.test.annotation.ExternalConnectionTest) Test(org.junit.Test) ChannelTest(com.blackducksoftware.integration.hub.alert.channel.ChannelTest)

Example 2 with GlobalHipChatConfigEntity

use of com.blackducksoftware.integration.hub.alert.channel.hipchat.repository.global.GlobalHipChatConfigEntity in project hub-alert by blackducksoftware.

the class HipChatChannelTest method testGlobalConfigThrowsExceptionTest.

@Test
public void testGlobalConfigThrowsExceptionTest() throws IntegrationException, MalformedURLException {
    final ChannelRestConnectionFactory restFactory = Mockito.mock(ChannelRestConnectionFactory.class);
    final HipChatChannel hipChatChannel = new HipChatChannel(null, null, null, null, null, restFactory);
    RestConnection restConnection = new UnauthenticatedRestConnection(new PrintStreamIntLogger(System.out, LogLevel.INFO), new URL("http://google.com"), 100, null, new UriCombiner());
    restConnection = Mockito.spy(restConnection);
    Mockito.doThrow(new IntegrationException("Mock exception")).when(restConnection).connect();
    Mockito.when(restFactory.createUnauthenticatedRestConnection(Mockito.anyString())).thenReturn(restConnection);
    hipChatMockUtil.setApiKey("apiKey");
    try {
        final GlobalHipChatConfigEntity entity = hipChatMockUtil.createGlobalEntity();
        hipChatChannel.testGlobalConfig(entity);
    } catch (final IntegrationException ex) {
        assertEquals("Invalid API key: Mock exception", ex.getMessage());
    }
}
Also used : UriCombiner(com.blackducksoftware.integration.hub.rest.UriCombiner) UnauthenticatedRestConnection(com.blackducksoftware.integration.hub.rest.UnauthenticatedRestConnection) RestConnection(com.blackducksoftware.integration.hub.rest.RestConnection) PrintStreamIntLogger(com.blackducksoftware.integration.log.PrintStreamIntLogger) IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) ChannelRestConnectionFactory(com.blackducksoftware.integration.hub.alert.channel.rest.ChannelRestConnectionFactory) GlobalHipChatConfigEntity(com.blackducksoftware.integration.hub.alert.channel.hipchat.repository.global.GlobalHipChatConfigEntity) UnauthenticatedRestConnection(com.blackducksoftware.integration.hub.rest.UnauthenticatedRestConnection) URL(java.net.URL) ExternalConnectionTest(com.blackducksoftware.integration.test.annotation.ExternalConnectionTest) Test(org.junit.Test) ChannelTest(com.blackducksoftware.integration.hub.alert.channel.ChannelTest)

Example 3 with GlobalHipChatConfigEntity

use of com.blackducksoftware.integration.hub.alert.channel.hipchat.repository.global.GlobalHipChatConfigEntity in project hub-alert by blackducksoftware.

the class HipChatChannelTest method testGlobalConfigAPIKeyNullTest.

@Test
public void testGlobalConfigAPIKeyNullTest() {
    final ChannelRestConnectionFactory restFactory = Mockito.mock(ChannelRestConnectionFactory.class);
    final HipChatChannel hipChatChannel = new HipChatChannel(null, null, null, null, null, restFactory);
    Mockito.when(restFactory.createUnauthenticatedRestConnection(Mockito.anyString())).thenReturn(null);
    try {
        final GlobalHipChatConfigEntity entity = hipChatMockUtil.createEmptyGlobalEntity();
        hipChatChannel.testGlobalConfig(entity);
        fail();
    } catch (final IntegrationException ex) {
        assertEquals("Invalid API key: API key not provided", ex.getMessage());
    }
}
Also used : IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) ChannelRestConnectionFactory(com.blackducksoftware.integration.hub.alert.channel.rest.ChannelRestConnectionFactory) GlobalHipChatConfigEntity(com.blackducksoftware.integration.hub.alert.channel.hipchat.repository.global.GlobalHipChatConfigEntity) ExternalConnectionTest(com.blackducksoftware.integration.test.annotation.ExternalConnectionTest) Test(org.junit.Test) ChannelTest(com.blackducksoftware.integration.hub.alert.channel.ChannelTest)

Example 4 with GlobalHipChatConfigEntity

use of com.blackducksoftware.integration.hub.alert.channel.hipchat.repository.global.GlobalHipChatConfigEntity in project hub-alert by blackducksoftware.

the class HipChatChannelTest method sendMessageTestIT.

@Test
@Category(ExternalConnectionTest.class)
public void sendMessageTestIT() throws IOException, IntegrationException {
    final AuditEntryRepositoryWrapper auditEntryRepository = Mockito.mock(AuditEntryRepositoryWrapper.class);
    final GlobalHubRepositoryWrapper mockedGlobalRepository = Mockito.mock(GlobalHubRepositoryWrapper.class);
    final TestGlobalProperties globalProperties = new TestGlobalProperties(mockedGlobalRepository, null);
    final ChannelRestConnectionFactory channelRestConnectionFactory = new ChannelRestConnectionFactory(globalProperties);
    HipChatChannel hipChatChannel = new HipChatChannel(gson, auditEntryRepository, null, null, null, channelRestConnectionFactory);
    final ProjectData data = createProjectData("Integration test project");
    final HipChatEvent event = new HipChatEvent(data, null);
    final int roomId = Integer.parseInt(properties.getProperty(TestPropertyKey.TEST_HIPCHAT_ROOM_ID));
    final boolean notify = false;
    final String color = "random";
    final HipChatDistributionConfigEntity config = new HipChatDistributionConfigEntity(roomId, notify, color);
    hipChatChannel = Mockito.spy(hipChatChannel);
    Mockito.doReturn(new GlobalHipChatConfigEntity(properties.getProperty(TestPropertyKey.TEST_HIPCHAT_API_KEY))).when(hipChatChannel).getGlobalConfigEntity();
    hipChatChannel.sendAuditedMessage(event, config);
    final boolean responseLine = outputLogger.isLineContainingText("Successfully sent a hipchat_channel message!");
    assertTrue(responseLine);
}
Also used : ChannelRestConnectionFactory(com.blackducksoftware.integration.hub.alert.channel.rest.ChannelRestConnectionFactory) AuditEntryRepositoryWrapper(com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryRepositoryWrapper) GlobalHipChatConfigEntity(com.blackducksoftware.integration.hub.alert.channel.hipchat.repository.global.GlobalHipChatConfigEntity) HipChatDistributionConfigEntity(com.blackducksoftware.integration.hub.alert.channel.hipchat.repository.distribution.HipChatDistributionConfigEntity) GlobalHubRepositoryWrapper(com.blackducksoftware.integration.hub.alert.datasource.entity.repository.global.GlobalHubRepositoryWrapper) TestGlobalProperties(com.blackducksoftware.integration.hub.alert.TestGlobalProperties) ProjectData(com.blackducksoftware.integration.hub.alert.digest.model.ProjectData) Category(org.junit.experimental.categories.Category) ExternalConnectionTest(com.blackducksoftware.integration.test.annotation.ExternalConnectionTest) Test(org.junit.Test) ChannelTest(com.blackducksoftware.integration.hub.alert.channel.ChannelTest)

Example 5 with GlobalHipChatConfigEntity

use of com.blackducksoftware.integration.hub.alert.channel.hipchat.repository.global.GlobalHipChatConfigEntity in project hub-alert by blackducksoftware.

the class MockHipChatGlobalEntity method createGlobalEntity.

@Override
public GlobalHipChatConfigEntity createGlobalEntity() {
    final GlobalHipChatConfigEntity configEntity = new GlobalHipChatConfigEntity(apiKey);
    configEntity.setId(id);
    return configEntity;
}
Also used : GlobalHipChatConfigEntity(com.blackducksoftware.integration.hub.alert.channel.hipchat.repository.global.GlobalHipChatConfigEntity)

Aggregations

GlobalHipChatConfigEntity (com.blackducksoftware.integration.hub.alert.channel.hipchat.repository.global.GlobalHipChatConfigEntity)8 Test (org.junit.Test)7 ChannelTest (com.blackducksoftware.integration.hub.alert.channel.ChannelTest)6 ChannelRestConnectionFactory (com.blackducksoftware.integration.hub.alert.channel.rest.ChannelRestConnectionFactory)6 ExternalConnectionTest (com.blackducksoftware.integration.test.annotation.ExternalConnectionTest)6 IntegrationException (com.blackducksoftware.integration.exception.IntegrationException)3 TestGlobalProperties (com.blackducksoftware.integration.hub.alert.TestGlobalProperties)3 AuditEntryRepositoryWrapper (com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryRepositoryWrapper)1 GlobalHipChatConfigRestModel (com.blackducksoftware.integration.hub.alert.channel.hipchat.controller.global.GlobalHipChatConfigRestModel)1 MockHipChatGlobalEntity (com.blackducksoftware.integration.hub.alert.channel.hipchat.mock.MockHipChatGlobalEntity)1 MockHipChatGlobalRestModel (com.blackducksoftware.integration.hub.alert.channel.hipchat.mock.MockHipChatGlobalRestModel)1 HipChatDistributionConfigEntity (com.blackducksoftware.integration.hub.alert.channel.hipchat.repository.distribution.HipChatDistributionConfigEntity)1 GlobalHubRepositoryWrapper (com.blackducksoftware.integration.hub.alert.datasource.entity.repository.global.GlobalHubRepositoryWrapper)1 ProjectData (com.blackducksoftware.integration.hub.alert.digest.model.ProjectData)1 RestConnection (com.blackducksoftware.integration.hub.rest.RestConnection)1 UnauthenticatedRestConnection (com.blackducksoftware.integration.hub.rest.UnauthenticatedRestConnection)1 UriCombiner (com.blackducksoftware.integration.hub.rest.UriCombiner)1 PrintStreamIntLogger (com.blackducksoftware.integration.log.PrintStreamIntLogger)1 URL (java.net.URL)1 Category (org.junit.experimental.categories.Category)1