use of com.synopsys.integration.blackduck.service.dataservice.NotificationService in project blackduck-common by blackducksoftware.
the class NotificationsTestIT method testProjectNotifications.
@Test
public void testProjectNotifications() throws IntegrationException, InterruptedException {
BlackDuckServicesFactory blackDuckServicesFactory = intHttpClientTestHelper.createBlackDuckServicesFactory();
String projectName = "notifications_test_" + System.currentTimeMillis();
String projectVersionName = "notifications_test_version_" + System.currentTimeMillis();
String projectVersion2Name = "notifications_test_version2_" + System.currentTimeMillis();
BlackDuckApiClient blackDuckApiClient = blackDuckServicesFactory.getBlackDuckApiClient();
ProjectService projectService = blackDuckServicesFactory.createProjectService();
NotificationService notificationService = blackDuckServicesFactory.createNotificationService();
UserService userService = blackDuckServicesFactory.createUserService();
ProjectSyncModel projectSyncModel = ProjectSyncModel.createWithDefaults(projectName, projectVersionName);
ProjectSyncModel projectSyncModel2 = ProjectSyncModel.createWithDefaults(projectName, projectVersion2Name);
UserView currentUser = userService.findCurrentUser();
Date startDate = notificationService.getLatestUserNotificationDate(currentUser);
Date endDate = Date.from(startDate.toInstant().plus(1, ChronoUnit.DAYS));
List<String> notificationTypes = new ArrayList<>();
notificationTypes.add(NotificationType.PROJECT.name());
notificationTypes.add(NotificationType.PROJECT_VERSION.name());
// CREATE
ProjectVersionWrapper projectVersionWrapper = projectService.syncProjectAndVersion(projectSyncModel);
ProjectVersionWrapper projectVersionWrapper2 = projectService.syncProjectAndVersion(projectSyncModel2, true);
// DELETE
blackDuckApiClient.delete(projectVersionWrapper2.getProjectVersionView());
blackDuckApiClient.delete(projectVersionWrapper.getProjectView());
// two project version create
// one project version delete, one project delete
Set<String> expectedKeys = new HashSet(Arrays.asList("CREATE" + projectVersionName, "CREATE" + projectVersion2Name, "DELETE" + projectName, "DELETE" + projectVersion2Name));
Set<String> foundKeys = new HashSet<>();
long start = System.currentTimeMillis();
long duration = 0;
while ((foundKeys.size() < expectedKeys.size()) && duration < FIVE_MINUTES) {
NotificationEditor notificationEditor = new NotificationEditor(startDate, endDate, notificationTypes);
List<NotificationUserView> notifications = notificationService.getAllUserNotifications(currentUser, notificationEditor);
for (NotificationUserView notificationUserView : notifications) {
if (notificationUserView instanceof ProjectNotificationUserView) {
ProjectNotificationContent content = ((ProjectNotificationUserView) notificationUserView).getContent();
if (projectName.equals(content.getProjectName())) {
foundKeys.add(content.getOperationType() + content.getProjectName());
}
} else if (notificationUserView instanceof ProjectVersionNotificationUserView) {
ProjectVersionNotificationContent content = ((ProjectVersionNotificationUserView) notificationUserView).getContent();
if (projectName.equals(content.getProjectName())) {
foundKeys.add(content.getOperationType() + content.getProjectVersionName());
}
}
}
Thread.sleep(2000);
duration = System.currentTimeMillis() - start;
}
assertEquals(expectedKeys, foundKeys);
}
use of com.synopsys.integration.blackduck.service.dataservice.NotificationService in project blackduck-common by blackducksoftware.
the class CodeLocationWaitJobConditionTest method testMultipleNotificationsExpected.
@Test
public void testMultipleNotificationsExpected() throws ParseException, IntegrationException {
BlackDuckApiClient mockBlackDuckApiClient = Mockito.mock(BlackDuckApiClient.class);
ProjectService mockProjectService = Mockito.mock(ProjectService.class);
NotificationService mockNotificationService = Mockito.mock(NotificationService.class);
UserView userView = new UserView();
userView.setUserName("squiggles");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date alanTuringBirth = sdf.parse("1912-06-23");
Date alanTuringUntimelyDeath = sdf.parse("1954-06-07");
NotificationTaskRange notificationTaskRange = new NotificationTaskRange(System.currentTimeMillis(), alanTuringBirth, alanTuringUntimelyDeath);
IntLogger logger = new BufferedIntLogger();
NameVersion projectAndVersion = new NameVersion("BigSpoon", "LittleSpoon");
String codeLocationName = "GraceIsButGloryBegunAndGloryIsButGracePerfected";
Set<String> codeLocationNames = new HashSet<>(Arrays.asList(codeLocationName));
CodeLocationWaitJobCondition codeLocationWaitJobCondition = new CodeLocationWaitJobCondition(logger, mockBlackDuckApiClient, mockProjectService, mockNotificationService, userView, notificationTaskRange, projectAndVersion, codeLocationNames, 2);
ProjectView projectView = new ProjectView();
ResourceLink resourceLink = new ResourceLink();
resourceLink.setRel(ProjectVersionView.CODELOCATIONS_LINK);
resourceLink.setHref(codeLocationsUrl);
ResourceMetadata projectVersionViewMeta = new ResourceMetadata();
projectVersionViewMeta.setLinks(Arrays.asList(resourceLink));
ProjectVersionView projectVersionView = new ProjectVersionView();
projectVersionView.setMeta(projectVersionViewMeta);
ProjectVersionWrapper projectVersionWrapper = new ProjectVersionWrapper(projectView, projectVersionView);
Mockito.when(mockProjectService.getProjectVersion(projectAndVersion)).thenReturn(Optional.of(projectVersionWrapper));
ResourceMetadata resourceMetadata = new ResourceMetadata();
resourceMetadata.setHref(codeLocationUrl);
CodeLocationView foundCodeLocationView = new CodeLocationView();
foundCodeLocationView.setName(codeLocationName);
foundCodeLocationView.setMeta(resourceMetadata);
Mockito.when(mockBlackDuckApiClient.getAllResponses(Mockito.eq(codeLocationResponses))).thenReturn(Arrays.asList(foundCodeLocationView));
NotificationEditor notificationEditor = new NotificationEditor(notificationTaskRange.getStartDate(), notificationTaskRange.getEndDate(), Arrays.asList(NotificationType.VERSION_BOM_CODE_LOCATION_BOM_COMPUTED.name()));
Mockito.when(mockNotificationService.getAllUserNotifications(userView, notificationEditor)).thenReturn(getExpectedNotifications());
assertTrue(codeLocationWaitJobCondition.isComplete());
}
use of com.synopsys.integration.blackduck.service.dataservice.NotificationService in project blackduck-common by blackducksoftware.
the class CodeLocationWaiterTest method testAllCodeLocationsFoundImmediately.
@Test
public void testAllCodeLocationsFoundImmediately() throws InterruptedException, IntegrationException {
BufferedIntLogger logger = new BufferedIntLogger();
MockCodeLocationData mockCodeLocationData = twoCodeLocations();
NotificationService mockNotificationService = Mockito.mock(NotificationService.class);
NotificationUserView first = createTestNotification("one");
NotificationUserView second = createTestNotification("two");
Mockito.when(mockNotificationService.getAllUserNotifications(Mockito.any(), Mockito.any())).thenReturn(Arrays.asList(first, second));
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, 0, 5);
assertTrue(CodeLocationWaitResult.Status.COMPLETE == codeLocationWaitResult.getStatus(), "Status was not COMPLETE but was " + 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 CodeLocationWaiterTest method testSomeCodeLocationsFoundEventually.
@Test
public void testSomeCodeLocationsFoundEventually() throws InterruptedException, IntegrationException {
BufferedIntLogger logger = new BufferedIntLogger();
MockCodeLocationData mockCodeLocationData = oneCodeLocation();
NotificationService mockNotificationService = Mockito.mock(NotificationService.class);
NotificationUserView first = createTestNotification("one");
Mockito.when(mockNotificationService.getAllUserNotifications(Mockito.any(), Mockito.any())).thenReturn(Arrays.asList(first));
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.PARTIAL == codeLocationWaitResult.getStatus());
assertTrue(codeLocationWaitResult.getCodeLocationNames().contains("one"));
assertTrue(codeLocationWaitResult.getErrorMessage().isPresent());
}
use of com.synopsys.integration.blackduck.service.dataservice.NotificationService in project blackduck-common by blackducksoftware.
the class CodeLocationWaiterTest method testTimoutIsObeyed.
@ParameterizedTest
@CsvSource({ "20, 30", "12, 22" })
public void testTimoutIsObeyed(int timeout, int potentialMaxWait) throws IntegrationException, InterruptedException {
BufferedIntLogger logger = new BufferedIntLogger();
ProjectService mockProjectService = Mockito.mock(ProjectService.class);
Mockito.when(mockProjectService.getProjectVersion(Mockito.any())).thenReturn(Optional.empty());
NotificationService mockNotificationService = Mockito.mock(NotificationService.class);
Mockito.when(mockNotificationService.getAllUserNotifications(Mockito.any(), Mockito.any())).thenReturn(Collections.emptyList());
NotificationTaskRange notificationTaskRange = createTestRange();
Set<String> codeLocationNames = new HashSet<>(Arrays.asList("one", "two"));
CodeLocationWaiter codeLocationWaiter = new CodeLocationWaiter(logger, null, mockProjectService, mockNotificationService);
long testStart = System.currentTimeMillis();
CodeLocationWaitResult codeLocationWaitResult = codeLocationWaiter.checkCodeLocationsAddedToBom(new UserView(), notificationTaskRange, null, codeLocationNames, 2, timeout, 5);
long testEnd = System.currentTimeMillis();
System.out.println((testEnd - testStart) / 1000);
// it should not timeout BEFORE the timeout, but might take a tiny bit longer.
assertTrue(timeout <= (testEnd - testStart) / 1000);
assertTrue(potentialMaxWait > (testEnd - testStart) / 1000);
assertEquals(CodeLocationWaitResult.Status.PARTIAL, codeLocationWaitResult.getStatus());
assertNull(logger.getOutputString(LogLevel.ERROR));
assertNull(logger.getOutputString(LogLevel.WARN));
}
Aggregations