Propagate grouping inference flag
[mdsal.git] / binding / mdsal-binding-generator-impl / src / test / java / org / opendaylight / mdsal / binding / generator / impl / UnionTypeDefTest.java
1 /*
2  * Copyright (c) 2016 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.mdsal.binding.generator.impl;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertFalse;
12 import static org.junit.Assert.assertNotNull;
13
14 import java.util.List;
15 import org.junit.Test;
16 import org.opendaylight.mdsal.binding.generator.api.BindingGenerator;
17 import org.opendaylight.mdsal.binding.model.api.GeneratedProperty;
18 import org.opendaylight.mdsal.binding.model.api.GeneratedType;
19 import org.opendaylight.mdsal.binding.model.api.Type;
20 import org.opendaylight.mdsal.binding.model.util.Types;
21 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
22 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
23
24 public class UnionTypeDefTest {
25
26     @Test
27     public void unionTypeResolvingTest() {
28         final SchemaContext context = YangParserTestUtils.parseYangResources(UnionTypeDefTest.class,
29             "/union-test-models/abstract-topology.yang", "/ietf/ietf-inet-types.yang");
30
31         assertNotNull("context is null", context);
32         final BindingGenerator bindingGen = new BindingGeneratorImpl();
33         final List<Type> genTypes = bindingGen.generateTypes(context);
34
35         assertNotNull("genTypes is null", genTypes);
36         assertFalse("genTypes is empty", genTypes.isEmpty());
37
38         // TODO: implement test
39     }
40
41     @Test
42     public void unionTypedefLeafrefTest() {
43         final SchemaContext schemaContext = YangParserTestUtils.parseYangResource(
44             "/leafref_typedef_union/bug8449.yang");
45         assertNotNull(schemaContext);
46         final List<Type> generateTypes = new BindingGeneratorImpl().generateTypes(schemaContext);
47         assertNotNull(generateTypes);
48         for (final Type type : generateTypes) {
49             if (type.getName().equals("Cont")) {
50                 final GeneratedType gt = (GeneratedType) type;
51                 assertNotNull(gt);
52                 final GeneratedType refType = gt.getEnclosedTypes().iterator().next();
53                 for (final GeneratedProperty generatedProperty : refType.getProperties()) {
54                     switch (generatedProperty.getName()) {
55                         case "stringRefValue":
56                             assertEquals(Types.STRING, generatedProperty.getReturnType());
57                             break;
58                         default:
59                             // ignore
60                     }
61                 }
62             }
63         }
64     }
65 }