Search in sources :

Example 1 with GeneratedTransferObject

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

the class UnionTypeCodec method extractUnionProperties.

private static List<String> extractUnionProperties(final Type type) {
    verify(type instanceof GeneratedTransferObject, "Unexpected runtime type %s", type);
    GeneratedTransferObject gto = (GeneratedTransferObject) type;
    while (true) {
        if (gto instanceof RuntimeGeneratedUnion) {
            return ((RuntimeGeneratedUnion) gto).typePropertyNames();
        }
        gto = verifyNotNull(gto.getSuperType(), "Cannot find union type information for %s", type);
    }
}
Also used : RuntimeGeneratedUnion(org.opendaylight.mdsal.binding.runtime.api.RuntimeGeneratedUnion) GeneratedTransferObject(org.opendaylight.mdsal.binding.model.api.GeneratedTransferObject)

Example 2 with GeneratedTransferObject

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

the class TypeUtilsTest method getBaseYangTypeWithExceptionTest.

@Test(expected = IllegalArgumentException.class)
public void getBaseYangTypeWithExceptionTest() throws Exception {
    final GeneratedTransferObject rootType = mock(GeneratedTransferObject.class);
    final GeneratedTransferObject innerType = mock(GeneratedTransferObject.class);
    final GeneratedProperty property = mock(GeneratedProperty.class);
    doReturn("test").when(property).getName();
    doReturn(rootType).when(innerType).getSuperType();
    doReturn(ImmutableList.of(property)).when(rootType).getProperties();
    TypeUtils.getBaseYangType(innerType);
}
Also used : GeneratedTransferObject(org.opendaylight.mdsal.binding.model.api.GeneratedTransferObject) GeneratedProperty(org.opendaylight.mdsal.binding.model.api.GeneratedProperty) Test(org.junit.Test)

Example 3 with GeneratedTransferObject

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

the class AnnotationBuilderTest method generatedPropertyAnnotationTest.

@Test
public void generatedPropertyAnnotationTest() {
    final GeneratedTOBuilder genTOBuilder = new CodegenGeneratedTOBuilder(JavaTypeName.create("org.opendaylight.controller", "AnnotInterface"));
    final GeneratedPropertyBuilder propertyBuilder = genTOBuilder.addProperty("simpleProperty");
    propertyBuilder.setReturnType(Types.typeForClass(Integer.class));
    final AnnotationTypeBuilder annotManAttr = propertyBuilder.addAnnotation("org.springframework.jmx.export.annotation", "ManagedAttribute");
    annotManAttr.addParameter("description", "\"The Name Attribute\"");
    annotManAttr.addParameter("currencyTimeLimit", "20");
    annotManAttr.addParameter("defaultValue", "\"bar\"");
    annotManAttr.addParameter("persistPolicy", "\"OnUpdate\"");
    final AnnotationTypeBuilder annotManProp = propertyBuilder.addAnnotation("org.springframework.jmx.export.annotation", "ManagedOperation");
    final List<String> typeValues = new ArrayList<>();
    typeValues.add("\"val1\"");
    typeValues.add("\"val2\"");
    typeValues.add("\"val3\"");
    annotManProp.addParameters("types", typeValues);
    final GeneratedTransferObject genTransObj = genTOBuilder.build();
    assertNotNull(genTransObj);
    assertNotNull(genTransObj.getAnnotations());
    assertNotNull(genTransObj.getProperties());
    assertNotNull(genTransObj.getProperties().get(0));
    assertNotNull(genTransObj.getProperties().get(0).getAnnotations());
    final List<AnnotationType> annotations = genTransObj.getProperties().get(0).getAnnotations();
    assertEquals(2, annotations.size());
    int annotCount = 0;
    for (final AnnotationType annotation : annotations) {
        if (annotation.getPackageName().equals("org.springframework.jmx.export.annotation") && annotation.getName().equals("ManagedAttribute")) {
            annotCount++;
            assertEquals(4, annotation.getParameters().size());
            assertNotNull(annotation.getParameter("description"));
            assertNotNull(annotation.getParameter("currencyTimeLimit"));
            assertNotNull(annotation.getParameter("defaultValue"));
            assertNotNull(annotation.getParameter("persistPolicy"));
            assertEquals("\"The Name Attribute\"", annotation.getParameter("description").getValue());
            assertEquals("20", annotation.getParameter("currencyTimeLimit").getValue());
            assertEquals("\"bar\"", annotation.getParameter("defaultValue").getValue());
            assertEquals("\"OnUpdate\"", annotation.getParameter("persistPolicy").getValue());
        }
        if (annotation.getPackageName().equals("org.springframework.jmx.export.annotation") && annotation.getName().equals("ManagedOperation")) {
            annotCount++;
            assertEquals(1, annotation.getParameters().size());
            assertNotNull(annotation.getParameter("types"));
            assertEquals(3, annotation.getParameter("types").getValues().size());
        }
    }
    assertEquals(2, annotCount);
}
Also used : AnnotationTypeBuilder(org.opendaylight.mdsal.binding.model.api.type.builder.AnnotationTypeBuilder) GeneratedPropertyBuilder(org.opendaylight.mdsal.binding.model.api.type.builder.GeneratedPropertyBuilder) GeneratedTOBuilder(org.opendaylight.mdsal.binding.model.api.type.builder.GeneratedTOBuilder) ArrayList(java.util.ArrayList) GeneratedTransferObject(org.opendaylight.mdsal.binding.model.api.GeneratedTransferObject) AnnotationType(org.opendaylight.mdsal.binding.model.api.AnnotationType) Test(org.junit.Test)

