X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fsal%2Fyang-prototype%2Fcode-generator%2Fyang-model-parser-impl%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fyang%2Fparser%2Fimpl%2FYangParserNegativeTest.java;h=0412013405c5ac8c317bb169fe28f359496a26f2;hp=35bfb1bebf449290cd97e58eb1af567bc637b35f;hb=ac39de5a9b96438d30df745895454c02e15e51e3;hpb=ab524667cd77b544066d913757d1e042e4e2afe7 diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/parser/impl/YangParserNegativeTest.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/parser/impl/YangParserNegativeTest.java index 35bfb1bebf..0412013405 100644 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/parser/impl/YangParserNegativeTest.java +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/parser/impl/YangParserNegativeTest.java @@ -13,6 +13,7 @@ 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 org.junit.Test; @@ -24,12 +25,12 @@ public class YangParserNegativeTest { @Test public void testInvalidImport() throws IOException { try { - try (InputStream stream = new FileInputStream(getClass().getResource - ("/negative-scenario/testfile1.yang").getPath())) { + try (InputStream stream = new FileInputStream(getClass().getResource("/negative-scenario/testfile1.yang") + .getPath())) { TestUtils.loadModule(stream); fail("ValidationException should by thrown"); } - } catch(YangValidationException e) { + } catch (YangValidationException e) { assertTrue(e.getMessage().contains("Not existing module imported")); } } @@ -37,13 +38,13 @@ public class YangParserNegativeTest { @Test public void testTypeNotFound() throws IOException { try { - try (InputStream stream = new FileInputStream(getClass().getResource - ("/negative-scenario/testfile2.yang").getPath())) { + try (InputStream stream = new FileInputStream(getClass().getResource("/negative-scenario/testfile2.yang") + .getPath())) { TestUtils.loadModule(stream); fail("YangParseException should by thrown"); } - } catch(YangParseException e) { - assertTrue(e.getMessage().contains("Error in module 'test2' on line 24: Referenced type 'int-ext' not found.")); + } catch (YangParseException e) { + assertEquals(e.getMessage(), "Error in module 'test2' at line 24: Referenced type 'int-ext' not found."); } } @@ -51,19 +52,18 @@ public class YangParserNegativeTest { public void testInvalidAugmentTarget() throws IOException { try { final List streams = new ArrayList<>(2); - try (InputStream testFile0 = new FileInputStream(getClass().getResource - ("/negative-scenario/testfile0.yang").getPath())) { + try (InputStream testFile0 = new FileInputStream(getClass() + .getResource("/negative-scenario/testfile0.yang").getPath())) { streams.add(testFile0); - try (InputStream testFile3 = new FileInputStream(getClass().getResource - ("/negative-scenario/testfile3.yang").getPath())) { + try (InputStream testFile3 = new FileInputStream(getClass().getResource( + "/negative-scenario/testfile3.yang").getPath())) { streams.add(testFile3); - assertEquals("Expected loaded files count is 2", 2, - streams.size()); + assertEquals("Expected loaded files count is 2", 2, streams.size()); TestUtils.loadModules(streams); fail("YangParseException should by thrown"); } } - } catch(YangParseException e) { + } catch (YangParseException e) { assertTrue(e.getMessage().contains("Failed to resolve augments in module 'test3'.")); } } @@ -71,14 +71,128 @@ public class YangParserNegativeTest { @Test public void testInvalidRefine() throws IOException { try { - try (InputStream stream = new FileInputStream(getClass().getResource - ("/negative-scenario/testfile4.yang").getPath())) { + try (InputStream stream = new FileInputStream(getClass().getResource("/negative-scenario/testfile4.yang") + .getPath())) { TestUtils.loadModule(stream); fail("YangParseException should by thrown"); } - } catch(YangParseException e) { + } catch (YangParseException e) { assertTrue(e.getMessage().contains("Can not refine 'presence' for 'node'.")); } } + @Test + public void testInvalidLength() throws IOException { + try { + try (InputStream stream = new FileInputStream(getClass().getResource("/negative-scenario/testfile5.yang") + .getPath())) { + TestUtils.loadModule(stream); + fail("YangParseException should by thrown"); + } + } catch (YangParseException e) { + assertTrue(e.getMessage().contains("Invalid length constraint: <4, 10>")); + } + } + + @Test + public void testInvalidRange() throws IOException { + try { + try (InputStream stream = new FileInputStream(getClass().getResource("/negative-scenario/testfile6.yang") + .getPath())) { + TestUtils.loadModule(stream); + fail("YangParseException should by thrown"); + } + } catch (YangParseException e) { + assertTrue(e.getMessage().contains("Invalid range constraint: <5, 20>")); + } + } + + @Test + public void testDuplicateContainer() throws IOException { + try { + try (InputStream stream = new FileInputStream(getClass().getResource( + "/negative-scenario/duplicity/container.yang").getPath())) { + TestUtils.loadModule(stream); + fail("YangParseException should by thrown"); + } + } catch (YangParseException e) { + String expected = "Error in module 'container' at line 10: Can not add 'container foo': node with same name already declared at line 6"; + assertEquals(expected, e.getMessage()); + } + } + + @Test + public void testDuplicateContainerList() throws IOException { + try { + try (InputStream stream = new FileInputStream(getClass().getResource( + "/negative-scenario/duplicity/container-list.yang").getPath())) { + TestUtils.loadModule(stream); + fail("YangParseException should by thrown"); + } + } catch (YangParseException e) { + String expected = "Error in module 'container-list' at line 10: Can not add 'list foo': node with same name already declared at line 6"; + assertEquals(expected, e.getMessage()); + } + } + + @Test + public void testDuplicateContainerLeaf() throws IOException { + try { + try (InputStream stream = new FileInputStream(getClass().getResource( + "/negative-scenario/duplicity/container-leaf.yang").getPath())) { + TestUtils.loadModule(stream); + fail("YangParseException should by thrown"); + } + } catch (YangParseException e) { + String expected = "Error in module 'container-leaf' at line 10: Can not add 'leaf foo': node with same name already declared at line 6"; + assertEquals(expected, e.getMessage()); + } + } + + @Test + public void testDuplicateTypedef() throws IOException { + try { + try (InputStream stream = new FileInputStream(getClass().getResource( + "/negative-scenario/duplicity/typedef.yang").getPath())) { + TestUtils.loadModule(stream); + fail("YangParseException should by thrown"); + } + } catch (YangParseException e) { + String expected = "Error in module 'typedef' at line 10: typedef with same name 'int-ext' already declared at line 6"; + assertEquals(expected, e.getMessage()); + } + } + + @Test + public void testDuplicityInAugmentTarget1() throws Exception { + try { + try (InputStream stream1 = new FileInputStream(getClass().getResource( + "/negative-scenario/duplicity/augment0.yang").getPath()); + InputStream stream2 = new FileInputStream(getClass().getResource( + "/negative-scenario/duplicity/augment1.yang").getPath())) { + TestUtils.loadModules(Arrays.asList(stream1, stream2)); + fail("YangParseException should by thrown"); + } + } catch (YangParseException e) { + String expected = "Error in module 'augment1' at line 11: Can not add 'leaf id' to node 'bar' in module 'augment0': node with same name already declared at line 9"; + assertEquals(expected, e.getMessage()); + } + } + + @Test + public void testDuplicityInAugmentTarget2() throws Exception { + try { + try (InputStream stream1 = new FileInputStream(getClass().getResource( + "/negative-scenario/duplicity/augment0.yang").getPath()); + InputStream stream2 = new FileInputStream(getClass().getResource( + "/negative-scenario/duplicity/augment2.yang").getPath())) { + TestUtils.loadModules(Arrays.asList(stream1, stream2)); + fail("YangParseException should by thrown"); + } + } catch (YangParseException e) { + String expected = "Error in module 'augment2' at line 11: Can not add 'anyxml delta' to node 'choice-ext' in module 'augment0': case with same name already declared at line 18"; + assertEquals(expected, e.getMessage()); + } + } + }