Search in sources :

Example 1 with UserInfo

use of org.commonjava.indy.pkg.npm.model.UserInfo in project indy by Commonjava.

the class PackageMetadataMergerTest method mergeTwoSimplePackageMetadataFiles.

@Test
public void mergeTwoSimplePackageMetadataFiles() throws Exception {
    String path = "jquery";
    HostedRepository h1 = new HostedRepository(NPM_PKG_KEY, "test-hosted-1");
    HostedRepository h2 = new HostedRepository(NPM_PKG_KEY, "test-hosted-2");
    Transfer t1 = cacheProvider.getTransfer(new ConcreteResource(LocationUtils.toLocation(h1), path));
    initTestData(t1, VERSION_META + "package-1.json");
    Transfer t2 = cacheProvider.getTransfer(new ConcreteResource(LocationUtils.toLocation(h2), path));
    initTestData(t2, VERSION_META + "package-2.json");
    Group g = new Group(NPM_PKG_KEY, "test-group", h1.getKey(), h2.getKey());
    List<Transfer> sources = Arrays.asList(t1, t2);
    byte[] output = new PackageMetadataMerger(Collections.emptyList(), mapper).merge(sources, g, path);
    PackageMetadata merged = mapper.readValue(IOUtils.toString(new ByteArrayInputStream(output)), 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));
}
Also used : Group(org.commonjava.indy.model.core.Group) UserInfo(org.commonjava.indy.pkg.npm.model.UserInfo) ByteArrayInputStream(java.io.ByteArrayInputStream) VersionMetadata(org.commonjava.indy.pkg.npm.model.VersionMetadata) PackageMetadata(org.commonjava.indy.pkg.npm.model.PackageMetadata) Transfer(org.commonjava.maven.galley.model.Transfer) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) HostedRepository(org.commonjava.indy.model.core.HostedRepository) Test(org.junit.Test)

Example 2 with UserInfo

use of org.commonjava.indy.pkg.npm.model.UserInfo 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 3 with UserInfo

use of org.commonjava.indy.pkg.npm.model.UserInfo in project indy by Commonjava.

the class PackageMetadataMergerTest method mergeOneTransferWithProviderContent.

@Test
public void mergeOneTransferWithProviderContent() throws Exception {
    String path = "jquery";
    HostedRepository h1 = new HostedRepository(NPM_PKG_KEY, "test-hosted-1");
    HostedRepository h2 = new HostedRepository(NPM_PKG_KEY, "test-hosted-2");
    Transfer t1 = cacheProvider.getTransfer(new ConcreteResource(LocationUtils.toLocation(h1), path));
    initTestData(t1, VERSION_META + "package-1.json");
    Transfer t2 = cacheProvider.getTransfer(new ConcreteResource(LocationUtils.toLocation(h2), path));
    initTestData(t2, VERSION_META + "package-2.json");
    Group g = new Group(NPM_PKG_KEY, "test-group", h1.getKey(), h2.getKey());
    List<Transfer> sources = Arrays.asList(t1, t2);
    PackageMetadata provided = new PackageMetadata("jquery");
    provided.setDescription("provider description test");
    provided.setRepository(new Repository("svn", "svn+https://svn.host/jquery"));
    provided.setBugs(new Bugs("https://github.com/jquery2/jquery2/issues", "jquery2@bug.com"));
    List<UserInfo> added = new ArrayList<UserInfo>();
    added.add(new UserInfo("testa", "testa@test.com"));
    provided.setMaintainers(added);
    TestPackageMetadataProvider testProvider = new TestPackageMetadataProvider(provided);
    byte[] output = new PackageMetadataMerger(Collections.singletonList(testProvider), mapper).merge(sources, g, path);
    PackageMetadata merged = mapper.readValue(IOUtils.toString(new ByteArrayInputStream(output)), PackageMetadata.class);
    // normal object fields merging verification
    assertThat(merged.getName(), equalTo("jquery"));
    assertThat(merged.getDescription(), equalTo("provider description test"));
    assertThat(merged.getRepository().getType(), equalTo("svn"));
    assertThat(merged.getRepository().getUrl(), equalTo("svn+https://svn.host/jquery"));
    assertThat(merged.getBugs().getUrl(), equalTo("https://github.com/jquery2/jquery2/issues"));
    assertThat(merged.getBugs().getEmail(), equalTo("jquery2@bug.com"));
    // maintainers list merging verification
    List<UserInfo> maintainers = merged.getMaintainers();
    assertThat(maintainers, notNullValue());
    assertThat(maintainers.size(), equalTo(4));
    assertThat(maintainers.get(0).getName(), equalTo("dmethvin"));
    assertThat(maintainers.get(1).getName(), equalTo("mgol"));
    assertThat(maintainers.get(2).getName(), equalTo("scott.gonzalez"));
    assertThat(maintainers.get(3).getName(), equalTo("testa"));
}
Also used : Bugs(org.commonjava.indy.pkg.npm.model.Bugs) Group(org.commonjava.indy.model.core.Group) ArrayList(java.util.ArrayList) UserInfo(org.commonjava.indy.pkg.npm.model.UserInfo) Repository(org.commonjava.indy.pkg.npm.model.Repository) HostedRepository(org.commonjava.indy.model.core.HostedRepository) ByteArrayInputStream(java.io.ByteArrayInputStream) PackageMetadata(org.commonjava.indy.pkg.npm.model.PackageMetadata) Transfer(org.commonjava.maven.galley.model.Transfer) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) HostedRepository(org.commonjava.indy.model.core.HostedRepository) Test(org.junit.Test)

