Search in sources :

Example 16 with ProjectSyncModel

use of com.synopsys.integration.blackduck.service.model.ProjectSyncModel in project blackduck-common by blackducksoftware.

the class BasicRecipe method createProjectSyncModel.

public ProjectSyncModel createProjectSyncModel(String projectName, String projectVersionName) {
    /*
         * the ProjectSyncModel is a wrapper around creating a
         * ProjectRequest that will also include a ProjectVersionRequest to
         * create both a project in Black Duck and a version for that created
         * project - a project must have at least one version
         */
    ProjectSyncModel projectSyncModel = new ProjectSyncModel(projectName, projectVersionName);
    projectSyncModel.setDescription("A sample testing project to demonstrate blackduck-common capabilities.");
    projectSyncModel.setPhase(ProjectVersionPhaseType.DEVELOPMENT);
    projectSyncModel.setDistribution(ProjectVersionDistributionType.OPENSOURCE);
    projectsToDelete.add(projectName);
    return projectSyncModel;
}
Also used : ProjectSyncModel(com.synopsys.integration.blackduck.service.model.ProjectSyncModel)

Example 17 with ProjectSyncModel

use of com.synopsys.integration.blackduck.service.model.ProjectSyncModel in project blackduck-common by blackducksoftware.

the class CheckPolicyForProjectVersionRecipeTest method setup.

@BeforeEach
public void setup() throws IntegrationException {
    String uniqueProjectName = PROJECT_NAME + System.currentTimeMillis();
    ProjectSyncModel projectSyncModel = createProjectSyncModel(uniqueProjectName, PROJECT_VERSION_NAME);
    /*
         * We can get the project and version like this, and if they don't
         * exist they will be created for us.
         */
    projectVersionWrapper = projectService.syncProjectAndVersion(projectSyncModel, false);
    policyRuleView = constructTestPolicy(blackDuckServicesFactory.createComponentService());
    /*
         * To create a Policy Rule we can construct a PolicyRuleView and create
         * it in Black Duck.
         */
    HttpUrl policyRuleUrl = policyRuleService.createPolicyRule(policyRuleView);
    policyRuleView = blackDuckApiClient.getResponse(policyRuleUrl, PolicyRuleView.class);
}
Also used : ProjectSyncModel(com.synopsys.integration.blackduck.service.model.ProjectSyncModel) PolicyRuleView(com.synopsys.integration.blackduck.api.generated.view.PolicyRuleView) HttpUrl(com.synopsys.integration.rest.HttpUrl) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 18 with ProjectSyncModel

use of com.synopsys.integration.blackduck.service.model.ProjectSyncModel in project blackduck-common by blackducksoftware.

the class ComponentManagementRecipeTest method setup.

@BeforeEach
public void setup() throws Exception {
    String uniqueProjectName = PROJECT_NAME + System.currentTimeMillis();
    String versionName = PROJECT_VERSION_NAME;
    /**
     * we can get the project and version like this, and if they don't exist we will create them
     */
    Optional<ProjectView> projectView = projectService.getProjectByName(uniqueProjectName);
    ProjectSyncModel projectSyncModel = createProjectSyncModel(uniqueProjectName, versionName);
    if (!projectView.isPresent()) {
        projectService.createProject(projectSyncModel.createProjectRequest());
        projectVersionWrapper = projectService.getProjectVersion(uniqueProjectName, versionName).get();
    } else {
        // the project exists, check the version
        Optional<ProjectVersionView> projectVersionView = projectService.getProjectVersion(projectView.get(), versionName);
        if (projectVersionView.isPresent()) {
            projectVersionWrapper = new ProjectVersionWrapper(projectView.get(), projectVersionView.get());
        } else {
            projectService.createProjectVersion(projectView.get(), projectSyncModel.createProjectVersionRequest());
            projectVersionWrapper = projectService.getProjectVersion(uniqueProjectName, versionName).get();
        }
    }
}
Also used : ProjectSyncModel(com.synopsys.integration.blackduck.service.model.ProjectSyncModel) ProjectVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView) ProjectView(com.synopsys.integration.blackduck.api.generated.view.ProjectView) ProjectVersionWrapper(com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 19 with ProjectSyncModel

use of com.synopsys.integration.blackduck.service.model.ProjectSyncModel in project blackduck-common by blackducksoftware.

the class ComprehensiveCookbookTestIT method createProjectVersionSingleCall.

@Test
public void createProjectVersionSingleCall() throws Exception {
    String testProjectName = intHttpClientTestHelper.getProperty("TEST_CREATE_PROJECT");
    ProjectService projectService = blackDuckServicesFactory.createProjectService();
    BlackDuckApiClient blackDuckApiClient = blackDuckServicesFactory.getBlackDuckApiClient();
    IntLogger logger = blackDuckServicesFactory.getLogger();
    // delete the project, if it exists
    intHttpClientTestHelper.deleteIfProjectExists(logger, projectService, blackDuckApiClient, testProjectName);
    // get the count of all projects now
    int projectCount = blackDuckApiClient.getAllResponses(apiDiscovery.metaProjectsLink()).size();
    String versionName = "RestConnectionTest";
    ProjectVersionDistributionType distribution = ProjectVersionDistributionType.INTERNAL;
    ProjectVersionPhaseType phase = ProjectVersionPhaseType.DEVELOPMENT;
    ProjectSyncModel projectSyncModel = new ProjectSyncModel(testProjectName, versionName);
    projectSyncModel.setPhase(phase);
    projectSyncModel.setDistribution(distribution);
    ProjectRequest projectRequest = projectSyncModel.createProjectRequest();
    // create the project
    ProjectVersionWrapper projectVersionWrapper = projectService.createProject(projectRequest);
    ProjectView projectItem = projectVersionWrapper.getProjectView();
    Optional<ProjectView> projectItemFromName = projectService.getProjectByName(testProjectName);
    // should return the same project
    assertTrue(projectItemFromName.isPresent());
    assertEquals(projectItem.toString(), projectItemFromName.get().toString());
    int projectCountAfterCreate = blackDuckApiClient.getAllResponses(apiDiscovery.metaProjectsLink()).size();
    assertTrue(projectCountAfterCreate > projectCount);
    Optional<ProjectVersionView> projectVersionItem = projectService.getProjectVersion(projectItem, versionName);
    assertTrue(projectVersionItem.isPresent());
    assertEquals(versionName, projectVersionItem.get().getVersionName());
    // should return the same project version
    assertEquals(projectVersionWrapper.getProjectVersionView().toString(), projectVersionItem.get().toString());
}
Also used : ProjectSyncModel(com.synopsys.integration.blackduck.service.model.ProjectSyncModel) ProjectVersionDistributionType(com.synopsys.integration.blackduck.api.generated.enumeration.ProjectVersionDistributionType) ProjectVersionPhaseType(com.synopsys.integration.blackduck.api.manual.temporary.enumeration.ProjectVersionPhaseType) ProjectService(com.synopsys.integration.blackduck.service.dataservice.ProjectService) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) SilentIntLogger(com.synopsys.integration.log.SilentIntLogger) IntLogger(com.synopsys.integration.log.IntLogger) ProjectRequest(com.synopsys.integration.blackduck.api.manual.temporary.component.ProjectRequest) ProjectVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView) ProjectView(com.synopsys.integration.blackduck.api.generated.view.ProjectView) ProjectVersionWrapper(com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper) Test(org.junit.jupiter.api.Test)

