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