import static org.junit.Assert.*;
+import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import org.junit.Test;
+import org.opendaylight.yangtools.yang.model.parser.api.YangModelParser;
import org.opendaylight.yangtools.yang.parser.util.YangParseException;
import org.opendaylight.yangtools.yang.parser.util.YangValidationException;
}
}
+ @Test
+ public void testMandatoryInAugment() throws IOException {
+ try {
+ try (InputStream stream1 = new FileInputStream(getClass().getResource("/negative-scenario/testfile8.yang")
+ .getPath());
+ InputStream stream2 = new FileInputStream(getClass().getResource(
+ "/negative-scenario/testfile7.yang").getPath())) {
+ TestUtils.loadModules(Arrays.asList(stream1, stream2));
+ fail("YangParseException should by thrown");
+ }
+ } catch (YangParseException e) {
+ String expected = "Error in module 'testfile7' at line 18: Error in augment parsing: cannot augment mandatory node";
+ assertEquals(expected, e.getMessage());
+ }
+ }
+
+ @Test
+ public void testWrongDependenciesDir() throws Exception {
+ try {
+ File yangFile = new File(getClass().getResource("/types/custom-types-test@2012-4-4.yang").getPath());
+ File dependenciesDir = new File("/invalid");
+ YangModelParser parser = new YangParserImpl();
+ parser.parseYangModels(yangFile, dependenciesDir);
+ fail("Exception should by thrown");
+ } catch (IllegalStateException e) {
+ String expected = File.separator + "invalid does not exists";
+ assertEquals(expected, e.getMessage());
+ }
+ }
+
+ @Test
+ public void testWrongDependenciesDir2() throws Exception {
+ try {
+ File yangFile = new File(getClass().getResource("/types/custom-types-test@2012-4-4.yang").getPath());
+ File dependenciesDir = new File(getClass().getResource("/model").getPath());
+ YangModelParser parser = new YangParserImpl();
+ parser.parseYangModels(yangFile, dependenciesDir);
+ fail("Exception should by thrown");
+ } catch (YangValidationException e) {
+ String expected = "Not existing module imported";
+ assertTrue(e.getMessage().contains(expected));
+ }
+ }
+
}