Search in sources :

Example 1 with GeneratedType

use of org.opendaylight.mdsal.binding.model.api.GeneratedType in project mdsal by opendaylight.

the class DataObjectCodecContext method getAugmentationPrototype.

@NonNull
private DataContainerCodecPrototype<?> getAugmentationPrototype(final AugmentRuntimeType augment) {
    final BindingRuntimeContext ctx = factory().getRuntimeContext();
    final GeneratedType javaType = augment.javaType();
    final Class<? extends Augmentation<?>> augClass;
    try {
        augClass = ctx.loadClass(javaType);
    } catch (final ClassNotFoundException e) {
        throw new IllegalStateException("RuntimeContext references type " + javaType + " but failed to load its class", e);
    }
    // TODO: at some point we need the effective children
    return DataContainerCodecPrototype.from(augClass, new AugmentationIdentifier(augment.statement().streamEffectiveSubstatements(SchemaTreeEffectiveStatement.class).map(SchemaTreeEffectiveStatement::getIdentifier).collect(ImmutableSet.toImmutableSet())), augment, factory());
}
Also used : AugmentationIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier) BindingRuntimeContext(org.opendaylight.mdsal.binding.runtime.api.BindingRuntimeContext) GeneratedType(org.opendaylight.mdsal.binding.model.api.GeneratedType) NonNull(org.eclipse.jdt.annotation.NonNull)

Example 2 with GeneratedType

use of org.opendaylight.mdsal.binding.model.api.GeneratedType in project mdsal by opendaylight.

the class AnnotationBuilderTest method generatedTypeAnnotationTest.

@Test
public void generatedTypeAnnotationTest() {
    final GeneratedTypeBuilder genTypeBuilder = new CodegenGeneratedTypeBuilder(JavaTypeName.create("org.opendaylight.controller", "AnnotInterface"));
    genTypeBuilder.addAnnotation("javax.management", "MXBean");
    final AnnotationTypeBuilder annotDesc = genTypeBuilder.addAnnotation("javax.management", "Description");
    annotDesc.addParameter("description", "some sort of interface");
    final GeneratedType genType = genTypeBuilder.build();
    assertNotNull(genType);
    assertNotNull(genType.getAnnotations());
    assertEquals(2, genType.getAnnotations().size());
    int annotCount = 0;
    for (final AnnotationType annotation : genType.getAnnotations()) {
        if (annotation.getPackageName().equals("javax.management") && annotation.getName().equals("MXBean")) {
            annotCount++;
            assertEquals(0, annotation.getParameters().size());
        }
        if (annotation.getPackageName().equals("javax.management") && annotation.getName().equals("Description")) {
            annotCount++;
            assertEquals(1, annotation.getParameters().size());
            AnnotationType.Parameter param = annotation.getParameter("description");
            assertNotNull(param);
            assertEquals("description", param.getName());
            assertNotNull(param.getValue());
            assertEquals("some sort of interface", param.getValue());
            assertNotNull(param.getValues());
            assertTrue(param.getValues().isEmpty());
        }
    }
    assertEquals(2, annotCount);
}
Also used : AnnotationTypeBuilder(org.opendaylight.mdsal.binding.model.api.type.builder.AnnotationTypeBuilder) GeneratedTypeBuilder(org.opendaylight.mdsal.binding.model.api.type.builder.GeneratedTypeBuilder) GeneratedType(org.opendaylight.mdsal.binding.model.api.GeneratedType) Parameter(org.opendaylight.mdsal.binding.model.api.AnnotationType.Parameter) AnnotationType(org.opendaylight.mdsal.binding.model.api.AnnotationType) Test(org.junit.Test)

Example 3 with GeneratedType

use of org.opendaylight.mdsal.binding.model.api.GeneratedType in project mdsal by opendaylight.

the class GeneratedTypeBuilderTest method addMethodTest.

