Search in sources :

Example 16 with BuildExecution

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

the class BuildGroupSetBrewPullActiveMetadataTest method verifyBrewPullActiveMetadataSetProperly.

private void verifyBrewPullActiveMetadataSetProperly(boolean brewPullActive, String buildId) throws RepositoryManagerException, org.commonjava.indy.client.core.IndyClientException {
    // create a dummy composed (chained) build execution and a repo session based on it
    BuildExecution execution = new TestBuildExecution(buildId);
    Indy indy = driver.getIndy(accessToken);
    RepositorySession repositoryConfiguration = driver.createBuildRepository(execution, accessToken, accessToken, RepositoryType.MAVEN, Collections.emptyMap(), brewPullActive);
    String repoId = repositoryConfiguration.getBuildRepositoryId();
    Group buildGroup = indy.stores().load(new StoreKey(MAVEN_PKG_KEY, StoreType.group, repoId), Group.class);
    Map<String, String> metadata = buildGroup.getMetadata();
    assertThat(metadata).containsEntry(AbstractRepositoryManagerDriverTest.BREW_PULL_ACTIVE_METADATA_KEY, Boolean.toString(brewPullActive));
}
Also used : Group(org.commonjava.indy.model.core.Group) TestBuildExecution(org.jboss.pnc.indyrepositorymanager.fixture.TestBuildExecution) Indy(org.commonjava.indy.client.core.Indy) TestBuildExecution(org.jboss.pnc.indyrepositorymanager.fixture.TestBuildExecution) BuildExecution(org.jboss.pnc.spi.repositorymanager.BuildExecution) RepositorySession(org.jboss.pnc.spi.repositorymanager.model.RepositorySession) StoreKey(org.commonjava.indy.model.core.StoreKey)

Example 17 with BuildExecution

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

the class ExcludeInternalRepoByNameTest method extractBuildArtifacts_ContainsTwoDownloads.

@Test
public void extractBuildArtifacts_ContainsTwoDownloads() throws Exception {
    // create a remote repo pointing at our server fixture's 'repo/test' directory.
    indy.stores().create(new RemoteRepository(MAVEN_PKG_KEY, INTERNAL, server.formatUrl(INTERNAL)), "Creating internal test remote repo", RemoteRepository.class);
    indy.stores().create(new RemoteRepository(MAVEN_PKG_KEY, EXTERNAL, server.formatUrl(EXTERNAL)), "Creating external test remote repo", RemoteRepository.class);
    Group publicGroup = indy.stores().load(new StoreKey(MAVEN_PKG_KEY, StoreType.group, PUBLIC_GROUP_ID), Group.class);
    if (publicGroup == null) {
        publicGroup = new Group(MAVEN_PKG_KEY, PUBLIC_GROUP_ID, new StoreKey(MAVEN_PKG_KEY, StoreType.remote, INTERNAL), new StoreKey(MAVEN_PKG_KEY, StoreType.remote, EXTERNAL));
        indy.stores().create(publicGroup, "creating public group", Group.class);
    } else {
        publicGroup.setConstituents(Arrays.asList(new StoreKey(MAVEN_PKG_KEY, StoreType.remote, INTERNAL), new StoreKey(MAVEN_PKG_KEY, StoreType.remote, EXTERNAL)));
        indy.stores().update(publicGroup, "adding test remotes to public group");
    }
    String internalPath = "org/foo/internal/1.0/internal-1.0.pom";
    String externalPath = "org/foo/external/1.1/external-1.1.pom";
    String content = "This is a test " + System.currentTimeMillis();
    // setup the expectation that the remote repo pointing at this server will request this file...and define its
    // content.
    server.expect(server.formatUrl(INTERNAL, internalPath), 200, content);
    server.expect(server.formatUrl(EXTERNAL, externalPath), 200, content);
    // 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().getDependencyUrl();
    // 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, internalPath)), equalTo(content));
    assertThat(download(UrlUtils.buildUrl(baseUrl, externalPath)), equalTo(content));
    // extract the build artifacts, which should contain the two imported deps.
    // This will also trigger promoting imported artifacts into the shared-imports hosted repo
    RepositoryManagerResult repositoryManagerResult = rc.extractBuildArtifacts(true);
    List<Artifact> deps = repositoryManagerResult.getDependencies();
    System.out.println(deps);
    assertThat(deps, notNullValue());
    assertThat(deps.size(), equalTo(2));
    Indy indy = driver.getIndy(accessToken);
    StoreKey sharedImportsKey = new StoreKey(MAVEN_PKG_KEY, StoreType.hosted, SHARED_IMPORTS_ID);
    // check that the imports from external locations are available from shared-imports
    InputStream stream = indy.content().get(sharedImportsKey, externalPath);
    String downloaded = IOUtils.toString(stream, (String) null);
    assertThat(downloaded, equalTo(content));
    stream.close();
    // check that the imports from internal/trusted locations are NOT available from shared-imports
    stream = indy.content().get(sharedImportsKey, internalPath);
    assertThat(stream, nullValue());
}
Also used : Group(org.commonjava.indy.model.core.Group) TestBuildExecution(org.jboss.pnc.indyrepositorymanager.fixture.TestBuildExecution) InputStream(java.io.InputStream) RepositoryManagerResult(org.jboss.pnc.spi.repositorymanager.RepositoryManagerResult) Indy(org.commonjava.indy.client.core.Indy) TestBuildExecution(org.jboss.pnc.indyrepositorymanager.fixture.TestBuildExecution) BuildExecution(org.jboss.pnc.spi.repositorymanager.BuildExecution) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) StoreKey(org.commonjava.indy.model.core.StoreKey) RepositorySession(org.jboss.pnc.spi.repositorymanager.model.RepositorySession) Artifact(org.jboss.pnc.model.Artifact) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 18 with BuildExecution

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

