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.HashSet;
16 import java.util.List;
18 import org.junit.Test;
19 import org.opendaylight.mdsal.binding.generator.api.BindingGenerator;
20 import org.opendaylight.mdsal.binding.generator.impl.BindingGeneratorImpl;
21 import org.opendaylight.mdsal.binding.model.api.Type;
22 import org.opendaylight.yangtools.yang.model.api.Module;
23 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
24 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
26 public class GenTypesSubSetTest {
29 public void genTypesFromSubsetOfTwoModulesTest() throws Exception {
30 File abstractTopology = new File(getClass().getResource(
31 "/leafref-test-models/abstract-topology@2013-02-08.yang").toURI());
32 File ietfInterfaces = new File(getClass().getResource("/ietf/ietf-interfaces.yang").toURI());
33 File ietfInetTypes = new File(getClass().getResource("/ietf/ietf-inet-types.yang").toURI());
34 File ietfYangTypes = new File(getClass().getResource("/ietf/ietf-yang-types.yang").toURI());
36 final SchemaContext context = YangParserTestUtils.parseYangSources(abstractTopology, ietfInterfaces,
37 ietfInetTypes, ietfYangTypes);
38 Set<Module> modules = context.getModules();
40 final Set<Module> toGenModules = new HashSet<>();
41 for (final Module module : modules) {
42 if (module.getName().equals("abstract-topology")) {
43 toGenModules.add(module);
44 } else if (module.getName().equals("ietf-interfaces")) {
45 toGenModules.add(module);
49 assertEquals("Set of to Generate Modules must contain 2 modules", 2, toGenModules.size());
50 assertNotNull("Schema Context is null", context);
51 final BindingGenerator bindingGen = new BindingGeneratorImpl(true);
52 final List<Type> genTypes = bindingGen.generateTypes(context, toGenModules);
53 assertNotNull("genTypes is null", genTypes);
54 assertFalse("genTypes is empty", genTypes.isEmpty());
55 assertEquals("Expected Generated Types from provided sub set of " + "modules should be 23!", 23,
60 public void genTypesFromSubsetOfThreeModulesTest() throws Exception {
61 File abstractTopology = new File(getClass().getResource(
62 "/leafref-test-models/abstract-topology@2013-02-08.yang").toURI());
63 File ietfInterfaces = new File(getClass().getResource("/ietf/ietf-interfaces.yang").toURI());
64 File ietfInetTypes = new File(getClass().getResource("/ietf/ietf-inet-types.yang").toURI());
65 File ietfYangTypes = new File(getClass().getResource("/ietf/ietf-yang-types.yang").toURI());
66 File ianaIfType = new File(getClass().getResource("/ietf/iana-if-type.yang").toURI());
68 final SchemaContext context = YangParserTestUtils.parseYangSources(abstractTopology, ietfInterfaces,
69 ietfInetTypes, ietfYangTypes, ianaIfType);
70 assertNotNull("Schema Context is null", context);
71 final Set<Module> modules = context.getModules();
73 final Set<Module> toGenModules = new HashSet<>();
74 for (final Module module : modules) {
75 if (module.getName().equals("abstract-topology")) {
76 toGenModules.add(module);
77 } else if (module.getName().equals("ietf-interfaces")) {
78 toGenModules.add(module);
79 } else if (module.getName().equals("iana-if-type")) {
80 toGenModules.add(module);
83 assertEquals("Set of to Generate Modules must contain 3 modules", 3, toGenModules.size());
85 final BindingGenerator bindingGen = new BindingGeneratorImpl(true);
86 final List<Type> genTypes = bindingGen.generateTypes(context, toGenModules);
87 assertNotNull("genTypes is null", genTypes);
88 assertFalse("genTypes is empty", genTypes.isEmpty());
89 assertEquals("Expected Generated Types", 24, genTypes.size());