use of com.synopsys.integration.blackduck.service.dataservice.NotificationService in project blackduck-common by blackducksoftware.
the class CodeLocationWaiterTest method testAllCodeLocationsFoundEventually.
@Test
public void testAllCodeLocationsFoundEventually() throws InterruptedException, IntegrationException {
BufferedIntLogger logger = new BufferedIntLogger();
MockCodeLocationData mockCodeLocationData = twoCodeLocations();
NotificationUserView first = createTestNotification("one");
NotificationUserView second = createTestNotification("two");
List<NotificationUserView> initialResponse = Arrays.asList(first);
List<NotificationUserView> eventualResponse = Arrays.asList(first, second);
Answer eventuallyFindBoth = new Answer() {
final long startTime = System.currentTimeMillis();
final long duration = 5 * 1000;
@Override
public Object answer(InvocationOnMock invocation) {
long currentTime = System.currentTimeMillis();
if (currentTime - startTime > duration) {
return eventualResponse;
}
return initialResponse;
}
};
NotificationService mockNotificationService = Mockito.mock(NotificationService.class);
Mockito.when(mockNotificationService.getAllUserNotifications(Mockito.any(), Mockito.any())).thenAnswer(eventuallyFindBoth);
NotificationTaskRange notificationTaskRange = createTestRange();
Set<String> codeLocationNames = new HashSet<>(Arrays.asList("one", "two"));
CodeLocationWaiter codeLocationWaiter = new CodeLocationWaiter(logger, mockCodeLocationData.mockBlackDuckApiClient, mockCodeLocationData.mockProjectService, mockNotificationService);
CodeLocationWaitResult codeLocationWaitResult = codeLocationWaiter.checkCodeLocationsAddedToBom(new UserView(), notificationTaskRange, mockCodeLocationData.testProjectAndVersion, codeLocationNames, 2, 7, 5);
assertTrue(CodeLocationWaitResult.Status.COMPLETE == codeLocationWaitResult.getStatus());
assertTrue(codeLocationWaitResult.getCodeLocationNames().contains("one"));
assertTrue(codeLocationWaitResult.getCodeLocationNames().contains("two"));
assertFalse(codeLocationWaitResult.getErrorMessage().isPresent());
}
use of com.synopsys.integration.blackduck.service.dataservice.NotificationService in project blackduck-common by blackducksoftware.
the class BlackDuckServicesFactory method createCodeLocationCreationService.
public CodeLocationCreationService createCodeLocationCreationService() {
ProjectService projectService = createProjectService();
NotificationService notificationService = createNotificationService();
UserService userService = createUserService();
CodeLocationWaiter codeLocationWaiter = new CodeLocationWaiter(logger, blackDuckApiClient, projectService, notificationService);
return new CodeLocationCreationService(blackDuckApiClient, apiDiscovery, logger, codeLocationWaiter, notificationService, userService);
}
use of com.synopsys.integration.blackduck.service.dataservice.NotificationService in project blackduck-common by blackducksoftware.
the class VerifyNotifications method verify.
public static void verify(UserView currentUser, BlackDuckRegistrationService blackDuckRegistrationService, NotificationService notificationService, Date userStartDate, Date systemStartDate) throws IntegrationException {
Date endDate = Date.from(new Date().toInstant().plus(7, ChronoUnit.DAYS));
NotificationEditor systemDateEditor = new NotificationEditor(systemStartDate, endDate);
NotificationEditor userDateEditor = new NotificationEditor(userStartDate, endDate);
List<String> bomComputedFilter = Arrays.asList(NotificationType.VERSION_BOM_CODE_LOCATION_BOM_COMPUTED.name());
NotificationEditor systemDateFilteredEditor = new NotificationEditor(systemStartDate, endDate, bomComputedFilter);
NotificationEditor userDateFilteredEditor = new NotificationEditor(userStartDate, endDate, bomComputedFilter);
List<NotificationView> allNotifications = notificationService.getAllNotifications(systemDateEditor);
List<NotificationUserView> allUserNotifications = notificationService.getAllUserNotifications(currentUser, userDateEditor);
List<NotificationView> filteredNotifications = notificationService.getAllNotifications(systemDateFilteredEditor);
List<NotificationUserView> filteredUserNotifications = notificationService.getAllUserNotifications(currentUser, userDateFilteredEditor);
assertFalse(allNotifications.isEmpty());
assertFalse(allUserNotifications.isEmpty());
assertFalse(filteredNotifications.isEmpty());
assertFalse(filteredUserNotifications.isEmpty());
List<VersionBomCodeLocationBomComputedNotificationView> bomComputedNotifications = filteredNotifications.stream().map(notificationView -> (VersionBomCodeLocationBomComputedNotificationView) notificationView).collect(Collectors.toList());
List<VersionBomCodeLocationBomComputedNotificationUserView> bomComputedUserNotifications = filteredUserNotifications.stream().map(notificationView -> (VersionBomCodeLocationBomComputedNotificationUserView) notificationView).collect(Collectors.toList());
// ejk - BD has a known bug in 2020.10.0 where version bom computed is
// NOT included when asking for all
/*
* ejk 2021-07-16
* TODO should this be in VersionSupport?
*/
String version = blackDuckRegistrationService.getBlackDuckServerData().getVersion();
if (!"2020.10.0".equals(version)) {
assertTrue(allNotifications.containsAll(bomComputedNotifications));
assertTrue(allUserNotifications.containsAll(bomComputedUserNotifications));
}
assertEquals(getContents(bomComputedNotifications), getContents(bomComputedUserNotifications));
}
Aggregations