use of com.blackducksoftware.integration.hub.alert.hub.controller.global.GlobalHubConfigRestModel 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());
}
use of com.blackducksoftware.integration.hub.alert.hub.controller.global.GlobalHubConfigRestModel in project hub-alert by blackducksoftware.
the class GlobalHubConfigActionsTest method testInvalidConfig.
@Override
public void testInvalidConfig() {
final MockGlobalHubRestModel mockUtil = new MockGlobalHubRestModel();
mockUtil.setHubTimeout("qqq");
final GlobalHubConfigRestModel restModel = mockUtil.createGlobalRestModel();
String result = null;
try {
result = configActions.validateConfig(restModel);
fail();
} catch (final AlertFieldException e) {
assertTrue(true);
}
assertNull(result);
mockUtil.setHubApiKey(StringUtils.repeat('a', 300));
final GlobalHubConfigRestModel restModelBigApi = mockUtil.createGlobalRestModel();
String resultBigApi = null;
try {
resultBigApi = configActions.validateConfig(restModelBigApi);
fail();
} catch (final AlertFieldException e) {
assertTrue(true);
}
assertNull(resultBigApi);
}
use of com.blackducksoftware.integration.hub.alert.hub.controller.global.GlobalHubConfigRestModel in project hub-alert by blackducksoftware.
the class ObjectTransformerTest method testTransformGlobalModels.
@Test
public void testTransformGlobalModels() throws Exception {
final ObjectTransformer objectTransformer = new ObjectTransformer();
final MockGlobalHubRestModel globalHubMockUtils = new MockGlobalHubRestModel();
final MockGlobalHubEntity mockGlobalHubEntity = new MockGlobalHubEntity();
final GlobalHubConfigRestModel restModel = globalHubMockUtils.createGlobalRestModel();
final GlobalHubConfigEntity configEntity = mockGlobalHubEntity.createGlobalEntity();
final GlobalHubConfigEntity transformedConfigEntity = objectTransformer.configRestModelToDatabaseEntity(restModel, GlobalHubConfigEntity.class);
final GlobalHubConfigRestModel transformedConfigRestModel = objectTransformer.databaseEntityToConfigRestModel(configEntity, GlobalHubConfigRestModel.class);
assertNull(transformedConfigRestModel.getHubAlwaysTrustCertificate());
assertEquals(restModel.getHubApiKey(), transformedConfigRestModel.getHubApiKey());
assertNull(transformedConfigRestModel.getHubProxyHost());
assertNull(transformedConfigRestModel.getHubProxyPassword());
assertNull(transformedConfigRestModel.getHubProxyPort());
assertNull(transformedConfigRestModel.getHubProxyUsername());
assertEquals(restModel.getHubTimeout(), transformedConfigRestModel.getHubTimeout());
assertNull(transformedConfigRestModel.getHubUrl());
assertEquals(restModel.getId(), transformedConfigRestModel.getId());
assertEquals(configEntity.getHubApiKey(), transformedConfigEntity.getHubApiKey());
assertEquals(configEntity.getHubTimeout(), transformedConfigEntity.getHubTimeout());
assertEquals(configEntity.getId(), transformedConfigEntity.getId());
}
use of com.blackducksoftware.integration.hub.alert.hub.controller.global.GlobalHubConfigRestModel 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