use of org.commonjava.indy.model.core.Group in project indy by Commonjava.
the class StoreReverseMapMigrationTest method run.
@Test
public void run() throws Exception {
/* @formatter:off */
final String repoAContent = "<?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>20150721164334</lastUpdated>\n" + " </versioning>\n" + "</metadata>\n";
/* @formatter:on */
/* @formatter:off */
final String repoBContent = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<metadata>\n" + " <groupId>org.foo</groupId>\n" + " <artifactId>bar</artifactId>\n" + " <versioning>\n" + " <latest>2.0</latest>\n" + " <release>2.0</release>\n" + " <versions>\n" + " <version>2.0</version>\n" + " </versions>\n" + " <lastUpdated>20160722164334</lastUpdated>\n" + " </versioning>\n" + "</metadata>\n";
/* @formatter:on */
/* @formatter:off */
final String repoCContent = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<metadata>\n" + " <groupId>org.foo</groupId>\n" + " <artifactId>bar</artifactId>\n" + " <versioning>\n" + " <latest>3.0</latest>\n" + " <release>3.0</release>\n" + " <versions>\n" + " <version>3.0</version>\n" + " </versions>\n" + " <lastUpdated>20160723164334</lastUpdated>\n" + " </versioning>\n" + "</metadata>\n";
/* @formatter:on */
createHostedStorePath(hostedA, path, repoAContent);
try (final InputStream stream = client.content().get(hostedA.getKey(), path)) {
assertContent(repoAContent, IOUtils.toString(stream));
}
createHostedStorePath(hostedB, path, repoBContent);
try (final InputStream stream = client.content().get(hostedB.getKey(), path)) {
assertContent(repoBContent, IOUtils.toString(stream));
}
createHostedStorePath(hostedC, path, repoCContent);
try (final InputStream stream = client.content().get(hostedC.getKey(), path)) {
assertContent(repoCContent, IOUtils.toString(stream));
}
/* @formatter:off */
final String mergedContent1 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + " <metadata>\n" + " <groupId>org.foo</groupId>\n" + " <artifactId>bar</artifactId>\n" + " <versioning>\n" + " <latest>2.0</latest>\n" + " <release>2.0</release>\n" + " <versions>\n" + " <version>1.0</version>\n" + " <version>2.0</version>\n" + " </versions>\n" + " <lastUpdated>20160722164334</lastUpdated>\n" + " </versioning>\n" + "</metadata>\n";
/* @formatter:on */
try (final InputStream stream = client.content().get(group, gY.getName(), path)) {
assertContent(mergedContent1, IOUtils.toString(stream));
}
gX.addConstituent(hostedC);
client.stores().update(gX, "test update");
gX = client.stores().load(StoreType.group, gX.getName(), Group.class);
logger.debug("\n\nGroup constituents are:\n {}\n\n", StringUtils.join(gX.getConstituents(), "\n "));
waitForEventPropagation();
/* @formatter:off */
final String mergedContent2 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + " <metadata>\n" + " <groupId>org.foo</groupId>\n" + " <artifactId>bar</artifactId>\n" + " <versioning>\n" + " <latest>3.0</latest>\n" + " <release>3.0</release>\n" + " <versions>\n" + " <version>1.0</version>\n" + " <version>2.0</version>\n" + " <version>3.0</version>\n" + " </versions>\n" + " <lastUpdated>20160723164334</lastUpdated>\n" + " </versioning>\n" + "</metadata>\n";
try (final InputStream stream = client.content().get(group, gY.getName(), path)) {
assertContent(mergedContent2, IOUtils.toString(stream));
}
}
use of org.commonjava.indy.model.core.Group in project indy by Commonjava.
the class ContentIndexDirLvWithMetadataTest method test.
@Test
public void test() throws Exception {
final String remoteName1 = newName();
RemoteRepository remote1 = new RemoteRepository(MAVEN_PKG_KEY, remoteName1, server.formatUrl(remoteName1));
remote1 = client.stores().create(remote1, name.getMethodName(), RemoteRepository.class);
final String remoteName2 = newName();
RemoteRepository remote2 = new RemoteRepository(MAVEN_PKG_KEY, remoteName2, server.formatUrl(remoteName2));
remote2 = client.stores().create(remote2, name.getMethodName(), RemoteRepository.class);
final String groupName = newName();
Group group = new Group(MAVEN_PKG_KEY, groupName, remote1.getKey(), remote2.getKey());
group = client.stores().create(group, name.getMethodName(), Group.class);
server.expect(server.formatUrl(remoteName2, PATH_META), 200, PATH_META_CONTENT);
try (InputStream s = client.content().get(group.getKey(), PATH_META)) {
assertThat(IOUtils.toString(s), equalTo(PATH_META_CONTENT));
}
AdvancedCache<IndexedStorePath, IndexedStorePath> advancedCache = (AdvancedCache) contentIndex.execute(c -> c);
System.out.println("[Content index DEBUG]: cached isps: " + advancedCache.keySet());
for (IndexedStorePath value : advancedCache.values()) {
assertThat(value.getOriginStoreKey(), equalTo(remote2.getKey()));
}
System.out.println("[Content index DEBUG]: cache size:" + advancedCache.size());
System.out.println("[Content index DEBUG]: cache hit:" + advancedCache.getStats().getHits());
System.out.println("[Content index DEBUG]: cache misses:" + advancedCache.getStats().getMisses());
}
use of org.commonjava.indy.model.core.Group in project indy by Commonjava.
the class RepositoryFilterTest method run.
/* @formatter:on */
@Test
public void run() throws Exception {
final String path_1 = "org/foo/bar/1.0/bar-1.0.pom";
final String content_1_remote = "This is a test from remote";
final String content_1 = "This is a test";
final String path_2 = "org/foo/bar/1.0-rh-0001/bar-1.0-rh-0001.pom";
final String content_2 = "This is a rh test";
final String remoteR = "R";
final String hostedBuild_1 = "build-1";
final String groupG = "G";
final String metadataPath = "org/foo/bar/maven-metadata.xml";
server.expect(server.formatUrl(remoteR, path_1), 200, content_1_remote);
server.expect(server.formatUrl(remoteR, metadataPath), 200, METADATA_TEMPLATE.replaceAll("%version%", "1.0"));
RemoteRepository remote = client.stores().create(new RemoteRepository(MAVEN_PKG_KEY, remoteR, server.formatUrl(remoteR)), "Add remote", RemoteRepository.class);
HostedRepository hosted = client.stores().create(new HostedRepository(MAVEN_PKG_KEY, hostedBuild_1), "Add hosted", HostedRepository.class);
client.content().store(hosted.getKey(), path_1, new ByteArrayInputStream(content_1.getBytes()));
client.content().store(hosted.getKey(), path_2, new ByteArrayInputStream(content_2.getBytes()));
client.content().store(hosted.getKey(), metadataPath, new ByteArrayInputStream(METADATA_TEMPLATE.replaceAll("%version%", "1.0-rh-0001").getBytes()));
// add confusing repos, hope it is not confused
List<StoreKey> storeKeys = new ArrayList<>();
for (int i = 100; i < 200; i++) {
HostedRepository h = client.stores().create(new HostedRepository(MAVEN_PKG_KEY, "build-" + i), "Add hosted", HostedRepository.class);
storeKeys.add(h.getKey());
}
storeKeys.add(hosted.getKey());
storeKeys.add(remote.getKey());
// create group
StoreKey[] keyArray = new StoreKey[storeKeys.size()];
Group g = client.stores().create(new Group(MAVEN_PKG_KEY, groupG, storeKeys.toArray(keyArray)), "Add group", Group.class);
System.out.printf("\n\nGroup constituents are:\n %s\n\n", StringUtils.join(g.getConstituents(), "\n "));
// get
try (InputStream stream = client.content().get(g.getKey(), path_1)) {
String str = IOUtils.toString(stream);
assertThat(str, equalTo(content_1_remote));
}
try (InputStream stream = client.content().get(g.getKey(), path_2)) {
String str = IOUtils.toString(stream);
assertThat(str, equalTo(content_2));
}
try (InputStream stream = client.content().get(g.getKey(), metadataPath)) {
String str = IOUtils.toString(stream);
assertThat(str, containsString("<version>1.0</version>"));
assertThat(str, containsString("<version>1.0-rh-0001</version>"));
}
}
use of org.commonjava.indy.model.core.Group in project indy by Commonjava.
the class StoreFileAndVerifyExistenceInGroupTest method storeFileInConstituentAndVerifyExistenceInGroup.
@Test
public void storeFileInConstituentAndVerifyExistenceInGroup() throws Exception {
final Group g = client.stores().load(group, PUBLIC, Group.class);
System.out.printf("\n\nGroup constituents are:\n %s\n\n", StringUtils.join(g.getConstituents(), "\n "));
assertThat(g.getConstituents().contains(new StoreKey(hosted, STORE)), equalTo(true));
final InputStream stream = new ByteArrayInputStream(("This is a test: " + System.nanoTime()).getBytes());
final String path = "/path/to/foo.class";
assertThat(client.content().exists(hosted, STORE, path), equalTo(false));
client.content().store(hosted, STORE, path, stream);
assertThat(client.content().exists(group, PUBLIC, path), equalTo(true));
}
use of org.commonjava.indy.model.core.Group in project indy by Commonjava.
the class StoreReverseMapInitTest method run.
@Test
public void run() throws Exception {
/* @formatter:off */
final String repoAContent = "<?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>20150721164334</lastUpdated>\n" + " </versioning>\n" + "</metadata>\n";
/* @formatter:on */
/* @formatter:off */
final String repoBContent = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<metadata>\n" + " <groupId>org.foo</groupId>\n" + " <artifactId>bar</artifactId>\n" + " <versioning>\n" + " <latest>2.0</latest>\n" + " <release>2.0</release>\n" + " <versions>\n" + " <version>2.0</version>\n" + " </versions>\n" + " <lastUpdated>20160722164334</lastUpdated>\n" + " </versioning>\n" + "</metadata>\n";
/* @formatter:on */
/* @formatter:off */
final String repoCContent = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<metadata>\n" + " <groupId>org.foo</groupId>\n" + " <artifactId>bar</artifactId>\n" + " <versioning>\n" + " <latest>3.0</latest>\n" + " <release>3.0</release>\n" + " <versions>\n" + " <version>3.0</version>\n" + " </versions>\n" + " <lastUpdated>20160723164334</lastUpdated>\n" + " </versioning>\n" + "</metadata>\n";
/* @formatter:on */
HostedRepository hostedA = client.stores().load(new StoreKey(PKG_TYPE_MAVEN, hosted, repoA), HostedRepository.class);
createHostedStorePath(hostedA, repoAContent);
try (final InputStream stream = client.content().get(hostedA.getKey(), path)) {
assertContent(repoAContent, IOUtils.toString(stream));
}
HostedRepository hostedB = client.stores().load(new StoreKey(PKG_TYPE_MAVEN, hosted, repoB), HostedRepository.class);
createHostedStorePath(hostedB, repoBContent);
try (final InputStream stream = client.content().get(hostedB.getKey(), path)) {
assertContent(repoBContent, IOUtils.toString(stream));
}
HostedRepository hostedC = client.stores().load(new StoreKey(PKG_TYPE_MAVEN, hosted, repoC), HostedRepository.class);
createHostedStorePath(hostedC, repoCContent);
try (final InputStream stream = client.content().get(hostedC.getKey(), path)) {
assertContent(repoCContent, IOUtils.toString(stream));
}
/* @formatter:off */
final String mergedContent1 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + " <metadata>\n" + " <groupId>org.foo</groupId>\n" + " <artifactId>bar</artifactId>\n" + " <versioning>\n" + " <latest>2.0</latest>\n" + " <release>2.0</release>\n" + " <versions>\n" + " <version>1.0</version>\n" + " <version>2.0</version>\n" + " </versions>\n" + " <lastUpdated>20160722164334</lastUpdated>\n" + " </versioning>\n" + "</metadata>\n";
/* @formatter:on */
Group gY = client.stores().load(new StoreKey(PKG_TYPE_MAVEN, group, groupY), Group.class);
try (final InputStream stream = client.content().get(gY.getKey(), path)) {
assertContent(mergedContent1, IOUtils.toString(stream));
}
Group gX = client.stores().load(new StoreKey(PKG_TYPE_MAVEN, group, groupX), Group.class);
gX.addConstituent(hostedC);
client.stores().update(gX, "test update");
gX = client.stores().load(gX.getKey(), Group.class);
logger.debug("\n\nGroup constituents are:\n {}\n\n", StringUtils.join(gX.getConstituents(), "\n "));
waitForEventPropagation();
/* @formatter:off */
final String mergedContent2 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + " <metadata>\n" + " <groupId>org.foo</groupId>\n" + " <artifactId>bar</artifactId>\n" + " <versioning>\n" + " <latest>3.0</latest>\n" + " <release>3.0</release>\n" + " <versions>\n" + " <version>1.0</version>\n" + " <version>2.0</version>\n" + " <version>3.0</version>\n" + " </versions>\n" + " <lastUpdated>20160723164334</lastUpdated>\n" + " </versioning>\n" + "</metadata>\n";
try (final InputStream stream = client.content().get(gY.getKey(), path)) {
assertContent(mergedContent2, IOUtils.toString(stream));
}
}
Aggregations