Search in sources :

Example 1 with TestGlobalProperties

use of com.blackducksoftware.integration.hub.alert.TestGlobalProperties in project hub-alert by blackducksoftware.

the class DistributionChannelTest method receiveMessageTest.

@Test
public void receiveMessageTest() {
    final GlobalProperties globalProperties = new TestGlobalProperties();
    final Gson gson = new Gson();
    final AuditEntryRepositoryWrapper auditEntryRepository = Mockito.mock(AuditEntryRepositoryWrapper.class);
    final GlobalEmailRepositoryWrapper globalEmailRepositoryWrapper = Mockito.mock(GlobalEmailRepositoryWrapper.class);
    final EmailGroupDistributionRepositoryWrapper emailGroupRepositoryWrapper = Mockito.mock(EmailGroupDistributionRepositoryWrapper.class);
    final CommonDistributionRepositoryWrapper commonRepositoryWrapper = Mockito.mock(CommonDistributionRepositoryWrapper.class);
    final EmailGroupChannel channel = new EmailGroupChannel(globalProperties, gson, auditEntryRepository, globalEmailRepositoryWrapper, emailGroupRepositoryWrapper, commonRepositoryWrapper);
    final Long commonId = 1L;
    final EmailGroupEvent event = new EmailGroupEvent(createProjectData("Distribution Channel Test"), commonId);
    final String jsonRepresentation = gson.toJson(event);
    final CommonDistributionConfigEntity commonEntity = new CommonDistributionConfigEntity(commonId, SupportedChannels.EMAIL_GROUP, "Email Config", DigestTypeEnum.REAL_TIME, false);
    Mockito.when(commonRepositoryWrapper.findOne(Mockito.anyLong())).thenReturn(commonEntity);
    final EmailGroupDistributionConfigEntity specificEntity = new EmailGroupDistributionConfigEntity("admins", "", "TEST SUBJECT LINE");
    Mockito.when(emailGroupRepositoryWrapper.findOne(Mockito.anyLong())).thenReturn(specificEntity);
    channel.receiveMessage(jsonRepresentation);
}
Also used : CommonDistributionConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity) EmailGroupDistributionRepositoryWrapper(com.blackducksoftware.integration.hub.alert.channel.email.repository.distribution.EmailGroupDistributionRepositoryWrapper) AuditEntryRepositoryWrapper(com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryRepositoryWrapper) EmailGroupChannel(com.blackducksoftware.integration.hub.alert.channel.email.EmailGroupChannel) Gson(com.google.gson.Gson) GlobalEmailRepositoryWrapper(com.blackducksoftware.integration.hub.alert.channel.email.repository.global.GlobalEmailRepositoryWrapper) CommonDistributionRepositoryWrapper(com.blackducksoftware.integration.hub.alert.datasource.entity.repository.CommonDistributionRepositoryWrapper) EmailGroupEvent(com.blackducksoftware.integration.hub.alert.channel.email.EmailGroupEvent) TestGlobalProperties(com.blackducksoftware.integration.hub.alert.TestGlobalProperties) GlobalProperties(com.blackducksoftware.integration.hub.alert.config.GlobalProperties) EmailGroupDistributionConfigEntity(com.blackducksoftware.integration.hub.alert.channel.email.repository.distribution.EmailGroupDistributionConfigEntity) TestGlobalProperties(com.blackducksoftware.integration.hub.alert.TestGlobalProperties) Test(org.junit.Test)

Example 2 with TestGlobalProperties

use of com.blackducksoftware.integration.hub.alert.TestGlobalProperties 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 3 with TestGlobalProperties

use of com.blackducksoftware.integration.hub.alert.TestGlobalProperties in project hub-alert by blackducksoftware.

the class RestDistributionChannelTest method sendMessageFailureTest.

@Test
public void sendMessageFailureTest() {
    final GlobalProperties globalProperties = new TestGlobalProperties();
    final ChannelRestConnectionFactory channelRestConnectionFactory = new ChannelRestConnectionFactory(globalProperties);
    final RestDistributionChannel<AbstractChannelEvent, GlobalChannelConfigEntity, DistributionChannelConfigEntity> restChannel = new RestDistributionChannel<AbstractChannelEvent, GlobalChannelConfigEntity, DistributionChannelConfigEntity>(null, null, null, null, null, null, channelRestConnectionFactory) {

        @Override
        public String getApiUrl() {
            return null;
        }

        @Override
        public Request createRequest(final ChannelRequestHelper channelRequestHelper, final DistributionChannelConfigEntity config, final ProjectData projectData) throws AlertException {
            return new Request.Builder().uri("http://google.com").build();
        }
    };
    final SlackEvent event = new SlackEvent(createProjectData("Rest channel test"), 1L);
    final SlackDistributionConfigEntity config = new SlackDistributionConfigEntity("more garbage", "garbage", "garbage");
    Exception thrownException = null;
    try {
        restChannel.sendAuditedMessage(event, config);
    } catch (final IntegrationException ex) {
        thrownException = ex;
    }
    assertNotNull(thrownException);
}
Also used : IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) SlackEvent(com.blackducksoftware.integration.hub.alert.channel.slack.SlackEvent) GlobalChannelConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.global.GlobalChannelConfigEntity) AlertException(com.blackducksoftware.integration.hub.alert.exception.AlertException) IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) AbstractChannelEvent(com.blackducksoftware.integration.hub.alert.event.AbstractChannelEvent) TestGlobalProperties(com.blackducksoftware.integration.hub.alert.TestGlobalProperties) GlobalProperties(com.blackducksoftware.integration.hub.alert.config.GlobalProperties) DistributionChannelConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.distribution.DistributionChannelConfigEntity) SlackDistributionConfigEntity(com.blackducksoftware.integration.hub.alert.channel.slack.repository.distribution.SlackDistributionConfigEntity) TestGlobalProperties(com.blackducksoftware.integration.hub.alert.TestGlobalProperties) ProjectData(com.blackducksoftware.integration.hub.alert.digest.model.ProjectData) Test(org.junit.Test) ChannelTest(com.blackducksoftware.integration.hub.alert.channel.ChannelTest)

