Search in sources :

Example 21 with TrackedContentEntryDTO

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

Example 22 with TrackedContentEntryDTO

use of org.commonjava.indy.folo.dto.TrackedContentEntryDTO in project indy by Commonjava.

the class GroupMetadataExcludedFromTrackingReportTest method run.

@Test
public void run() throws Exception {
    final String trackingId = newName();
    final String path = "org/commonjava/commonjava/maven-metadata.xml";
    centralServer.expect(centralServer.formatUrl(path), 200, Thread.currentThread().getContextClassLoader().getResourceAsStream("folo-content/commonjava-version-metadata.xml"));
    client.module(IndyFoloAdminClientModule.class).initReport(trackingId);
    final InputStream result = client.module(IndyFoloContentClientModule.class).get(trackingId, group, PUBLIC, path);
    assertThat(result, notNullValue());
    final String pom = IOUtils.toString(result);
    result.close();
    assertThat(pom.contains("<version>2</version>"), equalTo(true));
    boolean sealed = client.module(IndyFoloAdminClientModule.class).sealTrackingRecord(trackingId);
    assertThat(sealed, equalTo(true));
    TrackedContentDTO trackingReport = client.module(IndyFoloAdminClientModule.class).getTrackingReport(trackingId);
    Set<TrackedContentEntryDTO> downloads = trackingReport.getDownloads();
    assertThat(downloads == null || downloads.isEmpty(), equalTo(true));
}
Also used : IndyFoloAdminClientModule(org.commonjava.indy.folo.client.IndyFoloAdminClientModule) InputStream(java.io.InputStream) TrackedContentEntryDTO(org.commonjava.indy.folo.dto.TrackedContentEntryDTO) IndyFoloContentClientModule(org.commonjava.indy.folo.client.IndyFoloContentClientModule) TrackedContentDTO(org.commonjava.indy.folo.dto.TrackedContentDTO) Test(org.junit.Test)

Example 23 with TrackedContentEntryDTO

use of org.commonjava.indy.folo.dto.TrackedContentEntryDTO in project indy by Commonjava.

the class StoreOneTrackedAndVerifyUrlInReportTest method storeOneFileAndVerifyItInParentDirectoryListing.

