Search in sources :

Example 16 with BufferedIntLogger

use of com.synopsys.integration.log.BufferedIntLogger in project synopsys-detect by blackducksoftware.

the class DetectStatusLoggerTest method testDebugContent.

@Test
public void testDebugContent() throws IOException {
    File expectedOutputFile = new File("src/test/resources/workflow/status/expectedDebugStatusLoggerOutput.txt");
    String expectedOutput = FileUtils.readFileToString(expectedOutputFile, StandardCharsets.UTF_8);
    BufferedIntLogger loggerActual = new BufferedIntLogger();
    DetectStatusLogger statusLogger = new DetectStatusLogger();
    List<Status> statusSummaries = createStatus();
    List<DetectResult> detectResults = createResults();
    List<DetectIssue> detectIssues = createIssues();
    List<Operation> detectOperations = createOperations();
    statusLogger.logDetectStatus(loggerActual, statusSummaries, detectResults, detectIssues, detectOperations, ExitCodeType.SUCCESS);
    String actualOutput = loggerActual.getOutputString(LogLevel.DEBUG);
    assertEquals(expectedOutput.trim().replaceAll("\r?\n", "\n"), actualOutput.trim().replaceAll("\r?\n", "\n"));
}
Also used : AirGapDetectResult(com.synopsys.integration.detect.workflow.result.AirGapDetectResult) DetectResult(com.synopsys.integration.detect.workflow.result.DetectResult) ReportDetectResult(com.synopsys.integration.detect.workflow.result.ReportDetectResult) BlackDuckBomDetectResult(com.synopsys.integration.detect.workflow.result.BlackDuckBomDetectResult) BufferedIntLogger(com.synopsys.integration.log.BufferedIntLogger) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 17 with BufferedIntLogger

use of com.synopsys.integration.log.BufferedIntLogger 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 18 with BufferedIntLogger

use of com.synopsys.integration.log.BufferedIntLogger 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)

Example 19 with BufferedIntLogger

use of com.synopsys.integration.log.BufferedIntLogger 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 20 with BufferedIntLogger

use of com.synopsys.integration.log.BufferedIntLogger in project blackduck-common by blackducksoftware.

the class BasicRecipe method startRecipe.

@BeforeEach
public void startRecipe() throws IntegrationException {
    /*
         * the integration logger used to display log messages from our code
         * within a 3rd party integration environment
         */
    logger = new BufferedIntLogger();
    /*
         * any usage of Black Duck API's has to begin with a url for the Black Duck
         * server and either:
         *   an API key
         * --or--
         *   a username and a password (this is what we're using here)
         */
    BlackDuckServerConfig blackDuckServerConfig = restConnectionTestHelper.getBlackDuckServerConfig();
    /*
         * next, we need to create the pieces needed for the
         * BlackDuckServicesFactory, the wrapper to get/use all Black Duck API's
         */
    BlackDuckHttpClient blackDuckHttpClient;
    if (blackDuckServerConfig.getApiToken().isPresent()) {
        blackDuckHttpClient = blackDuckServerConfig.createApiTokenBlackDuckHttpClient(logger);
    } else {
        blackDuckHttpClient = blackDuckServerConfig.createCredentialsBlackDuckHttpClient(logger);
    }
    IntEnvironmentVariables intEnvironmentVariables = IntEnvironmentVariables.includeSystemEnv();
    blackDuckServicesFactory = new BlackDuckServicesFactory(intEnvironmentVariables, executorService, logger, blackDuckHttpClient);
    blackDuckApiClient = blackDuckServicesFactory.getBlackDuckApiClient();
    apiDiscovery = blackDuckServicesFactory.getApiDiscovery();
    projectService = blackDuckServicesFactory.createProjectService();
    projectUsersService = blackDuckServicesFactory.createProjectUsersService();
    projectBomService = blackDuckServicesFactory.createProjectBomService();
    codeLocationService = blackDuckServicesFactory.createCodeLocationService();
    notificationService = blackDuckServicesFactory.createNotificationService();
    codeLocationCreationService = blackDuckServicesFactory.createCodeLocationCreationService();
    policyRuleService = blackDuckServicesFactory.createPolicyRuleService();
    bdio2UploadService = blackDuckServicesFactory.createBdio2UploadService();
    uploadRunner = new UploadBatchRunner(logger, blackDuckApiClient, apiDiscovery, executorService);
}
Also used : IntEnvironmentVariables(com.synopsys.integration.util.IntEnvironmentVariables) BlackDuckHttpClient(com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) BufferedIntLogger(com.synopsys.integration.log.BufferedIntLogger) UploadBatchRunner(com.synopsys.integration.blackduck.codelocation.bdiolegacy.UploadBatchRunner) BlackDuckServerConfig(com.synopsys.integration.blackduck.configuration.BlackDuckServerConfig) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

BufferedIntLogger (com.synopsys.integration.log.BufferedIntLogger)26 Test (org.junit.jupiter.api.Test)20 IntLogger (com.synopsys.integration.log.IntLogger)8 File (java.io.File)7 UserView (com.synopsys.integration.blackduck.api.generated.view.UserView)6 NotificationTaskRange (com.synopsys.integration.blackduck.service.model.NotificationTaskRange)6 HttpUrl (com.synopsys.integration.rest.HttpUrl)6 CodeLocationView (com.synopsys.integration.blackduck.api.generated.view.CodeLocationView)5 NotificationUserView (com.synopsys.integration.blackduck.api.manual.view.NotificationUserView)5 VersionBomCodeLocationBomComputedNotificationUserView (com.synopsys.integration.blackduck.api.manual.view.VersionBomCodeLocationBomComputedNotificationUserView)5 BlackDuckHttpClient (com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient)5 BlackDuckServicesFactory (com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)5 NotificationService (com.synopsys.integration.blackduck.service.dataservice.NotificationService)5 HashSet (java.util.HashSet)5 ProjectVersionView (com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView)4 BlackDuckServerConfigBuilder (com.synopsys.integration.blackduck.configuration.BlackDuckServerConfigBuilder)4 BlackDuckResponseResolver (com.synopsys.integration.blackduck.http.transform.subclass.BlackDuckResponseResolver)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 Gson (com.google.gson.Gson)3 UploadBatchRunner (com.synopsys.integration.blackduck.codelocation.bdiolegacy.UploadBatchRunner)3