Search in sources :

Example 11 with PackageMetadata

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

the class PackageMetadataGeneratorTest method verifyMetadata.

private void verifyMetadata(Transfer metadataFile) throws Exception {
    final IndyObjectMapper mapper = new IndyObjectMapper(true);
    try (InputStream input = metadataFile.openInputStream()) {
        PackageMetadata packageMetadata = mapper.readValue(input, PackageMetadata.class);
        assertNotNull(packageMetadata);
        assertEquals(2, packageMetadata.getVersions().size());
        assertEquals("Unexpected package name.", "json", packageMetadata.getName());
        assertEquals("Unexpected latest version.", "9.0.6", packageMetadata.getDistTags().getLatest());
    }
}
Also used : IndyObjectMapper(org.commonjava.indy.model.core.io.IndyObjectMapper) InputStream(java.io.InputStream) PackageMetadata(org.commonjava.indy.pkg.npm.model.PackageMetadata)

Example 12 with PackageMetadata

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

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

the class PackageMetadataMergerTest method mergeWhenOneTransferIsInvalidXml.

@Test
public void mergeWhenOneTransferIsInvalidXml() 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 + "invalid.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/jquery1/jquery1.git"));
    assertThat(merged.getReadmeFilename(), equalTo("README1.md"));
    assertThat(merged.getHomepage(), equalTo("https://jquery1.com"));
    assertThat(merged.getBugs().getUrl(), equalTo("https://github.com/jquery1/jquery1/issues"));
    assertThat(merged.getLicense().getType(), equalTo("MIT1"));
    // dist-tags object merging verification
    assertThat(merged.getDistTags().getBeta(), equalTo("2.2.1"));
    assertThat(merged.getDistTags().getLatest(), equalTo("2.2.1"));
    // error, 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"));
}
Also used : Group(org.commonjava.indy.model.core.Group) 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 14 with PackageMetadata

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

the class NPMMetadataTimeoutTest method verifyMetadataBetaTag.

private void verifyMetadataBetaTag(final String betaTag, final String path, RemoteRepository repo) throws IndyClientException, IOException {
    try (InputStream remote = client.content().get(repo.getKey(), path)) {
        assertThat(remote, notNullValue());
        PackageMetadata merged = new IndyObjectMapper(true).readValue(IOUtils.toString(remote), PackageMetadata.class);
        assertThat(merged.getDistTags().getBeta(), equalTo(betaTag));
    }
}
Also used : IndyObjectMapper(org.commonjava.indy.model.core.io.IndyObjectMapper) InputStream(java.io.InputStream) PackageMetadata(org.commonjava.indy.pkg.npm.model.PackageMetadata)

Example 15 with PackageMetadata

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

the class PackageMetadataMergerTest method mergeOneTransferWithProviderError.

@Test
public void mergeOneTransferWithProviderError() throws Exception {
    String path = "jquery";
    HostedRepository h1 = new HostedRepository(NPM_PKG_KEY, "test-hosted-1");
    Transfer t1 = cacheProvider.getTransfer(new ConcreteResource(LocationUtils.toLocation(h1), path));
    initTestData(t1, VERSION_META + "package-1.json");
    Group g = new Group(NPM_PKG_KEY, "test-group", h1.getKey());
    List<Transfer> sources = Arrays.asList(t1);
    TestPackageMetadataProvider testProvider = new TestPackageMetadataProvider(new IndyWorkflowException("Failed to get provider content"));
    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.getAuthor().getName(), equalTo("JS Foundation and other contributors"));
    assertThat(merged.getRepository().getType(), equalTo("git"));
    assertThat(merged.getRepository().getUrl(), equalTo("git+https://github.com/jquery1/jquery1.git"));
    assertThat(merged.getReadmeFilename(), equalTo("README1.md"));
    assertThat(merged.getHomepage(), equalTo("https://jquery1.com"));
    assertThat(merged.getBugs().getUrl(), equalTo("https://github.com/jquery1/jquery1/issues"));
    assertThat(merged.getLicense().getType(), equalTo("MIT1"));
    // dist-tags object merging verification
    assertThat(merged.getDistTags().getBeta(), equalTo("2.2.1"));
    assertThat(merged.getDistTags().getLatest(), equalTo("2.2.1"));
    // error, 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"));
}
Also used : Group(org.commonjava.indy.model.core.Group) ByteArrayInputStream(java.io.ByteArrayInputStream) VersionMetadata(org.commonjava.indy.pkg.npm.model.VersionMetadata) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) 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)

Aggregations

PackageMetadata (org.commonjava.indy.pkg.npm.model.PackageMetadata)24 VersionMetadata (org.commonjava.indy.pkg.npm.model.VersionMetadata)15 Test (org.junit.Test)15 InputStream (java.io.InputStream)14 IndyObjectMapper (org.commonjava.indy.model.core.io.IndyObjectMapper)14 HostedRepository (org.commonjava.indy.model.core.HostedRepository)13 Transfer (org.commonjava.maven.galley.model.Transfer)10 ByteArrayInputStream (java.io.ByteArrayInputStream)9 AbstractContentManagementTest (org.commonjava.indy.ftest.core.AbstractContentManagementTest)8 Group (org.commonjava.indy.model.core.Group)8 StoreKey (org.commonjava.indy.model.core.StoreKey)8 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)7 DistTag (org.commonjava.indy.pkg.npm.model.DistTag)4 UserInfo (org.commonjava.indy.pkg.npm.model.UserInfo)4 IOException (java.io.IOException)3 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)3 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 ArrayList (java.util.ArrayList)2 Category (org.junit.experimental.categories.Category)2