Search in sources :

Example 1 with GeneratedProperty

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

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

the class GeneratedPropertyTest method testMethodsForGeneratedPropertyBuilderImpl.

@Test
public void testMethodsForGeneratedPropertyBuilderImpl() {
    final GeneratedPropertyBuilderImpl propertyBuilderImpl = new GeneratedPropertyBuilderImpl("testProperty");
    propertyBuilderImpl.setValue("new value");
    propertyBuilderImpl.setReadOnly(true);
    final GeneratedProperty genProperty = propertyBuilderImpl.toInstance();
    assertNotNull(genProperty);
    assertNotNull(propertyBuilderImpl.toString());
}
Also used : GeneratedProperty(org.opendaylight.mdsal.binding.model.api.GeneratedProperty) Test(org.junit.Test)

Example 3 with GeneratedProperty

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

the class AbstractTypeObjectGenerator method restrictType.

@NonNull
private static Type restrictType(@NonNull final Type baseType, final Restrictions restrictions, final TypeBuilderFactory builderFactory) {
    if (restrictions == null || restrictions.isEmpty()) {
        // No additional restrictions, return base type
        return baseType;
    }
    if (!(baseType instanceof GeneratedTransferObject)) {
        // This is a simple Java type, just wrap it with new restrictions
        return Types.restrictedType(baseType, restrictions);
    }
    // Base type is a GTO, we need to re-adjust it with new restrictions
    final GeneratedTransferObject gto = (GeneratedTransferObject) baseType;
    final GeneratedTOBuilder builder = builderFactory.newGeneratedTOBuilder(gto.getIdentifier());
    final GeneratedTransferObject parent = gto.getSuperType();
    if (parent != null) {
        builder.setExtendsType(parent);
    }
    builder.setRestrictions(restrictions);
    for (GeneratedProperty gp : gto.getProperties()) {
        builder.addProperty(gp.getName()).setValue(gp.getValue()).setReadOnly(gp.isReadOnly()).setAccessModifier(gp.getAccessModifier()).setReturnType(gp.getReturnType()).setFinal(gp.isFinal()).setStatic(gp.isStatic());
    }
    return builder.build();
}
Also used : GeneratedTOBuilder(org.opendaylight.mdsal.binding.model.api.type.builder.GeneratedTOBuilder) GeneratedTransferObject(org.opendaylight.mdsal.binding.model.api.GeneratedTransferObject) GeneratedProperty(org.opendaylight.mdsal.binding.model.api.GeneratedProperty) NonNull(org.eclipse.jdt.annotation.NonNull)

Example 4 with GeneratedProperty

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

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

GeneratedProperty (org.opendaylight.mdsal.binding.model.api.GeneratedProperty)24 Test (org.junit.Test)20 GeneratedTransferObject (org.opendaylight.mdsal.binding.model.api.GeneratedTransferObject)17 GeneratedType (org.opendaylight.mdsal.binding.model.api.GeneratedType)15 MethodSignature (org.opendaylight.mdsal.binding.model.api.MethodSignature)7 List (java.util.List)6 Type (org.opendaylight.mdsal.binding.model.api.Type)4 ConcreteType (org.opendaylight.mdsal.binding.model.api.ConcreteType)3 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 EffectiveModelContext (org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)2 LinkedHashMap (java.util.LinkedHashMap)1 NonNull (org.eclipse.jdt.annotation.NonNull)1 DefaultBindingGenerator (org.opendaylight.mdsal.binding.generator.impl.DefaultBindingGenerator)1 AnnotationType (org.opendaylight.mdsal.binding.model.api.AnnotationType)1 JavaTypeName (org.opendaylight.mdsal.binding.model.api.JavaTypeName)1 ParameterizedType (org.opendaylight.mdsal.binding.model.api.ParameterizedType)1 WildcardType (org.opendaylight.mdsal.binding.model.api.WildcardType)1 GeneratedPropertyBuilder (org.opendaylight.mdsal.binding.model.api.type.builder.GeneratedPropertyBuilder)1 GeneratedTOBuilder (org.opendaylight.mdsal.binding.model.api.type.builder.GeneratedTOBuilder)1