Search in sources :

Example 6 with CommonDistributionConfigEntity

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

the class AuditEntryHandlerTestIT method getTestIT.

@Test
public void getTestIT() {
    final MockNotificationEntity mockNotification = new MockNotificationEntity();
    final MockCommonDistributionEntity mockDistributionConfig = new MockCommonDistributionEntity();
    final NotificationEntity savedNotificationEntity = notificationRepository.save(mockNotification.createEntity());
    final CommonDistributionConfigEntity savedConfigEntity = commonDistributionRepository.save(mockDistributionConfig.createEntity());
    final AuditEntryEntity savedAuditEntryEntity = auditEntryRepository.save(new AuditEntryEntity(savedConfigEntity.getId(), new Date(System.currentTimeMillis()), new Date(System.currentTimeMillis()), StatusEnum.SUCCESS, null, null));
    auditNotificationRepository.save(new AuditNotificationRelation(savedAuditEntryEntity.getId(), savedNotificationEntity.getId()));
    final List<AuditEntryRestModel> auditEntries = auditEntryHandler.get();
    assertEquals(1, auditEntries.size());
    final AuditEntryRestModel auditEntry = auditEntryHandler.get(savedAuditEntryEntity.getId());
    assertNotNull(auditEntry);
    assertEquals(auditEntry, auditEntries.get(0));
    assertEquals(savedAuditEntryEntity.getId().toString(), auditEntry.getId());
    assertEquals(savedConfigEntity.getDistributionType(), auditEntry.getEventType());
    assertEquals(savedConfigEntity.getName(), auditEntry.getName());
    final NotificationRestModel notification = auditEntry.getNotification();
    assertEquals(savedNotificationEntity.getEventKey(), notification.getEventKey());
    assertEquals(savedNotificationEntity.getCreatedAt().toString(), notification.getCreatedAt());
    assertEquals(savedNotificationEntity.getNotificationType().name(), notification.getNotificationTypes().iterator().next());
    assertEquals(savedNotificationEntity.getProjectName(), notification.getProjectName());
    assertEquals(savedNotificationEntity.getProjectVersion(), notification.getProjectVersion());
    assertEquals(savedNotificationEntity.getProjectUrl(), notification.getProjectUrl());
    assertEquals(savedNotificationEntity.getProjectVersionUrl(), notification.getProjectVersionUrl());
    assertNotNull(notification.getComponents());
    assertTrue(!notification.getComponents().isEmpty());
    final ComponentRestModel component = notification.getComponents().iterator().next();
    assertEquals(savedNotificationEntity.getComponentName(), component.getComponentName());
    assertEquals(savedNotificationEntity.getComponentVersion(), component.getComponentVersion());
    assertEquals(savedNotificationEntity.getPolicyRuleName(), component.getPolicyRuleName());
    assertEquals(savedNotificationEntity.getPolicyRuleUser(), component.getPolicyRuleUser());
}
Also used : ComponentRestModel(com.blackducksoftware.integration.hub.alert.web.model.ComponentRestModel) MockNotificationEntity(com.blackducksoftware.integration.hub.alert.mock.entity.MockNotificationEntity) CommonDistributionConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity) NotificationRestModel(com.blackducksoftware.integration.hub.alert.web.model.NotificationRestModel) AuditNotificationRelation(com.blackducksoftware.integration.hub.alert.audit.repository.relation.AuditNotificationRelation) AuditEntryEntity(com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryEntity) MockCommonDistributionEntity(com.blackducksoftware.integration.hub.alert.mock.entity.MockCommonDistributionEntity) MockNotificationEntity(com.blackducksoftware.integration.hub.alert.mock.entity.MockNotificationEntity) NotificationEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationEntity) Date(java.sql.Date) DatabaseConnectionTest(com.blackducksoftware.integration.test.annotation.DatabaseConnectionTest) Test(org.junit.Test)

Example 7 with CommonDistributionConfigEntity

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

the class CommonDistributionRepositoryTestIT method saveEntityTestIT.

