Merge "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.*;
11
12 import java.io.File;
13 import java.util.ArrayList;
14 import java.util.List;
15 import java.util.Set;
16
17 import org.junit.BeforeClass;
18 import org.junit.Test;
19 import org.opendaylight.controller.sal.binding.generator.api.BindingGenerator;
20 import org.opendaylight.controller.sal.binding.model.api.GeneratedProperty;
21 import org.opendaylight.controller.sal.binding.model.api.GeneratedTransferObject;
22 import org.opendaylight.controller.sal.binding.model.api.GeneratedType;
23 import org.opendaylight.controller.sal.binding.model.api.Type;
24 import org.opendaylight.yangtools.yang.model.api.Module;
25 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
26 import org.opendaylight.yangtools.yang.model.parser.api.YangModelParser;
27 import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl;
28
29 public class BitAndUnionTOEnclosingTest {
30
31     private final static List<File> testModels = new ArrayList<File>();
32
33     @BeforeClass
34     public static void loadTestResources() {
35         final File listModelFile = new File(ExtendedTypedefTest.class.getResource("/bit_and_union_in_leaf.yang")
36                 .getPath());
37         testModels.add(listModelFile);
38     }
39
40     @Test
41     public void bitAndUnionEnclosingTest() {
42         final YangModelParser parser = new YangParserImpl();
43         final Set<Module> modules = parser.parseYangModels(testModels);
44         final SchemaContext context = parser.resolveSchemaContext(modules);
45
46         assertNotNull(context);
47         final BindingGenerator bindingGen = new BindingGeneratorImpl();
48         final List<Type> genTypes = bindingGen.generateTypes(context);
49
50         GeneratedType parentContainer = null;
51
52         for (Type type : genTypes) {
53             if ((type instanceof GeneratedType) && !(type instanceof GeneratedTransferObject)) {
54                 GeneratedType genTO = (GeneratedType) type;
55                 if (genTO.getName().equals("ParentContainer")) {
56                     parentContainer = genTO;
57                     break;
58                 }
59             }
60         }
61
62         assertNotNull("Parent container object wasn't found.", parentContainer);
63
64         GeneratedTransferObject bitLeaf = null;
65         GeneratedTransferObject unionLeaf = null;
66         List<GeneratedType> enclosedTypes = parentContainer.getEnclosedTypes();
67         for (GeneratedType genType : enclosedTypes) {
68             if (genType instanceof GeneratedTransferObject) {
69                 if (genType.getName().equals("BitLeaf")) {
70                     bitLeaf = (GeneratedTransferObject) genType;
71                 } else if (genType.getName().equals("UnionLeaf")) {
72                     unionLeaf = (GeneratedTransferObject) genType;
73                 }
74             }
75         }
76
77         assertNotNull("BitLeaf TO builder wasn't found.", bitLeaf);
78         assertNotNull("UnionLeaf TO builder wasn't found.", unionLeaf);
79
80         assertEquals("BitLeaf has incorrect package name.",
81                 "org.opendaylight.yang.gen.v1.urn.bit.union.in.leaf.rev2013626.ParentContainer",
82                 bitLeaf.getPackageName());
83         assertEquals("UnionLeaf has incorrect package name.",
84                 "org.opendaylight.yang.gen.v1.urn.bit.union.in.leaf.rev2013626.ParentContainer",
85                 bitLeaf.getPackageName());
86
87         List<GeneratedProperty> propertiesBitLeaf = bitLeaf.getProperties();
88         GeneratedProperty firstBitProperty = null;
89         GeneratedProperty secondBitProperty = null;
90         GeneratedProperty thirdBitProperty = null;
91         for (GeneratedProperty genProperty : propertiesBitLeaf) {
92             if (genProperty.getName().equals("firstBit")) {
93                 firstBitProperty = genProperty;
94             } else if (genProperty.getName().equals("secondBit")) {
95                 secondBitProperty = genProperty;
96             } else if (genProperty.getName().equals("thirdBit")) {
97                 thirdBitProperty = genProperty;
98             }
99         }
100
101         assertNotNull("firstBit property wasn't found", firstBitProperty);
102         assertNotNull("secondBit property wasn't found", secondBitProperty);
103         assertNotNull("thirdBit property wasn't found", thirdBitProperty);
104
105         assertEquals("firstBit property has incorrect type", "Boolean", firstBitProperty.getReturnType().getName());
106         assertEquals("secondBit property has incorrect type", "Boolean", secondBitProperty.getReturnType().getName());
107         assertEquals("thirdBit property has incorrect type", "Boolean", thirdBitProperty.getReturnType().getName());
108
109         GeneratedProperty uint32Property = null;
110         GeneratedProperty stringProperty = null;
111         GeneratedProperty uint8Property = null;
112         List<GeneratedProperty> propertiesUnionLeaf = unionLeaf.getProperties();
113         for (GeneratedProperty genProperty : propertiesUnionLeaf) {
114             if (genProperty.getName().equals("int32")) {
115                 uint32Property = genProperty;
116             } else if (genProperty.getName().equals("string")) {
117                 stringProperty = genProperty;
118             } else if (genProperty.getName().equals("uint8")) {
119                 uint8Property = genProperty;
120             }
121         }
122
123         assertNotNull("uint32 property wasn't found", uint32Property);
124         assertNotNull("string property wasn't found", stringProperty);
125         assertNotNull("uint8 property wasn't found", uint8Property);
126
127         assertEquals("uint32 property has incorrect type", "Integer", uint32Property.getReturnType().getName());
128         assertEquals("string property has incorrect type", "String", stringProperty.getReturnType().getName());
129         assertEquals("uint8 property has incorrect type", "Short", uint8Property.getReturnType().getName());
130
131     }
132 }