Search in sources :

Example 1 with IntegrationException

use of com.blackducksoftware.integration.exception.IntegrationException 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 2 with IntegrationException

use of com.blackducksoftware.integration.exception.IntegrationException 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 3 with IntegrationException

use of com.blackducksoftware.integration.exception.IntegrationException 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 IntegrationException

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

the class SlackChannelTestIT method testCreateRequestExceptions.

@Test
public void testCreateRequestExceptions() {
    final SlackChannel slackChannel = new SlackChannel(gson, null, null, null, null);
    final MockSlackEntity mockSlackEntity = new MockSlackEntity();
    Request request = null;
    try {
        request = slackChannel.createRequest(null, mockSlackEntity.createEmptyEntity(), null);
        fail();
    } catch (final IntegrationException e) {
        assertNull(request);
    }
    mockSlackEntity.setChannelName("");
    try {
        request = slackChannel.createRequest(null, mockSlackEntity.createEntity(), null);
        fail();
    } catch (final IntegrationException e) {
        assertNull(request);
    }
}
Also used : IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) Request(com.blackducksoftware.integration.hub.request.Request) MockSlackEntity(com.blackducksoftware.integration.hub.alert.channel.slack.mock.MockSlackEntity) ExternalConnectionTest(com.blackducksoftware.integration.test.annotation.ExternalConnectionTest) Test(org.junit.Test) ChannelTest(com.blackducksoftware.integration.hub.alert.channel.ChannelTest)

Example 5 with IntegrationException

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

the class ChannelRequestHelperTest method testSendGenericRequestThrowInegrationException.

@Test
public void testSendGenericRequestThrowInegrationException() throws Exception {
    final Request request = createRequest();
    final RestConnection restConnection = Mockito.mock(RestConnection.class);
    Mockito.when(restConnection.executeRequest(request)).thenThrow(new IntegrationException());
    final ChannelRequestHelper channelRequestHelper = new ChannelRequestHelper(restConnection);
    IntegrationException thrown = null;
    try {
        channelRequestHelper.sendGenericRequest(request);
    } catch (final IntegrationException ex) {
        thrown = ex;
    }
    assertNotNull(thrown);
}
Also used : RestConnection(com.blackducksoftware.integration.hub.rest.RestConnection) IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) Request(com.blackducksoftware.integration.hub.request.Request) Test(org.junit.Test)

Aggregations

IntegrationException (com.blackducksoftware.integration.exception.IntegrationException)49 Test (org.junit.Test)21 IOException (java.io.IOException)14 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)9 ProjectVersionView (com.blackducksoftware.integration.hub.api.generated.view.ProjectVersionView)8 RestConnection (com.blackducksoftware.integration.hub.rest.RestConnection)8 ChannelTest (com.blackducksoftware.integration.hub.alert.channel.ChannelTest)5 HubIntegrationException (com.blackducksoftware.integration.hub.exception.HubIntegrationException)5 ArrayList (java.util.ArrayList)5 Request (com.blackducksoftware.integration.hub.request.Request)4 HubServicesFactory (com.blackducksoftware.integration.hub.service.HubServicesFactory)4 UpdateFortifyApplicationAttributesRequest (com.blackducksoftware.integration.fortify.model.UpdateFortifyApplicationAttributesRequest)3 TestGlobalProperties (com.blackducksoftware.integration.hub.alert.TestGlobalProperties)3 AuditEntryRepositoryWrapper (com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryRepositoryWrapper)3 AlertException (com.blackducksoftware.integration.hub.alert.exception.AlertException)3 ProjectService (com.blackducksoftware.integration.hub.service.ProjectService)3 UserGroupService (com.blackducksoftware.integration.hub.service.UserGroupService)3 ExternalConnectionTest (com.blackducksoftware.integration.test.annotation.ExternalConnectionTest)3 File (java.io.File)3 Date (java.util.Date)3