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"));
}
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());
}
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));
}
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());
}
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);
}
Aggregations