Search in sources :

Example 51 with RemoteRepository

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

the class RemoteRepositoryTest method serializeRemoteWithServerPem.

@Test
public void serializeRemoteWithServerPem() throws JsonProcessingException {
    RemoteRepository remote = new RemoteRepository("test", "http://test.com/repo");
    remote.setServerCertPem("AAAAFFFASDFADSFASDFSADFa");
    remote.setServerTrustPolicy("self-signed");
    String json = new IndyObjectMapper(true).writeValueAsString(remote);
    System.out.println(json);
}
Also used : IndyObjectMapper(org.commonjava.indy.model.core.io.IndyObjectMapper) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) Test(org.junit.Test)

Example 52 with RemoteRepository

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

the class EndpointViewListingTest method jsonRoundTrip.

@Test
public void jsonRoundTrip() throws IOException {
    EndpointView first = new EndpointView(new RemoteRepository("test", "http://foo.com/repo"), "http://localhost:8080/api/remote/test");
    EndpointView second = new EndpointView(new RemoteRepository("test2", "http://foo2.com/repo2"), "http://localhost:8080/api/remote/test2");
    EndpointViewListing in = new EndpointViewListing(Arrays.asList(first, second));
    IndyObjectMapper mapper = new IndyObjectMapper(true);
    String json = mapper.writeValueAsString(in);
    EndpointViewListing out = mapper.readValue(json, EndpointViewListing.class);
    assertThat(out, notNullValue());
    List<EndpointView> items = out.getItems();
    assertThat(items, notNullValue());
    assertThat(items.size(), equalTo(2));
    int i = 0;
    EndpointView view = items.get(i++);
    assertThat(view.getKey(), equalTo(first.getKey()));
    assertThat(view.getName(), equalTo(first.getName()));
    assertThat(view.getResourceUri(), equalTo(first.getResourceUri()));
    assertThat(view.getStoreKey(), equalTo(first.getStoreKey()));
    assertThat(view.getStoreType(), equalTo(first.getStoreType()));
    assertThat(view, equalTo(first));
    view = items.get(i++);
    assertThat(view.getKey(), equalTo(second.getKey()));
    assertThat(view.getName(), equalTo(second.getName()));
    assertThat(view.getResourceUri(), equalTo(second.getResourceUri()));
    assertThat(view.getStoreKey(), equalTo(second.getStoreKey()));
    assertThat(view.getStoreType(), equalTo(second.getStoreType()));
    assertThat(view, equalTo(second));
}
Also used : IndyObjectMapper(org.commonjava.indy.model.core.io.IndyObjectMapper) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) Test(org.junit.Test)

Example 53 with RemoteRepository

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

the class RemoteRepositoryTest method serializeRemoteWithKeyPemAndPassword.

@Test
public void serializeRemoteWithKeyPemAndPassword() throws JsonProcessingException {
    RemoteRepository remote = new RemoteRepository("test", "http://test.com/repo");
    remote.setKeyCertPem("AAAAFFFASDFADSFASDFSADFa");
    remote.setKeyPassword("testme");
    String json = new IndyObjectMapper(true).writeValueAsString(remote);
    System.out.println(json);
}
Also used : IndyObjectMapper(org.commonjava.indy.model.core.io.IndyObjectMapper) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) Test(org.junit.Test)

Example 54 with RemoteRepository

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

the class RemoteRepoInValidUrlTest method run.

@Ignore("Disabling validating decorator around StoreDataManager until we can be more certain it's correct and stable for all use cases")
@Test(expected = IndyClientException.class)
public void run() throws Exception {
    final String INVALID_REPO = "invalid-repo";
    final String INVALID_URL = "this.is.not.valid.url";
    client.stores().create(new RemoteRepository(INVALID_REPO, INVALID_URL), "adding invalid test", RemoteRepository.class);
}
Also used : RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 55 with RemoteRepository

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

the class MetaListingRescheduleTimeoutTest method timeout.

@Test
@Category(TimingDependent.class)
public void timeout() throws Exception {
    final int METADATA_TIMEOUT_SECONDS = 4;
    final int METADATA_TIMEOUT_WAITING_MILLISECONDS = 3000;
    final String repoId = "test-repo";
    // path without trailing slash for ExpectationServer...
    String repoRootPath = "org/foo/bar";
    final String repoRootUrl = server.formatUrl(repoId, repoRootPath);
    // now append the trailing '/' so Indy knows to try a directory listing...
    repoRootPath += "/";
    final String repoSubPath1 = "org/foo/bar/1.0/pom.xml";
    final String repoSubPath2 = "org/foo/bar/1.1/pom.xml";
    final String repoSubUrl1 = server.formatUrl(repoId, repoSubPath1);
    final String repoSubUrl2 = server.formatUrl(repoId, repoSubPath2);
    // mocking up a http server that expects access to metadata
    final String listingContent = "<html>" + "<head><title>Index of /org/foo/bar</title></head>" + "<body><h1>Index of /org/foo/bar/</h1>" + "<hr><pre>" + "<a href=\"1.0/\">1.0/</a>" + "<a href=\"1.1/\">1.1/</a>" + "</pre><hr></body></html>";
    server.expect(repoRootUrl, 200, listingContent);
    final String datetime = (new Date()).toString();
    server.expect(repoSubUrl1, 200, String.format("metadata %s", datetime));
    server.expect(repoSubUrl2, 200, String.format("metadata %s", datetime));
    // set up remote repository pointing to the test http server, and timeout little later
    final String changelog = "Timeout Testing: " + name.getMethodName();
    final RemoteRepository repository = new RemoteRepository(repoId, server.formatUrl(repoId));
    repository.setMetadataTimeoutSeconds(METADATA_TIMEOUT_SECONDS);
    client.stores().create(repository, changelog, RemoteRepository.class);
    try (InputStream is = client.content().get(remote, repoId, repoSubPath1)) {
    }
    try (InputStream is = client.content().get(remote, repoId, repoSubPath2)) {
    }
    // first time trigger normal content storage with timeout, should be 4s
    InputStream content = client.content().get(remote, repoId, repoRootPath);
    assertThat("no metadata result", content, notNullValue());
    logger.debug("### will begin to get content");
    IOUtils.readLines(content).forEach(logger::info);
    content.close();
    final String listingMetaPath = "org/foo/bar/.listing.txt";
    File listingMetaFile = Paths.get(fixture.getBootOptions().getIndyHome(), "var/lib/indy/storage", MAVEN_PKG_KEY, remote.singularEndpointName() + "-" + repoId, listingMetaPath).toFile();
    assertThat("metadata doesn't exist: " + listingMetaFile, listingMetaFile.exists(), equalTo(true));
    // wait for first time
    Thread.sleep(METADATA_TIMEOUT_WAITING_MILLISECONDS);
    // as the metadata content re-request, the metadata timeout interval should NOT be re-scheduled
    client.content().get(remote, repoId, repoRootPath).close();
    // will wait second time for a longer period
    Thread.sleep(METADATA_TIMEOUT_WAITING_MILLISECONDS * getTestTimeoutMultiplier());
    //        logger.info( "Checking whether metadata file {} has been deleted...", listingMetaFile );
    // as rescheduled, the artifact should not be deleted
    assertThat("artifact should be removed as the rescheduled of metadata should not succeed", listingMetaFile.exists(), equalTo(false));
}
Also used : InputStream(java.io.InputStream) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) File(java.io.File) Date(java.util.Date) Category(org.junit.experimental.categories.Category) Test(org.junit.Test) AbstractContentManagementTest(org.commonjava.indy.ftest.core.AbstractContentManagementTest)

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