Search in sources :

Example 1 with GlobalHubRepositoryWrapper

use of com.blackducksoftware.integration.hub.alert.datasource.entity.repository.global.GlobalHubRepositoryWrapper 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 2 with GlobalHubRepositoryWrapper

use of com.blackducksoftware.integration.hub.alert.datasource.entity.repository.global.GlobalHubRepositoryWrapper in project hub-alert by blackducksoftware.

the class GlobalHubConfigActionsTest method testTestConfig.

@Test
public void testTestConfig() throws Exception {
    final RestConnection mockedRestConnection = Mockito.mock(RestConnection.class);
    final GlobalHubRepositoryWrapper mockedGlobalRepository = Mockito.mock(GlobalHubRepositoryWrapper.class);
    final TestGlobalProperties globalProperties = new TestGlobalProperties(mockedGlobalRepository);
    GlobalHubConfigActions configActions = new GlobalHubConfigActions(mockedGlobalRepository, globalProperties, new ObjectTransformer());
    configActions = Mockito.spy(configActions);
    Mockito.doAnswer(new Answer<RestConnection>() {

        @Override
        public RestConnection answer(final InvocationOnMock invocation) throws Throwable {
            return mockedRestConnection;
        }
    }).when(configActions).createRestConnection(Mockito.any(HubServerConfigBuilder.class));
    Mockito.doNothing().when(configActions).validateHubConfiguration(Mockito.any(HubServerConfigBuilder.class));
    configActions.testConfig(getGlobalRestModelMockUtil().createGlobalRestModel());
    Mockito.verify(mockedRestConnection, Mockito.times(1)).connect();
    Mockito.reset(mockedRestConnection);
    final GlobalHubConfigRestModel fullRestModel = getGlobalRestModelMockUtil().createGlobalRestModel();
    configActions.testConfig(fullRestModel);
    Mockito.verify(mockedRestConnection, Mockito.times(1)).connect();
    Mockito.reset(mockedRestConnection);
    final GlobalHubConfigRestModel restModel = getGlobalRestModelMockUtil().createGlobalRestModel();
    final GlobalHubConfigRestModel partialRestModel = configActions.maskRestModel(restModel);
    Mockito.doAnswer(new Answer<GlobalHubConfigEntity>() {

        @Override
        public GlobalHubConfigEntity answer(final InvocationOnMock invocation) throws Throwable {
            return getGlobalEntityMockUtil().createGlobalEntity();
        }
    }).when(mockedGlobalRepository).findOne(Mockito.anyLong());
    final String result = configActions.testConfig(partialRestModel);
    assertEquals("Successfully connected to the Hub.", result);
    Mockito.verify(mockedRestConnection, Mockito.times(1)).connect();
}
Also used : GlobalHubConfigActions(com.blackducksoftware.integration.hub.alert.hub.controller.global.GlobalHubConfigActions) GlobalHubConfigRestModel(com.blackducksoftware.integration.hub.alert.hub.controller.global.GlobalHubConfigRestModel) RestConnection(com.blackducksoftware.integration.hub.rest.RestConnection) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ObjectTransformer(com.blackducksoftware.integration.hub.alert.web.ObjectTransformer) HubServerConfigBuilder(com.blackducksoftware.integration.hub.configuration.HubServerConfigBuilder) GlobalHubRepositoryWrapper(com.blackducksoftware.integration.hub.alert.datasource.entity.repository.global.GlobalHubRepositoryWrapper) TestGlobalProperties(com.blackducksoftware.integration.hub.alert.TestGlobalProperties) GlobalHubConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.global.GlobalHubConfigEntity) Test(org.junit.Test) GlobalActionsTest(com.blackducksoftware.integration.hub.alert.web.actions.global.GlobalActionsTest)

Example 3 with GlobalHubRepositoryWrapper

use of com.blackducksoftware.integration.hub.alert.datasource.entity.repository.global.GlobalHubRepositoryWrapper in project hub-alert by blackducksoftware.

the class CommonGlobalConfigHandlerTest method postConfigWhenAlreadyExistsTest.

