Fix minor bug in FRM proactive flow code path
[controller.git] / opendaylight / sal / yang-prototype / code-generator / binding-generator-impl / src / test / java / org / opendaylight / controller / sal / binding / generator / impl / BitAndUnionTOEnclosingTest.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.sal.binding.generator.impl;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12
13 import java.io.File;
14 import java.util.ArrayList;
15 import java.util.List;
16 import java.util.Set;
17
18 import org.junit.BeforeClass;
19 import org.junit.Test;
20 import org.opendaylight.controller.sal.binding.generator.api.BindingGenerator;
21 import org.opendaylight.controller.sal.binding.model.api.GeneratedProperty;
22 import org.opendaylight.controller.sal.binding.model.api.GeneratedTransferObject;
23 import org.opendaylight.controller.sal.binding.model.api.GeneratedType;
24 import org.opendaylight.controller.sal.binding.model.api.Type;
25 import org.opendaylight.controller.yang.model.api.Module;
26 import org.opendaylight.controller.yang.model.api.SchemaContext;
27 import org.opendaylight.controller.yang.model.parser.api.YangModelParser;
28 import org.opendaylight.controller.yang.parser.impl.YangParserImpl;
29
30 public class BitAndUnionTOEnclosingTest {
31
32     private final static List<File> testModels = new ArrayList<File>();
33
34     @BeforeClass
35     public static void loadTestResources() {
36         final File listModelFile = new File(ExtendedTypedefTest.class.getResource("/bit_and_union_in_leaf.yang")
37                 .getPath());
38         testModels.add(listModelFile);
39     }
40
41     @Test
42     public void bitAndUnionEnclosingTest() {
43         final YangModelParser parser = new YangParserImpl();
44         final Set<Module> modules = parser.parseYangModels(testModels);
45         final SchemaContext context = parser.resolveSchemaContext(modules);
46
47         assertNotNull(context);
48         final BindingGenerator bindingGen = new BindingGeneratorImpl();
49         final List<Type> genTypes = bindingGen.generateTypes(context);
50
51         GeneratedType parentContainer = null;
52
53         for (Type type : genTypes) {
54             if ((type instanceof GeneratedType) && !(type instanceof GeneratedTransferObject)) {
55                 GeneratedType genTO = (GeneratedType) type;
56                 if (genTO.getName().equals("ParentContainer")) {
57                     parentContainer = genTO;
58                     break;
59                 }
60             }
61         }
62
63         assertNotNull("Parent container object wasn't found.", parentContainer);
64
65         GeneratedTransferObject bitLeaf = null;
66         GeneratedTransferObject unionLeaf = null;
67         List<GeneratedType> enclosedTypes = parentContainer.getEnclosedTypes();
68         for (GeneratedType genType : enclosedTypes) {
69             if (genType instanceof GeneratedTransferObject) {
70                 if (genType.getName().equals("BitLeaf")) {
71                     bitLeaf = (GeneratedTransferObject) genType;
72                 } else if (genType.getName().equals("UnionLeaf")) {
73                     unionLeaf = (GeneratedTransferObject) genType;
74                 }
75             }
76         }
77
78         assertNotNull("BitLeaf TO builder wasn't found.", bitLeaf);
79         assertNotNull("UnionLeaf TO builder wasn't found.", unionLeaf);
80
81         assertEquals("BitLeaf has incorrect package name.",
82                 "org.opendaylight.yang.gen.v1.urn.bit.union.in.leaf.rev2013626.ParentContainer",
83                 bitLeaf.getPackageName());
84         assertEquals("UnionLeaf has incorrect package name.",
85                 "org.opendaylight.yang.gen.v1.urn.bit.union.in.leaf.rev2013626.ParentContainer",
86                 bitLeaf.getPackageName());
87
88         List<GeneratedProperty> propertiesBitLeaf = bitLeaf.getProperties();
89         GeneratedProperty firstBitProperty = null;
90         GeneratedProperty secondBitProperty = null;
91         GeneratedProperty thirdBitProperty = null;
92         for (GeneratedProperty genProperty : propertiesBitLeaf) {
93             if (genProperty.getName().equals("firstBit")) {
94                 firstBitProperty = genProperty;
95             } else if (genProperty.getName().equals("secondBit")) {
96                 secondBitProperty = genProperty;
97             } else if (genProperty.getName().equals("thirdBit")) {
98                 thirdBitProperty = genProperty;
99             }
100         }
101
102         assertNotNull("firstBit property wasn't found", firstBitProperty);
103         assertNotNull("secondBit property wasn't found", secondBitProperty);
104         assertNotNull("thirdBit property wasn't found", thirdBitProperty);
105
106         assertEquals("firstBit property has incorrect type", "Boolean", firstBitProperty.getReturnType().getName());
107         assertEquals("secondBit property has incorrect type", "Boolean", secondBitProperty.getReturnType().getName());
108         assertEquals("thirdBit property has incorrect type", "Boolean", thirdBitProperty.getReturnType().getName());
109
110         GeneratedProperty uint32Property = null;
111         GeneratedProperty stringProperty = null;
112         GeneratedProperty uint8Property = null;
113         List<GeneratedProperty> propertiesUnionLeaf = unionLeaf.getProperties();
114         for (GeneratedProperty genProperty : propertiesUnionLeaf) {
115             if (genProperty.getName().equals("int32")) {
116                 uint32Property = genProperty;
117             } else if (genProperty.getName().equals("string")) {
118                 stringProperty = genProperty;
119             } else if (genProperty.getName().equals("uint8")) {
120                 uint8Property = genProperty;
121             }
122         }
123
124         assertNotNull("uint32 property wasn't found", uint32Property);
125         assertNotNull("string property wasn't found", stringProperty);
126         assertNotNull("uint8 property wasn't found", uint8Property);
127
128         assertEquals("uint32 property has incorrect type", "Integer", uint32Property.getReturnType().getName());
129         assertEquals("string property has incorrect type", "String", stringProperty.getReturnType().getName());
130         assertEquals("uint8 property has incorrect type", "Short", uint8Property.getReturnType().getName());
131
132     }
133 }