Search in sources :

Example 31 with CommonDistributionConfigEntity

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

the class DistributionConfigActions method constructRestModel.

public R constructRestModel(final D entity) throws AlertException {
    final D distributionEntity = getRepository().findOne(entity.getId());
    final CommonDistributionConfigEntity commonEntity = commonDistributionRepository.findByDistributionConfigIdAndDistributionType(entity.getId(), getDistributionName());
    if (distributionEntity != null && commonEntity != null) {
        final R restModel = constructRestModel(commonEntity, distributionEntity);
        restModel.setConfiguredProjects(configuredProjectsActions.getConfiguredProjects(commonEntity));
        restModel.setNotificationTypes(notificationTypesActions.getNotificationTypes(commonEntity));
        return restModel;
    }
    return null;
}
Also used : CommonDistributionConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity)

Example 32 with CommonDistributionConfigEntity

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

the class DistributionConfigActions method deleteConfig.

@Override
public void deleteConfig(final Long id) {
    if (id != null) {
        final CommonDistributionConfigEntity commonEntity = commonDistributionRepository.findOne(id);
        if (commonEntity != null) {
            final Long distributionConfigId = commonEntity.getDistributionConfigId();
            getRepository().delete(distributionConfigId);
            commonDistributionRepository.delete(id);
        }
        configuredProjectsActions.cleanUpConfiguredProjects();
        notificationTypesActions.removeOldNotificationTypes(id);
    }
}
Also used : CommonDistributionConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity)

Example 33 with CommonDistributionConfigEntity

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

the class DistributionChannelTest method handleEventWrongTypeTest.

@Test
public void handleEventWrongTypeTest() {
    final GlobalProperties globalProperties = new TestGlobalProperties();
    final Gson gson = new Gson();
    final CommonDistributionRepositoryWrapper commonRepositoryWrapper = Mockito.mock(CommonDistributionRepositoryWrapper.class);
    final EmailGroupChannel channel = new EmailGroupChannel(globalProperties, gson, null, null, null, commonRepositoryWrapper);
    final Long commonId = 1L;
    final EmailGroupEvent event = new EmailGroupEvent(createProjectData("Distribution Channel Test"), commonId);
    final CommonDistributionConfigEntity commonEntity = new CommonDistributionConfigEntity(commonId, SupportedChannels.SLACK, "Other Config", DigestTypeEnum.REAL_TIME, false);
    Mockito.when(commonRepositoryWrapper.findOne(Mockito.anyLong())).thenReturn(commonEntity);
    channel.handleEvent(event);
}
Also used : CommonDistributionRepositoryWrapper(com.blackducksoftware.integration.hub.alert.datasource.entity.repository.CommonDistributionRepositoryWrapper) EmailGroupEvent(com.blackducksoftware.integration.hub.alert.channel.email.EmailGroupEvent) TestGlobalProperties(com.blackducksoftware.integration.hub.alert.TestGlobalProperties) GlobalProperties(com.blackducksoftware.integration.hub.alert.config.GlobalProperties) CommonDistributionConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity) EmailGroupChannel(com.blackducksoftware.integration.hub.alert.channel.email.EmailGroupChannel) Gson(com.google.gson.Gson) TestGlobalProperties(com.blackducksoftware.integration.hub.alert.TestGlobalProperties) Test(org.junit.Test)

Example 34 with CommonDistributionConfigEntity

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

the class CommonDistributionConfigControllerTestIT method testDeleteConfig.

@Test
@Override
public void testDeleteConfig() throws Exception {
    entityRepository.deleteAll();
    final CommonDistributionConfigEntity savedEntity = entityRepository.save(entity);
    final MockHttpServletRequestBuilder request = MockMvcRequestBuilders.delete(restUrl).with(SecurityMockMvcRequestPostProcessors.user("admin").roles("ADMIN"));
    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)

Example 35 with CommonDistributionConfigEntity

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

the class CommonConfigHandlerTest method postWithInvalidConfigTest.

@Test
public void postWithInvalidConfigTest() throws AlertFieldException {
    final CommonDistributionConfigActions configActions = Mockito.mock(CommonDistributionConfigActions.class);
    final CommonConfigHandler<CommonDistributionConfigEntity, CommonDistributionConfigRestModel, CommonDistributionRepositoryWrapper> handler = new CommonConfigHandler<>(CommonDistributionConfigEntity.class, CommonDistributionConfigRestModel.class, configActions, objectTransformer);
    Mockito.when(configActions.doesConfigExist(Mockito.anyString())).thenReturn(false);
    Mockito.when(configActions.validateConfig(Mockito.any())).thenThrow(new AlertFieldException(Collections.emptyMap()));
    Mockito.when(configActions.getObjectTransformer()).thenReturn(objectTransformer);
    final CommonDistributionConfigRestModel restModel = mockCommonDistributionRestModel.createRestModel();
    final ResponseEntity<String> response = handler.postConfig(restModel);
    assertEquals(HttpStatus.BAD_REQUEST, response.getStatusCode());
}
Also used : CommonDistributionConfigActions(com.blackducksoftware.integration.hub.alert.web.actions.distribution.CommonDistributionConfigActions) CommonDistributionRepositoryWrapper(com.blackducksoftware.integration.hub.alert.datasource.entity.repository.CommonDistributionRepositoryWrapper) CommonDistributionConfigRestModel(com.blackducksoftware.integration.hub.alert.web.model.distribution.CommonDistributionConfigRestModel) CommonDistributionConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity) AlertFieldException(com.blackducksoftware.integration.hub.alert.exception.AlertFieldException) 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