@Test
public void addMethodTest() {
    GeneratedTypeBuilder generatedTypeBuilder = new CodegenGeneratedTypeBuilder(JavaTypeName.create("my.package", "MyName"));
    MethodSignatureBuilder methodBuilder = generatedTypeBuilder.addMethod("myMethodName");
    MethodSignatureBuilder methodBuilder2 = generatedTypeBuilder.addMethod("myMethodName2");
    assertNotNull(methodBuilder);
    assertNotNull(methodBuilder2);
    assertTrue(generatedTypeBuilder.containsMethod("myMethodName"));
    assertTrue(generatedTypeBuilder.containsMethod("myMethodName2"));
    assertFalse(generatedTypeBuilder.containsMethod("myMethodName3"));
    GeneratedType instance = generatedTypeBuilder.build();
    List<MethodSignature> methodDefinitions = instance.getMethodDefinitions();
    assertEquals(2, methodDefinitions.size());
    assertTrue(methodDefinitions.contains(methodBuilder.toInstance(instance)));
    assertTrue(methodDefinitions.contains(methodBuilder2.toInstance(instance)));
    assertFalse(methodDefinitions.contains(new MethodSignatureBuilderImpl("myMethodName3").toInstance(instance)));
}
Also used : GeneratedTypeBuilder(org.opendaylight.mdsal.binding.model.api.type.builder.GeneratedTypeBuilder) MethodSignature(org.opendaylight.mdsal.binding.model.api.MethodSignature) GeneratedType(org.opendaylight.mdsal.binding.model.api.GeneratedType) MethodSignatureBuilder(org.opendaylight.mdsal.binding.model.api.type.builder.MethodSignatureBuilder) Test(org.junit.Test)

Example 4 with GeneratedType

use of org.opendaylight.mdsal.binding.model.api.GeneratedType in project mdsal by opendaylight.

the class GeneratedTypeBuilderTest method addConstantTest.

@Test
public void addConstantTest() {
    GeneratedTypeBuilder generatedTypeBuilder = new CodegenGeneratedTypeBuilder(JavaTypeName.create("my.package", "MyName"));
    // assertNotNull(generatedTypeBuilder.addComment("My comment ..."));
    Constant constant = generatedTypeBuilder.addConstant(Types.typeForClass(String.class), "myConstant", "myConstantValue");
    // Constant constantx =
    // generatedTypeBuilder.addConstant(Types.typeForClass(String.class),
    // "myConstant", "myConstantValue");
    Constant constant2 = generatedTypeBuilder.addConstant(Types.typeForClass(int.class, mock(Restrictions.class)), "myIntConstant", 1);
    Constant constant3 = new ConstantImpl(Types.typeForClass(String.class), "myConstant", "myConstantValue");
    final Constant constant4 = new ConstantImpl(Types.typeForClass(String.class), "myConstant2", "myConstantValue");
    final Constant constant5 = new ConstantImpl(Types.typeForClass(String.class), "myConstant", "myConstantValue2");
    assertNotNull(constant);
    assertNotNull(constant2);
    assertNotNull(constant3);
    assertNotNull(constant4);
    assertNotNull(constant5);
    // assertNotNull(constantx);
    // assertTrue(constant!=constantx);
    assertFalse(constant.equals(null));
    assertFalse(constant.equals(new Object()));
    assertTrue(constant.equals(constant));
    assertTrue(constant.equals(constant3));
    assertFalse(constant.equals(constant2));
    assertFalse(constant.equals(constant4));
    assertFalse(constant.equals(constant5));
    assertTrue(constant.hashCode() == constant.hashCode());
    assertTrue(constant.hashCode() == constant3.hashCode());
    assertFalse(constant.hashCode() == constant2.hashCode());
    assertFalse(constant.hashCode() == constant4.hashCode());
    assertTrue(constant.hashCode() == constant5.hashCode());
    assertEquals("Constant [type=ConcreteTypeImpl{identifier=java.lang.String}, name=myConstant, value=myConstantValue]", constant.toString());
    GeneratedType instance = generatedTypeBuilder.build();
    List<Constant> constantDefinitions = instance.getConstantDefinitions();
    assertNotNull(constantDefinitions);
    assertEquals(2, constantDefinitions.size());
    assertTrue(constantDefinitions.contains(constant));
    assertTrue(constantDefinitions.contains(constant2));
    assertTrue(constantDefinitions.contains(constant3));
    assertFalse(constantDefinitions.contains(constant4));
    assertFalse(constantDefinitions.contains(constant5));
    assertEquals("myConstant", constant.getName());
    assertEquals("myConstantValue", constant.getValue());
    assertEquals(Types.typeForClass(String.class), constant.getType());
}
Also used : GeneratedTypeBuilder(org.opendaylight.mdsal.binding.model.api.type.builder.GeneratedTypeBuilder) GeneratedType(org.opendaylight.mdsal.binding.model.api.GeneratedType) Constant(org.opendaylight.mdsal.binding.model.api.Constant) GeneratedTransferObject(org.opendaylight.mdsal.binding.model.api.GeneratedTransferObject) Test(org.junit.Test)

