Search in sources :

Example 11 with ProjectRequest

use of com.synopsys.integration.blackduck.api.manual.temporary.component.ProjectRequest in project blackduck-common by blackducksoftware.

the class BasicRecipe method createThrowAwayProjects.

public void createThrowAwayProjects(int numberOfProjectsToCreate) throws IntegrationException {
    for (int i = 1; i <= numberOfProjectsToCreate; i++) {
        String uniqueProjectName = PROJECT_NAME + System.currentTimeMillis();
        ProjectSyncModel projectSyncModel = createProjectSyncModel(uniqueProjectName, PROJECT_VERSION_NAME);
        ProjectRequest projectRequest = projectSyncModel.createProjectRequest();
        projectService.createProject(projectRequest);
    }
}
Also used : ProjectSyncModel(com.synopsys.integration.blackduck.service.model.ProjectSyncModel) ProjectRequest(com.synopsys.integration.blackduck.api.manual.temporary.component.ProjectRequest)

Example 12 with ProjectRequest

use of com.synopsys.integration.blackduck.api.manual.temporary.component.ProjectRequest in project blackduck-common by blackducksoftware.

the class ComprehensiveCookbookTestIT method createProjectVersion.

@Test
public void createProjectVersion() 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();
    // create the project
    ProjectRequest projectRequest = new ProjectRequest();
    projectRequest.setName(testProjectName);
    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);
    int projectVersionCount = blackDuckApiClient.getAllResponses(projectItem.metaVersionsLink()).size();
    ProjectVersionRequest projectVersionRequest = new ProjectVersionRequest();
    projectVersionRequest.setDistribution(ProjectVersionDistributionType.INTERNAL);
    projectVersionRequest.setPhase(ProjectVersionPhaseType.DEVELOPMENT);
    projectVersionRequest.setVersionName("RestConnectionTest");
    ProjectVersionView projectVersionItem = projectService.createProjectVersion(projectItem, projectVersionRequest);
    Optional<ProjectVersionView> projectVersionItemFromName = projectService.getProjectVersion(projectItem, "RestConnectionTest");
    // should return the same project version
    assertTrue(projectVersionItemFromName.isPresent());
    assertEquals(projectVersionItem.toString(), projectVersionItemFromName.get().toString());
    assertTrue(blackDuckApiClient.getAllResponses(projectItem.metaVersionsLink()).size() > projectVersionCount);
}
Also used : ProjectRequest(com.synopsys.integration.blackduck.api.manual.temporary.component.ProjectRequest) ProjectVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView) 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) ProjectView(com.synopsys.integration.blackduck.api.generated.view.ProjectView) ProjectVersionWrapper(com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper) ProjectVersionRequest(com.synopsys.integration.blackduck.api.manual.temporary.component.ProjectVersionRequest) Test(org.junit.jupiter.api.Test)

Example 13 with ProjectRequest

use of com.synopsys.integration.blackduck.api.manual.temporary.component.ProjectRequest 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 14 with ProjectRequest

use of com.synopsys.integration.blackduck.api.manual.temporary.component.ProjectRequest in project blackduck-common by blackducksoftware.

the class ProjectServiceTestIT method testCreateDeleteWithNickname.

