Search in sources :

Example 26 with RepositorySession

use of org.jboss.pnc.spi.repositorymanager.model.RepositorySession in project pnc by project-ncl.

the class UploadOneThenDownloadAndVerifyArtifactHasOriginUrlTest method extractBuildArtifacts_ContainsTwoUploads.

@Test
public void extractBuildArtifacts_ContainsTwoUploads() throws Exception {
    // create a dummy non-chained build execution and repo session based on it
    BuildExecution execution = new TestBuildExecution();
    RepositorySession rc = driver.createBuildRepository(execution, accessToken, accessToken, RepositoryType.MAVEN, Collections.emptyMap(), false);
    assertThat(rc, notNullValue());
    String baseUrl = rc.getConnectionInfo().getDeployUrl();
    String path = "org/commonjava/indy/indy-core/0.17.0/indy-core-0.17.0.pom";
    String content = "This is a test";
    CloseableHttpClient client = HttpClientBuilder.create().build();
    // upload a couple files related to a single GAV using the repo session deployment url
    // this simulates a build deploying one jar and its associated POM
    final String url = UrlUtils.buildUrl(baseUrl, path);
    assertThat("Failed to upload: " + url, ArtifactUploadUtils.put(client, url, content), equalTo(true));
    // download the two files via the repo session's dependency URL, which will proxy the test http server
    // using the expectations above
    assertThat(download(UrlUtils.buildUrl(baseUrl, path)), equalTo(content));
    ProjectVersionRef pvr = new SimpleProjectVersionRef("org.commonjava.indy", "indy-core", "0.17.0");
    String artifactRef = new SimpleArtifactRef(pvr, "pom", null).toString();
    // extract the "builtArtifacts" artifacts we uploaded above.
    RepositoryManagerResult repositoryManagerResult = rc.extractBuildArtifacts(true);
    // check that both files are present in extracted result
    List<Artifact> builtArtifacts = repositoryManagerResult.getBuiltArtifacts();
    log.info("Built artifacts: " + builtArtifacts.toString());
    assertThat(builtArtifacts, notNullValue());
    assertThat(builtArtifacts.size(), equalTo(1));
    Artifact builtArtifact = builtArtifacts.get(0);
    assertThat(builtArtifact + " doesn't match pom ref: " + artifactRef, builtArtifact.getIdentifier(), equalTo(artifactRef));
    assertThat(builtArtifact + " doesn't have correct build category: " + BuildCategory.STANDARD, builtArtifact.getBuildCategory(), equalTo(BuildCategory.STANDARD));
    client.close();
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) TestBuildExecution(org.jboss.pnc.indyrepositorymanager.fixture.TestBuildExecution) ProjectVersionRef(org.commonjava.atlas.maven.ident.ref.ProjectVersionRef) SimpleProjectVersionRef(org.commonjava.atlas.maven.ident.ref.SimpleProjectVersionRef) RepositoryManagerResult(org.jboss.pnc.spi.repositorymanager.RepositoryManagerResult) TestBuildExecution(org.jboss.pnc.indyrepositorymanager.fixture.TestBuildExecution) BuildExecution(org.jboss.pnc.spi.repositorymanager.BuildExecution) SimpleArtifactRef(org.commonjava.atlas.maven.ident.ref.SimpleArtifactRef) SimpleProjectVersionRef(org.commonjava.atlas.maven.ident.ref.SimpleProjectVersionRef) RepositorySession(org.jboss.pnc.spi.repositorymanager.model.RepositorySession) Artifact(org.jboss.pnc.model.Artifact) Test(org.junit.Test) ContainerTest(org.jboss.pnc.test.category.ContainerTest)

Aggregations

RepositorySession (org.jboss.pnc.spi.repositorymanager.model.RepositorySession)26 TestBuildExecution (org.jboss.pnc.indyrepositorymanager.fixture.TestBuildExecution)20 BuildExecution (org.jboss.pnc.spi.repositorymanager.BuildExecution)20 Test (org.junit.Test)19 ContainerTest (org.jboss.pnc.test.category.ContainerTest)18 RepositoryManagerResult (org.jboss.pnc.spi.repositorymanager.RepositoryManagerResult)13 StoreKey (org.commonjava.indy.model.core.StoreKey)12 Artifact (org.jboss.pnc.model.Artifact)11 Indy (org.commonjava.indy.client.core.Indy)8 Group (org.commonjava.indy.model.core.Group)7 File (java.io.File)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ProjectVersionRef (org.commonjava.atlas.maven.ident.ref.ProjectVersionRef)4 SimpleArtifactRef (org.commonjava.atlas.maven.ident.ref.SimpleArtifactRef)4 SimpleProjectVersionRef (org.commonjava.atlas.maven.ident.ref.SimpleProjectVersionRef)4 IndyFoloContentClientModule (org.commonjava.indy.folo.client.IndyFoloContentClientModule)4 RunningEnvironment (org.jboss.pnc.spi.environment.RunningEnvironment)4 RepositoryConnectionInfo (org.jboss.pnc.spi.repositorymanager.model.RepositoryConnectionInfo)4 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)3 BuildProcessException (org.jboss.pnc.executor.exceptions.BuildProcessException)3