Search in sources :

Example 1 with NotificationService

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);
}
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)

Example 2 with NotificationService

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());
}
Also used : NameVersion(com.synopsys.integration.util.NameVersion) CodeLocationWaitJobCondition(com.synopsys.integration.blackduck.codelocation.CodeLocationWaitJobCondition) NotificationTaskRange(com.synopsys.integration.blackduck.service.model.NotificationTaskRange) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) ProjectService(com.synopsys.integration.blackduck.service.dataservice.ProjectService) UserView(com.synopsys.integration.blackduck.api.generated.view.UserView) VersionBomCodeLocationBomComputedNotificationUserView(com.synopsys.integration.blackduck.api.manual.view.VersionBomCodeLocationBomComputedNotificationUserView) NotificationUserView(com.synopsys.integration.blackduck.api.manual.view.NotificationUserView) NotificationService(com.synopsys.integration.blackduck.service.dataservice.NotificationService) IntLogger(com.synopsys.integration.log.IntLogger) BufferedIntLogger(com.synopsys.integration.log.BufferedIntLogger) BufferedIntLogger(com.synopsys.integration.log.BufferedIntLogger) ResourceMetadata(com.synopsys.integration.blackduck.api.core.ResourceMetadata) Date(java.util.Date) CodeLocationView(com.synopsys.integration.blackduck.api.generated.view.CodeLocationView) ResourceLink(com.synopsys.integration.blackduck.api.core.ResourceLink) ProjectVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView) NotificationEditor(com.synopsys.integration.blackduck.service.request.NotificationEditor) ProjectView(com.synopsys.integration.blackduck.api.generated.view.ProjectView) SimpleDateFormat(java.text.SimpleDateFormat) ProjectVersionWrapper(com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 3 with NotificationService

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());
}
Also used : NotificationTaskRange(com.synopsys.integration.blackduck.service.model.NotificationTaskRange) VersionBomCodeLocationBomComputedNotificationUserView(com.synopsys.integration.blackduck.api.manual.view.VersionBomCodeLocationBomComputedNotificationUserView) NotificationUserView(com.synopsys.integration.blackduck.api.manual.view.NotificationUserView) UserView(com.synopsys.integration.blackduck.api.generated.view.UserView) VersionBomCodeLocationBomComputedNotificationUserView(com.synopsys.integration.blackduck.api.manual.view.VersionBomCodeLocationBomComputedNotificationUserView) NotificationUserView(com.synopsys.integration.blackduck.api.manual.view.NotificationUserView) NotificationService(com.synopsys.integration.blackduck.service.dataservice.NotificationService) BufferedIntLogger(com.synopsys.integration.log.BufferedIntLogger) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with NotificationService

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());
}
Also used : NotificationTaskRange(com.synopsys.integration.blackduck.service.model.NotificationTaskRange) VersionBomCodeLocationBomComputedNotificationUserView(com.synopsys.integration.blackduck.api.manual.view.VersionBomCodeLocationBomComputedNotificationUserView) NotificationUserView(com.synopsys.integration.blackduck.api.manual.view.NotificationUserView) UserView(com.synopsys.integration.blackduck.api.generated.view.UserView) VersionBomCodeLocationBomComputedNotificationUserView(com.synopsys.integration.blackduck.api.manual.view.VersionBomCodeLocationBomComputedNotificationUserView) NotificationUserView(com.synopsys.integration.blackduck.api.manual.view.NotificationUserView) NotificationService(com.synopsys.integration.blackduck.service.dataservice.NotificationService) BufferedIntLogger(com.synopsys.integration.log.BufferedIntLogger) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with NotificationService

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));
}
Also used : NotificationTaskRange(com.synopsys.integration.blackduck.service.model.NotificationTaskRange) ProjectService(com.synopsys.integration.blackduck.service.dataservice.ProjectService) UserView(com.synopsys.integration.blackduck.api.generated.view.UserView) VersionBomCodeLocationBomComputedNotificationUserView(com.synopsys.integration.blackduck.api.manual.view.VersionBomCodeLocationBomComputedNotificationUserView) NotificationUserView(com.synopsys.integration.blackduck.api.manual.view.NotificationUserView) NotificationService(com.synopsys.integration.blackduck.service.dataservice.NotificationService) BufferedIntLogger(com.synopsys.integration.log.BufferedIntLogger) HashSet(java.util.HashSet) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

NotificationService (com.synopsys.integration.blackduck.service.dataservice.NotificationService)8 UserView (com.synopsys.integration.blackduck.api.generated.view.UserView)7 NotificationUserView (com.synopsys.integration.blackduck.api.manual.view.NotificationUserView)7 VersionBomCodeLocationBomComputedNotificationUserView (com.synopsys.integration.blackduck.api.manual.view.VersionBomCodeLocationBomComputedNotificationUserView)6 HashSet (java.util.HashSet)6 NotificationTaskRange (com.synopsys.integration.blackduck.service.model.NotificationTaskRange)5 BufferedIntLogger (com.synopsys.integration.log.BufferedIntLogger)5 Test (org.junit.jupiter.api.Test)5 ProjectService (com.synopsys.integration.blackduck.service.dataservice.ProjectService)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 NotificationEditor (com.synopsys.integration.blackduck.service.request.NotificationEditor)3 Date (java.util.Date)3 BlackDuckApiClient (com.synopsys.integration.blackduck.service.BlackDuckApiClient)2 UserService (com.synopsys.integration.blackduck.service.dataservice.UserService)2 ProjectVersionWrapper (com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper)2 ResourceLink (com.synopsys.integration.blackduck.api.core.ResourceLink)1 ResourceMetadata (com.synopsys.integration.blackduck.api.core.ResourceMetadata)1 CodeLocationView (com.synopsys.integration.blackduck.api.generated.view.CodeLocationView)1 ProjectVersionView (com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView)1 ProjectView (com.synopsys.integration.blackduck.api.generated.view.ProjectView)1