Search in sources :

Example 1 with RunningRepositoryDeletion

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

the class VerifyManualDeletionOfBuildRepoTest 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 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);
    // unset the readonly flag on the hosted repo to allow its deletion
    IndyStoresClientModule indyStoreAdmin = indy.stores();
    StoreKey key = new StoreKey(MAVEN_PKG_KEY, StoreType.hosted, record.getBuildContentId());
    HostedRepository store = indyStoreAdmin.load(key, HostedRepository.class);
    store.setReadonly(false);
    indyStoreAdmin.update(store, "Unsetting readonly-flag to allow deletion");
    // manually delete the build to the public group (since it's convenient)
    RunningRepositoryDeletion deletion = driver.deleteBuild(record, pkgType, accessToken);
    deletion.monitor(completed -> assertThat("Manual deletion failed.", completed.isSuccessful(), equalTo(true)), error -> {
        error.printStackTrace();
        fail("Failed to manually delete: " + error.getMessage());
    });
    // end result: the build hosted repo should no longer exist.
    assertThat(indyStoreAdmin.exists(hostedKey), equalTo(false));
}
Also used : 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) IndyStoresClientModule(org.commonjava.indy.client.core.module.IndyStoresClientModule) 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) RunningRepositoryDeletion(org.jboss.pnc.spi.repositorymanager.model.RunningRepositoryDeletion) ByteArrayInputStream(java.io.ByteArrayInputStream) File(java.io.File) HostedRepository(org.commonjava.indy.model.core.HostedRepository) Test(org.junit.Test) ContainerTest(org.jboss.pnc.test.category.ContainerTest)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 IndyStoresClientModule (org.commonjava.indy.client.core.module.IndyStoresClientModule)1 IndyFoloContentClientModule (org.commonjava.indy.folo.client.IndyFoloContentClientModule)1 HostedRepository (org.commonjava.indy.model.core.HostedRepository)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 RunningRepositoryDeletion (org.jboss.pnc.spi.repositorymanager.model.RunningRepositoryDeletion)1 ContainerTest (org.jboss.pnc.test.category.ContainerTest)1 Test (org.junit.Test)1