use of com.blackducksoftware.integration.hub.alert.datasource.entity.global.GlobalHubConfigEntity in project hub-alert by blackducksoftware.
the class GlobalHubConfigActions method channelTestConfig.
@Override
public String channelTestConfig(final GlobalHubConfigRestModel restModel) throws IntegrationException {
final Slf4jIntLogger intLogger = new Slf4jIntLogger(logger);
String apiToken;
if (restModel.isHubApiKeyIsSet()) {
final GlobalHubConfigEntity foundEntity = getRepository().findOne(Long.parseLong(restModel.getId()));
apiToken = foundEntity.getHubApiKey();
} else {
apiToken = restModel.getHubApiKey();
}
final HubServerConfigBuilder hubServerConfigBuilder = new HubServerConfigBuilder();
hubServerConfigBuilder.setHubUrl(globalProperties.getHubUrl());
hubServerConfigBuilder.setTimeout(restModel.getHubTimeout());
hubServerConfigBuilder.setProxyHost(globalProperties.getHubProxyHost());
hubServerConfigBuilder.setProxyPort(globalProperties.getHubProxyPort());
hubServerConfigBuilder.setProxyUsername(globalProperties.getHubProxyUsername());
hubServerConfigBuilder.setApiToken(apiToken);
hubServerConfigBuilder.setProxyPassword(globalProperties.getHubProxyPassword());
if (globalProperties.getHubTrustCertificate() != null) {
hubServerConfigBuilder.setAlwaysTrustServerCertificate(globalProperties.getHubTrustCertificate());
}
hubServerConfigBuilder.setLogger(intLogger);
validateHubConfiguration(hubServerConfigBuilder);
final RestConnection restConnection = createRestConnection(hubServerConfigBuilder);
restConnection.connect();
return "Successfully connected to the Hub.";
}
use of com.blackducksoftware.integration.hub.alert.datasource.entity.global.GlobalHubConfigEntity in project hub-alert by blackducksoftware.
the class GlobalHubConfigActions method getConfig.
@Override
public List<GlobalHubConfigRestModel> getConfig(final Long id) throws AlertException {
if (id != null) {
final GlobalHubConfigEntity foundEntity = getRepository().findOne(id);
if (foundEntity != null) {
GlobalHubConfigRestModel restModel = getObjectTransformer().databaseEntityToConfigRestModel(foundEntity, getConfigRestModelClass());
restModel = updateModelFromEnvironment(restModel);
if (restModel != null) {
final GlobalHubConfigRestModel maskedRestModel = maskRestModel(restModel);
return Arrays.asList(maskedRestModel);
}
}
return Collections.emptyList();
}
final List<GlobalHubConfigEntity> databaseEntities = getRepository().findAll();
List<GlobalHubConfigRestModel> restModels = null;
if (databaseEntities != null && !databaseEntities.isEmpty()) {
restModels = getObjectTransformer().databaseEntitiesToConfigRestModels(databaseEntities, getConfigRestModelClass());
} else {
restModels = new ArrayList<>();
restModels.add(new GlobalHubConfigRestModel());
}
restModels = updateModelsFromEnvironment(restModels);
restModels = maskRestModels(restModels);
return restModels;
}
use of com.blackducksoftware.integration.hub.alert.datasource.entity.global.GlobalHubConfigEntity 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();
}
use of com.blackducksoftware.integration.hub.alert.datasource.entity.global.GlobalHubConfigEntity in project hub-alert by blackducksoftware.
the class MockGlobalHubEntity method createGlobalEntity.
@Override
public GlobalHubConfigEntity createGlobalEntity() {
final GlobalHubConfigEntity entity = new GlobalHubConfigEntity(Integer.valueOf(hubTimeout), hubApiKey);
entity.setId(id);
return entity;
}
use of com.blackducksoftware.integration.hub.alert.datasource.entity.global.GlobalHubConfigEntity 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());
}
Aggregations