Search in sources :

Example 21 with ProjectSyncModel

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

the class CreateDetailedProjectRecipeTest method testCreatingAProject.

@Test
public void testCreatingAProject() throws IntegrationException {
    /*
         * let's post the project/version in Black Duck
         */
    String uniqueProjectName = PROJECT_NAME + System.currentTimeMillis();
    ProjectSyncModel projectSyncModel = createProjectSyncModel(uniqueProjectName, PROJECT_VERSION_NAME);
    ProjectService projectService = blackDuckServicesFactory.createProjectService();
    ProjectVersionWrapper projectVersionWrapper = projectService.createProject(projectSyncModel.createProjectRequest());
    HttpUrl projectUrl = projectVersionWrapper.getProjectView().getHref();
    /*
         * using the url of the created project, we can now verify that the
         * fields are set correctly with the BlackDuckService, a general purpose API
         * wrapper to handle common GET requests and their response payloads
         */
    BlackDuckApiClient blackDuckApiClient = blackDuckServicesFactory.getBlackDuckApiClient();
    projectView = blackDuckApiClient.getResponse(projectUrl, ProjectView.class);
    ProjectVersionView projectVersionView = blackDuckApiClient.getResponse(projectView.metaCanonicalVersionLink());
    Assertions.assertEquals(uniqueProjectName, projectView.getName());
    Assertions.assertEquals("A sample testing project to demonstrate blackduck-common capabilities.", projectView.getDescription());
    Assertions.assertEquals(PROJECT_VERSION_NAME, projectVersionView.getVersionName());
    Assertions.assertEquals(ProjectVersionPhaseType.DEVELOPMENT, projectVersionView.getPhase());
    Assertions.assertEquals(ProjectVersionDistributionType.OPENSOURCE, projectVersionView.getDistribution());
}
Also used : ProjectSyncModel(com.synopsys.integration.blackduck.service.model.ProjectSyncModel) ProjectVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView) ProjectService(com.synopsys.integration.blackduck.service.dataservice.ProjectService) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) ProjectView(com.synopsys.integration.blackduck.api.generated.view.ProjectView) ProjectVersionWrapper(com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper) HttpUrl(com.synopsys.integration.rest.HttpUrl) Test(org.junit.jupiter.api.Test)

Example 22 with ProjectSyncModel

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

the class ProjectErrorsRecipeTest method testTryingToCreateAProjectThatAlreadyExists.

@Test
public void testTryingToCreateAProjectThatAlreadyExists() throws IntegrationException {
    /*
         * First, create a project with a unique name
         */
    ProjectSyncModel projectSyncModel = createProjectSyncModel(uniqueName, PROJECT_VERSION_NAME);
    ProjectVersionWrapper projectVersionWrapper = projectService.createProject(projectSyncModel.createProjectRequest());
    projectView = projectVersionWrapper.getProjectView();
    /*
         * Try to create a project with the same name, which should throw an Exception
         */
    try {
        projectService.createProject(projectSyncModel.createProjectRequest());
        Assertions.fail("Should have thrown an IntegrationRestException");
    } catch (Exception e) {
        Assertions.assertTrue(e instanceof BlackDuckApiException);
        // since the project already existed, a 412 Precondition Failed http error response should occur
        Assertions.assertEquals(412, ((BlackDuckApiException) e).getOriginalIntegrationRestException().getHttpStatusCode());
    }
}
Also used : ProjectSyncModel(com.synopsys.integration.blackduck.service.model.ProjectSyncModel) BlackDuckApiException(com.synopsys.integration.blackduck.exception.BlackDuckApiException) ProjectVersionWrapper(com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper) IntegrationException(com.synopsys.integration.exception.IntegrationException) BlackDuckApiException(com.synopsys.integration.blackduck.exception.BlackDuckApiException) Test(org.junit.jupiter.api.Test)

Example 23 with ProjectSyncModel

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

the class ProjectMappingServiceTest method setUp.

@BeforeEach
void setUp() throws IntegrationException {
    IntHttpClientTestHelper intHttpClientTestHelper = new IntHttpClientTestHelper();
    blackDuckServicesFactory = intHttpClientTestHelper.createBlackDuckServicesFactory();
    projectMappingService = blackDuckServicesFactory.createProjectMappingService();
    ProjectService projectService = blackDuckServicesFactory.createProjectService();
    String testProjectName = intHttpClientTestHelper.getProperty("TEST_PROJECT");
    String testProjectVersion = intHttpClientTestHelper.getProperty("TEST_VERSION");
    ProjectSyncModel projectSyncModel = ProjectSyncModel.createWithDefaults(testProjectName, testProjectVersion);
    ProjectVersionWrapper projectVersionWrapper = projectService.syncProjectAndVersion(projectSyncModel);
    projectView = projectVersionWrapper.getProjectView();
}
Also used : ProjectSyncModel(com.synopsys.integration.blackduck.service.model.ProjectSyncModel) ProjectVersionWrapper(com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper) IntHttpClientTestHelper(com.synopsys.integration.blackduck.http.client.IntHttpClientTestHelper) BeforeEach(org.junit.jupiter.api.BeforeEach)

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