Search in sources :

Example 1 with VersionMetadata

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

the class PackageMetadataMergerTest method mergeTwoSimplePackageMetadataFiles.

@Test
public void mergeTwoSimplePackageMetadataFiles() throws Exception {
    String path = "jquery/package.json";
    HostedRepository h1 = new HostedRepository("test-hosted-1");
    HostedRepository h2 = new HostedRepository("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("test-group", h1.getKey(), h2.getKey());
    List<Transfer> sources = Arrays.asList(t1, t2);
    byte[] output = new PackageMetadataMerger(Collections.emptyList()).merge(sources, g, path);
    IndyObjectMapper mapper = new IndyObjectMapper(true);
    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(), 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) IndyObjectMapper(org.commonjava.indy.model.core.io.IndyObjectMapper) 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 VersionMetadata

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

the class PackageMetadataMergerTest method mergeWhenOneTransferIsInvalidXml.

@Test
public void mergeWhenOneTransferIsInvalidXml() throws Exception {
    String path = "jquery/package.json";
    HostedRepository h1 = new HostedRepository("test-hosted-1");
    HostedRepository h2 = new HostedRepository("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("test-group", h1.getKey(), h2.getKey());
    List<Transfer> sources = Arrays.asList(t1, t2);
    byte[] output = new PackageMetadataMerger(Collections.emptyList()).merge(sources, g, path);
    IndyObjectMapper mapper = new IndyObjectMapper(true);
    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(), 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) IndyObjectMapper(org.commonjava.indy.model.core.io.IndyObjectMapper) 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 3 with VersionMetadata

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

the class PackageMetadataMergerTest method mergeProviderWithSameVersionMetadata.

@Test
public void mergeProviderWithSameVersionMetadata() throws Exception {
    String path = "jquery/package.json";
    HostedRepository h1 = new HostedRepository("test-hosted-1");
    Transfer t1 = cacheProvider.getTransfer(new ConcreteResource(LocationUtils.toLocation(h1), path));
    initTestData(t1, VERSION_META + "package-1.json");
    Group g = new Group("test-group", h1.getKey());
    List<Transfer> sources = Arrays.asList(t1);
    PackageMetadata provided = new PackageMetadata("jquery");
    VersionMetadata versionMetadata = new VersionMetadata("jquery", "1.5.1");
    versionMetadata.setUrl("jquery.new.com");
    TestPackageMetadataProvider testProvider = new TestPackageMetadataProvider(provided);
    byte[] output = new PackageMetadataMerger(Collections.singletonList(testProvider)).merge(sources, g, path);
    IndyObjectMapper mapper = new IndyObjectMapper(true);
    PackageMetadata merged = mapper.readValue(IOUtils.toString(new ByteArrayInputStream(output)), PackageMetadata.class);
    assertThat(merged.getVersions().get("1.5.1"), notNullValue());
    assertThat(merged.getVersions().get("1.5.1").getUrl(), equalTo("jquery.com"));
}
Also used : Group(org.commonjava.indy.model.core.Group) IndyObjectMapper(org.commonjava.indy.model.core.io.IndyObjectMapper) 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 4 with VersionMetadata

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

the class PackageMetadataMergerTest method mergeOneTransferWithProviderError.

@Test
public void mergeOneTransferWithProviderError() throws Exception {
    String path = "jquery/package.json";
    HostedRepository h1 = new HostedRepository("test-hosted-1");
    Transfer t1 = cacheProvider.getTransfer(new ConcreteResource(LocationUtils.toLocation(h1), path));
    initTestData(t1, VERSION_META + "package-1.json");
    Group g = new Group("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)).merge(sources, g, path);
    IndyObjectMapper mapper = new IndyObjectMapper(true);
    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(), 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) IndyObjectMapper(org.commonjava.indy.model.core.io.IndyObjectMapper) 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)

Example 5 with VersionMetadata

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

the class PackageMetadataMergerTest method mergeWhenOneTransferIsMissing.

@Test
public void mergeWhenOneTransferIsMissing() throws Exception {
    String path = "jquery/package.json";
    HostedRepository h1 = new HostedRepository("test-hosted-1");
    HostedRepository h2 = new HostedRepository("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));
    Group g = new Group("test-group", h1.getKey(), h2.getKey());
    List<Transfer> sources = Arrays.asList(t1, t2);
    byte[] output = new PackageMetadataMerger(Collections.emptyList()).merge(sources, g, path);
    IndyObjectMapper mapper = new IndyObjectMapper(true);
    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(), 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) IndyObjectMapper(org.commonjava.indy.model.core.io.IndyObjectMapper) 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)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)5 Group (org.commonjava.indy.model.core.Group)5 HostedRepository (org.commonjava.indy.model.core.HostedRepository)5 IndyObjectMapper (org.commonjava.indy.model.core.io.IndyObjectMapper)5 PackageMetadata (org.commonjava.indy.pkg.npm.model.PackageMetadata)5 VersionMetadata (org.commonjava.indy.pkg.npm.model.VersionMetadata)5 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)5 Transfer (org.commonjava.maven.galley.model.Transfer)5 Test (org.junit.Test)5 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)1 UserInfo (org.commonjava.indy.pkg.npm.model.UserInfo)1