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);
}
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();
}
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();
}
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();
}
Aggregations