Search in sources :

Example 11 with Schema

use of org.apache.felix.schematizer.Schema in project felix by apache.

the class SchematizerServiceTest method testSchematizeDTO.

@Test
public void testSchematizeDTO() {
    Schema s = schematizer.schematize("MyDTO", new TypeReference<MyDTO>() {
    }).get("MyDTO");
    assertNotNull(s);
    Node root = s.rootNode();
    assertNodeEquals("", "/", false, MyDTO.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, 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);
}
Also used : Schema(org.apache.felix.schematizer.Schema) Node(org.apache.felix.schematizer.Node) TypeReference(org.osgi.util.converter.TypeReference) Test(org.junit.Test)

Example 12 with Schema

use of org.apache.felix.schematizer.Schema in project felix by apache.

the class SchematizerServiceTest method testGetParentNode.

@Test
public void testGetParentNode() {
    Schema s = schematizer.schematize("MyDTO", new TypeReference<MyDTO>() {
    }).get("MyDTO");
    assertNotNull(s);
    Node embeddedNode = s.nodeAtPath("/embedded/marco");
    assertTrue(!"ERROR".equals(embeddedNode.name()));
    Node parentNode = s.parentOf(embeddedNode);
    assertTrue(!"ERROR".equals(parentNode.name()));
    Node grandparentNode = s.parentOf(parentNode);
    assertTrue(!"ERROR".equals(grandparentNode.name()));
    assertEquals("/", grandparentNode.absolutePath());
}
Also used : Schema(org.apache.felix.schematizer.Schema) Node(org.apache.felix.schematizer.Node) TypeReference(org.osgi.util.converter.TypeReference) Test(org.junit.Test)

Aggregations

Schema (org.apache.felix.schematizer.Schema)12 TypeReference (org.osgi.util.converter.TypeReference)12 Test (org.junit.Test)11 Node (org.apache.felix.schematizer.Node)6 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Field (java.lang.reflect.Field)1 Type (java.lang.reflect.Type)1 Collection (java.util.Collection)1 Map (java.util.Map)1 Util.asDTO (org.apache.felix.schematizer.impl.Util.asDTO)1 Util.rawClassOf (org.apache.felix.schematizer.impl.Util.rawClassOf)1 Ignore (org.junit.Ignore)1 DTO (org.osgi.dto.DTO)1 ConversionException (org.osgi.util.converter.ConversionException)1 Converter (org.osgi.util.converter.Converter)1 ConverterFunction (org.osgi.util.converter.ConverterFunction)1 Converters (org.osgi.util.converter.Converters)1 TargetRule (org.osgi.util.converter.TargetRule)1