use of com.blackducksoftware.integration.hub.alert.web.model.distribution.CommonDistributionConfigRestModel in project hub-alert by blackducksoftware.
the class CommonDistributionConfigActions method constructRestModel.
@Override
public CommonDistributionConfigRestModel constructRestModel(final CommonDistributionConfigEntity commonEntity, final CommonDistributionConfigEntity distributionEntity) throws AlertException {
final CommonDistributionConfigRestModel restModel = getObjectTransformer().databaseEntityToConfigRestModel(commonEntity, CommonDistributionConfigRestModel.class);
restModel.setConfiguredProjects(getConfiguredProjectsActions().getConfiguredProjects(commonEntity));
restModel.setNotificationTypes(getNotificationTypesActions().getNotificationTypes(commonEntity));
return restModel;
}
use of com.blackducksoftware.integration.hub.alert.web.model.distribution.CommonDistributionConfigRestModel in project hub-alert by blackducksoftware.
the class ChannelEventFactoryTest method createEventWithChannelManagerTest.
@Test
public void createEventWithChannelManagerTest() {
final DistributionChannelManager<GlobalChannelConfigEntity, DistributionChannelConfigEntity, AbstractChannelEvent, CommonDistributionConfigRestModel> manager = Mockito.mock(DistributionChannelManager.class);
final List<DistributionChannelManager<GlobalChannelConfigEntity, DistributionChannelConfigEntity, AbstractChannelEvent, CommonDistributionConfigRestModel>> managers = Arrays.asList(manager);
final ChannelEventFactory<AbstractChannelEvent, DistributionChannelConfigEntity, GlobalChannelConfigEntity, CommonDistributionConfigRestModel> factory = new ChannelEventFactory<>(managers);
final Long id = 25L;
final ProjectData projectData = new ProjectData(DigestTypeEnum.REAL_TIME, "Project Name", "Project Version", Collections.emptyList(), Collections.emptyMap());
final AbstractChannelEvent mockEvent = new AbstractChannelEvent(projectData, id) {
@Override
public String getTopic() {
return DISTRIBUTION_TYPE;
}
};
Mockito.when(manager.isApplicable(DISTRIBUTION_TYPE)).thenReturn(true);
Mockito.when(manager.createChannelEvent(Mockito.any(), Mockito.anyLong())).thenReturn(mockEvent);
final AbstractChannelEvent event = factory.createEvent(id, "TYPE", projectData);
assertEquals(mockEvent, event);
}
use of com.blackducksoftware.integration.hub.alert.web.model.distribution.CommonDistributionConfigRestModel 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());
}
use of com.blackducksoftware.integration.hub.alert.web.model.distribution.CommonDistributionConfigRestModel in project hub-alert by blackducksoftware.
the class CommonConfigHandlerTest method postWithInternalServerErrorTest.
@Test
public void postWithInternalServerErrorTest() throws IntegrationException {
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.doNothing().when(configActions).configurationChangeTriggers(Mockito.any());
Mockito.when(configActions.saveConfig(Mockito.any())).thenThrow(new AlertException());
final CommonDistributionConfigRestModel restModel = mockCommonDistributionRestModel.createRestModel();
final ResponseEntity<String> response = handler.postConfig(restModel);
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode());
}
use of com.blackducksoftware.integration.hub.alert.web.model.distribution.CommonDistributionConfigRestModel in project hub-alert by blackducksoftware.
the class CommonConfigHandlerTest method testConfigWithRestExceptionTest.
@Test
public void testConfigWithRestExceptionTest() throws Exception {
final CommonDistributionConfigActions configActions = Mockito.mock(CommonDistributionConfigActions.class);
final CommonConfigHandler<CommonDistributionConfigEntity, CommonDistributionConfigRestModel, CommonDistributionRepositoryWrapper> handler = new CommonConfigHandler<>(CommonDistributionConfigEntity.class, CommonDistributionConfigRestModel.class, configActions, objectTransformer);
final int responseCode = HttpStatus.BAD_GATEWAY.value();
Mockito.when(configActions.testConfig(Mockito.any())).thenThrow(new IntegrationRestException(responseCode, "", ""));
Mockito.when(configActions.getObjectTransformer()).thenReturn(objectTransformer);
final CommonDistributionConfigRestModel restModel = mockCommonDistributionRestModel.createRestModel();
final ResponseEntity<String> response = handler.testConfig(restModel);
assertEquals(HttpStatus.BAD_GATEWAY, response.getStatusCode());
}
Aggregations