2 * Copyright (c) 2017 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
9 package org.opendaylight.mdsal.binding.javav2.generator.impl;
11 import com.google.common.annotations.Beta;
12 import java.io.BufferedReader;
13 import java.io.FileNotFoundException;
14 import java.io.IOException;
15 import java.io.InputStream;
16 import java.io.InputStreamReader;
17 import java.net.URISyntaxException;
19 import org.junit.Assert;
20 import org.junit.Before;
21 import org.junit.Test;
22 import org.opendaylight.mdsal.binding.javav2.generator.impl.txt.yangTemplateForModule;
23 import org.opendaylight.mdsal.binding.javav2.generator.util.YangSnippetCleaner;
24 import org.opendaylight.yangtools.yang.model.api.Module;
25 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
26 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
29 public class YangTemplateTest {
31 private Set<Module> modules;
34 public void setup() throws URISyntaxException, ReactorException, FileNotFoundException {
35 this.modules = YangParserTestUtils.parseYangSources("/yang-template").getModules();
39 public void printYangSnippetForModule() throws Exception{
40 for (final Module module : this.modules) {
43 originalFile = readFile(this.getClass().getResourceAsStream(
44 new StringBuilder("/yang-template/").append(module.getName()).append(".yang").toString()));
45 } catch (final Exception e) {
48 final String moduleBody = yangTemplateForModule.render(module).body().trim();
49 final String cleanedModuleBody = YangSnippetCleaner.clean(moduleBody);
50 Assert.assertEquals(originalFile, cleanedModuleBody);
54 private String readFile(final InputStream inputStream) throws IOException {
55 final BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
57 final StringBuilder sb = new StringBuilder();
58 String line = br.readLine();
60 while (line != null) {