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