Search in sources :

Example 86 with Group

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

the class NPMHttpMetaGenerationTest method test.

@Test
public void test() throws Exception {
    final InputStream content = Thread.currentThread().getContextClassLoader().getResourceAsStream("package-1.5.1.json");
    server.expect(server.formatUrl(REMOTE, PATH), 200, new ByteArrayInputStream(CONTENT_1.getBytes("UTF-8")));
    final RemoteRepository remote = new RemoteRepository(NPM_PKG_KEY, REMOTE, server.formatUrl(REMOTE));
    client.stores().create(remote, "adding npm remote repo", RemoteRepository.class);
    final HostedRepository hosted = new HostedRepository(NPM_PKG_KEY, HOSTED);
    client.stores().create(hosted, "adding npm hosted repo", HostedRepository.class);
    client.content().store(hosted.getKey(), PATH, content);
    final Group group = new Group(NPM_PKG_KEY, GROUP, hosted.getKey());
    client.stores().create(group, "adding npm group repo", Group.class);
    IndyObjectMapper mapper = new IndyObjectMapper(true);
    InputStream hostedStream = client.content().get(hosted.getKey(), PACKAGE_HTTP_META_PATH);
    HttpExchangeMetadata hostedMeta = mapper.readValue(IOUtils.toString(hostedStream), HttpExchangeMetadata.class);
    // assertThat( hostedMeta.getResponseHeaders().containsKey( "LAST-MODIFIED" ), equalTo( true ) );
    client.content().get(group.getKey(), PATH);
    InputStream groupStream = client.content().get(group.getKey(), PACKAGE_HTTP_META_PATH);
    HttpExchangeMetadata groupMeta = mapper.readValue(IOUtils.toString(groupStream), HttpExchangeMetadata.class);
    // assertThat( groupMeta.getResponseHeaders().containsKey( "LAST-MODIFIED" ), equalTo( true ) );
    content.close();
    hostedStream.close();
    groupStream.close();
}
Also used : Group(org.commonjava.indy.model.core.Group) ByteArrayInputStream(java.io.ByteArrayInputStream) IndyObjectMapper(org.commonjava.indy.model.core.io.IndyObjectMapper) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) HttpExchangeMetadata(org.commonjava.maven.galley.transport.htcli.model.HttpExchangeMetadata) HostedRepository(org.commonjava.indy.model.core.HostedRepository) Test(org.junit.Test) AbstractContentManagementTest(org.commonjava.indy.ftest.core.AbstractContentManagementTest)

Example 87 with Group

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

the class NPMRemoteMetadataContentDecoratorTest method test.

@Test
public void test() throws Exception {
    final String packageContent = IOUtils.toString(Thread.currentThread().getContextClassLoader().getResourceAsStream("package-1.5.1.json"));
    final String packagePath = "jquery";
    final String tarballUrl = "https://registry.npmjs.org/jquery/-/jquery-1.5.1.tgz";
    server.expect(server.formatUrl(STORE, packagePath), 200, new ByteArrayInputStream(packageContent.getBytes()));
    final RemoteRepository remoteRepository = new RemoteRepository(NPM_PKG_KEY, STORE, server.formatUrl(STORE));
    client.stores().create(remoteRepository, "adding npm remote repo", RemoteRepository.class);
    final Group group = new Group(NPM_PKG_KEY, GROUP, remoteRepository.getKey());
    client.stores().create(group, "adding group", Group.class);
    // retrieve from remote repo
    StoreKey storeKey = remoteRepository.getKey();
    InputStream stream = client.content().get(storeKey, packagePath);
    assertThat(stream, notNullValue());
    String contextUrl = UrlUtils.buildUrl(fixture.getUrl(), "content", NPM_PKG_KEY, storeKey.getType().name(), STORE);
    String decoratedContent = packageContent.replaceAll(tarballUrl, contextUrl + "/jquery/-/jquery-1.5.1.tgz");
    assertThat(IOUtils.toString(stream), equalTo(decoratedContent));
    stream.close();
    // retrieve from group G
    StoreKey groupKey = group.getKey();
    stream = client.content().get(groupKey, packagePath);
    assertThat(stream, notNullValue());
    contextUrl = UrlUtils.buildUrl(fixture.getUrl(), "content", NPM_PKG_KEY, groupKey.getType().name(), GROUP);
    String maskedUrl = contextUrl + "/jquery/-/jquery-1.5.1.tgz";
    // group metadata is not a simple copy of the remote repo so we only check if the decorated tarball url exists
    assertThat(IOUtils.toString(stream), containsString(maskedUrl));
    stream.close();
}
Also used : Group(org.commonjava.indy.model.core.Group) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) StoreKey(org.commonjava.indy.model.core.StoreKey) Test(org.junit.Test) AbstractContentManagementTest(org.commonjava.indy.ftest.core.AbstractContentManagementTest)

