Search in sources :

Example 1 with IndyFoloAdminClientModule

use of org.commonjava.indy.folo.client.IndyFoloAdminClientModule in project indy by Commonjava.

the class DownloadFromTrackedAndRetrieveInRepoZipTest method run.

@Test
public void run() throws Exception {
    final String trackingId = newName();
    String path = "org/commonjava/commonjava/2/commonjava-2.pom";
    centralServer.expect(centralServer.formatUrl(path), 200, Thread.currentThread().getContextClassLoader().getResourceAsStream("folo-content/commonjava-2.pom"));
    InputStream result = client.module(IndyFoloContentClientModule.class).get(trackingId, remote, CENTRAL, path);
    assertThat(result, notNullValue());
    final String pom = IOUtils.toString(result);
    result.close();
    assertThat(pom.contains("<groupId>org.commonjava</groupId>"), equalTo(true));
    IndyFoloAdminClientModule module = client.module(IndyFoloAdminClientModule.class);
    boolean success = module.sealTrackingRecord(trackingId);
    assertThat(success, equalTo(true));
    result = module.getTrackingRepoZip(trackingId);
    assertThat(result, notNullValue());
    // ZipInputStream wrapping this resulting InputStream didn't seem to work...I was probably doing something wrong
    File f = getTemp().newFile("downloaded.zip");
    try (FileOutputStream fos = new FileOutputStream(f)) {
        IOUtils.copy(result, fos);
    }
    ZipFile zf = new ZipFile(f);
    ZipEntry entry = zf.getEntry(path);
    assertThat(entry, notNullValue());
    try (InputStream stream = zf.getInputStream(entry)) {
        String fromZip = IOUtils.toString(stream);
        assertThat("zip contents differ from direct download!", fromZip, equalTo(pom));
    }
}
Also used : IndyFoloAdminClientModule(org.commonjava.indy.folo.client.IndyFoloAdminClientModule) ZipFile(java.util.zip.ZipFile) InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) ZipEntry(java.util.zip.ZipEntry) IndyFoloContentClientModule(org.commonjava.indy.folo.client.IndyFoloContentClientModule) File(java.io.File) ZipFile(java.util.zip.ZipFile) Test(org.junit.Test) AbstractFoloContentManagementTest(org.commonjava.indy.folo.ftest.content.AbstractFoloContentManagementTest)

Example 2 with IndyFoloAdminClientModule

use of org.commonjava.indy.folo.client.IndyFoloAdminClientModule in project indy by Commonjava.

the class StoreAndPromoteFileToTrackedHostedRepoTest method run.

@Test
public void run() throws Exception {
    String changelog = "Create test repo";
    IndyFoloContentClientModule folo = client.module(IndyFoloContentClientModule.class);
    IndyPromoteClientModule promote = client.module(IndyPromoteClientModule.class);
    IndyFoloAdminClientModule foloAdmin = client.module(IndyFoloAdminClientModule.class);
    // 0. Create tracking id and use it as promotion source
    String trackingId = newName();
    // 1. Create source and target repositories
    HostedRepository source = new HostedRepository(MavenPackageTypeDescriptor.MAVEN_PKG_KEY, trackingId);
    client.stores().create(source, changelog, HostedRepository.class);
    HostedRepository target = new HostedRepository(MavenPackageTypeDescriptor.MAVEN_PKG_KEY, "target");
    client.stores().create(target, changelog, HostedRepository.class);
    // 2. Store the artifact to source repo
    InputStream stream = new ByteArrayInputStream(bytes);
    folo.store(trackingId, source.getKey(), path, stream);
    // 3. Seal the record
    foloAdmin.sealTrackingRecord(trackingId);
    // 4. Promote to target repo (by path)
    PathsPromoteRequest promoteRequest = new PathsPromoteRequest(source.getKey(), target.getKey());
    promoteRequest.setFireEvents(true);
    promote.promoteByPath(promoteRequest);
    // 5. Check tracking record, the store is adjusted to target
    TrackedContentDTO trackingContent = foloAdmin.getRawTrackingContent(trackingId);
    List<TrackedContentEntryDTO> list = new ArrayList<>(trackingContent.getUploads());
    TrackedContentEntryDTO trackedContent = list.get(0);
    assertEquals(target.getKey(), trackedContent.getStoreKey());
}
Also used : IndyFoloAdminClientModule(org.commonjava.indy.folo.client.IndyFoloAdminClientModule) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) TrackedContentEntryDTO(org.commonjava.indy.folo.dto.TrackedContentEntryDTO) IndyFoloContentClientModule(org.commonjava.indy.folo.client.IndyFoloContentClientModule) ArrayList(java.util.ArrayList) PathsPromoteRequest(org.commonjava.indy.promote.model.PathsPromoteRequest) IndyPromoteClientModule(org.commonjava.indy.promote.client.IndyPromoteClientModule) HostedRepository(org.commonjava.indy.model.core.HostedRepository) TrackedContentDTO(org.commonjava.indy.folo.dto.TrackedContentDTO) Test(org.junit.Test)

Example 3 with IndyFoloAdminClientModule

use of org.commonjava.indy.folo.client.IndyFoloAdminClientModule in project indy by Commonjava.

the class StoreFileThenUploadThenDownloadAndVerifyInTrackingReportTest method sealAndCheck.

