Search in sources :

Example 36 with CommonDistributionConfigEntity

use of com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity 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());
}
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) AlertException(com.blackducksoftware.integration.hub.alert.exception.AlertException) Test(org.junit.Test)

Example 37 with CommonDistributionConfigEntity

use of com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity 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());
}
Also used : CommonDistributionConfigActions(com.blackducksoftware.integration.hub.alert.web.actions.distribution.CommonDistributionConfigActions) CommonDistributionRepositoryWrapper(com.blackducksoftware.integration.hub.alert.datasource.entity.repository.CommonDistributionRepositoryWrapper) IntegrationRestException(com.blackducksoftware.integration.hub.rest.exception.IntegrationRestException) CommonDistributionConfigRestModel(com.blackducksoftware.integration.hub.alert.web.model.distribution.CommonDistributionConfigRestModel) CommonDistributionConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity) Test(org.junit.Test)

Example 38 with CommonDistributionConfigEntity

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

the class CommonConfigHandlerTest method deleteConfigTest.

@Test
public void deleteConfigTest() throws AlertException {
    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(true);
    Mockito.doNothing().when(configActions).deleteConfig(Mockito.anyLong());
    final CommonDistributionConfigRestModel restModel = mockCommonDistributionRestModel.createRestModel();
    final ResponseEntity<String> response = handler.deleteConfig(restModel);
    assertEquals(HttpStatus.ACCEPTED, 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) Test(org.junit.Test)

Example 39 with CommonDistributionConfigEntity

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

the class ControllerTest method testPutConfig.

@Test
@WithMockUser(roles = "ADMIN")
public void testPutConfig() throws Exception {
    entityRepository.deleteAll();
    final E savedEntity = entityRepository.save(entity);
    final CommonDistributionConfigEntity commonEntity = commonDistributionRepository.save(distributionMockUtil.createEntity());
    final MockHttpServletRequestBuilder request = MockMvcRequestBuilders.put(restUrl).with(SecurityMockMvcRequestPostProcessors.user("admin").roles("ADMIN"));
    restModel.setDistributionConfigId(String.valueOf(savedEntity.getId()));
    restModel.setId(String.valueOf(commonEntity.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) WithMockUser(org.springframework.security.test.context.support.WithMockUser) ExternalConnectionTest(com.blackducksoftware.integration.test.annotation.ExternalConnectionTest) DatabaseConnectionTest(com.blackducksoftware.integration.test.annotation.DatabaseConnectionTest) Test(org.junit.Test)

Example 40 with CommonDistributionConfigEntity

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

the class ControllerTest method testTestConfig.

@Test
@WithMockUser(roles = "ADMIN")
public void testTestConfig() throws Exception {
    entityRepository.deleteAll();
    final E savedEntity = entityRepository.save(entity);
    final CommonDistributionConfigEntity commonEntity = commonDistributionRepository.save(distributionMockUtil.createEntity());
    final String testRestUrl = restUrl + "/test";
    final MockHttpServletRequestBuilder request = MockMvcRequestBuilders.post(testRestUrl).with(SecurityMockMvcRequestPostProcessors.user("admin").roles("ADMIN"));
    restModel.setDistributionConfigId(String.valueOf(savedEntity.getId()));
    restModel.setId(String.valueOf(commonEntity.getId()));
    request.content(gson.toJson(restModel));
    request.contentType(contentType);
    mockMvc.perform(request).andExpect(MockMvcResultMatchers.status().isOk());
}
Also used : CommonDistributionConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity) MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) WithMockUser(org.springframework.security.test.context.support.WithMockUser) ExternalConnectionTest(com.blackducksoftware.integration.test.annotation.ExternalConnectionTest) DatabaseConnectionTest(com.blackducksoftware.integration.test.annotation.DatabaseConnectionTest) 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