Search in sources :

Example 96 with TypeDef

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"));
        });
    });
}
Also used : RichTypeDef(io.sundr.model.RichTypeDef) TypeDef(io.sundr.model.TypeDef) ClassRef(io.sundr.model.ClassRef) Test(org.junit.Test)

Example 97 with TypeDef

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());
}
Also used : RichTypeDef(io.sundr.model.RichTypeDef) TypeDef(io.sundr.model.TypeDef) ClassRef(io.sundr.model.ClassRef) TypeRef(io.sundr.model.TypeRef) Test(org.junit.Test)

Example 98 with TypeDef

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());
}
Also used : RichTypeDef(io.sundr.model.RichTypeDef) TypeDef(io.sundr.model.TypeDef) ClassRef(io.sundr.model.ClassRef) ClassWithParam(io.sundr.adapter.testing.general.ClassWithParam) TypeRef(io.sundr.model.TypeRef) Test(org.junit.Test)

Example 99 with TypeDef

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")));
}
Also used : ClassWithSelfRefParam(io.sundr.adapter.testing.general.ClassWithSelfRefParam) Person(io.sundr.adapter.testing.person.Person) GetDefinition(io.sundr.model.functions.GetDefinition) StringList(io.sundr.adapter.testing.list.StringList) ClassWithPrimitiveArray(io.sundr.adapter.testing.general.ClassWithPrimitiveArray) AdapterContext(io.sundr.adapter.api.AdapterContext) ArrayList(java.util.ArrayList) ClassRef(io.sundr.model.ClassRef) Assert.assertArrayEquals(org.junit.Assert.assertArrayEquals) Address(io.sundr.adapter.testing.person.Address) SimpleClass(io.sundr.adapter.testing.general.SimpleClass) RichTypeDef(io.sundr.model.RichTypeDef) Types(io.sundr.model.utils.Types) ClassWithAnnotation(io.sundr.adapter.testing.general.ClassWithAnnotation) Assert.assertNotNull(org.junit.Assert.assertNotNull) ClassWithSuperClassParam(io.sundr.adapter.testing.general.ClassWithSuperClassParam) Adapters(io.sundr.adapter.api.Adapters) Assert.assertTrue(org.junit.Assert.assertTrue) Set(java.util.Set) Test(org.junit.Test) Method(io.sundr.model.Method) TypeRef(io.sundr.model.TypeRef) AnnotationRef(io.sundr.model.AnnotationRef) Collectors(java.util.stream.Collectors) Property(io.sundr.model.Property) List(java.util.List) ClassWithArray(io.sundr.adapter.testing.general.ClassWithArray) PrimitiveRef(io.sundr.model.PrimitiveRef) TypeArguments(io.sundr.model.utils.TypeArguments) Assert.assertFalse(org.junit.Assert.assertFalse) TypeDef(io.sundr.model.TypeDef) Optional(java.util.Optional) ClassWithParam(io.sundr.adapter.testing.general.ClassWithParam) Assert.assertEquals(org.junit.Assert.assertEquals) RichTypeDef(io.sundr.model.RichTypeDef) TypeDef(io.sundr.model.TypeDef) RichTypeDef(io.sundr.model.RichTypeDef) Test(org.junit.Test)

Aggregations

TypeDef (io.sundr.model.TypeDef)99 ClassRef (io.sundr.model.ClassRef)43 Test (org.junit.Test)40 RichTypeDef (io.sundr.model.RichTypeDef)38 TypeDefBuilder (io.sundr.model.TypeDefBuilder)35 TypeRef (io.sundr.model.TypeRef)26 Method (io.sundr.model.Method)22 Property (io.sundr.model.Property)22 ArrayList (java.util.ArrayList)20 List (java.util.List)15 TypeElement (javax.lang.model.element.TypeElement)15 Collectors (java.util.stream.Collectors)14 Element (javax.lang.model.element.Element)14 Set (java.util.Set)12 Test (org.junit.jupiter.api.Test)12 AnnotationRef (io.sundr.model.AnnotationRef)11 DefinitionRepository (io.sundr.model.repo.DefinitionRepository)11 HashMap (java.util.HashMap)11 AptContext (io.sundr.adapter.apt.AptContext)10 ClassRefBuilder (io.sundr.model.ClassRefBuilder)10