use of org.commonjava.indy.model.core.RemoteRepository in project indy by Commonjava.
the class RemoteRepositoryTest method copyFidelity.
@Test
public void copyFidelity() {
RemoteRepository src = new RemoteRepository(GenericPackageTypeDescriptor.GENERIC_PKG_KEY, "test", "http://test.com/repo");
src.setTimeoutSeconds(100);
src.setPassword("foo");
src.setUser("bar");
src.setMetadata("key", "value");
src.setCacheTimeoutSeconds(200);
src.setKeyCertPem("THISISACERTIFICATEPEM");
src.setKeyPassword("certpass");
src.setMetadataTimeoutSeconds(300);
src.setNfcTimeoutSeconds(400);
src.setPassthrough(false);
src.setProxyHost("127.0.0.1");
src.setProxyPort(8888);
src.setProxyUser("proxyuser");
src.setProxyPassword("proxypass");
src.setServerCertPem("ANOTHERCERTIFICATEPEM");
src.setServerTrustPolicy("all");
src.setAllowReleases(false);
src.setAllowSnapshots(false);
src.setDescription("some description");
src.setDisableTimeout(500);
src.setDisabled(true);
src.setPathMaskPatterns(Collections.singleton("some/path"));
src.setTransientMetadata("transient", "someval");
src.setPathStyle(PathStyle.hashed);
RemoteRepository target = src.copyOf();
Stream.of(RemoteRepository.class.getMethods()).filter(m -> m.getName().startsWith("get") && m.isAccessible() && m.getParameterCount() == 0).forEach(m -> {
try {
assertThat(m.getName() + " didn't get copied correctly!", m.invoke(target), equalTo(m.invoke(src)));
} catch (IllegalAccessException e) {
e.printStackTrace();
fail("Failed to invoke: " + m.getName());
} catch (InvocationTargetException e) {
e.printStackTrace();
}
});
}
use of org.commonjava.indy.model.core.RemoteRepository in project indy by Commonjava.
the class RemoteRepoTimeoutNeverDisableTest method assertResult.
@Override
protected void assertResult(RemoteRepository remoteRepo) throws Exception {
assertThat(remoteRepo.isDisabled(), equalTo(false));
Thread.sleep(2000);
RemoteRepository result = client.stores().load(remote, remoteRepo.getName(), RemoteRepository.class);
assertThat(result.isDisabled(), equalTo(false));
}
use of org.commonjava.indy.model.core.RemoteRepository in project indy by Commonjava.
the class RemoteRepoTimeoutReenableWithTimeoutSetTest method assertResult.
@Override
protected void assertResult(RemoteRepository remoteRepo) throws Exception {
assertThat(remoteRepo.isDisabled(), equalTo(true));
Thread.sleep(2000);
RemoteRepository result = client.stores().load(remote, remoteRepo.getName(), RemoteRepository.class);
assertThat(result.isDisabled(), equalTo(false));
}
use of org.commonjava.indy.model.core.RemoteRepository in project indy by Commonjava.
the class RepositoryPathMaskExtTest method run.
/**
* Extensive tests. Both regex patterns and "directory prefix" patterns need to be tested, involving all three store types:
* RemoteRepository (direct access)
* HostedRepository (direct access)
* Group (where one or more members has path masks)
* Case where two members contain the same path, but first one's path mask doesn't match
* - Should return content from the second member
*/
@Test
public void run() throws Exception {
final String content1 = "{\"content1\": \"This is a test: " + System.nanoTime() + "\"}";
final String content2 = "{\"content2\": \"This is a test: " + System.nanoTime() + "\"}";
final String path_1 = "org/foo/foo-project/1.0/pom.xml";
final String path_2 = "org/bar/bar-project/1.0/pom.xml";
final String remote1 = "remote1";
final String hosted1 = "hosted1";
server.expect(server.formatUrl(remote1, path_1), 200, new ByteArrayInputStream(content1.getBytes()));
RemoteRepository remoteRepo1 = new RemoteRepository(remote1, server.formatUrl(remote1));
Set<String> pathMaskPatterns = new HashSet<>();
// regex patterns
pathMaskPatterns.add("r|org/bar.*|");
remoteRepo1.setPathMaskPatterns(pathMaskPatterns);
remoteRepo1 = client.stores().create(remoteRepo1, "adding remote 1", RemoteRepository.class);
HostedRepository hostedRepo1 = new HostedRepository(hosted1);
pathMaskPatterns = new HashSet<>();
pathMaskPatterns.add("org/foo");
pathMaskPatterns.add("r|org/bar.*|");
hostedRepo1.setPathMaskPatterns(pathMaskPatterns);
hostedRepo1 = client.stores().create(hostedRepo1, "adding hosted 1", HostedRepository.class);
client.content().store(hosted, hosted1, path_1, new ByteArrayInputStream(content2.getBytes()));
client.content().store(hosted, hosted1, path_2, new ByteArrayInputStream(content2.getBytes()));
Group g = new Group("group1", remoteRepo1.getKey(), hostedRepo1.getKey());
g = client.stores().create(g, "adding group1", Group.class);
System.out.printf("\n\nGroup constituents are:\n %s\n\n", StringUtils.join(g.getConstituents(), "\n "));
InputStream stream = null;
String str = null;
// Case 1. return content from the repo with valid mask
// get stream for path-1 via group
stream = client.content().get(group, g.getName(), path_1);
assertThat(stream, notNullValue());
// return content from the repo with mask
str = IOUtils.toString(stream);
stream.close();
assertThat(str, equalTo(content2));
// Case 2. multiple repositories with same mask, use what can supply the real artifact
// get stream for path-2 via group (success)
stream = client.content().get(group, g.getName(), path_2);
assertThat(stream, notNullValue());
stream.close();
// Case 3. test direct access hosted repo with regex mask
// direct access for path-2 (success)
stream = client.content().get(hosted, hostedRepo1.getName(), path_2);
assertThat(stream, notNullValue());
stream.close();
}
use of org.commonjava.indy.model.core.RemoteRepository in project indy by Commonjava.
the class RepositoryPathMaskMetadataTest method run.
/**
* Case where user requests maven-metadata.xml which is allowed by path mask
* - Should include versions from the member that has a path mask
*/
@Test
public void run() throws Exception {
final String path_metadata = "org/bar/bar-project/maven-metadata.xml";
final String remote1 = "remote1";
final String hosted1 = "hosted1";
server.expect(server.formatUrl(remote1, path_metadata), 200, meta1);
RemoteRepository remoteRepo1 = new RemoteRepository(remote1, server.formatUrl(remote1));
Set<String> pathMaskPatterns = new HashSet<>();
// regex patterns
pathMaskPatterns.add("r|org/bar.*|");
remoteRepo1.setPathMaskPatterns(pathMaskPatterns);
remoteRepo1 = client.stores().create(remoteRepo1, "adding remote 1", RemoteRepository.class);
HostedRepository hostedRepo1 = new HostedRepository(hosted1);
pathMaskPatterns = new HashSet<>();
pathMaskPatterns.add("org/bar.*");
hostedRepo1.setPathMaskPatterns(pathMaskPatterns);
hostedRepo1 = client.stores().create(hostedRepo1, "adding hosted 1", HostedRepository.class);
client.content().store(hosted, hosted1, path_metadata, new ByteArrayInputStream(meta2.getBytes()));
Group g = new Group("group1", remoteRepo1.getKey(), hostedRepo1.getKey());
g = client.stores().create(g, "adding group1", Group.class);
System.out.printf("\n\nGroup constituents are:\n %s\n\n", StringUtils.join(g.getConstituents(), "\n "));
InputStream stream = null;
String str = null;
// get metadata from hosted1
stream = client.content().get(hosted, hostedRepo1.getName(), path_metadata);
assertThat(stream, notNullValue());
str = IOUtils.toString(stream);
System.out.println("hosted1.metadata >>>> " + str);
stream.close();
// get metadata from remote1
stream = client.content().get(remote, remoteRepo1.getName(), path_metadata);
assertThat(stream, notNullValue());
str = IOUtils.toString(stream);
System.out.println("remote1.metadata >>>> " + str);
stream.close();
// get metadata from group1
stream = client.content().get(group, g.getName(), path_metadata);
assertThat(stream, notNullValue());
// return aggregated versions from all repositories with valid mask
str = IOUtils.toString(stream);
System.out.println("group1.metadata >>>> " + str);
assertThat(str.trim(), equalTo(aggregatedMeta));
stream.close();
}
Aggregations