Search in sources :

Example 31 with IndyObjectMapper

use of org.commonjava.indy.model.core.io.IndyObjectMapper in project indy by Commonjava.

the class ValidationCatalogDTOTest method jsonRoundTrip.

@Test
public void jsonRoundTrip() throws IOException {
    ValidationRuleDTO firstRule = readRule("no-snapshots.groovy");
    ValidationRuleDTO secondRule = readRule("parsable-pom.groovy");
    Map<String, ValidationRuleDTO> rules = Stream.of(firstRule, secondRule).collect(Collectors.toMap(ValidationRuleDTO::getName, Function.identity()));
    String rsName = "test";
    ValidationRuleSet rs = new ValidationRuleSet(rsName, "remote:.*", Arrays.asList(firstRule.getName(), secondRule.getName()), Collections.emptyMap());
    ValidationCatalogDTO in = new ValidationCatalogDTO(true, rules, Collections.singletonMap(rsName, rs));
    IndyObjectMapper mapper = new IndyObjectMapper(true);
    String json = mapper.writeValueAsString(in);
    ValidationCatalogDTO out = mapper.readValue(json, ValidationCatalogDTO.class);
    assertThat(out, notNullValue());
    assertThat(out.isEnabled(), equalTo(in.isEnabled()));
    Map<String, ValidationRuleDTO> outRules = out.getRules();
    assertThat(rules, notNullValue());
    assertThat(rules.size(), equalTo(2));
    assertThat(rules.get(firstRule.getName()), equalTo(firstRule));
    assertThat(rules.get(secondRule.getName()), equalTo(secondRule));
    Map<String, ValidationRuleSet> outRuleSets = out.getRuleSets();
    assertThat(outRuleSets, notNullValue());
    assertThat(outRuleSets.size(), equalTo(1));
    assertThat(outRuleSets.get(rsName), equalTo(rs));
}
Also used : IndyObjectMapper(org.commonjava.indy.model.core.io.IndyObjectMapper) Test(org.junit.Test)

Example 32 with IndyObjectMapper

use of org.commonjava.indy.model.core.io.IndyObjectMapper in project indy by Commonjava.

the class NotFoundCacheSectionDTOTest method jsonRoundTrip.

@Test
public void jsonRoundTrip() throws IOException {
    String firstPath = "/path/to/first/file.pom";
    String secondPath = "/path/to/another/path.pom";
    NotFoundCacheSectionDTO in = new NotFoundCacheSectionDTO(new StoreKey(StoreType.remote, "test"), Arrays.asList(firstPath, secondPath));
    IndyObjectMapper mapper = new IndyObjectMapper(true);
    String json = mapper.writeValueAsString(in);
    NotFoundCacheSectionDTO out = mapper.readValue(json, NotFoundCacheSectionDTO.class);
    assertThat(out, notNullValue());
    assertThat(out.getKey(), equalTo(in.getKey()));
    Set<String> paths = out.getPaths();
    assertThat(paths, notNullValue());
    assertThat(paths.size(), equalTo(2));
    assertThat(paths.contains(firstPath), equalTo(true));
    assertThat(paths.contains(secondPath), equalTo(true));
}
Also used : IndyObjectMapper(org.commonjava.indy.model.core.io.IndyObjectMapper) StoreKey(org.commonjava.indy.model.core.StoreKey) Test(org.junit.Test)

Example 33 with IndyObjectMapper

use of org.commonjava.indy.model.core.io.IndyObjectMapper in project indy by Commonjava.

the class ReplicationDTOTest method serializeBasicReplicationRequest.

@Test
public void serializeBasicReplicationRequest() throws Exception {
    final ReplicationDTO dto = new ReplicationDTO();
    dto.setApiUrl("http://foo.com/api/1.0");
    dto.setActions(Collections.singletonList(new ReplicationAction(ActionType.PROXY)));
    final String json = new IndyObjectMapper(true).writeValueAsString(dto);
    System.out.println(json);
}
Also used : IndyObjectMapper(org.commonjava.indy.model.core.io.IndyObjectMapper) Test(org.junit.Test)

