96f05fb95364aae09cc9ef5062dde556cff8c2bd
[mdsal.git] / binding2 / mdsal-binding2-generator-impl / src / main / test / java / org / opendaylight / mdsal / binding2 / YangTemplateTest.java
1 /*
2  * Copyright (c) 2016 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
9 package org.opendaylight.mdsal.binding2;
10
11 import com.google.common.annotations.Beta;
12 import java.io.FileNotFoundException;
13 import java.net.URISyntaxException;
14 import java.util.Set;
15 import org.junit.Before;
16 import org.junit.Test;
17 import org.opendaylight.mdsal.binding2.txt.yangTemplateForModule;
18 import org.opendaylight.mdsal.binding2.txt.yangTemplateForNode;
19 import org.opendaylight.mdsal.binding2.txt.yangTemplateForNodes;
20 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
21 import org.opendaylight.yangtools.yang.model.api.Module;
22 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
23 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
24
25 @Beta
26 public class YangTemplateTest {
27
28     private Set<Module> modules;
29
30     @Before
31     public void setup() throws URISyntaxException, ReactorException, FileNotFoundException {
32         modules = YangParserTestUtils.parseYangSources("/yang-template").getModules();
33     }
34
35     @Test
36     public void printYangSnippetForModule() {
37         for (Module module : modules) {
38             /**
39              * We should be able to call Scala render method from Binding Generator implementation
40              * for 3 different inputs:
41              * 1. single SchemaNode
42              * 2. set of SchemaNode
43              * 3. whole Module
44              */
45             final String moduleBody = yangTemplateForModule.render(module).body();
46             //FIXME: don't do it this way, only for very first attempt to show results
47             System.out.println("module ".concat(module.getName()).concat(":").concat(moduleBody));
48
49             //TODO: finish following sections
50             for (DataSchemaNode dataSchemaNode : module.getChildNodes()) {
51                 final String nodeBody = yangTemplateForNode.render(dataSchemaNode).body();
52             }
53
54             final String rpcsBody = yangTemplateForNodes.render(module.getRpcs()).body();
55             final String notificationsBody = yangTemplateForNodes.render(module.getNotifications()).body();
56
57             //////////
58         }
59
60     }
61 }