the class ExtraDependencyRepositoriesTest method shouldAddExtraRepositoryToBuildGroup.

@Test
public void shouldAddExtraRepositoryToBuildGroup() throws RepositoryManagerException, IndyClientException {
    final String REPO_NAME = "i-test-com";
    Map<String, String> genericParams = createGenericParamsMap("http://test.com/maven/");
    BuildExecution execution = new TestBuildExecution();
    RepositorySession repositorySession = driver.createBuildRepository(execution, accessToken, accessToken, RepositoryType.MAVEN, genericParams, false);
    assertNotNull(repositorySession);
    StoreKey buildGroupKey = new StoreKey(MavenPackageTypeDescriptor.MAVEN_PKG_KEY, StoreType.group, repositorySession.getBuildRepositoryId());
    Group buildGroup = indy.stores().load(buildGroupKey, Group.class);
    long hits = buildGroup.getConstituents().stream().filter((key) -> REPO_NAME.equals(key.getName())).count();
    assertEquals(1, hits);
}
Also used : TestBuildExecution(org.jboss.pnc.indyrepositorymanager.fixture.TestBuildExecution) BuildConfigurationParameterKeys(org.jboss.pnc.api.constants.BuildConfigurationParameterKeys) ArtifactRepository(org.jboss.pnc.spi.repositorymanager.ArtifactRepository) RepositoryManagerException(org.jboss.pnc.spi.repositorymanager.RepositoryManagerException) Assert.assertNotNull(org.junit.Assert.assertNotNull) StoreType(org.commonjava.indy.model.core.StoreType) Test(org.junit.Test) HashMap(java.util.HashMap) Category(org.junit.experimental.categories.Category) Group(org.commonjava.indy.model.core.Group) ContainerTest(org.jboss.pnc.test.category.ContainerTest) List(java.util.List) MavenPackageTypeDescriptor(org.commonjava.indy.pkg.maven.model.MavenPackageTypeDescriptor) RepositorySession(org.jboss.pnc.spi.repositorymanager.model.RepositorySession) BuildExecution(org.jboss.pnc.spi.repositorymanager.BuildExecution) RepositoryType(org.jboss.pnc.enums.RepositoryType) Map(java.util.Map) IndyClientException(org.commonjava.indy.client.core.IndyClientException) StoreKey(org.commonjava.indy.model.core.StoreKey) Assert.assertEquals(org.junit.Assert.assertEquals) Group(org.commonjava.indy.model.core.Group) TestBuildExecution(org.jboss.pnc.indyrepositorymanager.fixture.TestBuildExecution) TestBuildExecution(org.jboss.pnc.indyrepositorymanager.fixture.TestBuildExecution) BuildExecution(org.jboss.pnc.spi.repositorymanager.BuildExecution) RepositorySession(org.jboss.pnc.spi.repositorymanager.model.RepositorySession) StoreKey(org.commonjava.indy.model.core.StoreKey) Test(org.junit.Test) ContainerTest(org.jboss.pnc.test.category.ContainerTest)

Example 19 with BuildExecution

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

the class UploadOneManagedSvcThenDownloadAndVerifyArtifactHasBuildCategoryTest 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();
    Map<String, String> genericParams = new HashMap<>(1);
    genericParams.put(BuildConfigurationParameterKeys.BUILD_CATEGORY.name(), BuildCategory.SERVICE.name());
    RepositorySession rc = driver.createBuildRepository(execution, accessToken, accessToken, RepositoryType.MAVEN, genericParams, 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.SERVICE, builtArtifact.getBuildCategory(), equalTo(BuildCategory.SERVICE));
    client.close();
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) TestBuildExecution(org.jboss.pnc.indyrepositorymanager.fixture.TestBuildExecution) HashMap(java.util.HashMap) 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) ProjectVersionRef(org.commonjava.atlas.maven.ident.ref.ProjectVersionRef) SimpleProjectVersionRef(org.commonjava.atlas.maven.ident.ref.SimpleProjectVersionRef) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 20 with BuildExecution

use of org.jboss.pnc.spi.repositorymanager.BuildExecution 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

BuildExecution (org.jboss.pnc.spi.repositorymanager.BuildExecution)20 RepositorySession (org.jboss.pnc.spi.repositorymanager.model.RepositorySession)20 TestBuildExecution (org.jboss.pnc.indyrepositorymanager.fixture.TestBuildExecution)19 ContainerTest (org.jboss.pnc.test.category.ContainerTest)18 Test (org.junit.Test)18 StoreKey (org.commonjava.indy.model.core.StoreKey)12 Artifact (org.jboss.pnc.model.Artifact)11 RepositoryManagerResult (org.jboss.pnc.spi.repositorymanager.RepositoryManagerResult)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 RepositoryConnectionInfo (org.jboss.pnc.spi.repositorymanager.model.RepositoryConnectionInfo)4 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)3 InputStream (java.io.InputStream)2 HashMap (java.util.HashMap)2