1 package org.opendaylight.yangtools.yang.stmt.test;
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertNotNull;
6 import java.io.IOException;
8 import java.io.FileReader;
9 import java.io.BufferedReader;
12 import org.opendaylight.yangtools.yang.model.api.Module;
13 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
14 import java.net.URISyntaxException;
15 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
16 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
17 import org.junit.Test;
19 public class ModuleSourceTest {
22 public void test() throws SourceException, ReactorException, URISyntaxException, IOException {
23 SchemaContext schema = StmtTestUtils.parseYangSources("/module-source");
25 assertNotNull(schema);
27 Set<Module> modules = schema.getModules();
28 assertNotNull(modules);
29 assertEquals(1,modules.size());
31 Module simpleModule = modules.iterator().next();
32 String source = simpleModule.getSource();
33 String moduleSourcePath = simpleModule.getModuleSourcePath();
35 File simpleYang = new File(getClass().getResource("/module-source/simple-module.yang").toURI());
37 assertEquals(simpleYang.getPath(), moduleSourcePath);
38 assertEquals(readFile(moduleSourcePath), source);
41 private String readFile(String fileName) throws IOException {
42 BufferedReader br = new BufferedReader(new FileReader(fileName));
44 StringBuilder sb = new StringBuilder();
45 String line = br.readLine();
47 while (line != null) {
49 sb.append(System.lineSeparator());