use of org.commonjava.indy.model.core.io.IndyObjectMapper 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"));
}
use of org.commonjava.indy.model.core.io.IndyObjectMapper in project indy by Commonjava.
the class PackageMetadataTest method ignoreCouchDBJsonDataTest.
@Test
public void ignoreCouchDBJsonDataTest() throws Exception {
final IndyObjectMapper mapper = new IndyObjectMapper(true);
String json = IOUtils.toString(Thread.currentThread().getContextClassLoader().getResourceAsStream("test-package.json"));
final PackageMetadata result = mapper.readValue(json, PackageMetadata.class);
final String jsonResult = mapper.writeValueAsString(result);
assertThat(jsonResult.contains("_rev"), equalTo(false));
assertThat(jsonResult.contains("_id"), equalTo(false));
assertThat(jsonResult.contains("_attachments"), equalTo(false));
}
use of org.commonjava.indy.model.core.io.IndyObjectMapper in project indy by Commonjava.
the class PackageMetadataTest method realPackageJsonTest.
@Test
public void realPackageJsonTest() throws Exception {
final IndyObjectMapper mapper = new IndyObjectMapper(true);
String json = IOUtils.toString(Thread.currentThread().getContextClassLoader().getResourceAsStream("test-package.json"));
final PackageMetadata result = mapper.readValue(json, PackageMetadata.class);
assertThat(result.getDistTags().getBeta(), equalTo("3.2.1"));
assertTrue(result.getVersions().containsKey("1.5.1"));
assertThat(result.getVersions().get("1.5.1").getNpmVersion(), equalTo("0.3.15"));
assertThat(result.getRepository().getType(), equalTo("git"));
final String jsonResult = mapper.writeValueAsString(result);
System.out.println(jsonResult);
}
use of org.commonjava.indy.model.core.io.IndyObjectMapper in project indy by Commonjava.
the class VersionMetadataTest method roundTripJson.
@Test
public void roundTripJson() throws Exception {
final IndyObjectMapper mapper = new IndyObjectMapper(true);
final VersionMetadata metadata = new VersionMetadata("test", "1.1.0");
final String json = mapper.writeValueAsString(metadata);
System.out.println(json);
final VersionMetadata result = mapper.readValue(json, VersionMetadata.class);
assertThat(result.getName(), equalTo(metadata.getName()));
assertThat(result.getVersion(), equalTo(metadata.getVersion()));
}
use of org.commonjava.indy.model.core.io.IndyObjectMapper in project indy by Commonjava.
the class LegacyDataMigrationActionTest method setup.
@Before
public void setup() throws Exception {
dfm = new DataFileManager(temp.newFolder("stores"), new DataFileEventManager());
IndyObjectMapper mapper = new IndyObjectMapper(true);
final StoreEventDispatcher sed = new StoreEventDispatcherStub();
action = new LegacyDataMigrationAction(dfm, new DataFileStoreDataManager(dfm, mapper, sed, new DefaultIndyConfiguration()), mapper);
}
Aggregations