Search in sources :

Example 6 with CodeLocationView

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);
    }
}
Also used : CodeLocationView(com.synopsys.integration.blackduck.api.generated.view.CodeLocationView) ProjectView(com.synopsys.integration.blackduck.api.generated.view.ProjectView)

Example 7 with CodeLocationView

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");
}
Also used : CodeLocationView(com.synopsys.integration.blackduck.api.generated.view.CodeLocationView) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) IntegrationException(com.synopsys.integration.exception.IntegrationException) BdioUploadService(com.synopsys.integration.blackduck.codelocation.bdiolegacy.BdioUploadService) Date(java.util.Date) VersionBomCodeLocationBomComputedNotificationContent(com.synopsys.integration.blackduck.api.manual.component.VersionBomCodeLocationBomComputedNotificationContent) ResilientJobConfig(com.synopsys.integration.wait.ResilientJobConfig) IntLogger(com.synopsys.integration.log.IntLogger) HttpUrl(com.synopsys.integration.rest.HttpUrl) NameVersion(com.synopsys.integration.util.NameVersion) PrintStreamIntLogger(com.synopsys.integration.log.PrintStreamIntLogger) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) LogLevel(com.synopsys.integration.log.LogLevel) Tag(org.junit.jupiter.api.Tag) UserView(com.synopsys.integration.blackduck.api.generated.view.UserView) RestConstants(com.synopsys.integration.rest.RestConstants) WaitJobCondition(com.synopsys.integration.wait.WaitJobCondition) UploadBatch(com.synopsys.integration.blackduck.codelocation.upload.UploadBatch) UploadBatchOutput(com.synopsys.integration.blackduck.codelocation.upload.UploadBatchOutput) Predicate(java.util.function.Predicate) NotificationType(com.synopsys.integration.blackduck.api.manual.temporary.enumeration.NotificationType) VersionBomCodeLocationBomComputedNotificationUserView(com.synopsys.integration.blackduck.api.manual.view.VersionBomCodeLocationBomComputedNotificationUserView) Set(java.util.Set) NotificationUserView(com.synopsys.integration.blackduck.api.manual.view.NotificationUserView) ProjectVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView) Collectors(java.util.stream.Collectors) ProjectVersionWrapper(com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper) File(java.io.File) WaitJob(com.synopsys.integration.wait.WaitJob) Test(org.junit.jupiter.api.Test) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) TimingExtension(com.synopsys.integration.blackduck.TimingExtension) ChronoUnit(java.time.temporal.ChronoUnit) CodeLocationView(com.synopsys.integration.blackduck.api.generated.view.CodeLocationView) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) CodeLocationCreationData(com.synopsys.integration.blackduck.codelocation.CodeLocationCreationData) IntHttpClientTestHelper(com.synopsys.integration.blackduck.http.client.IntHttpClientTestHelper) Optional(java.util.Optional) UploadTarget(com.synopsys.integration.blackduck.codelocation.upload.UploadTarget) NotificationEditor(com.synopsys.integration.blackduck.service.request.NotificationEditor) ProjectView(com.synopsys.integration.blackduck.api.generated.view.ProjectView) Set(java.util.Set) List(java.util.List) WaitJobCondition(com.synopsys.integration.wait.WaitJobCondition)

Example 8 with CodeLocationView

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");
}
Also used : CodeLocationView(com.synopsys.integration.blackduck.api.generated.view.CodeLocationView) ProjectVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView) ProjectVersionWrapper(com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper)