@Test
public void storeOneFileAndVerifyItInParentDirectoryListing() throws Exception {
    final byte[] data = "this is a test".getBytes();
    final ByteArrayInputStream stream = new ByteArrayInputStream(data);
    final String root = "/path/to/";
    final String path = root + "foo.txt";
    final String trackingId = "tracker";
    content.store(trackingId, hosted, STORE, path, stream);
    assertThat(client.module(IndyFoloAdminClientModule.class).sealTrackingRecord(trackingId), equalTo(true));
    final TrackedContentDTO report = admin.getTrackingReport(trackingId);
    final Set<TrackedContentEntryDTO> uploads = report.getUploads();
    for (final TrackedContentEntryDTO upload : uploads) {
        final String uploadPath = upload.getPath();
        final String localUrl = client.content().contentUrl(hosted, STORE, uploadPath);
        assertThat("Incorrect local URL for upload: '" + uploadPath + "'", upload.getLocalUrl(), equalTo(localUrl));
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) TrackedContentEntryDTO(org.commonjava.indy.folo.dto.TrackedContentEntryDTO) TrackedContentDTO(org.commonjava.indy.folo.dto.TrackedContentDTO) Test(org.junit.Test)

Example 24 with TrackedContentEntryDTO

use of org.commonjava.indy.folo.dto.TrackedContentEntryDTO in project indy by Commonjava.

the class RetrievedPomInAlwaysOnTrackingReportTest method run.

@Test
public void run() throws Exception {
    final String testRepo = "test";
    final PomRef pom = loadPom("simple.pom", Collections.<String, String>emptyMap());
    final String url = server.formatUrl(testRepo, pom.path);
    server.expect(url, 200, pom.pom);
    final HttpGet get = new HttpGet(url);
    final CloseableHttpClient client = proxiedHttp();
    CloseableHttpResponse response = null;
    InputStream stream = null;
    try {
        response = client.execute(get, proxyContext(USER, PASS));
        assertThat(response.getStatusLine().getStatusCode(), equalTo(200));
        stream = response.getEntity().getContent();
        final String resultingPom = IOUtils.toString(stream);
        assertThat(resultingPom, notNullValue());
        assertThat(resultingPom, equalTo(pom.pom));
    } finally {
        IOUtils.closeQuietly(stream);
        HttpResources.cleanupResources(get, response, client);
    }
    assertThat(this.client.module(IndyFoloAdminClientModule.class).sealTrackingRecord(USER), equalTo(true));
    final TrackedContentDTO content = this.client.module(IndyFoloAdminClientModule.class).getRawTrackingContent(USER);
    assertThat(content, notNullValue());
    final Set<TrackedContentEntryDTO> downloads = content.getDownloads();
    assertThat(downloads, notNullValue());
    // **/ Disabled behawior  because it is  affeecting  auditing  for folo records
    // assertThat( downloads.size(), equalTo( 1 ) );
    final TrackedContentEntryDTO entry = downloads.iterator().next();
    assertThat(entry, notNullValue());
    final String downloadPath = entry.getPath();
    assertThat(downloadPath, notNullValue());
    assertThat(downloadPath, equalTo("/test/" + pom.path));
// TODO: As new api format for "GET /folo/admin/track/record", these tests are deperacated, will keep for a while and remove later
// final String repoName = "httprox_127-0-0-1";
// final TrackedContentRecord record = this.client.module( IndyFoloAdminClientModule.class )
// .getRawTrackingRecord( USER );
// final Map<StoreKey, AffectedStoreRecord> affectedStores = record.getAffectedStores();
// assertThat( affectedStores, notNullValue() );
// assertThat( affectedStores.size(), equalTo( 1 ) );
// final AffectedStoreRecord storeRecord = affectedStores.get( new StoreKey( StoreType.remote, repoName ) );
// assertThat( storeRecord, notNullValue() );
// 
// final Set<String> downloads = storeRecord.getDownloadedPaths();
// assertThat( downloads, notNullValue() );
// assertThat( downloads.size(), equalTo( 1 ) );
// assertThat( downloads.iterator()
// .next(), equalTo( "/test/" + pom.path ) );
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) IndyFoloAdminClientModule(org.commonjava.indy.folo.client.IndyFoloAdminClientModule) InputStream(java.io.InputStream) TrackedContentEntryDTO(org.commonjava.indy.folo.dto.TrackedContentEntryDTO) HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) TrackedContentDTO(org.commonjava.indy.folo.dto.TrackedContentDTO) Test(org.junit.Test)

Aggregations

TrackedContentEntryDTO (org.commonjava.indy.folo.dto.TrackedContentEntryDTO)24 TrackedContentDTO (org.commonjava.indy.folo.dto.TrackedContentDTO)23 IndyFoloAdminClientModule (org.commonjava.indy.folo.client.IndyFoloAdminClientModule)19 Test (org.junit.Test)17 InputStream (java.io.InputStream)15 IndyFoloContentClientModule (org.commonjava.indy.folo.client.IndyFoloContentClientModule)13 ByteArrayInputStream (java.io.ByteArrayInputStream)12 StoreKey (org.commonjava.indy.model.core.StoreKey)10 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)5 BytemanTest (org.commonjava.indy.ftest.core.category.BytemanTest)3 BMRules (org.jboss.byteman.contrib.bmunit.BMRules)3 File (java.io.File)2 ArrayList (java.util.ArrayList)2 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)2 HttpGet (org.apache.http.client.methods.HttpGet)2 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)2 ApiImplicitParam (io.swagger.annotations.ApiImplicitParam)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponse (io.swagger.annotations.ApiResponse)1