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;
15 import java.util.List;
16 import org.junit.Test;
17 import org.opendaylight.mdsal.binding.generator.api.BindingGenerator;
18 import org.opendaylight.mdsal.binding.model.api.GeneratedProperty;
19 import org.opendaylight.mdsal.binding.model.api.GeneratedType;
20 import org.opendaylight.mdsal.binding.model.api.Type;
21 import org.opendaylight.mdsal.binding.model.util.Types;
22 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
23 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
25 public class UnionTypeDefTest {
28 public void unionTypeResolvingTest() throws Exception {
29 final File abstractTopology = new File(getClass().getResource("/union-test-models/abstract-topology.yang").toURI());
30 final File ietfInetTypes = new File(getClass().getResource("/ietf/ietf-inet-types.yang").toURI());
31 final SchemaContext context = YangParserTestUtils.parseYangFiles(abstractTopology, ietfInetTypes);
33 assertNotNull("context is null", context);
34 final BindingGenerator bindingGen = new BindingGeneratorImpl(true);
35 final List<Type> genTypes = bindingGen.generateTypes(context);
37 assertNotNull("genTypes is null", genTypes);
38 assertFalse("genTypes is empty", genTypes.isEmpty());
40 // TODO: implement test
44 public void unionTypedefLeafrefTest() throws Exception {
45 final File yang = new File(getClass().getResource("/leafref_typedef_union/bug8449.yang").toURI());
46 final SchemaContext schemaContext = YangParserTestUtils.parseYangFiles(yang);
47 assertNotNull(schemaContext);
48 final List<Type> generateTypes = new BindingGeneratorImpl(false).generateTypes(schemaContext);
49 assertNotNull(generateTypes);
50 for (final Type type : generateTypes) {
51 if (type.getName().equals("Cont")) {
52 final GeneratedType gt = ((GeneratedType) type);
54 final GeneratedType refType = gt.getEnclosedTypes().iterator().next();
55 for (final GeneratedProperty generatedProperty : refType.getProperties()) {
56 switch (generatedProperty.getName()) {
57 case "stringRefValue":
58 assertEquals(Types.STRING, generatedProperty.getReturnType());
61 assertEquals(Types.CHAR_ARRAY, generatedProperty.getReturnType());