Update BindingRuntime{Context,Generator,Types}
[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.model.api.GeneratedProperty;
17 import org.opendaylight.mdsal.binding.model.api.GeneratedType;
18 import org.opendaylight.mdsal.binding.model.api.Type;
19 import org.opendaylight.mdsal.binding.model.util.Types;
20 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
21
22 public class UnionTypeDefTest {
23     @Test
24     public void unionTypeResolvingTest() {
25         final List<Type> genTypes = DefaultBindingGenerator.generateFor(YangParserTestUtils.parseYangResources(
26             UnionTypeDefTest.class, "/union-test-models/abstract-topology.yang", "/ietf/ietf-inet-types.yang"));
27
28         assertNotNull("genTypes is null", genTypes);
29         assertFalse("genTypes is empty", genTypes.isEmpty());
30
31         // TODO: implement test
32     }
33
34     @Test
35     public void unionTypedefLeafrefTest() {
36         final List<Type> generateTypes = DefaultBindingGenerator.generateFor(YangParserTestUtils.parseYangResource(
37                 "/leafref_typedef_union/bug8449.yang"));
38         assertNotNull(generateTypes);
39         for (final Type type : generateTypes) {
40             if (type.getName().equals("Cont")) {
41                 final GeneratedType gt = (GeneratedType) type;
42                 assertNotNull(gt);
43                 final GeneratedType refType = gt.getEnclosedTypes().iterator().next();
44                 for (final GeneratedProperty generatedProperty : refType.getProperties()) {
45                     switch (generatedProperty.getName()) {
46                         case "stringRefValue":
47                             assertEquals(Types.STRING, generatedProperty.getReturnType());
48                             break;
49                         default:
50                             // ignore
51                     }
52                 }
53             }
54         }
55     }
56 }