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