Search in sources :

Example 1 with RunningRepositoryPromotion

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

the class VerifyManualPromotionOfBuildRepoTest method manuallyPromoteBuildRepoToChainGroup.

@Test
public void manuallyPromoteBuildRepoToChainGroup() throws Exception {
    String path = "/org/myproj/myproj/1.0/myproj-1.0.pom";
    String content = "This is a test " + System.currentTimeMillis();
    // String chainId = "chain";
    String buildId = "build";
    // create a dummy non-chained build execution and a repo session based on it
    BuildExecution execution = new TestBuildExecution(buildId);
    RepositorySession session = driver.createBuildRepository(execution, accessToken, accessToken, RepositoryType.MAVEN, Collections.emptyMap(), false);
    String pkgType = MAVEN_PKG_KEY;
    // simulate a build deploying a file.
    StoreKey hostedKey = new StoreKey(pkgType, StoreType.hosted, buildId);
    indy.module(IndyFoloContentClientModule.class).store(buildId, hostedKey, path, new ByteArrayInputStream(content.getBytes()));
    // now, extract the build artifacts. This will trigger promotion of the build hosted repo to the chain group.
    RepositoryManagerResult result = session.extractBuildArtifacts(true);
    // do some sanity checks while we're here
    List<Artifact> deps = result.getBuiltArtifacts();
    assertThat(deps.size(), equalTo(1));
    Artifact a = deps.get(0);
    assertThat(a.getFilename(), equalTo(new File(path).getName()));
    // construct a dummy BuildRecord for use below
    BuildRecord record = new BuildRecord();
    record.setBuildContentId(buildId);
    // manually promote the build to the public group (since it's convenient)
    RunningRepositoryPromotion promotion = driver.promoteBuild(record, pkgType, PUBLIC, accessToken);
    promotion.monitor(completed -> assertThat("Manual promotion failed.", completed.isSuccessful(), equalTo(true)), error -> {
        error.printStackTrace();
        fail("Failed to manually promote: " + error.getMessage());
    });
    // end result: the chain group should contain the build hosted repo.
    StoreKey publicKey = new StoreKey(pkgType, StoreType.group, PUBLIC);
    Group publicGroup = indy.stores().load(publicKey, Group.class);
    System.out.println("public group constituents: " + publicGroup.getConstituents());
    assertThat(publicGroup.getConstituents().contains(hostedKey), equalTo(true));
}
Also used : Group(org.commonjava.indy.model.core.Group) RunningRepositoryPromotion(org.jboss.pnc.spi.repositorymanager.model.RunningRepositoryPromotion) TestBuildExecution(org.jboss.pnc.indyrepositorymanager.fixture.TestBuildExecution) RepositoryManagerResult(org.jboss.pnc.spi.repositorymanager.RepositoryManagerResult) IndyFoloContentClientModule(org.commonjava.indy.folo.client.IndyFoloContentClientModule) 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) Artifact(org.jboss.pnc.model.Artifact) BuildRecord(org.jboss.pnc.model.BuildRecord) ByteArrayInputStream(java.io.ByteArrayInputStream) File(java.io.File) Test(org.junit.Test) ContainerTest(org.jboss.pnc.test.category.ContainerTest)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 IndyFoloContentClientModule (org.commonjava.indy.folo.client.IndyFoloContentClientModule)1 Group (org.commonjava.indy.model.core.Group)1 StoreKey (org.commonjava.indy.model.core.StoreKey)1 TestBuildExecution (org.jboss.pnc.indyrepositorymanager.fixture.TestBuildExecution)1 Artifact (org.jboss.pnc.model.Artifact)1 BuildRecord (org.jboss.pnc.model.BuildRecord)1 BuildExecution (org.jboss.pnc.spi.repositorymanager.BuildExecution)1 RepositoryManagerResult (org.jboss.pnc.spi.repositorymanager.RepositoryManagerResult)1 RepositorySession (org.jboss.pnc.spi.repositorymanager.model.RepositorySession)1 RunningRepositoryPromotion (org.jboss.pnc.spi.repositorymanager.model.RunningRepositoryPromotion)1 ContainerTest (org.jboss.pnc.test.category.ContainerTest)1 Test (org.junit.Test)1