Example 88 with Group

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

the class NPMGroupContentMergeRetrieveTest method test.

@Test
public void test() throws Exception {
    final String CONTENT_1 = IOUtils.toString(Thread.currentThread().getContextClassLoader().getResourceAsStream("package-1.5.1.json"));
    final String CONTENT_2 = IOUtils.toString(Thread.currentThread().getContextClassLoader().getResourceAsStream("package-1.6.2.json"));
    server.expect(server.formatUrl(REPO_X, PATH), 200, new ByteArrayInputStream(CONTENT_1.getBytes()));
    server.expect(server.formatUrl(REPO_Y, PATH), 200, new ByteArrayInputStream(CONTENT_2.getBytes()));
    final RemoteRepository repoX = new RemoteRepository(NPM_PKG_KEY, REPO_X, server.formatUrl(REPO_X));
    client.stores().create(repoX, "adding npm remote repo", RemoteRepository.class);
    final RemoteRepository repoY = new RemoteRepository(NPM_PKG_KEY, REPO_Y, server.formatUrl(REPO_Y));
    client.stores().create(repoY, "adding npm remote repo", RemoteRepository.class);
    final Group groupA = new Group(NPM_PKG_KEY, GROUP_A, repoX.getKey(), repoY.getKey());
    client.stores().create(groupA, "adding npm group repo", Group.class);
    System.out.printf("\n\n-------Group constituents are:\n  %s\n\n", StringUtils.join(groupA.getConstituents(), "\n  "));
    final InputStream remote = client.content().get(repoX.getKey(), PATH);
    final InputStream group = client.content().get(groupA.getKey(), PATH);
    assertThat(remote, notNullValue());
    assertThat(group, notNullValue());
    String contextUrl = UrlUtils.buildUrl(fixture.getUrl(), "content", NPM_PKG_KEY, repoX.getType().name(), REPO_X);
    String maskedUrl = contextUrl + "/jquery/-/jquery-1.5.1.tgz";
    assertThat(IOUtils.toString(remote), equalTo(CONTENT_1.replace("https://registry.npmjs.org/jquery/-/jquery-1.5.1.tgz", maskedUrl)));
    IndyObjectMapper mapper = new IndyObjectMapper(true);
    PackageMetadata merged = mapper.readValue(IOUtils.toString(group), PackageMetadata.class);
    // normal object fields merging verification
    assertThat(merged.getName(), equalTo("jquery"));
    assertThat(merged.getAuthor().getName(), equalTo("JS Foundation and other contributors"));
    assertThat(merged.getRepository().getType(), equalTo("git"));
    assertThat(merged.getRepository().getUrl(), equalTo("git+https://github.com/jquery/jquery.git"));
    assertThat(merged.getReadmeFilename(), equalTo("README.md"));
    assertThat(merged.getHomepage(), equalTo("https://jquery.com"));
    assertThat(merged.getBugs().getUrl(), equalTo("https://github.com/jquery/jquery/issues"));
    assertThat(merged.getLicense().getType(), equalTo("MIT"));
    // dist-tags object merging verification
    assertThat(merged.getDistTags().getBeta(), equalTo("3.2.1-beta.1"));
    assertThat(merged.getDistTags().getLatest(), equalTo("3.2.1"));
    // versions map merging verification
    Map<String, VersionMetadata> versions = merged.getVersions();
    assertThat(versions, notNullValue());
    assertThat(versions.size(), equalTo(2));
    assertThat(versions.get("1.5.1").getVersion(), equalTo("1.5.1"));
    assertThat(versions.get("1.6.2").getVersion(), equalTo("1.6.2"));
    // maintainers list merging verification
    List<UserInfo> maintainers = merged.getMaintainers();
    assertThat(maintainers, notNullValue());
    assertThat(maintainers.size(), equalTo(3));
    assertThat(maintainers.get(0).getName(), equalTo("dmethvin"));
    assertThat(maintainers.get(1).getName(), equalTo("mgol"));
    assertThat(maintainers.get(2).getName(), equalTo("scott.gonzalez"));
    // time map merging verification
    Map<String, String> times = merged.getTime();
    assertThat(times, notNullValue());
    assertThat(times.size(), equalTo(8));
    assertThat(times.get("modified"), equalTo("2017-05-23T10:57:14.309Z"));
    assertThat(times.get("created"), equalTo("2011-04-19T07:19:56.392Z"));
    // users map merging verification
    Map<String, Boolean> users = merged.getUsers();
    assertThat(users, notNullValue());
    assertThat(users.size(), equalTo(10));
    assertThat(users.get("fgribreau"), equalTo(true));
    // keywords list merging verification
    List<String> keywords = merged.getKeywords();
    assertThat(keywords, notNullValue());
    assertThat(keywords.size(), equalTo(4));
    assertThat(keywords.contains("javascript"), equalTo(true));
    remote.close();
    group.close();
}
Also used : Group(org.commonjava.indy.model.core.Group) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) UserInfo(org.commonjava.indy.pkg.npm.model.UserInfo) ByteArrayInputStream(java.io.ByteArrayInputStream) IndyObjectMapper(org.commonjava.indy.model.core.io.IndyObjectMapper) VersionMetadata(org.commonjava.indy.pkg.npm.model.VersionMetadata) PackageMetadata(org.commonjava.indy.pkg.npm.model.PackageMetadata) Test(org.junit.Test) AbstractContentManagementTest(org.commonjava.indy.ftest.core.AbstractContentManagementTest)