@Test
public void saveEntityTestIT() {
    final Long distributionConfigId = 1L;
    final String distributionType = SupportedChannels.EMAIL_GROUP;
    final String name = "My Config";
    final DigestTypeEnum frequency = DigestTypeEnum.DAILY;
    final Boolean filterByProject = Boolean.TRUE;
    final CommonDistributionConfigEntity entity = new CommonDistributionConfigEntity(distributionConfigId, distributionType, name, frequency, filterByProject);
    final CommonDistributionConfigEntity savedEntity = commonDistributionRepository.save(entity);
    assertEquals(1, commonDistributionRepository.count());
    assertNotNull(savedEntity.getId());
    assertEquals(distributionConfigId, savedEntity.getDistributionConfigId());
    assertEquals(distributionType, savedEntity.getDistributionType());
    assertEquals(name, savedEntity.getName());
    assertEquals(frequency, savedEntity.getFrequency());
    assertEquals(filterByProject, savedEntity.getFilterByProject());
}
Also used : DigestTypeEnum(com.blackducksoftware.integration.hub.alert.enumeration.DigestTypeEnum) CommonDistributionConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity) Test(org.junit.Test) DatabaseConnectionTest(com.blackducksoftware.integration.test.annotation.DatabaseConnectionTest)

Example 8 with CommonDistributionConfigEntity

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

the class MockCommonDistributionEntity method createEntity.

@Override
public CommonDistributionConfigEntity createEntity() {
    final CommonDistributionConfigEntity entity = new CommonDistributionConfigEntity(distributionConfigId, distributionType, name, frequency, filterByProject);
    entity.setId(id);
    return entity;
}
Also used : CommonDistributionConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity)

Example 9 with CommonDistributionConfigEntity

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

the class CommonDistributionConfigActionsTestIT method saveAndGetTestIT.

@Test
public void saveAndGetTestIT() throws AlertException {
    final String distributionType = null;
    final String name = "My Config";
    final String frequency = "DAILY";
    final String filterByProject = "true";
    final List<String> projectList = Arrays.asList("Project 1", "Project 2", "Project 3");
    final List<String> notificationTypeList = Arrays.asList("POLICY_VIOLATION", "VULNERABILITY");
    final Date lastRan = new Date(System.currentTimeMillis());
    final StatusEnum status = StatusEnum.SUCCESS;
    auditEntryRepository.save(new AuditEntryEntity(new Long(-1), lastRan, lastRan, status, "", ""));
    final CommonDistributionConfigRestModel commonDistributionConfigRestModel = new CommonDistributionConfigRestModel(null, null, distributionType, name, frequency, filterByProject, projectList, notificationTypeList);
    final CommonDistributionConfigActions commonDistributionConfigActions = new CommonDistributionConfigActions(commonDistributionRepository, auditEntryRepository, configuredProjectsActions, notificationTypesActions, objectTransformer);
    final CommonDistributionConfigEntity savedEntity = commonDistributionConfigActions.saveConfig(commonDistributionConfigRestModel);
    assertEquals(distributionType, savedEntity.getDistributionType());
    assertEquals(name, savedEntity.getName());
    assertEquals(frequency, savedEntity.getFrequency().name());
    assertEquals(filterByProject, savedEntity.getFilterByProject().toString());
    assertEquals(projectList.size(), configuredProjectsActions.getDistributionProjectRepository().count());
    assertEquals(projectList.size(), configuredProjectsActions.getConfiguredProjectsRepository().count());
    assertEquals(notificationTypeList.size(), notificationTypesActions.getDistributionNotificationTypeRepository().count());
    assertEquals(notificationTypeList.size(), notificationTypesActions.getNotificationTypeRepository().count());
    final CommonDistributionConfigRestModel updatedRestModel = objectTransformer.databaseEntityToConfigRestModel(savedEntity, CommonDistributionConfigRestModel.class);
    commonDistributionConfigActions.saveConfig(updatedRestModel);
    assertEquals(projectList.size(), configuredProjectsActions.getDistributionProjectRepository().count());
    assertEquals(projectList.size(), configuredProjectsActions.getConfiguredProjectsRepository().count());
    assertEquals(notificationTypeList.size(), notificationTypesActions.getDistributionNotificationTypeRepository().count());
    assertEquals(notificationTypeList.size(), notificationTypesActions.getNotificationTypeRepository().count());
    final List<CommonDistributionConfigRestModel> foundRestModels = commonDistributionConfigActions.getConfig(savedEntity.getId());
    assertEquals(1, foundRestModels.size());
    final CommonDistributionConfigRestModel foundRestModel = foundRestModels.get(0);
    assertEquals(savedEntity.getId(), objectTransformer.stringToLong(foundRestModel.getId()));
    assertEquals(savedEntity.getDistributionConfigId(), objectTransformer.stringToLong(foundRestModel.getDistributionConfigId()));
    assertEquals(savedEntity.getDistributionType(), foundRestModel.getDistributionType());
    assertEquals(savedEntity.getFilterByProject(), objectTransformer.stringToBoolean(foundRestModel.getFilterByProject()));
    assertEquals(projectList, foundRestModel.getConfiguredProjects());
}
Also used : StatusEnum(com.blackducksoftware.integration.hub.alert.enumeration.StatusEnum) CommonDistributionConfigRestModel(com.blackducksoftware.integration.hub.alert.web.model.distribution.CommonDistributionConfigRestModel) CommonDistributionConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity) AuditEntryEntity(com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryEntity) Date(java.util.Date) DatabaseConnectionTest(com.blackducksoftware.integration.test.annotation.DatabaseConnectionTest) Test(org.junit.Test)

