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