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));
}
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)));
}
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());
}
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);
}
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());
}
Aggregations