Search in sources :

Example 11 with IndyFoloAdminClientModule

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

the class StoreFileAndRecalculateTrackingEntryTest method run.

@Test
public void run() throws Exception {
    final String trackingId = newName();
    byte[] oldData = ("This is a test: " + System.nanoTime()).getBytes();
    InputStream stream = new ByteArrayInputStream(oldData);
    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));
    TrackedContentDTO report = adminModule.getTrackingReport(trackingId);
    assertThat(report, notNullValue());
    Set<TrackedContentEntryDTO> uploads = report.getUploads();
    assertThat(uploads, notNullValue());
    assertThat(uploads.size(), equalTo(1));
    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.getMd5(), equalTo(md5Hex(oldData)));
    assertThat(entry.getOriginUrl(), nullValue());
    byte[] newData = ("This is a REPLACED test: " + System.nanoTime()).getBytes();
    stream = new ByteArrayInputStream(newData);
    client.content().store(hosted, STORE, path, stream);
    report = adminModule.recalculateTrackingRecord(trackingId);
    assertThat(report, notNullValue());
    uploads = report.getUploads();
    assertThat(uploads, notNullValue());
    assertThat(uploads.size(), equalTo(1));
    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.getMd5(), equalTo(md5Hex(newData)));
    assertThat(entry.getOriginUrl(), nullValue());
}
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) StoreKey(org.commonjava.indy.model.core.StoreKey) TrackedContentDTO(org.commonjava.indy.folo.dto.TrackedContentDTO) 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