use of org.apache.felix.schematizer.Schema in project felix by apache.
the class SchemaTest method testEmbeddedValues.
@Test
public void testEmbeddedValues() {
Schema s = schematizer.schematize("MyDTO", new TypeReference<MyDTO>() {
}).get("MyDTO");
assertNotNull(s);
MyEmbeddedDTO embedded = new MyEmbeddedDTO();
embedded.alpha = Alpha.A;
embedded.marco = "mmmm";
embedded.polo = 66;
MyDTO dto = new MyDTO();
dto.ping = "lalala";
dto.pong = Long.MIN_VALUE;
dto.count = MyDTO.Count.ONE;
dto.embedded = embedded;
assertEquals("lalala", s.valuesAt("/ping", dto).iterator().next());
assertEquals(Long.MIN_VALUE, s.valuesAt("/pong", dto).iterator().next());
assertEquals(MyDTO.Count.ONE, s.valuesAt("/count", dto).iterator().next());
assertNotNull(s.valuesAt("/embedded", dto));
Object embeddedObject = s.valuesAt("/embedded", dto).iterator().next();
assertTrue(embeddedObject instanceof MyEmbeddedDTO);
assertEquals(Alpha.A, s.valuesAt("/embedded/alpha", dto).iterator().next());
assertEquals("mmmm", s.valuesAt("/embedded/marco", dto).iterator().next());
assertEquals(66L, s.valuesAt("/embedded/polo", dto).iterator().next());
}
use of org.apache.felix.schematizer.Schema in project felix by apache.
the class SchematizerServiceTest method testSchematizeToMap.
@Test
public void testSchematizeToMap() {
Schema s = schematizer.schematize("MyDTO", new TypeReference<MyDTO>() {
}).get("MyDTO");
Map<String, Node.DTO> map = s.toMap();
testMapValues(map);
}
use of org.apache.felix.schematizer.Schema in project felix by apache.
the class SchematizerServiceTest method testVisitor.
@Test
public void testVisitor() {
Schema s = schematizer.schematize("MyDTO", new TypeReference<MyDTO>() {
}).get("MyDTO");
StringBuilder sb = new StringBuilder();
s.visit(n -> sb.append("::").append(n.name()));
assertEquals("::::count::embedded::alpha::marco::polo::ping::pong", sb.toString());
}
use of org.apache.felix.schematizer.Schema in project felix by apache.
the class SchematizerServiceTest method testTypeRules.
@Test
public void testTypeRules() {
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 embeddedNode = s.nodeAtPath("/embedded/value");
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());
}
use of org.apache.felix.schematizer.Schema in project felix by apache.
the class SchemaBasedConverter method convertToCollection.
@SuppressWarnings({ "rawtypes", "unchecked" })
private <U, V extends Collection<U>> V convertToCollection(Class<U> targetCls, Class<V> collectionClass, Collection sourceCollection, Schema schema, String path) {
try {
V targetCollection = instantiateCollection(collectionClass);
sourceCollection.stream().map(obj -> convertCollectionItemToObject(obj, targetCls, schema, path)).forEach(u -> targetCollection.add((U) u));
return targetCollection;
} catch (Exception e) {
throw new ConversionException("Cannot create DTO " + targetCls, e);
}
}
Aggregations