@Test
public void testCreateDeleteWithNickname() throws IllegalArgumentException, IntegrationException {
    Long timestamp = (new Date()).getTime();
    String testProjectName = "hub-common-it-ProjectServiceTest-" + timestamp;
    String testProjectVersion1Name = "1";
    String testProjectVersion2Name = "2";
    String testProjectVersion3Name = "3";
    ProjectRequest projectRequest = new ProjectRequest();
    projectRequest.setName(testProjectName);
    ProjectVersionWrapper projectVersionWrapper = ProjectServiceTestIT.projectService.createProject(projectRequest);
    ProjectServiceTestIT.project = projectVersionWrapper.getProjectView();
    HttpUrl projectUrl = ProjectServiceTestIT.project.getHref();
    System.out.println("projectUrl: " + projectUrl);
    ProjectVersionRequest projectVersionRequest1 = new ProjectVersionRequest();
    projectVersionRequest1.setDistribution(ProjectVersionDistributionType.INTERNAL);
    projectVersionRequest1.setPhase(ProjectVersionPhaseType.DEVELOPMENT);
    projectVersionRequest1.setVersionName(testProjectVersion1Name);
    ProjectVersionRequest projectVersionRequest2 = new ProjectVersionRequest();
    projectVersionRequest2.setDistribution(ProjectVersionDistributionType.INTERNAL);
    projectVersionRequest2.setPhase(ProjectVersionPhaseType.DEVELOPMENT);
    projectVersionRequest2.setVersionName(testProjectVersion2Name);
    ProjectVersionRequest projectVersionRequest3 = new ProjectVersionRequest();
    projectVersionRequest3.setDistribution(ProjectVersionDistributionType.INTERNAL);
    projectVersionRequest3.setPhase(ProjectVersionPhaseType.DEVELOPMENT);
    projectVersionRequest3.setVersionName(testProjectVersion3Name);
    ProjectServiceTestIT.projectService.createProjectVersion(ProjectServiceTestIT.project, projectVersionRequest1);
    ProjectServiceTestIT.projectService.createProjectVersion(ProjectServiceTestIT.project, projectVersionRequest2);
    ProjectServiceTestIT.projectService.createProjectVersion(ProjectServiceTestIT.project, projectVersionRequest3);
    Optional<ProjectVersionView> projectVersion1 = ProjectServiceTestIT.projectService.getProjectVersion(ProjectServiceTestIT.project, testProjectVersion1Name);
    assertEquals(testProjectVersion1Name, projectVersion1.get().getVersionName());
    Optional<ProjectVersionView> projectVersion2 = ProjectServiceTestIT.projectService.getProjectVersion(ProjectServiceTestIT.project, testProjectVersion2Name);
    assertEquals(testProjectVersion2Name, projectVersion2.get().getVersionName());
    Optional<ProjectVersionView> projectVersion3 = ProjectServiceTestIT.projectService.getProjectVersion(ProjectServiceTestIT.project, testProjectVersion3Name);
    assertEquals(testProjectVersion3Name, projectVersion3.get().getVersionName());
    ProjectServiceTestIT.blackDuckApiClient.delete(ProjectServiceTestIT.project);
    ProjectServiceTestIT.project = null;
    try {
        ProjectServiceTestIT.blackDuckApiClient.getResponse(projectUrl, ProjectView.class);
        fail("This project should have been deleted");
    } catch (Exception e) {
        assertTrue(e instanceof BlackDuckApiException);
        assertTrue(RestConstants.NOT_FOUND_404 == ((BlackDuckApiException) e).getOriginalIntegrationRestException().getHttpStatusCode());
    }
}
Also used : BlackDuckApiException(com.synopsys.integration.blackduck.exception.BlackDuckApiException) ProjectRequest(com.synopsys.integration.blackduck.api.manual.temporary.component.ProjectRequest) ProjectVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView) ProjectVersionWrapper(com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper) Date(java.util.Date) HttpUrl(com.synopsys.integration.rest.HttpUrl) IntegrationException(com.synopsys.integration.exception.IntegrationException) BlackDuckApiException(com.synopsys.integration.blackduck.exception.BlackDuckApiException) ProjectVersionRequest(com.synopsys.integration.blackduck.api.manual.temporary.component.ProjectVersionRequest) Test(org.junit.jupiter.api.Test)

Example 15 with ProjectRequest

use of com.synopsys.integration.blackduck.api.manual.temporary.component.ProjectRequest in project blackduck-common by blackducksoftware.

the class ProjectServiceTestIT method testCreateUpdateProjectVersion.

