use of com.synopsys.integration.blackduck.api.manual.view.ProjectVersionNotificationUserView 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);
}
Aggregations