Example 89 with Group

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

the class NPMRemoteMetadataContentDecorator_ProxyOriginTest method test.

@Test
public void test() throws Exception {
    final String packageContent = IOUtils.toString(Thread.currentThread().getContextClassLoader().getResourceAsStream("package-1.5.1.json"));
    final String packagePath = "jquery";
    final String tarballUrl = "https://registry.npmjs.org/jquery/-/jquery-1.5.1.tgz";
    server.expect(server.formatUrl(STORE, packagePath), 200, new ByteArrayInputStream(packageContent.getBytes()));
    final RemoteRepository remoteRepository = new RemoteRepository(NPM_PKG_KEY, STORE, server.formatUrl(STORE));
    client.stores().create(remoteRepository, "adding npm remote repo", RemoteRepository.class);
    final Group group = new Group(NPM_PKG_KEY, GROUP, remoteRepository.getKey());
    client.stores().create(group, "adding group", Group.class);
    // prepare
    IndyClientHttp http = client.module(IndyRawHttpModule.class).getHttp();
    Map<String, String> headers = new HashMap<>();
    headers.put("proxy-origin", proxyOrigin);
    // retrieve from remote repo
    HttpResources ret = http.getRaw(client.content().contentPath(remoteRepository.getKey(), packagePath), headers);
    String content = HttpResources.entityToString(ret.getResponse());
    // logger.debug( "Get file content:\n{}", content );
    String expected = packageContent.replaceAll(tarballUrl, proxyOrigin + "/api/content/npm/remote/test/jquery/-/jquery-1.5.1.tgz");
    assertThat(content, equalTo(expected));
    // retrieve from group
    ret = http.getRaw(client.content().contentPath(group.getKey(), packagePath), headers);
    content = HttpResources.entityToString(ret.getResponse());
    Object obj = new JSONParser().parse(content);
    JSONObject jsonObject = (JSONObject) obj;
    JSONObject versions = (JSONObject) jsonObject.get("versions");
    JSONObject v151 = (JSONObject) versions.get("1.5.1");
    JSONObject dist = (JSONObject) v151.get("dist");
    String tarball = (String) dist.get("tarball");
    expected = proxyOrigin + "/api/content/npm/group/G/jquery/-/jquery-1.5.1.tgz";
    assertThat(tarball, equalTo(expected));
}
Also used : Group(org.commonjava.indy.model.core.Group) JSONObject(org.json.simple.JSONObject) ByteArrayInputStream(java.io.ByteArrayInputStream) HashMap(java.util.HashMap) IndyClientHttp(org.commonjava.indy.client.core.IndyClientHttp) HttpResources(org.commonjava.indy.client.core.helper.HttpResources) IndyRawHttpModule(org.commonjava.indy.client.core.module.IndyRawHttpModule) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) JSONObject(org.json.simple.JSONObject) JSONParser(org.json.simple.parser.JSONParser) Test(org.junit.Test) AbstractContentManagementTest(org.commonjava.indy.ftest.core.AbstractContentManagementTest)