void sealAndCheck(String trackingId) throws IndyClientException {
    // seal
    IndyFoloAdminClientModule adminModule = client.module(IndyFoloAdminClientModule.class);
    boolean success = adminModule.sealTrackingRecord(trackingId);
    assertThat(success, equalTo(true));
    // check report
    final TrackedContentDTO report = adminModule.getTrackingReport(trackingId);
    assertThat(report, notNullValue());
    final Set<TrackedContentEntryDTO> downloads = report.getDownloads();
    assertThat(downloads, notNullValue());
    assertThat(downloads.size(), equalTo(1));
    final Set<TrackedContentEntryDTO> uploads = report.getUploads();
    assertThat(uploads, notNullValue());
    assertThat(uploads.size(), equalTo(1));
}
Also used : IndyFoloAdminClientModule(org.commonjava.indy.folo.client.IndyFoloAdminClientModule) TrackedContentEntryDTO(org.commonjava.indy.folo.dto.TrackedContentEntryDTO) TrackedContentDTO(org.commonjava.indy.folo.dto.TrackedContentDTO)

Example 4 with IndyFoloAdminClientModule

use of org.commonjava.indy.folo.client.IndyFoloAdminClientModule in project indy by Commonjava.

the class FoloBackupListenerTest method run.

@Test
public void run() throws Exception {
    final String trackingId = newName();
    final InputStream stream = new ByteArrayInputStream(("This is a test: " + System.nanoTime()).getBytes());
    final String path = "/path/to/foo.class";
    client.module(IndyFoloContentClientModule.class).store(trackingId, hosted, STORE, path, stream);
    IndyFoloAdminClientModule adminModule = client.module(IndyFoloAdminClientModule.class);
    boolean success = adminModule.sealTrackingRecord(trackingId);
    assertThat(success, equalTo(true));
    final TrackedContentDTO report = adminModule.getTrackingReport(trackingId);
    assertThat(report, notNullValue());
    final Set<TrackedContentEntryDTO> uploads = report.getUploads();
    assertThat(uploads, notNullValue());
    assertThat(uploads.size(), equalTo(1));
    final TrackedContentEntryDTO entry = uploads.iterator().next();
    System.out.println(entry);
    assertThat(entry, notNullValue());
    assertThat(entry.getStoreKey(), equalTo(new StoreKey(hosted, STORE)));
    assertThat(entry.getPath(), equalTo(path));
    assertThat(entry.getLocalUrl(), equalTo(client.content().contentUrl(hosted, STORE, path)));
    assertThat(entry.getOriginUrl(), nullValue());
    // /////////////////////////////////////////////////////////////////////////////
    // the above are copied from StoreFileAndVerifyInTrackingReportTest
    // next, we check the backup dir contains two files, one from startup action, the other is just added
    // **/
    // File f1 = new File( dataDir, FOLO_DIR + "/" + BAK_DIR +"/sealed/" + trackingId );
    // assertTrue( f1.exists() );
    File f2 = new File(dataDir, FOLO_DIR + "/" + BAK_DIR + "/sealed");
    assertDumped(f2);
}
Also used : IndyFoloAdminClientModule(org.commonjava.indy.folo.client.IndyFoloAdminClientModule) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) TrackedContentEntryDTO(org.commonjava.indy.folo.dto.TrackedContentEntryDTO) IndyFoloContentClientModule(org.commonjava.indy.folo.client.IndyFoloContentClientModule) StoreKey(org.commonjava.indy.model.core.StoreKey) File(java.io.File) TrackedContentDTO(org.commonjava.indy.folo.dto.TrackedContentDTO) Test(org.junit.Test)

Example 5 with IndyFoloAdminClientModule

use of org.commonjava.indy.folo.client.IndyFoloAdminClientModule in project indy by Commonjava.

the class RecordsMigrationTest method run.

@Test
public void run() throws Exception {
    IndyFoloAdminClientModule adminClientModule = client.module(IndyFoloAdminClientModule.class);
    TrackingIdsDTO idsDTO = adminClientModule.getTrackingIds(SEALED.getValue());
    assertNotNull(idsDTO);
    List<String> expectedIds = Arrays.asList("Mg4NV207", "qC8c1cZB");
// **/ Disabled behawior  because it is  affeecting  auditing  for folo records
// checkIdsDTO( idsDTO, expectedIds, adminClientModule );
}
Also used : TrackingIdsDTO(org.commonjava.indy.folo.dto.TrackingIdsDTO) IndyFoloAdminClientModule(org.commonjava.indy.folo.client.IndyFoloAdminClientModule) Test(org.junit.Test)

Aggregations

IndyFoloAdminClientModule (org.commonjava.indy.folo.client.IndyFoloAdminClientModule)11 Test (org.junit.Test)9 InputStream (java.io.InputStream)8 ByteArrayInputStream (java.io.ByteArrayInputStream)7 IndyFoloContentClientModule (org.commonjava.indy.folo.client.IndyFoloContentClientModule)7 TrackedContentDTO (org.commonjava.indy.folo.dto.TrackedContentDTO)7 TrackedContentEntryDTO (org.commonjava.indy.folo.dto.TrackedContentEntryDTO)7 StoreKey (org.commonjava.indy.model.core.StoreKey)4 File (java.io.File)3 ArrayList (java.util.ArrayList)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 ZipEntry (java.util.zip.ZipEntry)1 ZipFile (java.util.zip.ZipFile)1 PathInfo (org.commonjava.indy.client.core.helper.PathInfo)1 TrackingIdsDTO (org.commonjava.indy.folo.dto.TrackingIdsDTO)1 AbstractFoloContentManagementTest (org.commonjava.indy.folo.ftest.content.AbstractFoloContentManagementTest)1 AbstractTrackingReportTest (org.commonjava.indy.folo.ftest.report.AbstractTrackingReportTest)1 TrackedContent (org.commonjava.indy.folo.model.TrackedContent)1