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));
}
Aggregations