Search in sources :

Example 1 with MethodSignature

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

the class AbstractTypeMemberTest method testMethodsForAbstractTypeMemberBuilder.

@Test
public void testMethodsForAbstractTypeMemberBuilder() {
    final MethodSignatureBuilderImpl methodSignatureBuilderImpl = new MethodSignatureBuilderImpl("TestProperty");
    final CodegenGeneratedTypeBuilder typeBuilderImpl = new CodegenGeneratedTypeBuilder(JavaTypeName.create("org.opendaylight.yangtools.test", "TestType"));
    final CodegenGeneratedTypeBuilder typeBuilderImpl2 = new CodegenGeneratedTypeBuilder(JavaTypeName.create("org.opendaylight.yangtools.test", "TestType2"));
    methodSignatureBuilderImpl.setComment(TypeMemberComment.contractOf("test comment"));
    methodSignatureBuilderImpl.setFinal(true);
    methodSignatureBuilderImpl.setStatic(true);
    final MethodSignature genProperty = methodSignatureBuilderImpl.toInstance(typeBuilderImpl);
    final MethodSignature genProperty2 = methodSignatureBuilderImpl.toInstance(typeBuilderImpl2);
    assertEquals(TypeMemberComment.contractOf("test comment"), genProperty.getComment());
    assertTrue(genProperty.isFinal());
    assertTrue(genProperty.isStatic());
    assertEquals(genProperty.hashCode(), genProperty2.hashCode());
    assertEquals("MethodSignatureImpl [name=TestProperty, comment=TypeMemberComment{contract=test comment}, " + "returnType=null, params=[], annotations=[]]", genProperty.toString());
    assertNotNull(genProperty.toString());
    assertTrue(genProperty.equals(genProperty2));
    assertFalse(genProperty.equals(null));
}
Also used : MethodSignature(org.opendaylight.mdsal.binding.model.api.MethodSignature) Test(org.junit.Test)

Example 2 with MethodSignature

use of org.opendaylight.mdsal.binding.model.api.MethodSignature 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 3 with MethodSignature

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

the class MethodSignatureBuilderImplTest method testSetAbstractMethod.

@Test
public void testSetAbstractMethod() {
    final MethodSignatureBuilderImpl signatureBuilderImpl = new MethodSignatureBuilderImpl("testMethod");
    signatureBuilderImpl.setAbstract(true);
    final MethodSignature methodSignature = signatureBuilderImpl.toInstance(null);
    assertTrue(methodSignature.isAbstract());
}
Also used : MethodSignature(org.opendaylight.mdsal.binding.model.api.MethodSignature) Test(org.junit.Test)

Example 4 with MethodSignature

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

the class AugmentRelativeXPathTest method testAugmentationWithRelativeXPath.

