use of com.synopsys.integration.blackduck.api.generated.view.CodeLocationView in project blackduck-common by blackducksoftware.
the class CreateProjectWithBdioAndVerifyBOMTest method cleanBlackDuckTestElements.
private void cleanBlackDuckTestElements() throws IntegrationException {
Optional<ProjectView> projectView = blackDuckServices.projectService.getProjectByName(PROJECT_NAME);
if (projectView.isPresent()) {
blackDuckServices.blackDuckApiClient.delete(projectView.get());
}
List<CodeLocationView> codeLocationsToDelete = blackDuckServices.blackDuckApiClient.getSomeMatchingResponses(blackDuckServices.apiDiscovery.metaCodelocationsLink(), shouldDeleteCodeLocation, CODE_LOCATION_NAMES.size());
for (CodeLocationView codeLocationToDelete : codeLocationsToDelete) {
blackDuckServices.blackDuckApiClient.delete(codeLocationToDelete);
}
}
use of com.synopsys.integration.blackduck.api.generated.view.CodeLocationView in project blackduck-common by blackducksoftware.
the class CreateProjectWithBdioAndVerifyBOMTest method waitForCodeLocations.
private boolean waitForCodeLocations(Set<String> expectedCodeLocationNames, ProjectVersionView projectVersionView) throws InterruptedException, IntegrationException {
Predicate<CodeLocationView> nameInSet = (codeLocationView) -> expectedCodeLocationNames.contains(codeLocationView.getName());
WaitJobCondition findAllCodeLocationNames = () -> {
List<CodeLocationView> codeLocationViews = blackDuckServices.blackDuckApiClient.getSomeMatchingResponses(projectVersionView.metaCodelocationsLink(), nameInSet, expectedCodeLocationNames.size());
Set<String> foundCodeLocationNames = codeLocationViews.stream().map(CodeLocationView::getName).collect(Collectors.toSet());
printOutCodeLocations(codeLocationViews);
return expectedCodeLocationNames.equals(foundCodeLocationNames);
};
return WaitJob.waitFor(jobbyConfig, findAllCodeLocationNames, "wait for code locations");
}
use of com.synopsys.integration.blackduck.api.generated.view.CodeLocationView in project blackduck-common by blackducksoftware.
the class CreateProjectWithBdioAndVerifyBOMTest method assertCodeLocationsAddedToBOM.
private void assertCodeLocationsAddedToBOM(Set<String> expectedCodeLocationNames, Date startDate, Date endDate) throws InterruptedException, IntegrationException {
boolean foundProject = waitForProject();
assertTrue(foundProject, "Project was not found");
Optional<ProjectVersionWrapper> projectVersionWrapperOptional = blackDuckServices.projectService.getProjectVersion(PROJECT_NAME, PROJECT_VERSION_NAME);
ProjectVersionView projectVersionView = projectVersionWrapperOptional.get().getProjectVersionView();
boolean foundAllCodeLocations = waitForCodeLocations(expectedCodeLocationNames, projectVersionView);
assertTrue(foundAllCodeLocations, "All code locations were not found");
List<CodeLocationView> codeLocationViews = blackDuckServices.blackDuckApiClient.getAllResponses(projectVersionView.metaCodelocationsLink());
Set<String> expectedCodeLocationUrls = codeLocationViews.stream().map(CodeLocationView::getHref).map(HttpUrl::string).collect(Collectors.toSet());
boolean foundAllCodeLocationUrls = waitForNotifications(startDate, endDate, expectedCodeLocationUrls);
assertTrue(foundAllCodeLocationUrls, "All code location urls were not found");
}
use of com.synopsys.integration.blackduck.api.generated.view.CodeLocationView in project blackduck-common by blackducksoftware.
the class InstallAndRunSignatureScannerTestIT method testInstallingAndRunningSignatureScanner.
@Test
void testInstallingAndRunningSignatureScanner() throws IOException, InterruptedException, IntegrationException {
// here, we do not want to automatically trust the server's certificate
BlackDuckServerConfigBuilder blackDuckServerConfigBuilder = intHttpClientTestHelper.getBlackDuckServerConfigBuilder();
blackDuckServerConfigBuilder.setTrustCert(false);
BlackDuckServerConfig blackDuckServerConfig = blackDuckServerConfigBuilder.build();
File installDirectory = new File(scannerDirectoryPath, "scanner_install");
File outputDirectory = new File(scannerDirectoryPath, "scanner_output");
ScanBatch scanBatch = createScanBatch(blackDuckServerConfig, outputDirectory);
BufferedIntLogger logger = new BufferedIntLogger();
BlackDuckServicesFactory blackDuckServicesFactory = blackDuckServerConfig.createBlackDuckServicesFactory(logger);
IntEnvironmentVariables environmentVariables = blackDuckServicesFactory.getEnvironmentVariables();
OperatingSystemType operatingSystemType = OperatingSystemType.determineFromSystem();
ExecutorService executorService = BlackDuckServicesFactory.NO_THREAD_EXECUTOR_SERVICE;
BlackDuckHttpClient blackDuckHttpClient = blackDuckServicesFactory.getBlackDuckHttpClient();
BlackDuckRegistrationService blackDuckRegistrationService = blackDuckServicesFactory.createBlackDuckRegistrationService();
CleanupZipExpander cleanupZipExpander = new CleanupZipExpander(logger);
HttpUrl blackDuckServerUrl = blackDuckHttpClient.getBlackDuckUrl();
ScanPathsUtility scanPathsUtility = new ScanPathsUtility(logger, environmentVariables, operatingSystemType);
ScanCommandRunner scanCommandRunner = new ScanCommandRunner(logger, environmentVariables, scanPathsUtility, executorService);
// first, run a scan with an install that will NOT update the embedded keystore, which should fail
KeyStoreHelper noOpKeyStoreHelper = new NoOpKeyStoreHelper();
ScannerZipInstaller installerWithoutKeyStoreManagement = new ScannerZipInstaller(logger, new SignatureScannerClient(blackDuckHttpClient), blackDuckRegistrationService, cleanupZipExpander, scanPathsUtility, noOpKeyStoreHelper, blackDuckServerUrl, operatingSystemType, installDirectory);
ScanBatchRunner scanBatchRunnerWithout = ScanBatchRunner.createComplete(environmentVariables, scanPathsUtility, scanCommandRunner, installerWithoutKeyStoreManagement);
SignatureScannerService signatureScannerServiceWithout = blackDuckServicesFactory.createSignatureScannerService(scanBatchRunnerWithout);
assertScanFailure(logger, blackDuckRegistrationService, signatureScannerServiceWithout, scanBatch);
// now, delete the failed installation
FileUtils.deleteDirectory(installDirectory);
// second, run a scan with an install that DOES update the embedded keystore, which should succeed
logger.resetAllLogs();
KeyStoreHelper keyStoreHelper = new KeyStoreHelper(logger);
ScannerZipInstaller installerWithKeyStoreManagement = new ScannerZipInstaller(logger, new SignatureScannerClient(blackDuckHttpClient), blackDuckRegistrationService, cleanupZipExpander, scanPathsUtility, keyStoreHelper, blackDuckServerUrl, operatingSystemType, installDirectory);
ScanBatchRunner scanBatchRunnerWith = ScanBatchRunner.createComplete(environmentVariables, scanPathsUtility, scanCommandRunner, installerWithKeyStoreManagement);
SignatureScannerService signatureScannerServiceWith = blackDuckServicesFactory.createSignatureScannerService(scanBatchRunnerWith);
assertScanSuccess(logger, signatureScannerServiceWith, scanBatch);
// finally, verify the code location exists and then delete it to clean up
CodeLocationService codeLocationService = blackDuckServicesFactory.createCodeLocationService();
BlackDuckApiClient blackDuckApiClient = blackDuckServicesFactory.getBlackDuckApiClient();
ResilientJobConfig jobConfig = new ResilientJobConfig(logger, 120, System.currentTimeMillis(), 10);
WaitJob.waitFor(jobConfig, () -> codeLocationService.getCodeLocationByName(CODE_LOCATION_NAME).isPresent(), "codeLocationTest");
Optional<CodeLocationView> codeLocationViewOptional = codeLocationService.getCodeLocationByName(CODE_LOCATION_NAME);
assertTrue(codeLocationViewOptional.isPresent());
blackDuckApiClient.delete(codeLocationViewOptional.get());
}
use of com.synopsys.integration.blackduck.api.generated.view.CodeLocationView 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());
}
Aggregations