Example 90 with Group

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

the class NpmPathMappingTest method test.

@Test
public void test() throws Exception {
    server.expect(server.formatUrl(REMOTE, PATH), 200, new ByteArrayInputStream(CONTENT_1.getBytes("UTF-8")));
    final RemoteRepository remote = new RemoteRepository(NPM_PKG_KEY, REMOTE, server.formatUrl(REMOTE));
    client.stores().create(remote, "adding npm remote repo", RemoteRepository.class);
    final HostedRepository hosted = new HostedRepository(NPM_PKG_KEY, HOSTED);
    client.stores().create(hosted, "adding npm hosted repo", HostedRepository.class);
    client.content().store(hosted.getKey(), PATH, new ByteArrayInputStream(CONTENT_1.getBytes()));
    final Group group = new Group(NPM_PKG_KEY, GROUP, remote.getKey(), hosted.getKey());
    client.stores().create(group, "adding npm group repo", Group.class);
    assertThat(client.content().exists(remote.getKey(), MAPPING_PATH), equalTo(false));
    assertThat(client.content().exists(remote.getKey(), PATH), equalTo(true));
    assertThat(client.content().exists(hosted.getKey(), MAPPING_PATH), equalTo(true));
    assertThat(client.content().exists(hosted.getKey(), PATH), equalTo(true));
    assertThat(client.content().exists(group.getKey(), MAPPING_PATH), equalTo(true));
    assertThat(client.content().exists(group.getKey(), PATH), equalTo(true));
}
Also used : Group(org.commonjava.indy.model.core.Group) ByteArrayInputStream(java.io.ByteArrayInputStream) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) HostedRepository(org.commonjava.indy.model.core.HostedRepository) Test(org.junit.Test) AbstractContentManagementTest(org.commonjava.indy.ftest.core.AbstractContentManagementTest)

Aggregations

Group (org.commonjava.indy.model.core.Group)211 Test (org.junit.Test)111 HostedRepository (org.commonjava.indy.model.core.HostedRepository)89 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)82 StoreKey (org.commonjava.indy.model.core.StoreKey)76 ByteArrayInputStream (java.io.ByteArrayInputStream)67 InputStream (java.io.InputStream)62 IndyDataException (org.commonjava.indy.data.IndyDataException)44 AbstractContentManagementTest (org.commonjava.indy.ftest.core.AbstractContentManagementTest)42 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)42 Transfer (org.commonjava.maven.galley.model.Transfer)31 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)30 Logger (org.slf4j.Logger)30 Before (org.junit.Before)29 StoreDataManager (org.commonjava.indy.data.StoreDataManager)27 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)27 HashSet (java.util.HashSet)26 ArrayList (java.util.ArrayList)25 List (java.util.List)22 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)22