Example 4 with GeneratedTransferObject

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

the class GeneratedTOBuilderImplTest method testSetRestrictions.

@Test
public void testSetRestrictions() {
    final CodegenGeneratedTOBuilder genTOBuilder = new CodegenGeneratedTOBuilder(JavaTypeName.create("org.opendaylight.yangtools.test", "Test"));
    final Restrictions restrictions = new Restrictions() {

        @Override
        public boolean isEmpty() {
            return false;
        }

        @Override
        public Optional<? extends RangeConstraint<?>> getRangeConstraint() {
            return Optional.empty();
        }

        @Override
        public List<PatternConstraint> getPatternConstraints() {
            return null;
        }

        @Override
        public Optional<LengthConstraint> getLengthConstraint() {
            return Optional.empty();
        }
    };
    genTOBuilder.setRestrictions(restrictions);
    final GeneratedTransferObject genTO = genTOBuilder.build();
    assertNotNull(genTO.getRestrictions());
}
Also used : LengthConstraint(org.opendaylight.yangtools.yang.model.api.type.LengthConstraint) GeneratedTransferObject(org.opendaylight.mdsal.binding.model.api.GeneratedTransferObject) PatternConstraint(org.opendaylight.yangtools.yang.model.api.type.PatternConstraint) Restrictions(org.opendaylight.mdsal.binding.model.api.Restrictions) Test(org.junit.Test)

Example 5 with GeneratedTransferObject

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

the class GeneratedTOBuilderImplTest method testAddEqualsIdentity.

@Test
public void testAddEqualsIdentity() {
    final CodegenGeneratedTOBuilder genTOBuilder = new CodegenGeneratedTOBuilder(JavaTypeName.create("org.opendaylight.yangtools.test", "Test"));
    final GeneratedPropertyBuilderImpl propertyBuilder = new GeneratedPropertyBuilderImpl("testProperty");
    genTOBuilder.addEqualsIdentity(propertyBuilder);
    final GeneratedTransferObject genTO = genTOBuilder.build();
    assertEquals(1, genTO.getEqualsIdentifiers().size());
    assertEquals("testProperty", genTO.getEqualsIdentifiers().get(0).getName());
}
Also used : GeneratedTransferObject(org.opendaylight.mdsal.binding.model.api.GeneratedTransferObject) Test(org.junit.Test)

Aggregations

GeneratedTransferObject (org.opendaylight.mdsal.binding.model.api.GeneratedTransferObject)59 Test (org.junit.Test)47 GeneratedType (org.opendaylight.mdsal.binding.model.api.GeneratedType)34 GeneratedProperty (org.opendaylight.mdsal.binding.model.api.GeneratedProperty)19 List (java.util.List)9 Type (org.opendaylight.mdsal.binding.model.api.Type)9 MethodSignature (org.opendaylight.mdsal.binding.model.api.MethodSignature)8 GeneratedTOBuilder (org.opendaylight.mdsal.binding.model.api.type.builder.GeneratedTOBuilder)8 ConcreteType (org.opendaylight.mdsal.binding.model.api.ConcreteType)5 GeneratedPropertyBuilder (org.opendaylight.mdsal.binding.model.api.type.builder.GeneratedPropertyBuilder)5 ArrayList (java.util.ArrayList)4 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)4 AnnotationType (org.opendaylight.mdsal.binding.model.api.AnnotationType)4 CoreMatchers.instanceOf (org.hamcrest.CoreMatchers.instanceOf)3 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)3 Assert.assertEquals (org.junit.Assert.assertEquals)3 ParameterizedType (org.opendaylight.mdsal.binding.model.api.ParameterizedType)3 Map (java.util.Map)2 Optional (java.util.Optional)2 Collectors (java.util.stream.Collectors)2