Search in sources :

Example 36 with RemoteRepository

use of org.commonjava.indy.model.core.RemoteRepository in project indy by Commonjava.

the class RelDownloadPomNotFound404Test method run.

@Test
public void run() throws Exception {
    final String repo1 = "repo1";
    server.expect(server.formatUrl(repo1, path), 404, "not found");
    RemoteRepository remote1 = new RemoteRepository(repo1, server.formatUrl(repo1));
    client.stores().create(remote1, "adding remote", RemoteRepository.class);
    // Download .rel before even touching POM
    InputStream rel = client.content().get(remote, repo1, pathRel);
    assertThat(rel, nullValue());
    logger.debug(">>> register again ...");
    // upstream restored
    server.expect(server.formatUrl(repo1, path), 200, content);
    remote1.setDisabled(false);
    // disabled due to previous error, need to enable it again
    client.stores().update(remote1, "enable it");
    // Retrieve it again
    rel = client.content().get(remote, repo1, pathRel);
    assertThat(rel, notNullValue());
    String s = IOUtils.toString(rel);
    logger.debug(">>> " + s);
    assertThat(StringUtils.isNotEmpty(s), equalTo(true));
    // check POM is downloaded
    boolean exists = client.content().exists(remote, repo1, path, true);
    assertThat(exists, equalTo(true));
}
Also used : InputStream(java.io.InputStream) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) AbstractIndyFunctionalTest(org.commonjava.indy.ftest.core.AbstractIndyFunctionalTest) Test(org.junit.Test)

Example 37 with RemoteRepository

use of org.commonjava.indy.model.core.RemoteRepository in project indy by Commonjava.

the class PomDownloadDepFromParentTest method run.

@Test
public void run() throws Exception {
    String depPom = readTestResource(repo + "/" + pathDep);
    server.expect(server.formatUrl(repo1, pathDep), 200, depPom);
    String consumerPom = readTestResource(repo + "/" + pathConsumer);
    server.expect(server.formatUrl(repo1, pathConsumer), 200, consumerPom);
    String consumerParentPom = readTestResource(repo + "/" + pathConsumerParent);
    server.expect(server.formatUrl(repo1, pathConsumerParent), 200, consumerParentPom);
    // Create remote repositories
    RemoteRepository remote1 = new RemoteRepository(repo1, server.formatUrl(repo1));
    client.stores().create(remote1, "adding remote1", RemoteRepository.class);
    // Get consumer pom
    InputStream is = client.content().get(remote, repo1, pathConsumer);
    assertThat(is, notNullValue());
    String s = IOUtils.toString(is);
    logger.debug(">>> " + s);
    assertThat(s, equalTo(consumerPom));
    waitForEventPropagation();
    boolean exists = false;
    // Check consumer rel exists
    exists = client.content().exists(remote, repo1, pathConsumerRel, true);
    assertThat(exists, equalTo(true));
    // Check consumer's parent pom exists
    exists = client.content().exists(remote, repo1, pathConsumerParent, true);
    assertThat(exists, equalTo(true));
    // Check consumer's parent rel exists
    exists = client.content().exists(remote, repo1, pathConsumerParentRel, true);
    assertThat(exists, equalTo(true));
    // Check consumer rel content
    InputStream ris = client.content().get(remote, repo1, pathConsumerRel);
    assertThat(ris, notNullValue());
    String rel = IOUtils.toString(ris);
    logger.debug(">>> " + rel);
    String output = readTestResource(resource + "/output/rel.json");
    EProjectDirectRelationships eRel = mapper.readValue(rel, EProjectDirectRelationships.class);
    EProjectDirectRelationships eRelOutput = mapper.readValue(output, EProjectDirectRelationships.class);
    assertThat(eRel.getParent(), equalTo(eRelOutput.getParent()));
}
Also used : InputStream(java.io.InputStream) EProjectDirectRelationships(org.commonjava.maven.atlas.graph.model.EProjectDirectRelationships) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) AbstractIndyFunctionalTest(org.commonjava.indy.ftest.core.AbstractIndyFunctionalTest) Test(org.junit.Test)

