use of org.osgi.util.converter.TypeReference in project felix by apache.
the class SchemaTest method testNullValues.
@Test
public void testNullValues() {
Schema s = schematizer.schematize("MyDTO", new TypeReference<MyDTO3<MyEmbeddedDTO2<String>>>() {
}).get("MyDTO");
assertNotNull(s);
MyEmbeddedDTO2<String> embedded1 = new MyEmbeddedDTO2<>();
MyEmbeddedDTO2<String> embedded2 = new MyEmbeddedDTO2<>();
MyEmbeddedDTO2<String> embedded3 = new MyEmbeddedDTO2<>();
MyDTO3<MyEmbeddedDTO2<String>> dto = new MyDTO3<>();
dto.ping = "lalala";
dto.pong = Long.MIN_VALUE;
dto.count = MyDTO3.Count.ONE;
dto.embedded = new ArrayList<>();
dto.embedded.add(embedded1);
dto.embedded.add(embedded2);
dto.embedded.add(embedded3);
assertEquals("lalala", s.valuesAt("/ping", dto).iterator().next());
assertEquals(Long.MIN_VALUE, s.valuesAt("/pong", dto).iterator().next());
assertEquals(MyDTO3.Count.ONE, s.valuesAt("/count", dto).iterator().next());
assertNotNull(s.valuesAt("/embedded", dto));
assertListEquals(Arrays.asList(new String[] { null, null, null }), s.valuesAt("/embedded/value", dto));
}
use of org.osgi.util.converter.TypeReference in project felix by apache.
the class SchemaTest method testValues.
@Test
public void testValues() {
final Schema s = schematizer.schematize("MyDTO", new TypeReference<MyDTO3<MyEmbeddedDTO2<String>>>() {
}).get("MyDTO");
assertNotNull(s);
MyEmbeddedDTO2<String> embedded1 = new MyEmbeddedDTO2<>();
embedded1.value = "value1";
MyEmbeddedDTO2<String> embedded2 = new MyEmbeddedDTO2<>();
embedded2.value = "value2";
MyEmbeddedDTO2<String> embedded3 = new MyEmbeddedDTO2<>();
embedded3.value = "value3";
MyDTO3<MyEmbeddedDTO2<String>> dto = new MyDTO3<>();
dto.ping = "lalala";
dto.pong = Long.MIN_VALUE;
dto.count = MyDTO3.Count.ONE;
dto.embedded = new ArrayList<>();
dto.embedded.add(embedded1);
dto.embedded.add(embedded2);
dto.embedded.add(embedded3);
assertEquals("lalala", s.valuesAt("/ping", dto).iterator().next());
assertEquals(Long.MIN_VALUE, s.valuesAt("/pong", dto).iterator().next());
assertEquals(MyDTO3.Count.ONE, s.valuesAt("/count", dto).iterator().next());
assertNotNull(s.valuesAt("/embedded", dto));
Object embeddedList = s.valuesAt("/embedded", dto).iterator().next();
assertNotNull(embeddedList);
assertTrue(embeddedList instanceof List);
assertFalse(((List<?>) embeddedList).isEmpty());
Object embeddedObject = ((List<?>) embeddedList).get(0);
assertTrue(embeddedObject instanceof MyEmbeddedDTO2);
assertListEquals(Arrays.asList(new String[] { "value1", "value2", "value3" }), s.valuesAt("/embedded/value", dto));
}
use of org.osgi.util.converter.TypeReference 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.osgi.util.converter.TypeReference 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.osgi.util.converter.TypeReference 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());
}
Aggregations