Search in sources :

Example 6 with TestGlobalProperties

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

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

the class LoginActionsTestIT method authenticateUserTestIT.

@Test
public void authenticateUserTestIT() throws IntegrationException {
    final LoginActions loginActions = new LoginActions(new TestGlobalProperties());
    final boolean userAuthenticated = loginActions.authenticateUser(mockLoginRestModel.createRestModel(), new Slf4jIntLogger(logger));
    Assert.assertTrue(userAuthenticated);
}
Also used : Slf4jIntLogger(com.blackducksoftware.integration.log.Slf4jIntLogger) TestGlobalProperties(com.blackducksoftware.integration.hub.alert.TestGlobalProperties) Test(org.junit.Test) HubConnectionTest(com.blackducksoftware.integration.test.annotation.HubConnectionTest)

Example 8 with TestGlobalProperties

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

the class NotificationItemProcessorTest method testInit.

@Test
public void testInit() {
    final GlobalProperties globalProperties = new TestGlobalProperties();
    final NotificationItemProcessor notificationItemProcessor = new NotificationItemProcessor(globalProperties, new TestLogger());
    assertTrue(notificationItemProcessor.getCacheList().size() == 2);
    assertTrue(notificationItemProcessor.getProcessorMap().size() == 4);
}
Also used : TestGlobalProperties(com.blackducksoftware.integration.hub.alert.TestGlobalProperties) GlobalProperties(com.blackducksoftware.integration.hub.alert.config.GlobalProperties) TestLogger(com.blackducksoftware.integration.test.TestLogger) TestGlobalProperties(com.blackducksoftware.integration.hub.alert.TestGlobalProperties) Test(org.junit.Test)

Example 9 with TestGlobalProperties

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

Example 10 with TestGlobalProperties

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

the class GlobalHubConfigActionsTest method getMockedConfigActions.

@Override
public GlobalHubConfigActions getMockedConfigActions() {
    final GlobalHubRepositoryWrapper mockedGlobalRepository = Mockito.mock(GlobalHubRepositoryWrapper.class);
    final GlobalProperties globalProperties = new TestGlobalProperties(mockedGlobalRepository);
    final GlobalHubConfigActions configActions = new GlobalHubConfigActions(mockedGlobalRepository, globalProperties, new ObjectTransformer());
    return configActions;
}
Also used : GlobalProperties(com.blackducksoftware.integration.hub.alert.config.GlobalProperties) TestGlobalProperties(com.blackducksoftware.integration.hub.alert.TestGlobalProperties) 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)

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