use of com.synopsys.integration.log.BufferedIntLogger in project blackduck-common by blackducksoftware.
the class BlackDuckJsonTransformerTest method setup.
@BeforeAll
public static void setup() {
BlackDuckJsonTransformerTest.gson = BlackDuckServicesFactory.createDefaultGson();
BlackDuckJsonTransformerTest.objectMapper = BlackDuckServicesFactory.createDefaultObjectMapper();
BlackDuckJsonTransformerTest.blackDuckResponseResolver = new BlackDuckResponseResolver(gson);
BlackDuckJsonTransformerTest.logger = new BufferedIntLogger();
BlackDuckJsonTransformerTest.blackDuckJsonTransformer = new BlackDuckJsonTransformer(gson, objectMapper, blackDuckResponseResolver, logger);
}
use of com.synopsys.integration.log.BufferedIntLogger in project blackduck-common by blackducksoftware.
the class BdioUploadRecipeTest method testBdioUploadAndMapToVersion.
@Test
public void testBdioUploadAndMapToVersion() throws InterruptedException, IntegrationException {
assertCodeLocationDoesNotExist();
File file = BasicRecipe.restConnectionTestHelper.getFile("bdio/hub_common_bdio_without_project_section.jsonld");
// in this case we upload the bdio but we have to map it to a project and version ourselves since the Project information is missing in the bdio file
IntLogger logger = new BufferedIntLogger();
UploadBatchRunner uploadBatchRunner = new UploadBatchRunner(logger, blackDuckApiClient, apiDiscovery, BlackDuckServicesFactory.NO_THREAD_EXECUTOR_SERVICE);
UploadBatch uploadBatch = new UploadBatch();
uploadBatch.addUploadTarget(UploadTarget.createDefault(projectAndVersion, codeLocationName, file));
BdioUploadCodeLocationCreationRequest scanRequest = new BdioUploadCodeLocationCreationRequest(uploadBatchRunner, uploadBatch);
codeLocationCreationService.createCodeLocations(scanRequest);
// now that the file is uploaded, we want to lookup the code location that was created by the upload. in this case we know the name of the code location that was specified in the bdio file
Optional<CodeLocationView> optionalCodeLocationView = codeLocationService.getCodeLocationByName(codeLocationName);
int maxAttempts = 6;
int attempt = 0;
while (!optionalCodeLocationView.isPresent() && attempt < maxAttempts) {
// creating the code location can take a few seconds
attempt++;
Thread.sleep(5000);
optionalCodeLocationView = codeLocationService.getCodeLocationByName(codeLocationName);
}
CodeLocationView codeLocationView = optionalCodeLocationView.get();
// then we map the code location to a version
String versionName = "27.0.0-SNAPSHOT";
ProjectSyncModel projectSyncModel = ProjectSyncModel.createWithDefaults(projectAndVersion);
projectService.createProject(projectSyncModel.createProjectRequest());
projectVersionWrapper = projectService.getProjectVersion(projectAndVersion);
List<CodeLocationView> versionCodeLocations = blackDuckApiClient.getAllResponses(projectVersionWrapper.get().getProjectVersionView().metaCodelocationsLink());
assertTrue(versionCodeLocations.isEmpty());
NotificationTaskRange notificationTaskRange = codeLocationCreationService.calculateCodeLocationRange();
System.out.println(RestConstants.formatDate(notificationTaskRange.getStartDate()));
System.out.println(RestConstants.formatDate(notificationTaskRange.getEndDate()));
codeLocationService.mapCodeLocation(codeLocationView, projectVersionWrapper.get().getProjectVersionView());
CodeLocationWaitResult waitResult = codeLocationCreationService.waitForCodeLocations(notificationTaskRange, projectAndVersion, new HashSet<>(Arrays.asList(codeLocationView.getName())), 1, 3 * 60);
System.out.println("wait status: " + waitResult.getStatus());
if (waitResult.getErrorMessage().isPresent()) {
System.out.println(waitResult.getErrorMessage().get());
}
waitResult.getCodeLocationNames().stream().forEach(System.out::println);
assertEquals(CodeLocationWaitResult.Status.COMPLETE, waitResult.getStatus());
assertEquals(1, waitResult.getCodeLocationNames().size());
assertTrue(waitResult.getCodeLocationNames().contains(codeLocationName));
versionCodeLocations = blackDuckApiClient.getAllResponses(projectVersionWrapper.get().getProjectVersionView().metaCodelocationsLink());
CodeLocationView versionCodeLocation = versionCodeLocations.get(0);
assertEquals(codeLocationName, versionCodeLocation.getName());
}
use of com.synopsys.integration.log.BufferedIntLogger in project blackduck-common by blackducksoftware.
the class BdioUploadRecipeTest method testBdioUpload.
@Test
public void testBdioUpload() throws IntegrationException, InterruptedException {
assertCodeLocationDoesNotExist();
File file = BasicRecipe.restConnectionTestHelper.getFile("bdio/hub_common_bdio_with_project_section.jsonld");
// in this case we can upload the bdio and it will be mapped to a project and version because it has the Project information within the bdio file
IntLogger logger = new BufferedIntLogger();
UploadBatchRunner uploadBatchRunner = new UploadBatchRunner(logger, blackDuckApiClient, apiDiscovery, BlackDuckServicesFactory.NO_THREAD_EXECUTOR_SERVICE);
UploadBatch uploadBatch = new UploadBatch();
uploadBatch.addUploadTarget(UploadTarget.createDefault(projectAndVersion, codeLocationName, file));
BdioUploadCodeLocationCreationRequest scanRequest = new BdioUploadCodeLocationCreationRequest(uploadBatchRunner, uploadBatch);
codeLocationCreationService.createCodeLocationsAndWait(scanRequest, 15 * 60);
projectVersionWrapper = projectService.getProjectVersion(projectAndVersion);
assertTrue(projectVersionWrapper.isPresent());
List<CodeLocationView> versionCodeLocations = blackDuckApiClient.getAllResponses(projectVersionWrapper.get().getProjectVersionView().metaCodelocationsLink());
assertEquals(1, versionCodeLocations.size());
CodeLocationView versionCodeLocation = versionCodeLocations.get(0);
assertEquals(codeLocationName, versionCodeLocation.getName());
}
use of com.synopsys.integration.log.BufferedIntLogger 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());
}
use of com.synopsys.integration.log.BufferedIntLogger in project blackduck-common by blackducksoftware.
the class ScannerZipInstallerTest method testActualDownload.
@Test
void testActualDownload() throws Exception {
String signatureScannerDownloadPath = TestingPropertyKey.TEST_BLACKDUCK_SIGNATURE_SCANNER_DOWNLOAD_PATH.fromEnvironment();
String blackDuckUrl = TestingPropertyKey.TEST_BLACK_DUCK_SERVER_URL.fromEnvironment();
String blackDuckUsername = TestingPropertyKey.TEST_USERNAME.fromEnvironment();
String blackDuckPassword = TestingPropertyKey.TEST_PASSWORD.fromEnvironment();
assertTrue(StringUtils.isNotBlank(signatureScannerDownloadPath));
IntLogger logger = new BufferedIntLogger();
BlackDuckServerConfigBuilder blackDuckServerConfigBuilder = BlackDuckServerConfig.newCredentialsBuilder();
blackDuckServerConfigBuilder.setUrl(blackDuckUrl);
blackDuckServerConfigBuilder.setUsername(blackDuckUsername);
blackDuckServerConfigBuilder.setPassword(blackDuckPassword);
blackDuckServerConfigBuilder.setTimeoutInSeconds(120);
blackDuckServerConfigBuilder.setTrustCert(true);
blackDuckServerConfigBuilder.setLogger(logger);
BlackDuckServerConfig blackDuckServerConfig = blackDuckServerConfigBuilder.build();
BlackDuckHttpClient blackDuckHttpClient = blackDuckServerConfig.createBlackDuckHttpClient(logger);
BlackDuckServicesFactory blackDuckServicesFactory = blackDuckServerConfig.createBlackDuckServicesFactory(blackDuckHttpClient, logger);
BlackDuckRegistrationService blackDuckRegistrationService = blackDuckServicesFactory.createBlackDuckRegistrationService();
OperatingSystemType operatingSystemType = OperatingSystemType.determineFromSystem();
ScanPathsUtility scanPathsUtility = new ScanPathsUtility(logger, IntEnvironmentVariables.includeSystemEnv(), operatingSystemType);
CleanupZipExpander cleanupZipExpander = new CleanupZipExpander(logger);
KeyStoreHelper keyStoreHelper = new KeyStoreHelper(logger);
File downloadTarget = new File(signatureScannerDownloadPath);
ScannerZipInstaller scannerZipInstaller = new ScannerZipInstaller(logger, new SignatureScannerClient(blackDuckHttpClient), blackDuckRegistrationService, cleanupZipExpander, scanPathsUtility, keyStoreHelper, new HttpUrl(blackDuckUrl), operatingSystemType, downloadTarget);
scannerZipInstaller.installOrUpdateScanner();
ScanPaths scanPaths = scanPathsUtility.searchForScanPaths(downloadTarget);
assertTrue(scanPaths.isManagedByLibrary());
assertTrue(StringUtils.isNotBlank(scanPaths.getPathToJavaExecutable()));
assertTrue(StringUtils.isNotBlank(scanPaths.getPathToOneJar()));
assertTrue(StringUtils.isNotBlank(scanPaths.getPathToScanExecutable()));
assertTrue(new File(scanPaths.getPathToJavaExecutable()).canExecute());
assertTrue(new File(scanPaths.getPathToOneJar()).canExecute());
assertTrue(new File(scanPaths.getPathToScanExecutable()).canExecute());
}
Aggregations