use of io.sundr.model.TypeDef in project sundrio by sundrio.
the class AbstractAdapterTest method testWithInnerTypes.
//
// Person
//
@Test
public void testWithInnerTypes() {
T input = getInput(Person.class);
TypeDef person = Adapters.adaptType(input, getContext());
Optional<ClassRef> personType = findClassRef(person, "type");
assertTrue(personType.isPresent());
personType.ifPresent(p -> {
assertEquals(Person.class.getName() + ".Type", p.getFullyQualifiedName());
Set<String> properties = GetDefinition.of(p).getProperties().stream().map(Property::getName).collect(Collectors.toSet());
assertTrue(properties.contains("O_MINUS"));
});
Optional<ClassRef> addresses = findClassRef(person, "addresses");
assertTrue(addresses.isPresent());
addresses.ifPresent(l -> {
ClassRef address = (ClassRef) l.getArguments().get(0);
TypeDef addressDef = GetDefinition.of(address);
Optional<ClassRef> addressType = findClassRef(addressDef, "type");
assertFalse(addressDef.getProperties().isEmpty());
assertTrue(addressType.isPresent());
addressType.ifPresent(a -> {
assertEquals(Address.class.getName() + ".Type", a.getFullyQualifiedName());
Set<String> properties = GetDefinition.of(a).getProperties().stream().map(Property::getName).collect(Collectors.toSet());
assertTrue(properties.contains("WORK"));
});
});
}
use of io.sundr.model.TypeDef in project sundrio by sundrio.
the class AbstractAdapterTest method testWithArray.
@Test
public void testWithArray() {
T input = getInput(ClassWithArray.class);
TypeDef typeDef = Adapters.adaptType(input, getContext());
assertNotNull(typeDef);
assertEquals("ClassWithArray", typeDef.getName());
assertEquals(1, typeDef.getProperties().size());
TypeRef typeRef = typeDef.getProperties().iterator().next().getTypeRef();
assertTrue(typeRef instanceof ClassRef);
assertEquals(1, ((ClassRef) typeRef).getDimensions());
}
use of io.sundr.model.TypeDef in project sundrio by sundrio.
the class AbstractAdapterTest method testWithSuperClassParam.
@Test
public void testWithSuperClassParam() {
T input = getInput(ClassWithSuperClassParam.class);
TypeDef typeDef = Adapters.adaptType(input, getContext());
List<ClassRef> extendsList = typeDef.getExtendsList();
assertNotNull(extendsList);
assertEquals(1, extendsList.size());
ClassRef classRef = extendsList.get(0);
assertEquals(ClassWithParam.class.getName(), classRef.getFullyQualifiedName());
List<TypeRef> arguments = classRef.getArguments();
assertEquals(1, arguments.size());
assertEquals("java.lang.String", arguments.get(0).render());
}
use of io.sundr.model.TypeDef in project sundrio by sundrio.
the class AbstractAdapterTest method testWithTypeParams.
//
// List
//
@Test
public void testWithTypeParams() throws Exception {
java.lang.reflect.Method method = ArrayList.class.getDeclaredMethod("get", int.class);
T input = getInput(StringList.class);
TypeDef typeDef = Adapters.adaptType(input, getContext());
RichTypeDef stringList = TypeArguments.apply(typeDef);
// methods
assertFalse(stringList.getMethods().stream().anyMatch(m -> m.getName().equals("get")));
assertTrue(stringList.getAllMethods().stream().anyMatch(m -> m.getName().equals("get") && m.getReturnType().equals(Types.STRING_REF)));
// properties
assertFalse(stringList.getProperties().stream().anyMatch(m -> m.getName().equals("elementData")));
assertTrue(stringList.getAllProperties().stream().anyMatch(m -> m.getName().equals("elementData")));
}
Aggregations