X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-rest-connector%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Frestconf%2Fimpl%2Ftest%2FToJsonChoiceCaseTest.java;h=c5682cb5cc1381eb31c66716a06118aa2e557e48;hb=1257b6b217ae7fb2fca640b5991eac2a0266a93f;hp=141ffdb75467f8db326c03763e83ce4cb2d27b74;hpb=d5096acfd89788c89f26b393abe81bfd65292086;p=controller.git diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/ToJsonChoiceCaseTest.java b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/ToJsonChoiceCaseTest.java index 141ffdb754..c5682cb5cc 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/ToJsonChoiceCaseTest.java +++ b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/ToJsonChoiceCaseTest.java @@ -1,63 +1,71 @@ package org.opendaylight.controller.sal.restconf.impl.test; -import static org.junit.Assert.*; +import static org.junit.Assert.assertTrue; import java.io.IOException; -import java.util.Set; -import javax.activation.UnsupportedDataTypeException; import javax.ws.rs.WebApplicationException; import org.junit.*; -import org.opendaylight.yangtools.yang.model.api.*; -public class ToJsonChoiceCaseTest { - - private static Set modules; - private static DataSchemaNode dataSchemaNode; +public class ToJsonChoiceCaseTest extends YangAndXmlAndDataSchemaLoader { @BeforeClass public static void initialization() { - modules = TestUtils.resolveModules("/yang-to-json-conversion/choice"); - Module module = TestUtils.resolveModule(null, modules); - dataSchemaNode = TestUtils.resolveDataSchemaNode(module, null); - + dataLoad("/yang-to-json-conversion/choice"); } /** - * Test when some data are in one case node and other in another. Exception - * expected!! + * Test when some data are in one case node and other in another. This isn't + * correct. Next Json validator should return error because nodes has to be + * from one case below concrete choice. + * */ @Test - public void compNodeDataOnVariousChoiceCasePathTest() { - boolean exceptionCatched = false; + public void nodeSchemasOnVariousChoiceCasePathTest() { try { TestUtils.writeCompNodeWithSchemaContextToJson( - TestUtils.loadCompositeNode("/yang-to-json-conversion/choice/xml/data_various_path.xml"), + TestUtils.loadCompositeNode("/yang-to-json-conversion/choice/xml/data_various_path_err.xml"), "/yang-to-json-conversion/choice/xml", modules, dataSchemaNode); - } catch (UnsupportedDataTypeException e) { - exceptionCatched = true; - } catch (WebApplicationException | IOException e) { // shouldn't end here assertTrue(false); } + } - assertTrue(exceptionCatched); - + /** + * Test when some data are in one case node and other in another. + * Additionally data are loadef from various choices. This isn't correct. + * Next Json validator should return error because nodes has to be from one + * case below concrete choice. + * + */ + @Test + public void nodeSchemasOnVariousChoiceCasePathAndMultipleChoicesTest() { + try { + TestUtils + .writeCompNodeWithSchemaContextToJson( + TestUtils + .loadCompositeNode("/yang-to-json-conversion/choice/xml/data_more_choices_same_level_various_paths_err.xml"), + "/yang-to-json-conversion/choice/xml", modules, dataSchemaNode); + } catch (WebApplicationException | IOException e) { + // shouldn't end here + assertTrue(false); + } } /** * Test when second level data are red first, then first and at the end * third level. Level represents pass through couple choice-case */ - @Ignore + @Test - public void compNodeDataWithRandomOrderAccordingLevel() { + public void nodeSchemasWithRandomOrderAccordingLevel() { try { - String jsonOutput = TestUtils.writeCompNodeWithSchemaContextToJson( + TestUtils.writeCompNodeWithSchemaContextToJson( TestUtils.loadCompositeNode("/yang-to-json-conversion/choice/xml/data_random_level.xml"), "/yang-to-json-conversion/choice/xml", modules, dataSchemaNode); + } catch (WebApplicationException | IOException e) { // shouldn't end here assertTrue(false); @@ -67,11 +75,10 @@ public class ToJsonChoiceCaseTest { /** * Test when element from no first case is used */ - @Ignore @Test - public void compNodeDataNoFirstCase() { + public void nodeSchemasNotInFirstCase() { try { - String jsonOutput = TestUtils.writeCompNodeWithSchemaContextToJson( + TestUtils.writeCompNodeWithSchemaContextToJson( TestUtils.loadCompositeNode("/yang-to-json-conversion/choice/xml/data_no_first_case.xml"), "/yang-to-json-conversion/choice/xml", modules, dataSchemaNode); } catch (WebApplicationException | IOException e) { @@ -83,11 +90,10 @@ public class ToJsonChoiceCaseTest { /** * Test when element in case is list */ - @Ignore @Test - public void compNodeDataAsList() { + public void nodeSchemaAsList() { try { - String jsonOutput = TestUtils.writeCompNodeWithSchemaContextToJson( + TestUtils.writeCompNodeWithSchemaContextToJson( TestUtils.loadCompositeNode("/yang-to-json-conversion/choice/xml/data_list.xml"), "/yang-to-json-conversion/choice/xml", modules, dataSchemaNode); } catch (WebApplicationException | IOException e) { @@ -99,11 +105,10 @@ public class ToJsonChoiceCaseTest { /** * Test when element in case is container */ - @Ignore @Test - public void compNodeDataAsContainer() { + public void nodeSchemaAsContainer() { try { - String jsonOutput = TestUtils.writeCompNodeWithSchemaContextToJson( + TestUtils.writeCompNodeWithSchemaContextToJson( TestUtils.loadCompositeNode("/yang-to-json-conversion/choice/xml/data_container.xml"), "/yang-to-json-conversion/choice/xml", modules, dataSchemaNode); } catch (WebApplicationException | IOException e) { @@ -113,13 +118,12 @@ public class ToJsonChoiceCaseTest { } /** - * Test when element in case is container + * Test when element in case is leaflist */ - @Ignore @Test - public void compNodeDataAsLeafList() { + public void nodeSchemaAsLeafList() { try { - String jsonOutput = TestUtils.writeCompNodeWithSchemaContextToJson( + TestUtils.writeCompNodeWithSchemaContextToJson( TestUtils.loadCompositeNode("/yang-to-json-conversion/choice/xml/data_leaflist.xml"), "/yang-to-json-conversion/choice/xml", modules, dataSchemaNode); } catch (WebApplicationException | IOException e) { @@ -128,4 +132,50 @@ public class ToJsonChoiceCaseTest { } } + /** + * + */ + @Test + public void nodeSchemasInMultipleChoicesTest() { + try { + TestUtils + .writeCompNodeWithSchemaContextToJson(TestUtils + .loadCompositeNode("/yang-to-json-conversion/choice/xml/data_more_choices_same_level.xml"), + "/yang-to-json-conversion/choice/xml", modules, dataSchemaNode); + } catch (WebApplicationException | IOException e) { + // shouldn't end here + assertTrue(false); + } + } + + /** + * Test whether is possible to find data schema for node which is specified + * as dirrect subnode of choice (case without CASE key word) + */ + @Test + public void nodeSchemasInCaseNotDefinedWithCaseKeyword() { + try { + TestUtils.writeCompNodeWithSchemaContextToJson(TestUtils + .loadCompositeNode("/yang-to-json-conversion/choice/xml/data_case_defined_without_case.xml"), + "/yang-to-json-conversion/choice/xml", modules, dataSchemaNode); + } catch (WebApplicationException | IOException e) { + // shouldn't end here + assertTrue(false); + } + } + + /** + * Test of multiple use of choices + */ + @Test + public void nodeSchemasInThreeChoicesAtSameLevel() { + try { + TestUtils.writeCompNodeWithSchemaContextToJson(TestUtils + .loadCompositeNode("/yang-to-json-conversion/choice/xml/data_three_choices_same_level.xml"), + "/yang-to-json-conversion/choice/xml", modules, dataSchemaNode); + } catch (WebApplicationException | IOException e) { + // shouldn't end here + assertTrue(false); + } + } }