Search in sources :

Example 6 with GlobalHubConfigActions

use of com.blackducksoftware.integration.hub.alert.hub.controller.global.GlobalHubConfigActions in project hub-alert by blackducksoftware.

the class GlobalHubConfigActionsTest method createMockedConfigActionsUsingObjectTransformer.

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

Example 7 with GlobalHubConfigActions

use of com.blackducksoftware.integration.hub.alert.hub.controller.global.GlobalHubConfigActions in project hub-alert by blackducksoftware.

the class GlobalHubConfigActionsTest method testValidConfig.

@Test
@Override
public void testValidConfig() throws Exception {
    final GlobalHubConfigActions configActions = new GlobalHubConfigActions(null, null, null);
    final String url = "https://www.google.com/";
    final String user = "User";
    final String password = "Password";
    HubServerConfigBuilder serverConfigBuilder = new HubServerConfigBuilder();
    serverConfigBuilder.setHubUrl(url);
    serverConfigBuilder.setUsername(user);
    serverConfigBuilder.setUsername(password);
    try {
        configActions.validateHubConfiguration(serverConfigBuilder);
        fail();
    } catch (final AlertFieldException e) {
        assertNotNull(e);
        assertEquals("There were issues with the configuration.", e.getMessage());
        assertTrue(!e.getFieldErrors().isEmpty());
    }
    final HubServerConfigValidator validator = Mockito.mock(HubServerConfigValidator.class);
    serverConfigBuilder = Mockito.spy(serverConfigBuilder);
    Mockito.when(serverConfigBuilder.createValidator()).thenReturn(validator);
    Mockito.when(validator.assertValid()).thenReturn(new ValidationResults());
    try {
        configActions.validateHubConfiguration(serverConfigBuilder);
    } catch (final AlertFieldException e) {
        fail();
    }
}
Also used : ValidationResults(com.blackducksoftware.integration.validator.ValidationResults) HubServerConfigBuilder(com.blackducksoftware.integration.hub.configuration.HubServerConfigBuilder) AlertFieldException(com.blackducksoftware.integration.hub.alert.exception.AlertFieldException) GlobalHubConfigActions(com.blackducksoftware.integration.hub.alert.hub.controller.global.GlobalHubConfigActions) HubServerConfigValidator(com.blackducksoftware.integration.hub.configuration.HubServerConfigValidator) Test(org.junit.Test) GlobalActionsTest(com.blackducksoftware.integration.hub.alert.web.actions.global.GlobalActionsTest)

Example 8 with GlobalHubConfigActions

use of com.blackducksoftware.integration.hub.alert.hub.controller.global.GlobalHubConfigActions in project hub-alert by blackducksoftware.

the class GlobalHubConfigActionsTest method testCreateRestConnection.

@Test
public void testCreateRestConnection() throws Exception {
    final GlobalHubConfigActions configActions = new GlobalHubConfigActions(null, null, null);
    final String url = "https://www.google.com/";
    final String apiToken = "User";
    HubServerConfigBuilder serverConfigBuilder = new HubServerConfigBuilder();
    serverConfigBuilder.setHubUrl(url);
    serverConfigBuilder.setApiToken(apiToken);
    // we create this spy to skip the server validation that happens in the build method
    serverConfigBuilder = Mockito.spy(serverConfigBuilder);
    Mockito.doAnswer(new Answer<HubServerConfig>() {

        @Override
        public HubServerConfig answer(final InvocationOnMock invocation) throws Throwable {
            final HubServerConfig hubServerConfig = new HubServerConfig(new URL(url), 0, apiToken, new ProxyInfo(null, 0, null, null, null, null), false, new UriCombiner());
            return hubServerConfig;
        }
    }).when(serverConfigBuilder).build();
    final RestConnection restConnection = configActions.createRestConnection(serverConfigBuilder);
    assertNotNull(restConnection);
}
Also used : ProxyInfo(com.blackducksoftware.integration.hub.proxy.ProxyInfo) UriCombiner(com.blackducksoftware.integration.hub.rest.UriCombiner) RestConnection(com.blackducksoftware.integration.hub.rest.RestConnection) HubServerConfig(com.blackducksoftware.integration.hub.configuration.HubServerConfig) InvocationOnMock(org.mockito.invocation.InvocationOnMock) HubServerConfigBuilder(com.blackducksoftware.integration.hub.configuration.HubServerConfigBuilder) GlobalHubConfigActions(com.blackducksoftware.integration.hub.alert.hub.controller.global.GlobalHubConfigActions) URL(java.net.URL) Test(org.junit.Test) GlobalActionsTest(com.blackducksoftware.integration.hub.alert.web.actions.global.GlobalActionsTest)

