Search in sources :

Example 6 with NotificationService

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());
}
Also used : NotificationTaskRange(com.synopsys.integration.blackduck.service.model.NotificationTaskRange) 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) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) VersionBomCodeLocationBomComputedNotificationUserView(com.synopsys.integration.blackduck.api.manual.view.VersionBomCodeLocationBomComputedNotificationUserView) NotificationUserView(com.synopsys.integration.blackduck.api.manual.view.NotificationUserView) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 7 with NotificationService

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);
}
Also used : CodeLocationCreationService(com.synopsys.integration.blackduck.codelocation.CodeLocationCreationService) UserService(com.synopsys.integration.blackduck.service.dataservice.UserService) ProjectService(com.synopsys.integration.blackduck.service.dataservice.ProjectService) NotificationService(com.synopsys.integration.blackduck.service.dataservice.NotificationService) CodeLocationWaiter(com.synopsys.integration.blackduck.codelocation.CodeLocationWaiter)

Example 8 with NotificationService

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));
}
Also used : VersionBomCodeLocationBomComputedNotificationView(com.synopsys.integration.blackduck.api.manual.view.VersionBomCodeLocationBomComputedNotificationView) Arrays(java.util.Arrays) IntegrationException(com.synopsys.integration.exception.IntegrationException) Date(java.util.Date) NotificationType(com.synopsys.integration.blackduck.api.manual.temporary.enumeration.NotificationType) VersionBomCodeLocationBomComputedNotificationUserView(com.synopsys.integration.blackduck.api.manual.view.VersionBomCodeLocationBomComputedNotificationUserView) NotificationService(com.synopsys.integration.blackduck.service.dataservice.NotificationService) NotificationUserView(com.synopsys.integration.blackduck.api.manual.view.NotificationUserView) BlackDuckRegistrationService(com.synopsys.integration.blackduck.service.dataservice.BlackDuckRegistrationService) VersionBomCodeLocationBomComputedNotificationContent(com.synopsys.integration.blackduck.api.manual.component.VersionBomCodeLocationBomComputedNotificationContent) Collectors(java.util.stream.Collectors) List(java.util.List) ChronoUnit(java.time.temporal.ChronoUnit) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) NotificationEditor(com.synopsys.integration.blackduck.service.request.NotificationEditor) NotificationView(com.synopsys.integration.blackduck.api.manual.view.NotificationView) UserView(com.synopsys.integration.blackduck.api.generated.view.UserView) VersionBomCodeLocationBomComputedNotificationView(com.synopsys.integration.blackduck.api.manual.view.VersionBomCodeLocationBomComputedNotificationView) NotificationView(com.synopsys.integration.blackduck.api.manual.view.NotificationView) Date(java.util.Date) VersionBomCodeLocationBomComputedNotificationUserView(com.synopsys.integration.blackduck.api.manual.view.VersionBomCodeLocationBomComputedNotificationUserView) VersionBomCodeLocationBomComputedNotificationView(com.synopsys.integration.blackduck.api.manual.view.VersionBomCodeLocationBomComputedNotificationView) NotificationEditor(com.synopsys.integration.blackduck.service.request.NotificationEditor) VersionBomCodeLocationBomComputedNotificationUserView(com.synopsys.integration.blackduck.api.manual.view.VersionBomCodeLocationBomComputedNotificationUserView) NotificationUserView(com.synopsys.integration.blackduck.api.manual.view.NotificationUserView)

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