Example 34 with IndyObjectMapper

use of org.commonjava.indy.model.core.io.IndyObjectMapper in project indy by Commonjava.

the class StoreListingDTOTest method deserializeStoreListingDTO.

@Test
public void deserializeStoreListingDTO() throws Exception {
    /* @formatter:off */
    final String json = "{\n" + "  \"items\" : [ {\n" + "    \"type\": \"hosted\",\n" + "    \"key\" : \"maven:hosted:eSPeEZPG\",\n" + "    \"snapshotTimeoutSeconds\" : 0,\n" + "    \"name\" : \"eSPeEZPG\",\n" + "    \"doctype\" : \"hosted\",\n" + "    \"allow_snapshots\" : false,\n" + "    \"allow_releases\" : true\n" + "  }, {\n" + "    \"type\": \"hosted\",\n" + "    \"key\" : \"maven:hosted:qI3Cq2OZ\",\n" + "    \"snapshotTimeoutSeconds\" : 0,\n" + "    \"name\" : \"qI3Cq2OZ\",\n" + "    \"doctype\" : \"hosted\",\n" + "    \"allow_snapshots\" : false,\n" + "    \"allow_releases\" : true\n" + "  }, {\n" + "    \"type\": \"hosted\",\n" + "    \"key\" : \"maven:hosted:local-deployments\",\n" + "    \"snapshotTimeoutSeconds\" : 86400,\n" + "    \"name\" : \"local-deployments\",\n" + "    \"doctype\" : \"hosted\",\n" + "    \"allow_snapshots\" : true,\n" + "    \"allow_releases\" : true\n" + "  }, {\n" + "    \"type\": \"hosted\",\n" + "    \"key\" : \"maven:hosted:AFhJnQLW\",\n" + "    \"snapshotTimeoutSeconds\" : 0,\n" + "    \"name\" : \"AFhJnQLW\",\n" + "    \"doctype\" : \"hosted\",\n" + "    \"allow_snapshots\" : false,\n" + "    \"allow_releases\" : true\n" + "  } ]\n" + "}";
    /* @formatter:on */
    final StoreListingDTO<HostedRepository> value = new IndyObjectMapper(true).readValue(json, new TypeReference<StoreListingDTO<HostedRepository>>() {
    });
    final List<HostedRepository> items = value.getItems();
    assertThat(items.size(), equalTo(4));
    int i = 0;
    assertThat(items.get(i++).getName(), equalTo("eSPeEZPG"));
    assertThat(items.get(i++).getName(), equalTo("qI3Cq2OZ"));
    assertThat(items.get(i++).getName(), equalTo("local-deployments"));
    assertThat(items.get(i++).getName(), equalTo("AFhJnQLW"));
}
Also used : IndyObjectMapper(org.commonjava.indy.model.core.io.IndyObjectMapper) HostedRepository(org.commonjava.indy.model.core.HostedRepository) Test(org.junit.Test)

Example 35 with IndyObjectMapper

use of org.commonjava.indy.model.core.io.IndyObjectMapper in project indy by Commonjava.

the class DirectoryListingEntryDTOTest method jsonRoundTrip.

@Test
public void jsonRoundTrip() throws IOException {
    DirectoryListingEntryDTO in = new DirectoryListingEntryDTO(new StoreKey(StoreType.remote, "test"), "/this/is/a/path.pom");
    IndyObjectMapper mapper = new IndyObjectMapper(true);
    String json = mapper.writeValueAsString(in);
    DirectoryListingEntryDTO out = mapper.readValue(json, DirectoryListingEntryDTO.class);
    assertThat(out, notNullValue());
    assertThat(out.getKey(), equalTo(in.getKey()));
    assertThat(out.getPath(), equalTo(in.getPath()));
}
Also used : IndyObjectMapper(org.commonjava.indy.model.core.io.IndyObjectMapper) StoreKey(org.commonjava.indy.model.core.StoreKey) Test(org.junit.Test)

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