Search in sources :

Example 1 with GlobalHubConfigEntity

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.";
}
Also used : RestConnection(com.blackducksoftware.integration.hub.rest.RestConnection) Slf4jIntLogger(com.blackducksoftware.integration.log.Slf4jIntLogger) HubServerConfigBuilder(com.blackducksoftware.integration.hub.configuration.HubServerConfigBuilder) GlobalHubConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.global.GlobalHubConfigEntity)

Example 2 with GlobalHubConfigEntity

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;
}
Also used : GlobalHubConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.global.GlobalHubConfigEntity)

Example 3 with GlobalHubConfigEntity

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();
}
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 4 with GlobalHubConfigEntity

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;
}
Also used : GlobalHubConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.global.GlobalHubConfigEntity)

Example 5 with GlobalHubConfigEntity

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());
}
Also used : GlobalHubConfigRestModel(com.blackducksoftware.integration.hub.alert.hub.controller.global.GlobalHubConfigRestModel) GlobalHubConfigActions(com.blackducksoftware.integration.hub.alert.hub.controller.global.GlobalHubConfigActions) GlobalHubRepositoryWrapper(com.blackducksoftware.integration.hub.alert.datasource.entity.repository.global.GlobalHubRepositoryWrapper) GlobalHubConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.global.GlobalHubConfigEntity) Test(org.junit.Test)

Aggregations

GlobalHubConfigEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.global.GlobalHubConfigEntity)13 Test (org.junit.Test)7 GlobalHubRepositoryWrapper (com.blackducksoftware.integration.hub.alert.datasource.entity.repository.global.GlobalHubRepositoryWrapper)5 GlobalHubConfigRestModel (com.blackducksoftware.integration.hub.alert.hub.controller.global.GlobalHubConfigRestModel)5 GlobalHubConfigActions (com.blackducksoftware.integration.hub.alert.hub.controller.global.GlobalHubConfigActions)4 TestGlobalProperties (com.blackducksoftware.integration.hub.alert.TestGlobalProperties)3 ObjectTransformer (com.blackducksoftware.integration.hub.alert.web.ObjectTransformer)2 GlobalActionsTest (com.blackducksoftware.integration.hub.alert.web.actions.global.GlobalActionsTest)2 HubServerConfigBuilder (com.blackducksoftware.integration.hub.configuration.HubServerConfigBuilder)2 RestConnection (com.blackducksoftware.integration.hub.rest.RestConnection)2 AuditEntryRepositoryWrapper (com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryRepositoryWrapper)1 ChannelTest (com.blackducksoftware.integration.hub.alert.channel.ChannelTest)1 MockEmailEntity (com.blackducksoftware.integration.hub.alert.channel.email.mock.MockEmailEntity)1 GlobalEmailConfigEntity (com.blackducksoftware.integration.hub.alert.channel.email.repository.global.GlobalEmailConfigEntity)1 ProjectData (com.blackducksoftware.integration.hub.alert.digest.model.ProjectData)1 MockGlobalHubEntity (com.blackducksoftware.integration.hub.alert.hub.mock.MockGlobalHubEntity)1 MockGlobalHubRestModel (com.blackducksoftware.integration.hub.alert.hub.mock.MockGlobalHubRestModel)1 Slf4jIntLogger (com.blackducksoftware.integration.log.Slf4jIntLogger)1 DatabaseConnectionTest (com.blackducksoftware.integration.test.annotation.DatabaseConnectionTest)1 ExternalConnectionTest (com.blackducksoftware.integration.test.annotation.ExternalConnectionTest)1