Search in sources :

Example 6 with RepositorySession

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

the class BuildGroupIndySidecarActivatedTest method verifyGroupComposition_ProductVersion_WithConfSet.

@Test
public void verifyGroupComposition_ProductVersion_WithConfSet() throws Exception {
    // create a dummy composed (chained) build execution and a repo session based on it
    BuildExecution execution = new TestBuildExecution("build_myproject_1111");
    Indy indy = driver.getIndy(accessToken);
    RepositorySession repositoryConfiguration = driver.createBuildRepository(execution, accessToken, accessToken, RepositoryType.MAVEN, Collections.emptyMap(), false);
    RepositoryConnectionInfo info = repositoryConfiguration.getConnectionInfo();
    assertThat(info.getDependencyUrl()).startsWith(sideCarUrl);
    assertThat(info.getDeployUrl()).startsWith(sideCarUrl);
}
Also used : 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) RepositoryConnectionInfo(org.jboss.pnc.spi.repositorymanager.model.RepositoryConnectionInfo) RepositorySession(org.jboss.pnc.spi.repositorymanager.model.RepositorySession) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 7 with RepositorySession

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

the class BuildGroupIndySidecarDeActivatedTest method verifyGroupComposition_ProductVersion_WithConfSet.

@Test
public void verifyGroupComposition_ProductVersion_WithConfSet() throws Exception {
    // create a dummy composed (chained) build execution and a repo session based on it
    BuildExecution execution = new TestBuildExecution("build_myproject_1111");
    Indy indy = driver.getIndy(accessToken);
    RepositorySession repositoryConfiguration = driver.createBuildRepository(execution, accessToken, accessToken, RepositoryType.MAVEN, Collections.emptyMap(), false);
    RepositoryConnectionInfo info = repositoryConfiguration.getConnectionInfo();
    assertThat(info.getDependencyUrl()).doesNotStartWith(sideCarUrl);
    assertThat(info.getDeployUrl()).doesNotStartWith(sideCarUrl);
}
Also used : 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) RepositoryConnectionInfo(org.jboss.pnc.spi.repositorymanager.model.RepositoryConnectionInfo) RepositorySession(org.jboss.pnc.spi.repositorymanager.model.RepositorySession) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 8 with RepositorySession

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

the class DependencyUrlIncludesTrackingIdAndGeneratedBuildGroupNameTest method formatRepositoryURLForSimpleInfo_CheckDependencyURL.

@Test
public void formatRepositoryURLForSimpleInfo_CheckDependencyURL() throws Exception {
    // create a dummy non-chained build execution and repo session based on it
    BuildExecution execution = new TestBuildExecution();
    RepositorySession repositoryConfiguration = driver.createBuildRepository(execution, accessToken, accessToken, RepositoryType.MAVEN, Collections.emptyMap(), false);
    assertThat(repositoryConfiguration, notNullValue());
    // verify the URLs in the connection info reference this build, and refer to a tracked repository group URL
    RepositoryConnectionInfo connectionInfo = repositoryConfiguration.getConnectionInfo();
    assertThat(connectionInfo, notNullValue());
    String expectedUrlPrefix = String.format("%sfolo/track/%s", url, execution.getBuildContentId());
    String expectedGroupPathPrefix = String.format("/group/%s", execution.getBuildContentId());
    assertThat("Expected URL prefix: " + expectedUrlPrefix + "\nActual URL was: " + connectionInfo.getDependencyUrl(), connectionInfo.getDependencyUrl().startsWith(expectedUrlPrefix), equalTo(true));
    assertThat("Expected URL to contain group path prefix: " + expectedGroupPathPrefix + "\nActual URL was: " + connectionInfo.getDependencyUrl(), connectionInfo.getDependencyUrl().contains(expectedGroupPathPrefix), equalTo(true));
}
Also used : TestBuildExecution(org.jboss.pnc.indyrepositorymanager.fixture.TestBuildExecution) TestBuildExecution(org.jboss.pnc.indyrepositorymanager.fixture.TestBuildExecution) BuildExecution(org.jboss.pnc.spi.repositorymanager.BuildExecution) RepositoryConnectionInfo(org.jboss.pnc.spi.repositorymanager.model.RepositoryConnectionInfo) RepositorySession(org.jboss.pnc.spi.repositorymanager.model.RepositorySession) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 9 with RepositorySession

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

the class DownloadTwoThenVerifyExtractedArtifactsContainThemTest method extractBuildArtifacts_ContainsTwoDownloads.

@Test
public void extractBuildArtifacts_ContainsTwoDownloads() throws Exception {
    String pomPath = "org/commonjava/indy/indy-core/0.17.0/indy-core-0.17.0.pom";
    String jarPath = "org/commonjava/indy/indy-core/0.17.0/indy-core-0.17.0.jar";
    String pomContent = "This is a pom test " + System.currentTimeMillis();
    String jarContent = "This is a jar 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(STORE, pomPath), 200, pomContent);
    server.expect(server.formatUrl(STORE, jarPath), 200, jarContent);
    // 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, pomPath)), equalTo(pomContent));
    assertThat(download(UrlUtils.buildUrl(baseUrl, jarPath)), equalTo(jarContent));
    // 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("Expected 2 dependencies, got: " + deps, deps.size(), equalTo(2));
    ProjectVersionRef pvr = new SimpleProjectVersionRef("org.commonjava.indy", "indy-core", "0.17.0");
    Set<String> refs = new HashSet<>();
    refs.add(new SimpleArtifactRef(pvr, "pom", null).toString());
    refs.add(new SimpleArtifactRef(pvr, "jar", null).toString());
    // check that both files are in the dep artifacts list using getIdentifier() to match on GAVT[C]
    for (Artifact artifact : deps) {
        assertThat(artifact + " is not in the expected list of deps: " + refs, refs.contains(artifact.getIdentifier()), equalTo(true));
    }
    Indy indy = driver.getIndy(accessToken);
    // check that the new imports are available from shared-imports
    assertAvailableInSharedImports(indy, pomContent, pomPath);
    assertAvailableInSharedImports(indy, jarContent, jarPath);
}
Also used : TestBuildExecution(org.jboss.pnc.indyrepositorymanager.fixture.TestBuildExecution) 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) Indy(org.commonjava.indy.client.core.Indy) HashSet(java.util.HashSet) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 10 with RepositorySession

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

the class ExcludeInternalRepoByRegexTest 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);
    StoreKey publicKey = new StoreKey(MAVEN_PKG_KEY, StoreType.group, PUBLIC_GROUP_ID);
    StoreKey internalKey = new StoreKey(MAVEN_PKG_KEY, StoreType.remote, INTERNAL);
    StoreKey externalKey = new StoreKey(MAVEN_PKG_KEY, StoreType.remote, EXTERNAL);
    Group publicGroup = indy.stores().load(publicKey, Group.class);
    if (publicGroup == null) {
        publicGroup = new Group(MAVEN_PKG_KEY, PUBLIC_GROUP_ID, internalKey, externalKey);
        indy.stores().create(publicGroup, "creating public group", Group.class);
    } else {
        publicGroup.setConstituents(Arrays.asList(internalKey, externalKey));
        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)

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