use of org.commonjava.indy.model.core.RemoteRepository in project indy by Commonjava.
the class RemoteRepoHeadErrorTest method run.
@Test
public void run() throws Exception {
final String repo1 = "repo1";
final String path = "org/foo/bar/maven-metadata.xml";
server.registerException(server.formatUrl(repo1, path), "upstream error");
RemoteRepository remote1 = new RemoteRepository(repo1, server.formatUrl(repo1));
remote1.setMetadata(Location.CONNECTION_TIMEOUT_SECONDS, Integer.toString(1));
remote1 = client.stores().create(remote1, "adding remote", RemoteRepository.class);
try (InputStream is = client.content().get(remote, repo1, path)) {
} catch (final IndyClientException e) {
assertThat(e.getStatusCode(), equalTo(HttpStatus.SC_BAD_GATEWAY));
}
}
use of org.commonjava.indy.model.core.RemoteRepository in project indy by Commonjava.
the class RemoteRepoHeadExistenceCheckTest method run.
@Ignore
@Test
public void run() throws Exception {
final InputStream stream = new ByteArrayInputStream(("{\"content\": \"This is a test: " + System.nanoTime() + "\"}").getBytes());
final String path = "org/foo/foo-project/1/foo-1.txt";
final String nonExistPath = "org/foo/foo-project/1/foo-2.txt";
server.expect(server.formatUrl(STORE, path), 200, stream);
server.expect(server.formatUrl(STORE, nonExistPath), 404, "not exist");
client.stores().create(new RemoteRepository(STORE, server.formatUrl(STORE)), "adding test proxy", RemoteRepository.class);
final PathInfo result = client.content().getInfo(remote, STORE, path);
try {
boolean exists = client.content().exists(remote, STORE, path);
assertTrue(exists);
File f = new File(new File(fixture.getBootOptions().getIndyHome()), "var/lib/indy/storage/remote-test/" + path);
assertTrue(!f.exists());
//TODO: this breaks because for whatever reason the head can not get content-length and we have to fall over to get().
//Refer to NCL-2729 and we will have a better fix in future
exists = client.content().exists(remote, STORE, nonExistPath);
assertFalse(exists);
} catch (final IndyClientException e) {
fail("IndyClientException: " + e);
}
}
use of org.commonjava.indy.model.core.RemoteRepository in project indy by Commonjava.
the class GroupIgnoresDisabledRemoteRepositoryTest method run.
@Test
public void run() throws Exception {
final String repo1 = "repo1";
final String repo2 = "repo2";
final String path = "path/to/test.txt";
String disabledContent = "This is disabled.";
String enabledContent = "This is enabled.";
server.expect(server.formatUrl(repo1, path), 200, disabledContent);
server.expect(server.formatUrl(repo2, path), 200, enabledContent);
RemoteRepository remote1 = new RemoteRepository(repo1, server.formatUrl(repo1));
remote1.setDisabled(true);
remote1 = client.stores().create(remote1, "adding remote", RemoteRepository.class);
RemoteRepository remote2 = new RemoteRepository(repo2, server.formatUrl(repo2));
remote2 = client.stores().create(remote2, "adding remote", RemoteRepository.class);
Group g = new Group("test", remote1.getKey(), remote2.getKey());
g = client.stores().create(g, "adding group", Group.class);
System.out.printf("\n\nGroup constituents are:\n %s\n\n", StringUtils.join(g.getConstituents(), "\n "));
final InputStream stream = client.content().get(group, g.getName(), path);
assertThat(stream, notNullValue());
final String content = IOUtils.toString(stream);
assertThat(content, equalTo(enabledContent));
stream.close();
}
use of org.commonjava.indy.model.core.RemoteRepository in project indy by Commonjava.
the class GroupMetadataMergeWithRepoErrorTest method run.
@Test
public void run() throws Exception {
final String repo1 = "repo1";
final String repo2 = "repo2";
final String path = "org/foo/bar/maven-metadata.xml";
/* @formatter:off */
final String repo1Content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<metadata>\n" + " <groupId>org.foo</groupId>\n" + " <artifactId>bar</artifactId>\n" + " <versioning>\n" + " <latest>1.0</latest>\n" + " <release>1.0</release>\n" + " <versions>\n" + " <version>1.0</version>\n" + " </versions>\n" + " <lastUpdated>20150722164334</lastUpdated>\n" + " </versioning>\n" + "</metadata>\n";
/* @formatter:on */
server.expect(server.formatUrl(repo1, path), 200, repo1Content);
server.registerException(server.formatUrl(repo2, path), "Server error");
RemoteRepository remote1 = new RemoteRepository(repo1, server.formatUrl(repo1));
remote1 = client.stores().create(remote1, "adding remote", RemoteRepository.class);
RemoteRepository remote2 = new RemoteRepository(repo2, server.formatUrl(repo2));
remote2.setMetadata(Location.CONNECTION_TIMEOUT_SECONDS, Integer.toString(1));
remote2 = client.stores().create(remote2, "adding remote", RemoteRepository.class);
Group g = new Group("test", remote1.getKey(), remote2.getKey());
g = client.stores().create(g, "adding group", Group.class);
System.out.printf("\n\nGroup constituents are:\n %s\n\n", StringUtils.join(g.getConstituents(), "\n "));
final InputStream stream = client.content().get(group, g.getName(), path);
assertThat(stream, notNullValue());
final String metadata = IOUtils.toString(stream);
assertThat(metadata, equalTo(repo1Content));
stream.close();
}
use of org.commonjava.indy.model.core.RemoteRepository in project indy by Commonjava.
the class GroupMetadataMergeWithRepoTimeoutTest method run.
@Test
public void run() throws Exception {
final String repo1 = "repo1";
final String repo2 = "repo2";
final String path = "org/foo/bar/maven-metadata.xml";
/* @formatter:off */
final String repo1Content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<metadata>\n" + " <groupId>org.foo</groupId>\n" + " <artifactId>bar</artifactId>\n" + " <versioning>\n" + " <latest>1.0</latest>\n" + " <release>1.0</release>\n" + " <versions>\n" + " <version>1.0</version>\n" + " </versions>\n" + " <lastUpdated>20150722164334</lastUpdated>\n" + " </versioning>\n" + "</metadata>\n";
/* @formatter:on */
server.expect(server.formatUrl(repo1, path), 200, repo1Content);
server.expect("GET", server.formatUrl(repo2, path), (request, response) -> {
try {
Thread.sleep(5000);
} catch (final InterruptedException e) {
}
response.setStatus(404);
});
RemoteRepository remote1 = new RemoteRepository(repo1, server.formatUrl(repo1));
remote1 = client.stores().create(remote1, "adding remote", RemoteRepository.class);
RemoteRepository remote2 = new RemoteRepository(repo2, server.formatUrl(repo2));
remote2.setTimeoutSeconds(2);
remote2.setMetadata(Location.CONNECTION_TIMEOUT_SECONDS, Integer.toString(1));
remote2 = client.stores().create(remote2, "adding remote", RemoteRepository.class);
Group g = new Group("test", remote1.getKey(), remote2.getKey());
g = client.stores().create(g, "adding group", Group.class);
System.out.printf("\n\nGroup constituents are:\n %s\n\n", StringUtils.join(g.getConstituents(), "\n "));
final InputStream stream = client.content().get(group, g.getName(), path);
assertThat(stream, notNullValue());
final String metadata = IOUtils.toString(stream);
assertThat(metadata, equalTo(repo1Content));
stream.close();
}
Aggregations