use of org.commonjava.indy.folo.dto.TrackedContentEntryDTO in project indy by Commonjava.
the class RecalculateMissingChecksumForTrackingRecordTest method run.
@BMRules(rules = { @BMRule(name = "setup_metadata_retrieval_countdown", targetClass = "^org.commonjava.indy.content.ContentDigester", isInterface = true, targetMethod = "<init>", targetLocation = "ENTRY", action = "System.out.println(\"SETUP COUNTDOWN\"); createCountDown(\"COUNTDOWN\", 1);"), @BMRule(name = "prevent_first_metadata_retrieval", targetClass = "^org.commonjava.indy.content.ContentDigester", isInterface = true, targetMethod = "getContentMetadata", targetLocation = "ENTRY", binding = "path:String = $1.getPath();", condition = "path.endsWith(\"path/to/foo.class\") && !countDown(\"COUNTDOWN\")", action = "System.out.println(\"RETURN NULL\"); return null;") })
@Test
public void run() throws Exception {
final String trackingId = newName();
final String repoId = "repo";
final String path = "/path/to/foo.class";
final InputStream stream = new ByteArrayInputStream("This is a test with the same content each time.".getBytes());
server.expect(server.formatUrl(repoId, path), 200, stream);
RemoteRepository rr = new RemoteRepository(repoId, server.formatUrl(repoId));
rr = client.stores().create(rr, "adding test remote", RemoteRepository.class);
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final InputStream in = client.module(IndyFoloContentClientModule.class).get(trackingId, remote, repoId, path);
IOUtils.copy(in, baos);
in.close();
final byte[] bytes = baos.toByteArray();
final String md5 = md5Hex(bytes);
final String sha256 = sha256Hex(bytes);
assertThat(md5, equalTo(DigestUtils.md5Hex(bytes)));
assertThat(sha256, equalTo(DigestUtils.sha256Hex(bytes)));
waitForEventPropagation();
assertThat(client.module(IndyFoloAdminClientModule.class).sealTrackingRecord(trackingId), equalTo(true));
final TrackedContentDTO report = client.module(IndyFoloAdminClientModule.class).getTrackingReport(trackingId);
assertThat(report, notNullValue());
final Set<TrackedContentEntryDTO> downloads = report.getDownloads();
assertThat(downloads, notNullValue());
assertThat(downloads.size(), equalTo(1));
final TrackedContentEntryDTO entry = downloads.iterator().next();
System.out.println(entry);
assertThat(entry, notNullValue());
assertThat(entry.getStoreKey(), equalTo(new StoreKey(remote, repoId)));
assertThat(entry.getPath(), equalTo(path));
assertThat(entry.getLocalUrl(), equalTo(client.content().contentUrl(remote, repoId, path)));
assertThat(entry.getOriginUrl(), equalTo(server.formatUrl(repoId, path)));
assertThat(entry.getMd5(), equalTo(md5));
assertThat(entry.getSha256(), equalTo(sha256));
}
use of org.commonjava.indy.folo.dto.TrackedContentEntryDTO in project indy by Commonjava.
the class RetrieveTrackingReportAfterCacheExpirationTest method run.
@Test
public void run() throws Exception {
final String trackingId = newName();
final String repoId = "repo";
final String path = "/path/to/foo.class";
final InputStream stream = new ByteArrayInputStream(("This is a test: " + System.nanoTime()).getBytes());
server.expect(server.formatUrl(repoId, path), 200, stream);
RemoteRepository rr = new RemoteRepository(repoId, server.formatUrl(repoId));
rr = client.stores().create(rr, "adding test remote", RemoteRepository.class);
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final InputStream in = client.module(IndyFoloContentClientModule.class).get(trackingId, remote, repoId, path);
IOUtils.copy(in, baos);
in.close();
final byte[] bytes = baos.toByteArray();
final String md5 = md5Hex(bytes);
final String sha256 = sha256Hex(bytes);
assertThat(md5, equalTo(DigestUtils.md5Hex(bytes)));
assertThat(sha256, equalTo(DigestUtils.sha256Hex(bytes)));
// sleep so the cache evicts the record
Thread.sleep(2000);
assertThat(client.module(IndyFoloAdminClientModule.class).sealTrackingRecord(trackingId), equalTo(true));
final TrackedContentDTO report = client.module(IndyFoloAdminClientModule.class).getTrackingReport(trackingId);
assertThat(report, notNullValue());
final Set<TrackedContentEntryDTO> downloads = report.getDownloads();
assertThat(downloads, notNullValue());
assertThat(downloads.size(), equalTo(1));
final TrackedContentEntryDTO entry = downloads.iterator().next();
System.out.println(entry);
assertThat(entry, notNullValue());
assertThat(entry.getStoreKey(), equalTo(new StoreKey(remote, repoId)));
assertThat(entry.getPath(), equalTo(path));
assertThat(entry.getLocalUrl(), equalTo(client.content().contentUrl(remote, repoId, path)));
assertThat(entry.getOriginUrl(), equalTo(server.formatUrl(repoId, path)));
assertThat(entry.getMd5(), equalTo(md5));
assertThat(entry.getSha256(), equalTo(sha256));
}
use of org.commonjava.indy.folo.dto.TrackedContentEntryDTO 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());
}
use of org.commonjava.indy.folo.dto.TrackedContentEntryDTO in project indy by Commonjava.
the class StoreFileAndVerifyInTrackingReportTest 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());
}
use of org.commonjava.indy.folo.dto.TrackedContentEntryDTO in project indy by Commonjava.
the class StoreFileThenDownloadThenUploadAndVerifyInTrackingReportTest 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));
}
Aggregations