Search in sources :

Example 6 with GlobalHubConfigEntity

use of com.blackducksoftware.integration.hub.alert.datasource.entity.global.GlobalHubConfigEntity in project hub-alert by blackducksoftware.

the class CommonGlobalConfigHandlerTest method postConfigWhenDoesNotExistsTest.

@Test
public void postConfigWhenDoesNotExistsTest() {
    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(Collections.emptyList());
    final ResponseEntity<String> response = handler.postConfig(null);
    assertEquals(HttpStatus.BAD_REQUEST, 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)

Example 7 with GlobalHubConfigEntity

use of com.blackducksoftware.integration.hub.alert.datasource.entity.global.GlobalHubConfigEntity in project hub-alert by blackducksoftware.

the class GlobalHubRepositoryWrapper method decryptSensitiveData.

@Override
public GlobalHubConfigEntity decryptSensitiveData(final GlobalHubConfigEntity entity) throws EncryptionException {
    String hubApiKey = entity.getHubApiKey();
    if (StringUtils.isBlank(hubApiKey)) {
        return entity;
    } else {
        final Integer hubTimeout = entity.getHubTimeout();
        hubApiKey = PasswordDecrypter.decrypt(hubApiKey);
        final GlobalHubConfigEntity newEntity = new GlobalHubConfigEntity(hubTimeout, hubApiKey);
        newEntity.setId(entity.getId());
        return newEntity;
    }
}
Also used : GlobalHubConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.global.GlobalHubConfigEntity)

Example 8 with GlobalHubConfigEntity

use of com.blackducksoftware.integration.hub.alert.datasource.entity.global.GlobalHubConfigEntity 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());
}
Also used : GlobalHubConfigRestModel(com.blackducksoftware.integration.hub.alert.hub.controller.global.GlobalHubConfigRestModel) ObjectTransformer(com.blackducksoftware.integration.hub.alert.web.ObjectTransformer) 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) 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 9 with GlobalHubConfigEntity

use of com.blackducksoftware.integration.hub.alert.datasource.entity.global.GlobalHubConfigEntity in project hub-alert by blackducksoftware.

the class GlobalRepositoryIT method testSaveEntity.

@Test
public void testSaveEntity() {
    final Integer hubTimeout = 300;
    final String hubApiKey = "hub_api_key";
    final GlobalHubConfigEntity entity = new GlobalHubConfigEntity(hubTimeout, hubApiKey);
    final GlobalHubConfigEntity savedEntity = repository.save(entity);
    final long count = repository.count();
    assertEquals(1, count);
    final GlobalHubConfigEntity foundEntity = repository.findOne(savedEntity.getId());
    assertEquals(hubTimeout, foundEntity.getHubTimeout());
    assertEquals(hubApiKey, foundEntity.getHubApiKey());
}
Also used : GlobalHubConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.global.GlobalHubConfigEntity) Test(org.junit.Test) DatabaseConnectionTest(com.blackducksoftware.integration.test.annotation.DatabaseConnectionTest)

Example 10 with GlobalHubConfigEntity

use of com.blackducksoftware.integration.hub.alert.datasource.entity.global.GlobalHubConfigEntity in project hub-alert by blackducksoftware.

the class EmailChannelTestIT method sendEmailTest.

@Test
@Category(ExternalConnectionTest.class)
public void sendEmailTest() throws Exception {
    final AuditEntryRepositoryWrapper auditEntryRepository = Mockito.mock(AuditEntryRepositoryWrapper.class);
    final GlobalHubRepositoryWrapper globalRepository = Mockito.mock(GlobalHubRepositoryWrapper.class);
    final GlobalHubConfigEntity globalConfig = new GlobalHubConfigEntity(300, properties.getProperty(TestPropertyKey.TEST_HUB_API_KEY));
    Mockito.when(globalRepository.findAll()).thenReturn(Arrays.asList(globalConfig));
    final TestGlobalProperties globalProperties = new TestGlobalProperties(globalRepository);
    globalProperties.setHubUrl(properties.getProperty(TestPropertyKey.TEST_HUB_SERVER_URL));
    final String trustCert = properties.getProperty(TestPropertyKey.TEST_TRUST_HTTPS_CERT);
    if (trustCert != null) {
        globalProperties.setHubTrustCertificate(Boolean.valueOf(trustCert));
    }
    EmailGroupChannel emailChannel = new EmailGroupChannel(globalProperties, gson, auditEntryRepository, null, null, null);
    final ProjectData projectData = createProjectData("Manual test project");
    final EmailGroupEvent event = new EmailGroupEvent(projectData, 1L);
    final String smtpHost = properties.getProperty(TestPropertyKey.TEST_EMAIL_SMTP_HOST);
    final String smtpFrom = properties.getProperty(TestPropertyKey.TEST_EMAIL_SMTP_FROM);
    final GlobalEmailConfigEntity emailGlobalConfigEntity = new GlobalEmailConfigEntity(smtpHost, null, null, null, null, null, smtpFrom, null, null, null, null, null, null, null);
    emailChannel = Mockito.spy(emailChannel);
    Mockito.doReturn(emailGlobalConfigEntity).when(emailChannel).getGlobalConfigEntity();
    final MockEmailEntity mockEmailEntity = new MockEmailEntity();
    mockEmailEntity.setGroupName("IntegrationTest");
    emailChannel.sendAuditedMessage(event, mockEmailEntity.createEntity());
}
Also used : GlobalEmailConfigEntity(com.blackducksoftware.integration.hub.alert.channel.email.repository.global.GlobalEmailConfigEntity) AuditEntryRepositoryWrapper(com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryRepositoryWrapper) GlobalHubRepositoryWrapper(com.blackducksoftware.integration.hub.alert.datasource.entity.repository.global.GlobalHubRepositoryWrapper) TestGlobalProperties(com.blackducksoftware.integration.hub.alert.TestGlobalProperties) ProjectData(com.blackducksoftware.integration.hub.alert.digest.model.ProjectData) MockEmailEntity(com.blackducksoftware.integration.hub.alert.channel.email.mock.MockEmailEntity) GlobalHubConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.global.GlobalHubConfigEntity) Category(org.junit.experimental.categories.Category) Test(org.junit.Test) ExternalConnectionTest(com.blackducksoftware.integration.test.annotation.ExternalConnectionTest) ChannelTest(com.blackducksoftware.integration.hub.alert.channel.ChannelTest)

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