Remove @Deprecated ClassLoaderUtils as it's now in yangtools.util
[mdsal.git] / binding / mdsal-binding-generator-impl / src / test / java / org / opendaylight / yangtools / sal / binding / generator / impl / stmt / parser / retest / GenTypesSubSetTest.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.sal.binding.generator.impl.stmt.parser.retest;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertFalse;
12 import static org.junit.Assert.assertNotNull;
13
14 import org.opendaylight.yangtools.sal.binding.generator.impl.BindingGeneratorImpl;
15
16 import java.io.File;
17 import java.util.HashSet;
18 import java.util.List;
19 import java.util.Set;
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
26 public class GenTypesSubSetTest {
27
28     @Test
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());
35
36         final SchemaContext context = RetestUtils.parseYangSources(abstractTopology, ietfInterfaces,
37                 ietfInetTypes, ietfYangTypes);
38         Set<Module> modules = context.getModules();
39
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);
46             }
47         }
48
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,
56                 genTypes.size());
57     }
58
59     @Test
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());
67
68         final SchemaContext context = RetestUtils.parseYangSources(abstractTopology, ietfInterfaces,
69                 ietfInetTypes, ietfYangTypes, ianaIfType);
70         assertNotNull("Schema Context is null", context);
71         final Set<Module> modules = context.getModules();
72
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);
81             }
82         }
83         assertEquals("Set of to Generate Modules must contain 3 modules", 3, toGenModules.size());
84
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());
90     }
91 }