Search in sources :

Example 1 with ProjectVersionNotificationUserView

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);
}
Also used : ProjectNotificationContent(com.synopsys.integration.blackduck.api.manual.component.ProjectNotificationContent) UserService(com.synopsys.integration.blackduck.service.dataservice.UserService) ProjectSyncModel(com.synopsys.integration.blackduck.service.model.ProjectSyncModel) ArrayList(java.util.ArrayList) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) ProjectService(com.synopsys.integration.blackduck.service.dataservice.ProjectService) ProjectNotificationUserView(com.synopsys.integration.blackduck.api.manual.view.ProjectNotificationUserView) UserView(com.synopsys.integration.blackduck.api.generated.view.UserView) NotificationUserView(com.synopsys.integration.blackduck.api.manual.view.NotificationUserView) ProjectVersionNotificationUserView(com.synopsys.integration.blackduck.api.manual.view.ProjectVersionNotificationUserView) NotificationService(com.synopsys.integration.blackduck.service.dataservice.NotificationService) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) Date(java.util.Date) ProjectVersionNotificationContent(com.synopsys.integration.blackduck.api.manual.component.ProjectVersionNotificationContent) ProjectVersionNotificationUserView(com.synopsys.integration.blackduck.api.manual.view.ProjectVersionNotificationUserView) NotificationEditor(com.synopsys.integration.blackduck.service.request.NotificationEditor) ProjectNotificationUserView(com.synopsys.integration.blackduck.api.manual.view.ProjectNotificationUserView) NotificationUserView(com.synopsys.integration.blackduck.api.manual.view.NotificationUserView) ProjectVersionNotificationUserView(com.synopsys.integration.blackduck.api.manual.view.ProjectVersionNotificationUserView) ProjectNotificationUserView(com.synopsys.integration.blackduck.api.manual.view.ProjectNotificationUserView) ProjectVersionWrapper(com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Aggregations

UserView (com.synopsys.integration.blackduck.api.generated.view.UserView)1 ProjectNotificationContent (com.synopsys.integration.blackduck.api.manual.component.ProjectNotificationContent)1 ProjectVersionNotificationContent (com.synopsys.integration.blackduck.api.manual.component.ProjectVersionNotificationContent)1 NotificationUserView (com.synopsys.integration.blackduck.api.manual.view.NotificationUserView)1 ProjectNotificationUserView (com.synopsys.integration.blackduck.api.manual.view.ProjectNotificationUserView)1 ProjectVersionNotificationUserView (com.synopsys.integration.blackduck.api.manual.view.ProjectVersionNotificationUserView)1 BlackDuckApiClient (com.synopsys.integration.blackduck.service.BlackDuckApiClient)1 BlackDuckServicesFactory (com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)1 NotificationService (com.synopsys.integration.blackduck.service.dataservice.NotificationService)1 ProjectService (com.synopsys.integration.blackduck.service.dataservice.ProjectService)1 UserService (com.synopsys.integration.blackduck.service.dataservice.UserService)1 ProjectSyncModel (com.synopsys.integration.blackduck.service.model.ProjectSyncModel)1 ProjectVersionWrapper (com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper)1 NotificationEditor (com.synopsys.integration.blackduck.service.request.NotificationEditor)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 Test (org.junit.jupiter.api.Test)1