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