Example 4 with TestGlobalProperties

use of com.blackducksoftware.integration.hub.alert.TestGlobalProperties in project hub-alert by blackducksoftware.

the class ChannelRestConnectionFactoryTest method testNullUrl.

@Test
public void testNullUrl() throws IOException {
    final TestGlobalProperties globalProperties = new TestGlobalProperties();
    final ChannelRestConnectionFactory channelRestConnectionFactory = new ChannelRestConnectionFactory(globalProperties);
    final RestConnection restConnection = channelRestConnectionFactory.createUnauthenticatedRestConnection("bad");
    assertNull(restConnection);
    assertTrue(outputLogger.isLineContainingText("Problem generating the URL: "));
}
Also used : RestConnection(com.blackducksoftware.integration.hub.rest.RestConnection) ChannelRestConnectionFactory(com.blackducksoftware.integration.hub.alert.channel.rest.ChannelRestConnectionFactory) TestGlobalProperties(com.blackducksoftware.integration.hub.alert.TestGlobalProperties) Test(org.junit.Test)

Example 5 with TestGlobalProperties

use of com.blackducksoftware.integration.hub.alert.TestGlobalProperties in project hub-alert by blackducksoftware.

the class ChannelRestConnectionFactoryTest method testConnectionFields.

@Test
public void testConnectionFields() throws EncryptionException {
    final String host = "host";
    final int port = 1;
    final Credentials credentials = new Credentials("username", "password");
    final TestGlobalProperties globalProperties = new TestGlobalProperties();
    globalProperties.setHubProxyHost(host);
    globalProperties.setHubProxyUsername(credentials.getUsername());
    globalProperties.setHubProxyPassword(credentials.getDecryptedPassword());
    globalProperties.setHubProxyPort(String.valueOf(port));
    globalProperties.setHubTrustCertificate(true);
    final ChannelRestConnectionFactory channelRestConnectionFactory = new ChannelRestConnectionFactory(globalProperties);
    final RestConnection restConnection = channelRestConnectionFactory.createUnauthenticatedRestConnection("https:url");
    final ProxyInfo expectedProxyInfo = new ProxyInfo(host, port, credentials, null, null, null);
    assertNotNull(restConnection);
    assertEquals(expectedProxyInfo, restConnection.getProxyInfo());
}
Also used : ProxyInfo(com.blackducksoftware.integration.hub.proxy.ProxyInfo) RestConnection(com.blackducksoftware.integration.hub.rest.RestConnection) ChannelRestConnectionFactory(com.blackducksoftware.integration.hub.alert.channel.rest.ChannelRestConnectionFactory) Credentials(com.blackducksoftware.integration.hub.Credentials) TestGlobalProperties(com.blackducksoftware.integration.hub.alert.TestGlobalProperties) Test(org.junit.Test)

Aggregations

TestGlobalProperties (com.blackducksoftware.integration.hub.alert.TestGlobalProperties)24 Test (org.junit.Test)20 GlobalProperties (com.blackducksoftware.integration.hub.alert.config.GlobalProperties)8 GlobalHubRepositoryWrapper (com.blackducksoftware.integration.hub.alert.datasource.entity.repository.global.GlobalHubRepositoryWrapper)8 ChannelTest (com.blackducksoftware.integration.hub.alert.channel.ChannelTest)6 ChannelRestConnectionFactory (com.blackducksoftware.integration.hub.alert.channel.rest.ChannelRestConnectionFactory)6 GlobalHubConfigActions (com.blackducksoftware.integration.hub.alert.hub.controller.global.GlobalHubConfigActions)5 RestConnection (com.blackducksoftware.integration.hub.rest.RestConnection)5 Slf4jIntLogger (com.blackducksoftware.integration.log.Slf4jIntLogger)5 ExternalConnectionTest (com.blackducksoftware.integration.test.annotation.ExternalConnectionTest)5 HubConnectionTest (com.blackducksoftware.integration.test.annotation.HubConnectionTest)5 AuditEntryRepositoryWrapper (com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryRepositoryWrapper)4 ProjectData (com.blackducksoftware.integration.hub.alert.digest.model.ProjectData)4 ObjectTransformer (com.blackducksoftware.integration.hub.alert.web.ObjectTransformer)4 IntegrationException (com.blackducksoftware.integration.exception.IntegrationException)3 GlobalHipChatConfigEntity (com.blackducksoftware.integration.hub.alert.channel.hipchat.repository.global.GlobalHipChatConfigEntity)3 GlobalHubConfigEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.global.GlobalHubConfigEntity)3 GlobalHubConfigRestModel (com.blackducksoftware.integration.hub.alert.hub.controller.global.GlobalHubConfigRestModel)3 GlobalActionsTest (com.blackducksoftware.integration.hub.alert.web.actions.global.GlobalActionsTest)3 HubServerConfigBuilder (com.blackducksoftware.integration.hub.configuration.HubServerConfigBuilder)3