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());
}
}
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());
}
}
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);
}
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);
}
}
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);
}
Aggregations