*/
package org.opendaylight.yangtools.yang.parser.impl;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
+import java.io.*;
+import java.util.*;
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;
}
}
} catch (YangParseException e) {
- assertEquals("Error in module 'test3' at line 10: Error in augment parsing: failed to find augment target",
+ assertEquals(
+ "Error in module 'test3' at line 10: Error in augment parsing: failed to find augment target: augment /data:unknown",
e.getMessage());
}
}
}
}
+ @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 linkleaf";
+ 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));
+ }
+ }
+
}