Example 20 with ProjectSyncModel

use of com.synopsys.integration.blackduck.service.model.ProjectSyncModel in project blackduck-common by blackducksoftware.

the class ProjectBomServiceTestIT method testAddingComponentToBom.

@Test
public void testAddingComponentToBom() throws Exception {
    String projectName = "adding_component_test";
    String projectVersionName = "1.0.0";
    BlackDuckServicesFactory blackDuckServicesFactory = intHttpClientTestHelper.createBlackDuckServicesFactory();
    BlackDuckApiClient blackDuckApiClient = blackDuckServicesFactory.getBlackDuckApiClient();
    ProjectService projectService = blackDuckServicesFactory.createProjectService();
    ProjectBomService projectBomService = blackDuckServicesFactory.createProjectBomService();
    IntLogger logger = blackDuckServicesFactory.getLogger();
    // delete the project, if it exists
    intHttpClientTestHelper.deleteIfProjectExists(logger, projectService, blackDuckApiClient, projectName);
    // create the project
    ProjectSyncModel projectSyncModel = ProjectSyncModel.createWithDefaults(projectName, projectVersionName);
    ProjectVersionWrapper projectVersionWrapper = projectService.syncProjectAndVersion(projectSyncModel);
    // verify the bom
    List<ProjectVersionComponentVersionView> bomComponents = projectBomService.getComponentsForProjectVersion(projectVersionWrapper.getProjectVersionView());
    assertEquals(0, bomComponents.size());
    ExternalId externalId = new ExternalIdFactory().createMavenExternalId("com.synopsys.integration", "blackduck-common", "47.0.0");
    projectBomService.addComponentToProjectVersion(externalId, projectVersionWrapper.getProjectVersionView());
    bomComponents = projectBomService.getComponentsForProjectVersion(projectVersionWrapper.getProjectVersionView());
    assertEquals(1, bomComponents.size());
}
Also used : ProjectSyncModel(com.synopsys.integration.blackduck.service.model.ProjectSyncModel) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) ProjectService(com.synopsys.integration.blackduck.service.dataservice.ProjectService) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) IntLogger(com.synopsys.integration.log.IntLogger) ProjectVersionWrapper(com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper) ProjectBomService(com.synopsys.integration.blackduck.service.dataservice.ProjectBomService) ProjectVersionComponentVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView) Test(org.junit.jupiter.api.Test)

Aggregations

ProjectSyncModel (com.synopsys.integration.blackduck.service.model.ProjectSyncModel)23 ProjectVersionWrapper (com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper)15 Test (org.junit.jupiter.api.Test)13 ProjectVersionView (com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView)6 BlackDuckApiClient (com.synopsys.integration.blackduck.service.BlackDuckApiClient)6 ProjectService (com.synopsys.integration.blackduck.service.dataservice.ProjectService)6 ProjectVersionComponentVersionView (com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView)5 ProjectRequest (com.synopsys.integration.blackduck.api.manual.temporary.component.ProjectRequest)5 IntLogger (com.synopsys.integration.log.IntLogger)5 ProjectView (com.synopsys.integration.blackduck.api.generated.view.ProjectView)4 BlackDuckServicesFactory (com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)4 HttpUrl (com.synopsys.integration.rest.HttpUrl)4 ExternalId (com.synopsys.integration.bdio.model.externalid.ExternalId)3 ProjectBomService (com.synopsys.integration.blackduck.service.dataservice.ProjectBomService)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 ExternalIdFactory (com.synopsys.integration.bdio.model.externalid.ExternalIdFactory)2 CodeLocationView (com.synopsys.integration.blackduck.api.generated.view.CodeLocationView)2 PolicyRuleView (com.synopsys.integration.blackduck.api.generated.view.PolicyRuleView)2 ProjectVersionRequest (com.synopsys.integration.blackduck.api.manual.temporary.component.ProjectVersionRequest)2 BlackDuckApiException (com.synopsys.integration.blackduck.exception.BlackDuckApiException)2