@Test
public void postConfigWhenAlreadyExistsTest() {
    final GlobalHubConfigActions configActions = Mockito.mock(GlobalHubConfigActions.class);
    final CommonGlobalConfigHandler<GlobalHubConfigEntity, GlobalHubConfigRestModel, GlobalHubRepositoryWrapper> handler = new CommonGlobalConfigHandler<>(GlobalHubConfigEntity.class, GlobalHubConfigRestModel.class, configActions, objectTransformer);
    final GlobalHubRepositoryWrapper repository = Mockito.mock(GlobalHubRepositoryWrapper.class);
    Mockito.when(configActions.getRepository()).thenReturn(repository);
    Mockito.when(repository.findAll()).thenReturn(Arrays.asList(null, null));
    final ResponseEntity<String> response = handler.postConfig(null);
    assertEquals(HttpStatus.PRECONDITION_FAILED, response.getStatusCode());
}
Also used : GlobalHubConfigRestModel(com.blackducksoftware.integration.hub.alert.hub.controller.global.GlobalHubConfigRestModel) GlobalHubConfigActions(com.blackducksoftware.integration.hub.alert.hub.controller.global.GlobalHubConfigActions) GlobalHubRepositoryWrapper(com.blackducksoftware.integration.hub.alert.datasource.entity.repository.global.GlobalHubRepositoryWrapper) GlobalHubConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.global.GlobalHubConfigEntity) Test(org.junit.Test)

Example 4 with GlobalHubRepositoryWrapper

use of com.blackducksoftware.integration.hub.alert.datasource.entity.repository.global.GlobalHubRepositoryWrapper in project hub-alert by blackducksoftware.

the class CommonGlobalConfigHandlerTest method postConfigWhenDoesNotExistsTest.

@Test
public void postConfigWhenDoesNotExistsTest() {
    final GlobalHubConfigActions configActions = Mockito.mock(GlobalHubConfigActions.class);
    final CommonGlobalConfigHandler<GlobalHubConfigEntity, GlobalHubConfigRestModel, GlobalHubRepositoryWrapper> handler = new CommonGlobalConfigHandler<>(GlobalHubConfigEntity.class, GlobalHubConfigRestModel.class, configActions, objectTransformer);
    final GlobalHubRepositoryWrapper repository = Mockito.mock(GlobalHubRepositoryWrapper.class);
    Mockito.when(configActions.getRepository()).thenReturn(repository);
    Mockito.when(repository.findAll()).thenReturn(Collections.emptyList());
    final ResponseEntity<String> response = handler.postConfig(null);
    assertEquals(HttpStatus.BAD_REQUEST, response.getStatusCode());
}
Also used : GlobalHubConfigRestModel(com.blackducksoftware.integration.hub.alert.hub.controller.global.GlobalHubConfigRestModel) GlobalHubConfigActions(com.blackducksoftware.integration.hub.alert.hub.controller.global.GlobalHubConfigActions) GlobalHubRepositoryWrapper(com.blackducksoftware.integration.hub.alert.datasource.entity.repository.global.GlobalHubRepositoryWrapper) GlobalHubConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.global.GlobalHubConfigEntity) Test(org.junit.Test)

Example 5 with GlobalHubRepositoryWrapper

use of com.blackducksoftware.integration.hub.alert.datasource.entity.repository.global.GlobalHubRepositoryWrapper in project hub-alert by blackducksoftware.

the class GlobalHubConfigActionsTest method testGetConfig.

