Search in sources :

Example 46 with IndyObjectMapper

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"));
}
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 47 with IndyObjectMapper

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));
}
Also used : IndyObjectMapper(org.commonjava.indy.model.core.io.IndyObjectMapper) Test(org.junit.Test)

Example 48 with IndyObjectMapper

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);
}
Also used : IndyObjectMapper(org.commonjava.indy.model.core.io.IndyObjectMapper) Test(org.junit.Test)

Example 49 with IndyObjectMapper

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()));
}
Also used : IndyObjectMapper(org.commonjava.indy.model.core.io.IndyObjectMapper) Test(org.junit.Test)

Example 50 with IndyObjectMapper

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);
}
Also used : StoreEventDispatcher(org.commonjava.indy.data.StoreEventDispatcher) IndyObjectMapper(org.commonjava.indy.model.core.io.IndyObjectMapper) DataFileEventManager(org.commonjava.indy.subsys.datafile.change.DataFileEventManager) DataFileManager(org.commonjava.indy.subsys.datafile.DataFileManager) StoreEventDispatcherStub(org.commonjava.indy.core.data.testutil.StoreEventDispatcherStub) DefaultIndyConfiguration(org.commonjava.indy.conf.DefaultIndyConfiguration) Before(org.junit.Before)

Aggregations

IndyObjectMapper (org.commonjava.indy.model.core.io.IndyObjectMapper)59 Test (org.junit.Test)41 StoreKey (org.commonjava.indy.model.core.StoreKey)16 HostedRepository (org.commonjava.indy.model.core.HostedRepository)10 Group (org.commonjava.indy.model.core.Group)9 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)8 PackageMetadata (org.commonjava.indy.pkg.npm.model.PackageMetadata)8 Transfer (org.commonjava.maven.galley.model.Transfer)8 ByteArrayInputStream (java.io.ByteArrayInputStream)7 MemoryStoreDataManager (org.commonjava.indy.mem.data.MemoryStoreDataManager)7 DataFileManager (org.commonjava.indy.subsys.datafile.DataFileManager)6 DataFileEventManager (org.commonjava.indy.subsys.datafile.change.DataFileEventManager)6 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)6 Before (org.junit.Before)6 VersionMetadata (org.commonjava.indy.pkg.npm.model.VersionMetadata)5 MemoryNotFoundCache (org.commonjava.maven.galley.nfc.MemoryNotFoundCache)5 ChangeSummary (org.commonjava.indy.audit.ChangeSummary)4 Indy (org.commonjava.indy.client.core.Indy)4 DirectContentAccess (org.commonjava.indy.content.DirectContentAccess)4 DefaultContentDigester (org.commonjava.indy.core.content.DefaultContentDigester)4