@Test
public void testAugmentationWithRelativeXPath() {
    final List<GeneratedType> genTypes = DefaultBindingGenerator.generateFor(YangParserTestUtils.parseYangResourceDirectory("/augment-relative-xpath-models"));
    assertNotNull("genTypes is null", genTypes);
    assertEquals(27, genTypes.size());
    GeneratedTransferObject gtInterfaceKey = null;
    GeneratedType gtInterface = null;
    GeneratedType gtTunnel = null;
    GeneratedTransferObject gtTunnelKey = null;
    for (final GeneratedType type : genTypes) {
        if (!type.getPackageName().contains("augment._abstract.topology")) {
            continue;
        }
        if (type.getName().equals("InterfaceKey")) {
            gtInterfaceKey = (GeneratedTransferObject) type;
            final List<GeneratedProperty> properties = gtInterfaceKey.getProperties();
            assertNotNull("InterfaceKey properties are null", properties);
            assertEquals(1, properties.size());
            final GeneratedProperty property = properties.get(0);
            assertEquals("interfaceId", property.getName());
            assertNotNull("interfaceId return type is null", property.getReturnType());
            assertEquals(JavaTypeName.create(String.class), property.getReturnType().getIdentifier());
        } else if (type.getName().equals("Interface")) {
            gtInterface = type;
            final List<MethodSignature> gtInterfaceMethods = gtInterface.getMethodDefinitions();
            assertNotNull("Interface methods are null", gtInterfaceMethods);
            assertEquals(9, gtInterfaceMethods.size());
            MethodSignature getIfcKeyMethod = null;
            for (final MethodSignature method : gtInterfaceMethods) {
                if (BindingMapping.IDENTIFIABLE_KEY_NAME.equals(method.getName())) {
                    getIfcKeyMethod = method;
                    break;
                }
            }
            assertNotNull("getKey method is null", getIfcKeyMethod);
            assertNotNull("getKey method return type is null", getIfcKeyMethod.getReturnType());
            assertEquals(JavaTypeName.create("org.opendaylight.yang.gen.v1.urn.model.augment._abstract.topology.rev130503.topology.interfaces", "InterfaceKey"), getIfcKeyMethod.getReturnType().getIdentifier());
        } else if (type.getName().equals("Tunnel")) {
            gtTunnel = type;
            final List<MethodSignature> tunnelMethods = gtTunnel.getMethodDefinitions();
            assertNotNull("Tunnel methods are null", tunnelMethods);
            assertEquals(7, tunnelMethods.size());
            MethodSignature getTunnelKeyMethod = null;
            for (MethodSignature method : tunnelMethods) {
                if (BindingMapping.IDENTIFIABLE_KEY_NAME.equals(method.getName())) {
                    getTunnelKeyMethod = method;
                    break;
                }
            }
            assertNotNull("getKey method is null", getTunnelKeyMethod);
            assertNotNull("getKey method return type", getTunnelKeyMethod.getReturnType());
            assertEquals(JavaTypeName.create("org.opendaylight.yang.gen.v1.urn.model.augment._abstract.topology" + ".rev130503.topology.network.links.network.link.tunnels", "TunnelKey"), getTunnelKeyMethod.getReturnType().getIdentifier());
        } else if (type.getName().equals("TunnelKey")) {
            assertThat(type, instanceOf(GeneratedTransferObject.class));
            gtTunnelKey = (GeneratedTransferObject) type;
            final List<GeneratedProperty> properties = gtTunnelKey.getProperties();
            assertNotNull("TunnelKey properties are null", properties);
            assertEquals(1, properties.size());
            final GeneratedProperty property = properties.get(0);
            assertEquals("tunnelId", property.getName());
            assertNotNull("tunnelId return type is null", property.getReturnType());
            assertEquals(JavaTypeName.create("org.opendaylight.yang.gen.v1.urn.model._abstract.topology.rev130208", "Uri"), property.getReturnType().getIdentifier());
        }
    }
    assertNotNull("Interface is null", gtInterface);
    assertNotNull("InterfaceKey is null", gtInterfaceKey);
    assertNotNull("Tunnel is null", gtTunnel);
    assertNotNull("TunnelKey is null", gtTunnelKey);
}
Also used : MethodSignature(org.opendaylight.mdsal.binding.model.api.MethodSignature) GeneratedType(org.opendaylight.mdsal.binding.model.api.GeneratedType) GeneratedTransferObject(org.opendaylight.mdsal.binding.model.api.GeneratedTransferObject) List(java.util.List) GeneratedProperty(org.opendaylight.mdsal.binding.model.api.GeneratedProperty) Test(org.junit.Test)

Example 5 with MethodSignature

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

the class AugmentedTypeTest method augmentedAbstractTopologyTest.

