Search in sources :

Example 21 with PackageMetadata

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

the class NPMMetadataRevisitTimeoutTest method test.

@Test
@Category(TimingDependent.class)
public void test() throws Exception {
    IndyObjectMapper mapper = new IndyObjectMapper(true);
    final PackageMetadata src = new PackageMetadata();
    final DistTag dts = new DistTag();
    dts.setBeta("1");
    src.setDistTags(dts);
    server.expect("GET", server.formatUrl(REPO, PATH), (req, resp) -> {
        resp.setStatus(200);
        mapper.writeValue(resp.getWriter(), src);
        resp.getWriter().flush();
    });
    final int METADATA_TIMEOUT_SECOND = 3;
    final int TIMEOUT_WAIT_MILLI_S = 1000;
    final RemoteRepository repo = new RemoteRepository(NPM_PKG_KEY, REPO, server.formatUrl(REPO));
    logger.info("\n\nCreate repo: {}\n\n", repo);
    repo.setMetadataTimeoutSeconds(METADATA_TIMEOUT_SECOND);
    client.stores().create(repo, "adding npm remote repo", RemoteRepository.class);
    logger.info("\n\nFirst retrieval\n\n");
    // First retrieval
    verifyMetadataBetaTag("1", repo);
    dts.setBeta("2");
    // wait for repo metadata timeout
    Thread.sleep(TIMEOUT_WAIT_MILLI_S * 2);
    logger.info("\n\nSecond retrieval: try to reset timeout\n\n");
    // Second retrieval when not timeout for first
    verifyMetadataBetaTag("1", repo);
    // wait for repo metadata timeout
    Thread.sleep(TIMEOUT_WAIT_MILLI_S * 2);
    assertThat("Metadata not cleaned up!", client.content().exists(repo.getKey(), PATH + "/package.json", true), equalTo(false));
    logger.info("\n\nThird retrieval: check if timeout happened\n\n");
    // Third retrieval
    verifyMetadataBetaTag("2", repo);
}
Also used : IndyObjectMapper(org.commonjava.indy.model.core.io.IndyObjectMapper) PackageMetadata(org.commonjava.indy.pkg.npm.model.PackageMetadata) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) DistTag(org.commonjava.indy.pkg.npm.model.DistTag) Category(org.junit.experimental.categories.Category) Test(org.junit.Test) AbstractContentManagementTest(org.commonjava.indy.ftest.core.AbstractContentManagementTest)

Example 22 with PackageMetadata

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

Example 23 with PackageMetadata

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

the class NPMTwoTimesUploadsGeneratedContentsTest 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.6.2.json");
    final String path = "jquery";
    final String firstTarballPath = "jquery/-/jquery-1.5.1.tgz";
    final String firstVersionPath = "jquery/1.5.1";
    final String secondTarballPath = "jquery/-/jquery-1.6.2.tgz";
    final String secondVersionPath = "jquery/1.6.2";
    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);
    final InputStream is = client.content().get(storeKey, path);
    IndyObjectMapper mapper = new IndyObjectMapper(true);
    PackageMetadata packageMetadata = mapper.readValue(is, PackageMetadata.class);
    Map<String, VersionMetadata> versions = packageMetadata.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"));
    assertThat(client.content().exists(storeKey, firstTarballPath), equalTo(true));
    assertThat(client.content().exists(storeKey, firstVersionPath), equalTo(true));
    assertThat(client.content().exists(storeKey, secondTarballPath), equalTo(true));
    assertThat(client.content().exists(storeKey, secondVersionPath), equalTo(true));
    content1.close();
    content2.close();
}
Also used : IndyObjectMapper(org.commonjava.indy.model.core.io.IndyObjectMapper) 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 24 with PackageMetadata

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

the class NPMVersionMetaGenerationWhenUploadTest method test.

@Test
public void test() throws Exception {
    final String content = IOUtils.toString(Thread.currentThread().getContextClassLoader().getResourceAsStream("package-1.5.1.json"));
    final String path = "jquery";
    final String versionPath = "jquery/1.5.1";
    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();
    assertThat(client.content().exists(storeKey, path), equalTo(false));
    client.content().store(storeKey, path, IOUtils.toInputStream(content));
    IndyObjectMapper mapper = new IndyObjectMapper(true);
    PackageMetadata packageMetadata = mapper.readValue(content, PackageMetadata.class);
    VersionMetadata versionMetadata = packageMetadata.getVersions().get("1.5.1");
    String name = versionMetadata.getName();
    String desc = versionMetadata.getDescription();
    String version = versionMetadata.getVersion();
    InputStream stream = client.content().get(storeKey, versionPath);
    VersionMetadata actualVersionMeta = mapper.readValue(IOUtils.toString(stream), VersionMetadata.class);
    String actualName = actualVersionMeta.getName();
    String actualDesc = actualVersionMeta.getDescription();
    String actualVersion = actualVersionMeta.getVersion();
    assertEquals(name, actualName);
    assertEquals(desc, actualDesc);
    assertEquals(version, actualVersion);
    stream.close();
}
Also used : IndyObjectMapper(org.commonjava.indy.model.core.io.IndyObjectMapper) VersionMetadata(org.commonjava.indy.pkg.npm.model.VersionMetadata) InputStream(java.io.InputStream) 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)

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