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