@Test
public void augmentedAbstractTopologyTest() {
    final EffectiveModelContext context = YangParserTestUtils.parseYangResources(AugmentedTypeTest.class, "/augment-test-models/abstract-topology@2013-02-08.yang", "/augment-test-models/augment-abstract-topology@2013-05-03.yang", "/augment-test-models/augment-network-link-attributes@2013-05-03.yang", "/augment-test-models/augment-topology-tunnels@2013-05-03.yang", "/augment-test-models/ietf-interfaces@2012-11-15.yang");
    assertNotNull("Schema Context is null", context);
    final List<GeneratedType> genTypes = DefaultBindingGenerator.generateFor(context);
    assertEquals(31, genTypes.size());
    GeneratedTransferObject gtInterfaceKey = null;
    GeneratedType gtInterface = null;
    GeneratedType gtTunnel = null;
    GeneratedTransferObject gtTunnelKey = null;
    GeneratedType gtNetworkLink2 = null;
    for (final GeneratedType type : genTypes) {
        if (!type.getPackageName().contains("augment._abstract.topology")) {
            continue;
        }
        if (type.getName().equals("InterfaceKey")) {
            gtInterfaceKey = (GeneratedTransferObject) type;
        } else if (type.getName().equals("Interface")) {
            gtInterface = type;
        } else if (type.getName().equals("Tunnel")) {
            gtTunnel = type;
        } else if (type.getName().equals("TunnelKey")) {
            gtTunnelKey = (GeneratedTransferObject) type;
        } else if (type.getName().equals("NetworkLink2")) {
            gtNetworkLink2 = type;
        }
    }
    // 'Interface
    assertNotNull("gtInterface is null", gtInterface);
    final List<MethodSignature> gtInterfaceMethods = gtInterface.getMethodDefinitions();
    assertNotNull("gtInterfaceMethods is null", gtInterfaceMethods);
    MethodSignature getIfcKeyMethod = null;
    for (final MethodSignature method : gtInterfaceMethods) {
        if (BindingMapping.IDENTIFIABLE_KEY_NAME.equals(method.getName())) {
            getIfcKeyMethod = method;
            break;
        }
    }
    assertNotNull("getIfcKeyMethod is null", getIfcKeyMethod);
    assertThat(getIfcKeyMethod.getReturnType(), instanceOf(GeneratedTransferObject.class));
    assertEquals(JavaTypeName.create("org.opendaylight.yang.gen.v1.urn.model.augment._abstract.topology.rev130503.topology.interfaces", "InterfaceKey"), getIfcKeyMethod.getReturnType().getIdentifier());
    MethodSignature getHigherLayerIfMethod = null;
    for (final MethodSignature method : gtInterfaceMethods) {
        if (method.getName().equals("getHigherLayerIf")) {
            getHigherLayerIfMethod = method;
            break;
        }
    }
    assertNotNull("getHigherLayerIf method is null", getHigherLayerIfMethod);
    assertEquals(Types.setTypeFor(Types.STRING), getHigherLayerIfMethod.getReturnType());
    // 'InterfaceKey'
    assertNotNull("InterfaceKey is null", gtInterfaceKey);
    final List<GeneratedProperty> properties = gtInterfaceKey.getProperties();
    assertNotNull("properties is null", properties);
    GeneratedProperty gtInterfaceId = null;
    for (final GeneratedProperty property : properties) {
        if (property.getName().equals("interfaceId")) {
            gtInterfaceId = property;
            break;
        }
    }
    assertNotNull("interfaceId is null", gtInterfaceId);
    assertEquals(Types.STRING, gtInterfaceId.getReturnType());
    // 'Tunnel'
    assertNotNull("Tunnel is null", gtTunnel);
    final List<MethodSignature> tunnelMethods = gtTunnel.getMethodDefinitions();
    assertNotNull("Tunnel methods are null", tunnelMethods);
    MethodSignature getTunnelKeyMethod = null;
    for (MethodSignature method : tunnelMethods) {
        if (BindingMapping.IDENTIFIABLE_KEY_NAME.equals(method.getName())) {
            getTunnelKeyMethod = method;
            break;
        }
    }
    assertNotNull("getKey method of Tunnel is null", getTunnelKeyMethod);
    var retType = getTunnelKeyMethod.getReturnType();
    assertThat(retType, instanceOf(GeneratedTransferObject.class));
    assertEquals(JavaTypeName.create("org.opendaylight.yang.gen.v1.urn.model.augment._abstract.topology.rev130503" + ".topology.network.links.network.link.tunnels", "TunnelKey"), retType.getIdentifier());
    // 'TunnelKey'
    assertNotNull("TunnelKey is null", gtTunnelKey);
    final List<GeneratedProperty> tunnelKeyProperties = gtTunnelKey.getProperties();
    assertNotNull("TunnelKey properties are null", tunnelKeyProperties);
    GeneratedProperty gtTunnelId = null;
    for (final GeneratedProperty property : tunnelKeyProperties) {
        if (property.getName().equals("tunnelId")) {
            gtTunnelId = property;
        }
    }
    assertNotNull("tunnelId is null", gtTunnelId);
    assertEquals(Types.typeForClass(Integer.class), gtTunnelId.getReturnType());
    // 'NetworkLink2'
    assertNotNull("NetworkLink2 is null", gtNetworkLink2);
    final List<MethodSignature> networkLink2Methods = gtNetworkLink2.getMethodDefinitions();
    assertNotNull("NetworkLink2 methods are null", networkLink2Methods);
    MethodSignature getIfcMethod = null;
    for (MethodSignature method : networkLink2Methods) {
        if (method.getName().equals("getInterface")) {
            getIfcMethod = method;
            break;
        }
    }
    assertNotNull("getInterface method is null", getIfcMethod);
    assertEquals(Types.STRING, getIfcMethod.getReturnType());
}
Also used : MethodSignature(org.opendaylight.mdsal.binding.model.api.MethodSignature) GeneratedType(org.opendaylight.mdsal.binding.model.api.GeneratedType) GeneratedTransferObject(org.opendaylight.mdsal.binding.model.api.GeneratedTransferObject) GeneratedProperty(org.opendaylight.mdsal.binding.model.api.GeneratedProperty) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext) Test(org.junit.Test)

Aggregations

MethodSignature (org.opendaylight.mdsal.binding.model.api.MethodSignature)33 GeneratedType (org.opendaylight.mdsal.binding.model.api.GeneratedType)28 Test (org.junit.Test)25 Type (org.opendaylight.mdsal.binding.model.api.Type)13 GeneratedTransferObject (org.opendaylight.mdsal.binding.model.api.GeneratedTransferObject)8 GeneratedProperty (org.opendaylight.mdsal.binding.model.api.GeneratedProperty)7 List (java.util.List)5 AnnotationType (org.opendaylight.mdsal.binding.model.api.AnnotationType)5 EffectiveModelContext (org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)4 ArrayList (java.util.ArrayList)3 ParameterizedType (org.opendaylight.mdsal.binding.model.api.ParameterizedType)3 Assert.assertEquals (org.junit.Assert.assertEquals)2 ConcreteType (org.opendaylight.mdsal.binding.model.api.ConcreteType)2 Enumeration (org.opendaylight.mdsal.binding.model.api.Enumeration)2 YangParserTestUtils (org.opendaylight.yangtools.yang.test.util.YangParserTestUtils)2 ImmutableRangeSet (com.google.common.collect.ImmutableRangeSet)1 Range (com.google.common.collect.Range)1 RangeSet (com.google.common.collect.RangeSet)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1