@Test
@Override
public void testGetConfig() throws Exception {
    final GlobalHubRepositoryWrapper mockedGlobalRepository = Mockito.mock(GlobalHubRepositoryWrapper.class);
    Mockito.when(mockedGlobalRepository.findOne(Mockito.anyLong())).thenReturn(getGlobalEntityMockUtil().createGlobalEntity());
    Mockito.when(mockedGlobalRepository.findAll()).thenReturn(Arrays.asList(getGlobalEntityMockUtil().createGlobalEntity()));
    final GlobalHubConfigEntity databaseEntity = getGlobalEntityMockUtil().createGlobalEntity();
    final TestGlobalProperties globalProperties = new TestGlobalProperties(mockedGlobalRepository);
    globalProperties.setHubTrustCertificate(null);
    globalProperties.setHubUrl(null);
    final ObjectTransformer objectTransformer = new ObjectTransformer();
    final GlobalHubConfigActions configActions = new GlobalHubConfigActions(mockedGlobalRepository, globalProperties, objectTransformer);
    final GlobalHubConfigRestModel defaultRestModel = objectTransformer.databaseEntityToConfigRestModel(databaseEntity, GlobalHubConfigRestModel.class);
    final GlobalHubConfigRestModel maskedRestModel = configActions.maskRestModel(defaultRestModel);
    List<GlobalHubConfigRestModel> globalConfigsById = configActions.getConfig(1L);
    List<GlobalHubConfigRestModel> allGlobalConfigs = configActions.getConfig(null);
    assertTrue(globalConfigsById.size() == 1);
    assertTrue(allGlobalConfigs.size() == 1);
    final GlobalHubConfigRestModel globalConfigById = globalConfigsById.get(0);
    final GlobalHubConfigRestModel globalConfig = allGlobalConfigs.get(0);
    System.out.println(maskedRestModel.toString());
    System.out.println(globalConfigById.toString());
    assertEquals(maskedRestModel, globalConfigById);
    assertEquals(maskedRestModel, globalConfig);
    Mockito.when(mockedGlobalRepository.findOne(Mockito.anyLong())).thenReturn(null);
    Mockito.when(mockedGlobalRepository.findAll()).thenReturn(null);
    globalConfigsById = configActions.getConfig(1L);
    allGlobalConfigs = configActions.getConfig(null);
    assertNotNull(globalConfigsById);
    assertNotNull(allGlobalConfigs);
    assertTrue(globalConfigsById.isEmpty());
    assertTrue(allGlobalConfigs.size() == 1);
    final GlobalHubConfigRestModel environmentGlobalConfig = allGlobalConfigs.get(0);
    assertEquals(maskedRestModel.getHubAlwaysTrustCertificate(), environmentGlobalConfig.getHubAlwaysTrustCertificate());
    assertNull(environmentGlobalConfig.getHubApiKey());
    assertEquals(maskedRestModel.getHubProxyHost(), environmentGlobalConfig.getHubProxyHost());
    assertNull(environmentGlobalConfig.getHubProxyPassword());
    assertEquals(maskedRestModel.getHubProxyPort(), environmentGlobalConfig.getHubProxyPort());
    assertEquals(maskedRestModel.getHubProxyUsername(), environmentGlobalConfig.getHubProxyUsername());
    assertNull(environmentGlobalConfig.getHubTimeout());
    assertEquals(maskedRestModel.getHubUrl(), environmentGlobalConfig.getHubUrl());
    assertNull(environmentGlobalConfig.getId());
}
Also used : GlobalHubConfigRestModel(com.blackducksoftware.integration.hub.alert.hub.controller.global.GlobalHubConfigRestModel) ObjectTransformer(com.blackducksoftware.integration.hub.alert.web.ObjectTransformer) GlobalHubConfigActions(com.blackducksoftware.integration.hub.alert.hub.controller.global.GlobalHubConfigActions) GlobalHubRepositoryWrapper(com.blackducksoftware.integration.hub.alert.datasource.entity.repository.global.GlobalHubRepositoryWrapper) TestGlobalProperties(com.blackducksoftware.integration.hub.alert.TestGlobalProperties) GlobalHubConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.global.GlobalHubConfigEntity) Test(org.junit.Test) GlobalActionsTest(com.blackducksoftware.integration.hub.alert.web.actions.global.GlobalActionsTest)

Aggregations

GlobalHubRepositoryWrapper (com.blackducksoftware.integration.hub.alert.datasource.entity.repository.global.GlobalHubRepositoryWrapper)10 TestGlobalProperties (com.blackducksoftware.integration.hub.alert.TestGlobalProperties)8 Test (org.junit.Test)8 GlobalHubConfigActions (com.blackducksoftware.integration.hub.alert.hub.controller.global.GlobalHubConfigActions)7 GlobalHubConfigEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.global.GlobalHubConfigEntity)5 GlobalHubConfigRestModel (com.blackducksoftware.integration.hub.alert.hub.controller.global.GlobalHubConfigRestModel)5 ObjectTransformer (com.blackducksoftware.integration.hub.alert.web.ObjectTransformer)4 AuditEntryRepositoryWrapper (com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryRepositoryWrapper)3 ChannelTest (com.blackducksoftware.integration.hub.alert.channel.ChannelTest)3 ProjectData (com.blackducksoftware.integration.hub.alert.digest.model.ProjectData)3 GlobalActionsTest (com.blackducksoftware.integration.hub.alert.web.actions.global.GlobalActionsTest)3 ExternalConnectionTest (com.blackducksoftware.integration.test.annotation.ExternalConnectionTest)3 Category (org.junit.experimental.categories.Category)3 ChannelRestConnectionFactory (com.blackducksoftware.integration.hub.alert.channel.rest.ChannelRestConnectionFactory)2 GlobalProperties (com.blackducksoftware.integration.hub.alert.config.GlobalProperties)2 HubServerConfigBuilder (com.blackducksoftware.integration.hub.configuration.HubServerConfigBuilder)2 RestConnection (com.blackducksoftware.integration.hub.rest.RestConnection)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 MockEmailEntity (com.blackducksoftware.integration.hub.alert.channel.email.mock.MockEmailEntity)1 GlobalEmailConfigEntity (com.blackducksoftware.integration.hub.alert.channel.email.repository.global.GlobalEmailConfigEntity)1