use of org.apache.felix.schematizer.Node in project felix by apache.
the class SchematizerServiceTest method testSchematizeDTOWithAnnotatedColletion.
@Test
public void testSchematizeDTOWithAnnotatedColletion() {
Schema s = schematizer.schematize("MyDTO4", new TypeReference<MyDTO4>() {
}).get("MyDTO4");
assertNotNull(s);
Node root = s.rootNode();
assertNodeEquals("", "/", false, MyDTO4.class, false, root);
assertEquals(4, root.children().size());
Node pingNode = root.children().get("/ping");
assertNodeEquals("ping", "/ping", false, String.class, true, pingNode);
Node pongNode = root.children().get("/pong");
assertNodeEquals("pong", "/pong", false, Long.class, true, pongNode);
Node countNode = root.children().get("/count");
assertNodeEquals("count", "/count", false, MyDTO4.Count.class, true, countNode);
Node embeddedNode = root.children().get("/embedded");
assertEquals(3, embeddedNode.children().size());
assertNodeEquals("embedded", "/embedded", true, MyEmbeddedDTO.class, true, embeddedNode);
Node marcoNode = embeddedNode.children().get("/marco");
assertNodeEquals("marco", "/embedded/marco", false, String.class, true, marcoNode);
Node poloNode = embeddedNode.children().get("/polo");
assertNodeEquals("polo", "/embedded/polo", false, Long.class, true, poloNode);
Node alphaNode = embeddedNode.children().get("/alpha");
assertNodeEquals("alpha", "/embedded/alpha", false, MyEmbeddedDTO.Alpha.class, true, alphaNode);
Node sRoot = s.nodeAtPath("/");
assertNodeEquals("", "/", false, MyDTO4.class, false, sRoot);
Node sPingNode = s.nodeAtPath("/ping");
assertNodeEquals("ping", "/ping", false, String.class, true, sPingNode);
Node sPongNode = s.nodeAtPath("/pong");
assertNodeEquals("pong", "/pong", false, Long.class, true, sPongNode);
Node sCountNode = s.nodeAtPath("/count");
assertNodeEquals("count", "/count", false, MyDTO4.Count.class, true, sCountNode);
Node sEmbeddedNode = s.nodeAtPath("/embedded");
assertNodeEquals("embedded", "/embedded", true, MyEmbeddedDTO.class, true, sEmbeddedNode);
Node sMarcoNode = s.nodeAtPath("/embedded/marco");
assertNodeEquals("marco", "/embedded/marco", false, String.class, true, sMarcoNode);
Node sPoloNode = s.nodeAtPath("/embedded/polo");
assertNodeEquals("polo", "/embedded/polo", false, Long.class, true, sPoloNode);
Node sAlphaNode = s.nodeAtPath("/embedded/alpha");
assertNodeEquals("alpha", "/embedded/alpha", false, MyEmbeddedDTO.Alpha.class, true, sAlphaNode);
}
use of org.apache.felix.schematizer.Node in project felix by apache.
the class SchematizerServiceTest method testSchematizeDTOWithColletion.
@Test
public void testSchematizeDTOWithColletion() {
Schema s = schematizer.type("MyDTO", "/embedded", new TypeReference<MyEmbeddedDTO2<String>>() {
}).type("MyDTO", "/embedded/value", String.class).schematize("MyDTO", new TypeReference<MyDTO3<MyEmbeddedDTO2<String>>>() {
}).get("MyDTO");
assertNotNull(s);
Node root = s.rootNode();
assertNodeEquals("", "/", false, new TypeReference<MyDTO3<MyEmbeddedDTO2<String>>>() {
}.getType(), false, root);
assertEquals(4, root.children().size());
Node pingNode = root.children().get("/ping");
assertNodeEquals("ping", "/ping", false, String.class, true, pingNode);
Node pongNode = root.children().get("/pong");
assertNodeEquals("pong", "/pong", false, Long.class, true, pongNode);
Node countNode = root.children().get("/count");
assertNodeEquals("count", "/count", false, MyDTO3.Count.class, true, countNode);
Node embeddedNode = root.children().get("/embedded");
assertEquals(1, embeddedNode.children().size());
assertNodeEquals("embedded", "/embedded", true, new TypeReference<MyEmbeddedDTO2<String>>() {
}.getType(), true, embeddedNode);
Node valueNode = embeddedNode.children().get("/value");
assertNodeEquals("value", "/embedded/value", false, String.class, true, valueNode);
Node sRoot = s.nodeAtPath("/");
assertNodeEquals("", "/", false, new TypeReference<MyDTO3<MyEmbeddedDTO2<String>>>() {
}.getType(), false, sRoot);
Node sPingNode = s.nodeAtPath("/ping");
assertNodeEquals("ping", "/ping", false, String.class, true, sPingNode);
Node sPongNode = s.nodeAtPath("/pong");
assertNodeEquals("pong", "/pong", false, Long.class, true, sPongNode);
Node sCountNode = s.nodeAtPath("/count");
assertNodeEquals("count", "/count", false, MyDTO3.Count.class, true, sCountNode);
Node sEmbeddedNode = s.nodeAtPath("/embedded");
assertNodeEquals("embedded", "/embedded", true, new TypeReference<MyEmbeddedDTO2<String>>() {
}.getType(), true, sEmbeddedNode);
Node sValueNode = s.nodeAtPath("/embedded/value");
assertNodeEquals("value", "/embedded/value", false, String.class, true, sValueNode);
}
use of org.apache.felix.schematizer.Node in project felix by apache.
the class SchematizerServiceTest method testSchema.
@SuppressWarnings("unused")
private void testSchema(Schema s) {
// Assume that the map is serialized, then deserialized "as is".
assertNotNull(s);
Node root = s.rootNode();
assertEquals(4, root.children().size());
assertNodeEquals("", "/", false, MyDTO.class, false, root);
Node pingNode = root.children().get("/ping");
assertNodeEquals("ping", "/ping", false, String.class, true, pingNode);
Node pongNode = root.children().get("/pong");
assertNodeEquals("pong", "/pong", false, Long.class, true, pongNode);
Node countNode = root.children().get("/count");
assertNodeEquals("count", "/count", false, MyDTO.Count.class, true, countNode);
Node embeddedNode = root.children().get("/embedded");
assertEquals(3, embeddedNode.children().size());
assertNodeEquals("embedded", "/embedded", false, MyEmbeddedDTO.class, true, embeddedNode);
Node marcoNode = embeddedNode.children().get("/marco");
assertNodeEquals("marco", "/embedded/marco", false, String.class, true, marcoNode);
Node poloNode = embeddedNode.children().get("/polo");
assertNodeEquals("polo", "/embedded/polo", false, Long.class, true, poloNode);
Node alphaNode = embeddedNode.children().get("/alpha");
assertNodeEquals("alpha", "/embedded/alpha", false, MyEmbeddedDTO.Alpha.class, true, alphaNode);
Node sRoot = s.nodeAtPath("/");
assertNodeEquals("", "/", false, MyDTO.class, false, sRoot);
Node sPingNode = s.nodeAtPath("/ping");
assertNodeEquals("ping", "/ping", false, String.class, true, sPingNode);
Node sPongNode = s.nodeAtPath("/pong");
assertNodeEquals("pong", "/pong", false, Long.class, true, sPongNode);
Node sCountNode = s.nodeAtPath("/count");
assertNodeEquals("count", "/count", false, MyDTO.Count.class, true, sCountNode);
Node sEmbeddedNode = s.nodeAtPath("/embedded");
assertNodeEquals("embedded", "/embedded", false, MyEmbeddedDTO.class, true, sEmbeddedNode);
Node sMarcoNode = s.nodeAtPath("/embedded/marco");
assertNodeEquals("marco", "/embedded/marco", false, String.class, true, sMarcoNode);
Node sPoloNode = s.nodeAtPath("/embedded/polo");
assertNodeEquals("polo", "/embedded/polo", false, Long.class, true, sPoloNode);
Node sAlphaNode = s.nodeAtPath("/embedded/alpha");
assertNodeEquals("alpha", "/embedded/alpha", false, MyEmbeddedDTO.Alpha.class, true, sAlphaNode);
}
use of org.apache.felix.schematizer.Node in project felix by apache.
the class SchemaBasedConverter method convertMap.
@SuppressWarnings("unchecked")
private T convertMap(Map<?, ?> map, Schema s, String contextPath) {
Node node = s.nodeAtPath(contextPath);
Class<?> cls = Util.rawClassOf(node.type());
if (!asDTO(cls))
return handleInvalid();
if (!contextPath.endsWith("/"))
contextPath = contextPath + "/";
return (T) convertToDTO((Class<? extends DTO>) cls, map, s, contextPath);
}
use of org.apache.felix.schematizer.Node in project felix by apache.
the class SchemaImpl method convertToType.
@SuppressWarnings("rawtypes")
private Object convertToType(String path, Map map) {
if (!hasNodeAtPath(path))
return map;
Node node = nodeAtPath(path);
Object result = Converters.standardConverter().convert(map).targetAsDTO().to(node.type());
return result;
}
Aggregations