2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.mdsal.binding.generator.impl;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertFalse;
12 import static org.junit.Assert.assertNotNull;
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;
23 public class UnionTypeDefTest {
26 public void unionTypeResolvingTest() {
27 final SchemaContext context = YangParserTestUtils.parseYangResources(UnionTypeDefTest.class,
28 "/union-test-models/abstract-topology.yang", "/ietf/ietf-inet-types.yang");
30 assertNotNull("context is null", context);
31 final List<Type> genTypes = DefaultBindingGenerator.generateFor(context);
33 assertNotNull("genTypes is null", genTypes);
34 assertFalse("genTypes is empty", genTypes.isEmpty());
36 // TODO: implement 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;
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());