Example 10 with CommonDistributionConfigEntity

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

the class CommonDistributionConfigControllerTestIT method testPutConfig.

@Test
@Override
public void testPutConfig() throws Exception {
    entityRepository.deleteAll();
    final CommonDistributionConfigEntity savedEntity = entityRepository.save(entity);
    final MockHttpServletRequestBuilder request = MockMvcRequestBuilders.put(restUrl).with(SecurityMockMvcRequestPostProcessors.user("admin").roles("ADMIN"));
    restModel.setDistributionConfigId(String.valueOf(savedEntity.getId()));
    restModel.setId(String.valueOf(savedEntity.getId()));
    request.content(gson.toJson(restModel));
    request.contentType(contentType);
    mockMvc.perform(request).andExpect(MockMvcResultMatchers.status().isAccepted());
}
Also used : CommonDistributionConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity) MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) Test(org.junit.Test)

Aggregations

CommonDistributionConfigEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity)49 Test (org.junit.Test)38 CommonDistributionConfigRestModel (com.blackducksoftware.integration.hub.alert.web.model.distribution.CommonDistributionConfigRestModel)24 CommonDistributionRepositoryWrapper (com.blackducksoftware.integration.hub.alert.datasource.entity.repository.CommonDistributionRepositoryWrapper)22 CommonDistributionConfigActions (com.blackducksoftware.integration.hub.alert.web.actions.distribution.CommonDistributionConfigActions)18 DatabaseConnectionTest (com.blackducksoftware.integration.test.annotation.DatabaseConnectionTest)14 AlertException (com.blackducksoftware.integration.hub.alert.exception.AlertException)7 AlertFieldException (com.blackducksoftware.integration.hub.alert.exception.AlertFieldException)7 AuditEntryEntity (com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryEntity)6 NotificationEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationEntity)6 ProjectData (com.blackducksoftware.integration.hub.alert.digest.model.ProjectData)6 DigestTypeEnum (com.blackducksoftware.integration.hub.alert.enumeration.DigestTypeEnum)6 IntegrationException (com.blackducksoftware.integration.exception.IntegrationException)5 AuditNotificationRelation (com.blackducksoftware.integration.hub.alert.audit.repository.relation.AuditNotificationRelation)5 AbstractChannelEvent (com.blackducksoftware.integration.hub.alert.event.AbstractChannelEvent)5 NotificationModel (com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel)5 ConfiguredProjectEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.ConfiguredProjectEntity)4 DistributionProjectRelation (com.blackducksoftware.integration.hub.alert.datasource.relation.DistributionProjectRelation)4 ArrayList (java.util.ArrayList)4 AuditEntryRepositoryWrapper (com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryRepositoryWrapper)3