Example 4 with UserInfo

use of org.commonjava.indy.pkg.npm.model.UserInfo in project indy by Commonjava.

the class NPMUploadContentMergeRetrieveTest method test.

// @Test
public void test() throws Exception {
    final InputStream content1 = Thread.currentThread().getContextClassLoader().getResourceAsStream("package-1.5.1.json");
    final InputStream content2 = Thread.currentThread().getContextClassLoader().getResourceAsStream("package-1.5.1-reupload.json");
    final String path = "jquery";
    final String repoName = "test-hosted";
    HostedRepository repo = new HostedRepository(NPM_PKG_KEY, repoName);
    repo = client.stores().create(repo, "adding npm hosted repo", HostedRepository.class);
    StoreKey storeKey = repo.getKey();
    client.content().store(storeKey, path, content1);
    client.content().store(storeKey, path, content2);
    InputStream meta = client.content().get(storeKey, path);
    IndyObjectMapper mapper = new IndyObjectMapper(true);
    PackageMetadata merged = mapper.readValue(IOUtils.toString(meta), 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(), 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(1));
    assertThat(versions.get("1.5.1").getVersion(), equalTo("1.5.1"));
    assertThat(versions.get("1.5.1").getDescription(), equalTo("This is a new reupload for 1.5.1"));
    assertThat(versions.get("1.5.1").getUrl(), equalTo("jquery.com.new"));
    // 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));
    content1.close();
    content2.close();
    meta.close();
}
Also used : InputStream(java.io.InputStream) UserInfo(org.commonjava.indy.pkg.npm.model.UserInfo) StoreKey(org.commonjava.indy.model.core.StoreKey) IndyObjectMapper(org.commonjava.indy.model.core.io.IndyObjectMapper) VersionMetadata(org.commonjava.indy.pkg.npm.model.VersionMetadata) PackageMetadata(org.commonjava.indy.pkg.npm.model.PackageMetadata) HostedRepository(org.commonjava.indy.model.core.HostedRepository)

Aggregations

PackageMetadata (org.commonjava.indy.pkg.npm.model.PackageMetadata)4 UserInfo (org.commonjava.indy.pkg.npm.model.UserInfo)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 Group (org.commonjava.indy.model.core.Group)3 HostedRepository (org.commonjava.indy.model.core.HostedRepository)3 VersionMetadata (org.commonjava.indy.pkg.npm.model.VersionMetadata)3 Test (org.junit.Test)3 InputStream (java.io.InputStream)2 IndyObjectMapper (org.commonjava.indy.model.core.io.IndyObjectMapper)2 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)2 Transfer (org.commonjava.maven.galley.model.Transfer)2 ArrayList (java.util.ArrayList)1 AbstractContentManagementTest (org.commonjava.indy.ftest.core.AbstractContentManagementTest)1 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)1 StoreKey (org.commonjava.indy.model.core.StoreKey)1 Bugs (org.commonjava.indy.pkg.npm.model.Bugs)1 Repository (org.commonjava.indy.pkg.npm.model.Repository)1