Example 5 with GeneratedType

use of org.opendaylight.mdsal.binding.model.api.GeneratedType in project mdsal by opendaylight.

the class GeneratedTypeBuilderTest method addImplementsTypeTest.

@Test
public void addImplementsTypeTest() {
    CodegenGeneratedTypeBuilder generatedTypeBuilder = new CodegenGeneratedTypeBuilder(JavaTypeName.create("my.package", "MyName"));
    assertEquals(generatedTypeBuilder, generatedTypeBuilder.addImplementsType(Types.typeForClass(Serializable.class)));
    assertEquals(generatedTypeBuilder, generatedTypeBuilder.addImplementsType(Types.typeForClass(Runnable.class)));
    GeneratedType instance = generatedTypeBuilder.build();
    List<Type> implementTypes = instance.getImplements();
    assertEquals(2, implementTypes.size());
    assertTrue(implementTypes.contains(Types.typeForClass(Serializable.class)));
    assertTrue(implementTypes.contains(Types.typeForClass(Runnable.class)));
    assertFalse(implementTypes.contains(Types.typeForClass(Throwable.class)));
}
Also used : Type(org.opendaylight.mdsal.binding.model.api.Type) GeneratedType(org.opendaylight.mdsal.binding.model.api.GeneratedType) GeneratedType(org.opendaylight.mdsal.binding.model.api.GeneratedType) Test(org.junit.Test)

Aggregations

GeneratedType (org.opendaylight.mdsal.binding.model.api.GeneratedType)93 Test (org.junit.Test)65 GeneratedTransferObject (org.opendaylight.mdsal.binding.model.api.GeneratedTransferObject)36 Type (org.opendaylight.mdsal.binding.model.api.Type)28 MethodSignature (org.opendaylight.mdsal.binding.model.api.MethodSignature)27 GeneratedProperty (org.opendaylight.mdsal.binding.model.api.GeneratedProperty)17 List (java.util.List)13 ParameterizedType (org.opendaylight.mdsal.binding.model.api.ParameterizedType)12 ArrayList (java.util.ArrayList)10 AnnotationType (org.opendaylight.mdsal.binding.model.api.AnnotationType)9 EffectiveModelContext (org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)9 GeneratedTypeBuilder (org.opendaylight.mdsal.binding.model.api.type.builder.GeneratedTypeBuilder)8 ConcreteType (org.opendaylight.mdsal.binding.model.api.ConcreteType)7 NonNull (org.eclipse.jdt.annotation.NonNull)6 Enumeration (org.opendaylight.mdsal.binding.model.api.Enumeration)6 Assert.assertEquals (org.junit.Assert.assertEquals)5 Collectors (java.util.stream.Collectors)4 WildcardType (org.opendaylight.mdsal.binding.model.api.WildcardType)4 Module (org.opendaylight.yangtools.yang.model.api.Module)4 YangParserTestUtils (org.opendaylight.yangtools.yang.test.util.YangParserTestUtils)4