Example 9 with CodeLocationView

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());
}
Also used : CodeLocationService(com.synopsys.integration.blackduck.service.dataservice.CodeLocationService) BlackDuckServerConfigBuilder(com.synopsys.integration.blackduck.configuration.BlackDuckServerConfigBuilder) SignatureScannerService(com.synopsys.integration.blackduck.codelocation.signaturescanner.SignatureScannerService) KeyStoreHelper(com.synopsys.integration.blackduck.keystore.KeyStoreHelper) ScannerZipInstaller(com.synopsys.integration.blackduck.codelocation.signaturescanner.command.ScannerZipInstaller) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) CleanupZipExpander(com.synopsys.integration.util.CleanupZipExpander) CodeLocationView(com.synopsys.integration.blackduck.api.generated.view.CodeLocationView) IntEnvironmentVariables(com.synopsys.integration.util.IntEnvironmentVariables) ScanBatch(com.synopsys.integration.blackduck.codelocation.signaturescanner.ScanBatch) ScanPathsUtility(com.synopsys.integration.blackduck.codelocation.signaturescanner.command.ScanPathsUtility) SignatureScannerClient(com.synopsys.integration.blackduck.http.client.SignatureScannerClient) BlackDuckHttpClient(com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) BufferedIntLogger(com.synopsys.integration.log.BufferedIntLogger) ScanCommandRunner(com.synopsys.integration.blackduck.codelocation.signaturescanner.command.ScanCommandRunner) HttpUrl(com.synopsys.integration.rest.HttpUrl) BlackDuckServerConfig(com.synopsys.integration.blackduck.configuration.BlackDuckServerConfig) BlackDuckRegistrationService(com.synopsys.integration.blackduck.service.dataservice.BlackDuckRegistrationService) ScanBatchRunner(com.synopsys.integration.blackduck.codelocation.signaturescanner.ScanBatchRunner) OperatingSystemType(com.synopsys.integration.util.OperatingSystemType) ExecutorService(java.util.concurrent.ExecutorService) ResilientJobConfig(com.synopsys.integration.wait.ResilientJobConfig) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 10 with CodeLocationView

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());
}
Also used : NameVersion(com.synopsys.integration.util.NameVersion) CodeLocationWaitJobCondition(com.synopsys.integration.blackduck.codelocation.CodeLocationWaitJobCondition) NotificationTaskRange(com.synopsys.integration.blackduck.service.model.NotificationTaskRange) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) 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) IntLogger(com.synopsys.integration.log.IntLogger) BufferedIntLogger(com.synopsys.integration.log.BufferedIntLogger) BufferedIntLogger(com.synopsys.integration.log.BufferedIntLogger) ResourceMetadata(com.synopsys.integration.blackduck.api.core.ResourceMetadata) Date(java.util.Date) CodeLocationView(com.synopsys.integration.blackduck.api.generated.view.CodeLocationView) ResourceLink(com.synopsys.integration.blackduck.api.core.ResourceLink) ProjectVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView) NotificationEditor(com.synopsys.integration.blackduck.service.request.NotificationEditor) ProjectView(com.synopsys.integration.blackduck.api.generated.view.ProjectView) SimpleDateFormat(java.text.SimpleDateFormat) ProjectVersionWrapper(com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Aggregations

CodeLocationView (com.synopsys.integration.blackduck.api.generated.view.CodeLocationView)26 Test (org.junit.jupiter.api.Test)9 ProjectVersionWrapper (com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper)8 File (java.io.File)7 ResourceMetadata (com.synopsys.integration.blackduck.api.core.ResourceMetadata)6 IntegrationException (com.synopsys.integration.exception.IntegrationException)6 BufferedIntLogger (com.synopsys.integration.log.BufferedIntLogger)6 HttpUrl (com.synopsys.integration.rest.HttpUrl)6 ProjectVersionView (com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView)5 IntLogger (com.synopsys.integration.log.IntLogger)5 ProjectView (com.synopsys.integration.blackduck.api.generated.view.ProjectView)4 UserView (com.synopsys.integration.blackduck.api.generated.view.UserView)4 UploadBatch (com.synopsys.integration.blackduck.codelocation.upload.UploadBatch)4 BlackDuckApiClient (com.synopsys.integration.blackduck.service.BlackDuckApiClient)4 NameVersion (com.synopsys.integration.util.NameVersion)4 JsonNodeFactory (com.fasterxml.jackson.databind.node.JsonNodeFactory)3 NullNode (com.fasterxml.jackson.databind.node.NullNode)3 BdioUploadCodeLocationCreationRequest (com.synopsys.integration.blackduck.codelocation.bdiolegacy.BdioUploadCodeLocationCreationRequest)3 BdioUploadService (com.synopsys.integration.blackduck.codelocation.bdiolegacy.BdioUploadService)3 UploadTarget (com.synopsys.integration.blackduck.codelocation.upload.UploadTarget)3