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.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;
24 public class UnionTypeDefTest {
27 public void unionTypeResolvingTest() {
28 final SchemaContext context = YangParserTestUtils.parseYangResources(UnionTypeDefTest.class,
29 "/union-test-models/abstract-topology.yang", "/ietf/ietf-inet-types.yang");
31 assertNotNull("context is null", context);
32 final BindingGenerator bindingGen = new BindingGeneratorImpl();
33 final List<Type> genTypes = bindingGen.generateTypes(context);
35 assertNotNull("genTypes is null", genTypes);
36 assertFalse("genTypes is empty", genTypes.isEmpty());
38 // TODO: implement 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;
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());