Example 38 with RemoteRepository

use of org.commonjava.indy.model.core.RemoteRepository in project indy by Commonjava.

the class RetrieveFileAndVerifyInTrackingReportTest 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 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));
}
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) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) ByteArrayOutputStream(java.io.ByteArrayOutputStream) StoreKey(org.commonjava.indy.model.core.StoreKey) TrackedContentDTO(org.commonjava.indy.folo.dto.TrackedContentDTO) Test(org.junit.Test)

Example 39 with RemoteRepository

use of org.commonjava.indy.model.core.RemoteRepository in project indy by Commonjava.

the class RetrieveFileFromGroupAndVerifyInTrackingReportTest method run.

@Test
public void run() throws Exception {
    final String trackingId = newName();
    final String repoId = "repo";
    final String groupId = "group";
    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);
    Group g = new Group(groupId, rr.getKey());
    g = client.stores().create(g, "Adding test group", Group.class);
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final InputStream in = client.module(IndyFoloContentClientModule.class).get(trackingId, group, groupId, 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)));
    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));
}
Also used : Group(org.commonjava.indy.model.core.Group) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IndyFoloContentClientModule(org.commonjava.indy.folo.client.IndyFoloContentClientModule) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) ByteArrayOutputStream(java.io.ByteArrayOutputStream) StoreKey(org.commonjava.indy.model.core.StoreKey) TrackedContentDTO(org.commonjava.indy.folo.dto.TrackedContentDTO) IndyFoloAdminClientModule(org.commonjava.indy.folo.client.IndyFoloAdminClientModule) ByteArrayInputStream(java.io.ByteArrayInputStream) TrackedContentEntryDTO(org.commonjava.indy.folo.dto.TrackedContentEntryDTO) Test(org.junit.Test)

Example 40 with RemoteRepository

use of org.commonjava.indy.model.core.RemoteRepository in project indy by Commonjava.

the class AutoProxCalculationTest method jsonRoundTrip_RemoteRepoCreation.

@Test
public void jsonRoundTrip_RemoteRepoCreation() throws IOException {
    RemoteRepository repo = new RemoteRepository("test", "http://foo.com/test");
    AutoProxCalculation in = new AutoProxCalculation(repo, "test-rule.groovy");
    IndyObjectMapper mapper = new IndyObjectMapper(true);
    String json = mapper.writeValueAsString(in);
    AutoProxCalculation out = mapper.readValue(json, AutoProxCalculation.class);
    assertThat(out, notNullValue());
    assertThat(out.getRuleName(), equalTo(in.getRuleName()));
    assertThat(out.getStore(), equalTo(in.getStore()));
    assertThat(out, equalTo(in));
}
Also used : IndyObjectMapper(org.commonjava.indy.model.core.io.IndyObjectMapper) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) Test(org.junit.Test)

Aggregations

RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)149 Test (org.junit.Test)99 InputStream (java.io.InputStream)52 Group (org.commonjava.indy.model.core.Group)48 AbstractContentManagementTest (org.commonjava.indy.ftest.core.AbstractContentManagementTest)32 StoreKey (org.commonjava.indy.model.core.StoreKey)31 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)27 ByteArrayInputStream (java.io.ByteArrayInputStream)22 File (java.io.File)17 ChangeSummary (org.commonjava.indy.audit.ChangeSummary)17 HostedRepository (org.commonjava.indy.model.core.HostedRepository)17 PathInfo (org.commonjava.indy.client.core.helper.PathInfo)16 IndyDataException (org.commonjava.indy.data.IndyDataException)14 Before (org.junit.Before)13 Category (org.junit.experimental.categories.Category)12 Date (java.util.Date)10 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)10 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)10 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)9 HttpGet (org.apache.http.client.methods.HttpGet)9