@Test
public void testCreateUpdateProjectVersion() throws IllegalArgumentException, IntegrationException {
    String projectName = "InitialName";
    deleteProjectIfExists(projectName);
    ProjectRequest projectRequest = new ProjectRequest();
    projectRequest.setName(projectName);
    projectRequest.setProjectTier(2);
    projectRequest.setDescription("Initial Description");
    ProjectVersionRequest projectVersionRequest = new ProjectVersionRequest();
    projectVersionRequest.setVersionName("Initial VersionName");
    projectVersionRequest.setPhase(ProjectVersionPhaseType.PLANNING);
    projectVersionRequest.setDistribution(ProjectVersionDistributionType.EXTERNAL);
    projectRequest.setVersionRequest(projectVersionRequest);
    ProjectVersionWrapper projectVersionWrapper = ProjectServiceTestIT.projectService.createProject(projectRequest);
    ProjectServiceTestIT.project = projectVersionWrapper.getProjectView();
    ProjectVersionView projectVersionView = projectVersionWrapper.getProjectVersionView();
    assertEquals("Initial VersionName", projectVersionView.getVersionName());
    assertEquals(ProjectVersionPhaseType.PLANNING, projectVersionView.getPhase());
    assertEquals(ProjectVersionDistributionType.EXTERNAL, projectVersionView.getDistribution());
    projectVersionView.setVersionName("New VersionName");
    projectVersionView.setPhase(ProjectVersionPhaseType.DEPRECATED);
    projectVersionView.setDistribution(ProjectVersionDistributionType.INTERNAL);
    ProjectServiceTestIT.blackDuckApiClient.put(projectVersionView);
    projectVersionView = ProjectServiceTestIT.blackDuckApiClient.getResponse(projectVersionView.getHref(), ProjectVersionView.class);
    assertEquals("New VersionName", projectVersionView.getVersionName());
    assertEquals(ProjectVersionPhaseType.DEPRECATED, projectVersionView.getPhase());
    assertEquals(ProjectVersionDistributionType.INTERNAL, projectVersionView.getDistribution());
}
Also used : ProjectRequest(com.synopsys.integration.blackduck.api.manual.temporary.component.ProjectRequest) ProjectVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView) ProjectVersionWrapper(com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper) ProjectVersionRequest(com.synopsys.integration.blackduck.api.manual.temporary.component.ProjectVersionRequest) Test(org.junit.jupiter.api.Test)

Aggregations

ProjectRequest (com.synopsys.integration.blackduck.api.manual.temporary.component.ProjectRequest)19 ProjectVersionWrapper (com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper)15 Test (org.junit.jupiter.api.Test)12 ProjectVersionRequest (com.synopsys.integration.blackduck.api.manual.temporary.component.ProjectVersionRequest)11 ProjectVersionView (com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView)8 ProjectService (com.synopsys.integration.blackduck.service.dataservice.ProjectService)6 ProjectSyncModel (com.synopsys.integration.blackduck.service.model.ProjectSyncModel)5 ProjectView (com.synopsys.integration.blackduck.api.generated.view.ProjectView)4 BlackDuckApiClient (com.synopsys.integration.blackduck.service.BlackDuckApiClient)4 HttpUrl (com.synopsys.integration.rest.HttpUrl)3 Date (java.util.Date)3 IntLogger (com.synopsys.integration.log.IntLogger)2 SilentIntLogger (com.synopsys.integration.log.SilentIntLogger)2 ProjectVersionDistributionType (com.synopsys.integration.blackduck.api.generated.enumeration.ProjectVersionDistributionType)1 ComplexLicenseRequest (com.synopsys.integration.blackduck.api.manual.temporary.component.ComplexLicenseRequest)1 ProjectVersionPhaseType (com.synopsys.integration.blackduck.api.manual.temporary.enumeration.ProjectVersionPhaseType)1 AssignedUserView (com.synopsys.integration.blackduck.api.manual.temporary.view.AssignedUserView)1 BlackDuckApiException (com.synopsys.integration.blackduck.exception.BlackDuckApiException)1 IntegrationException (com.synopsys.integration.exception.IntegrationException)1