Example 9 with GlobalHubConfigActions

use of com.blackducksoftware.integration.hub.alert.hub.controller.global.GlobalHubConfigActions in project hub-alert by blackducksoftware.

the class GlobalHubConfigActionsTest method testChannelTestConfig.

@Test
@Override
public void testChannelTestConfig() throws Exception {
    final MockGlobalHubRestModel mockUtils = new MockGlobalHubRestModel();
    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(mockUtils.createGlobalRestModel());
    Mockito.verify(mockedRestConnection, Mockito.times(1)).connect();
    Mockito.reset(mockedRestConnection);
    final GlobalHubConfigRestModel restModel = mockUtils.createGlobalRestModel();
    final String result = configActions.channelTestConfig(restModel);
    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) MockGlobalHubRestModel(com.blackducksoftware.integration.hub.alert.hub.mock.MockGlobalHubRestModel) GlobalHubRepositoryWrapper(com.blackducksoftware.integration.hub.alert.datasource.entity.repository.global.GlobalHubRepositoryWrapper) TestGlobalProperties(com.blackducksoftware.integration.hub.alert.TestGlobalProperties) Test(org.junit.Test) GlobalActionsTest(com.blackducksoftware.integration.hub.alert.web.actions.global.GlobalActionsTest)

Aggregations

GlobalHubConfigActions (com.blackducksoftware.integration.hub.alert.hub.controller.global.GlobalHubConfigActions)9 GlobalHubRepositoryWrapper (com.blackducksoftware.integration.hub.alert.datasource.entity.repository.global.GlobalHubRepositoryWrapper)7 Test (org.junit.Test)7 TestGlobalProperties (com.blackducksoftware.integration.hub.alert.TestGlobalProperties)5 GlobalHubConfigRestModel (com.blackducksoftware.integration.hub.alert.hub.controller.global.GlobalHubConfigRestModel)5 GlobalActionsTest (com.blackducksoftware.integration.hub.alert.web.actions.global.GlobalActionsTest)5 GlobalHubConfigEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.global.GlobalHubConfigEntity)4 ObjectTransformer (com.blackducksoftware.integration.hub.alert.web.ObjectTransformer)4 HubServerConfigBuilder (com.blackducksoftware.integration.hub.configuration.HubServerConfigBuilder)4 RestConnection (com.blackducksoftware.integration.hub.rest.RestConnection)3 InvocationOnMock (org.mockito.invocation.InvocationOnMock)3 GlobalProperties (com.blackducksoftware.integration.hub.alert.config.GlobalProperties)2 AlertFieldException (com.blackducksoftware.integration.hub.alert.exception.AlertFieldException)1 MockGlobalHubRestModel (com.blackducksoftware.integration.hub.alert.hub.mock.MockGlobalHubRestModel)1 HubServerConfig (com.blackducksoftware.integration.hub.configuration.HubServerConfig)1 HubServerConfigValidator (com.blackducksoftware.integration.hub.configuration.HubServerConfigValidator)1 ProxyInfo (com.blackducksoftware.integration.hub.proxy.ProxyInfo)1 UriCombiner (com.blackducksoftware.integration.hub.rest.UriCombiner)1 ValidationResults (com.blackducksoftware.integration.validator.ValidationResults)1 URL (java.net.URL)1