Search in sources :

Example 16 with PackageMetadata

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

the class PackageMetadataMergerTest method mergeProviderWithSameVersionMetadata.

@Test
public void mergeProviderWithSameVersionMetadata() 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);
    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), mapper).merge(sources, g, path);
    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) 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 17 with PackageMetadata

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

the class PackageMetadataMergerTest method mergeProviderWithDistTagVersionSorted.

@Test
public void mergeProviderWithDistTagVersionSorted() 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-dist-tag-version.json");
    Group g = new Group(NPM_PKG_KEY, "test-group", h1.getKey());
    List<Transfer> sources = Arrays.asList(t1);
    PackageMetadata provided = new PackageMetadata("jquery");
    DistTag distTag = new DistTag();
    distTag.putTag(DistTag.LATEST, "3.2.3-rc.3");
    distTag.putTag(DistTag.STABLE, "2.0");
    distTag.putTag(DistTag.BETA, "3.2.1-beta.2");
    distTag.putTag(DistTag.DEV, "3.2.3-alpha");
    provided.setDistTags(distTag);
    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);
    assertThat(merged.getDistTags().getLatest(), equalTo("3.2.3-rc.3"));
    assertThat(merged.getDistTags().getStable(), equalTo("3.2.1"));
    assertThat(merged.getDistTags().getBeta(), equalTo("3.2.1-beta.2"));
    assertThat(merged.getDistTags().getDev(), equalTo("3.2.3-alpha"));
}
Also used : Group(org.commonjava.indy.model.core.Group) 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) DistTag(org.commonjava.indy.pkg.npm.model.DistTag) HostedRepository(org.commonjava.indy.model.core.HostedRepository) Test(org.junit.Test)

Example 18 with PackageMetadata

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

the class PackageMetadataMergerTest method mergeWhenOneTransferIsMissing.

@Test
public void mergeWhenOneTransferIsMissing() 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));
    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 19 with PackageMetadata

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

the class NPMHostedRetrieveFileTest method test.

@Test
public void test() throws Exception {
    final String packageContent = "{\"name\": \"jquery\",\n" + "\"description\": \"JavaScript library for DOM operations\",\n" + "\"license\": \"MIT\"}";
    final String versionContent = "{\"name\": \"jquery\",\n" + "\"url\": \"jquery.com\",\n" + "\"version\": \"2.1.0\"}";
    byte[] tgz = new byte[32];
    new Random().nextBytes(tgz);
    final String packagePath = "jquery";
    final String versionPath = "jquery/2.1.0";
    final String tarballPath = "jquery/-/jquery-2.1.0.tgz";
    final HostedRepository hostedRepository = new HostedRepository(NPM_PKG_KEY, STORE);
    final StoreKey storeKey = hostedRepository.getKey();
    client.stores().create(hostedRepository, "adding npm hosted repo", HostedRepository.class);
    client.content().store(storeKey, packagePath, new ByteArrayInputStream(packageContent.getBytes()));
    client.content().store(storeKey, versionPath, new ByteArrayInputStream(versionContent.getBytes()));
    client.content().store(storeKey, tarballPath, new ByteArrayInputStream(tgz));
    final InputStream packageStream = client.content().get(storeKey, packagePath);
    final InputStream tarballStream = client.content().get(storeKey, tarballPath);
    assertThat(packageStream, notNullValue());
    assertThat(tarballStream, notNullValue());
    IndyObjectMapper mapper = new IndyObjectMapper(true);
    PackageMetadata pkgMetadata = mapper.readValue(packageStream, PackageMetadata.class);
    VersionMetadata versionMetadata = pkgMetadata.getVersions().get("2.1.0");
    assertNotNull(versionMetadata);
    packageStream.close();
    tarballStream.close();
}
Also used : Random(java.util.Random) ByteArrayInputStream(java.io.ByteArrayInputStream) IndyObjectMapper(org.commonjava.indy.model.core.io.IndyObjectMapper) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) VersionMetadata(org.commonjava.indy.pkg.npm.model.VersionMetadata) PackageMetadata(org.commonjava.indy.pkg.npm.model.PackageMetadata) StoreKey(org.commonjava.indy.model.core.StoreKey) HostedRepository(org.commonjava.indy.model.core.HostedRepository) Test(org.junit.Test) AbstractContentManagementTest(org.commonjava.indy.ftest.core.AbstractContentManagementTest)

Example 20 with PackageMetadata

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

the class NPMMetadataRevisitTimeoutTest method verifyMetadataBetaTag.

private void verifyMetadataBetaTag(final String betaTag, 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)

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