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 / 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;
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 java.io.File;
15 import java.util.Arrays;
16 import java.util.HashSet;
17 import java.util.List;
18 import java.util.Set;
19
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;
26
27 public class GenTypesSubSetTest {
28
29     @Test
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());
36
37         final SchemaContext context = new YangParserImpl().parseFiles(Arrays.asList(abstractTopology, ietfInterfaces,
38                 ietfInetTypes, ietfYangTypes));
39         Set<Module> modules = context.getModules();
40
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);
47             }
48         }
49
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,
57                 genTypes.size());
58     }
59
60     @Test
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());
68
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();
73
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);
82             }
83         }
84         assertEquals("Set of to Generate Modules must contain 3 modules", 3, toGenModules.size());
85
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());
91     }
92 }