use of com.blackducksoftware.integration.hub.alert.web.ObjectTransformer in project hub-alert by blackducksoftware.
the class GlobalEmailConfigActionsTest method getMockedConfigActions.
@Override
public GlobalEmailConfigActions getMockedConfigActions() {
final GlobalEmailRepositoryWrapper repository = Mockito.mock(GlobalEmailRepositoryWrapper.class);
final ObjectTransformer objectTransformer = new ObjectTransformer();
return new GlobalEmailConfigActions(repository, objectTransformer);
}
use of com.blackducksoftware.integration.hub.alert.web.ObjectTransformer in project hub-alert by blackducksoftware.
the class GlobalHipChatConfigActionsTest method getMockedConfigActions.
@Override
public GlobalHipChatConfigActions getMockedConfigActions() {
final GlobalHipChatRepositoryWrapper hipChatRepo = Mockito.mock(GlobalHipChatRepositoryWrapper.class);
final ObjectTransformer objectTransformer = new ObjectTransformer();
final HipChatManager hipChatManager = Mockito.mock(HipChatManager.class);
return new GlobalHipChatConfigActions(hipChatRepo, objectTransformer, hipChatManager);
}
use of com.blackducksoftware.integration.hub.alert.web.ObjectTransformer in project hub-alert by blackducksoftware.
the class AuditEntryActionsTest method testGetException.
@Test
public void testGetException() throws AlertException, IOException {
final AuditEntryRepositoryWrapper auditEntryRepository = Mockito.mock(AuditEntryRepositoryWrapper.class);
final NotificationRepositoryWrapper notificationRepository = Mockito.mock(NotificationRepositoryWrapper.class);
final VulnerabilityRepositoryWrapper vulnerabilityRepository = Mockito.mock(VulnerabilityRepositoryWrapper.class);
final AuditNotificationRepositoryWrapper auditNotificationRepository = Mockito.mock(AuditNotificationRepositoryWrapper.class);
final CommonDistributionRepositoryWrapper commonDistributionRepositoryWrapper = Mockito.mock(CommonDistributionRepositoryWrapper.class);
final ObjectTransformer objectTransformer = new ObjectTransformer();
final ObjectTransformer spyObjectTransformer = Mockito.spy(objectTransformer);
final MockAuditEntryEntity mockAuditEntryEntity = new MockAuditEntryEntity();
final MockNotificationEntity mockNotificationEntity = new MockNotificationEntity();
final MockCommonDistributionEntity mockCommonDistributionEntity = new MockCommonDistributionEntity();
Mockito.when(auditEntryRepository.findOne(Mockito.anyLong())).thenReturn(mockAuditEntryEntity.createEmptyEntity());
Mockito.when(commonDistributionRepositoryWrapper.findOne(Mockito.anyLong())).thenReturn(mockCommonDistributionEntity.createEntity());
Mockito.doThrow(new AlertException()).when(spyObjectTransformer).databaseEntityToConfigRestModel(Mockito.any(), Mockito.any());
Mockito.when(notificationRepository.findAll(Mockito.any())).thenReturn(Arrays.asList(mockNotificationEntity.createEntity()));
final AuditEntryActions auditEntryActions = new AuditEntryActions(auditEntryRepository, new NotificationManager(notificationRepository, vulnerabilityRepository, auditEntryRepository, auditNotificationRepository), auditNotificationRepository, commonDistributionRepositoryWrapper, spyObjectTransformer, null, null, null);
auditEntryActions.get(1L);
assertTrue(outputLogger.isLineContainingText("Problem converting audit entry"));
}
use of com.blackducksoftware.integration.hub.alert.web.ObjectTransformer in project hub-alert by blackducksoftware.
the class GlobalHubConfigActionsTest method testTestConfig.
@Test
public void testTestConfig() throws Exception {
final RestConnection mockedRestConnection = Mockito.mock(RestConnection.class);
final GlobalHubRepositoryWrapper mockedGlobalRepository = Mockito.mock(GlobalHubRepositoryWrapper.class);
final TestGlobalProperties globalProperties = new TestGlobalProperties(mockedGlobalRepository);
GlobalHubConfigActions configActions = new GlobalHubConfigActions(mockedGlobalRepository, globalProperties, new ObjectTransformer());
configActions = Mockito.spy(configActions);
Mockito.doAnswer(new Answer<RestConnection>() {
@Override
public RestConnection answer(final InvocationOnMock invocation) throws Throwable {
return mockedRestConnection;
}
}).when(configActions).createRestConnection(Mockito.any(HubServerConfigBuilder.class));
Mockito.doNothing().when(configActions).validateHubConfiguration(Mockito.any(HubServerConfigBuilder.class));
configActions.testConfig(getGlobalRestModelMockUtil().createGlobalRestModel());
Mockito.verify(mockedRestConnection, Mockito.times(1)).connect();
Mockito.reset(mockedRestConnection);
final GlobalHubConfigRestModel fullRestModel = getGlobalRestModelMockUtil().createGlobalRestModel();
configActions.testConfig(fullRestModel);
Mockito.verify(mockedRestConnection, Mockito.times(1)).connect();
Mockito.reset(mockedRestConnection);
final GlobalHubConfigRestModel restModel = getGlobalRestModelMockUtil().createGlobalRestModel();
final GlobalHubConfigRestModel partialRestModel = configActions.maskRestModel(restModel);
Mockito.doAnswer(new Answer<GlobalHubConfigEntity>() {
@Override
public GlobalHubConfigEntity answer(final InvocationOnMock invocation) throws Throwable {
return getGlobalEntityMockUtil().createGlobalEntity();
}
}).when(mockedGlobalRepository).findOne(Mockito.anyLong());
final String result = configActions.testConfig(partialRestModel);
assertEquals("Successfully connected to the Hub.", result);
Mockito.verify(mockedRestConnection, Mockito.times(1)).connect();
}
use of com.blackducksoftware.integration.hub.alert.web.ObjectTransformer in project hub-alert by blackducksoftware.
the class HubDataHandlerTest method testGetHubGroupsThrowException.
@Test
public void testGetHubGroupsThrowException() throws Exception {
final ObjectTransformer objectTransformer = new ObjectTransformer();
final Gson gson = new Gson();
final HubDataActions hubDataActions = Mockito.mock(HubDataActions.class);
Mockito.when(hubDataActions.getHubGroups()).thenThrow(new IllegalStateException("ErrorMessage"));
final HubDataHandler hubDataHandler = new HubDataHandler(objectTransformer, gson, hubDataActions);
final ResponseEntity<String> responseEntity = hubDataHandler.getHubGroups();
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, responseEntity.getStatusCode());
assertEquals("{\"id\":-1,\"message\":\"ErrorMessage\"}", responseEntity.getBody());
}
Aggregations