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