sal-rest-connector test refactoring
[controller.git] / opendaylight / md-sal / sal-rest-connector / src / test / java / org / opendaylight / controller / sal / restconf / impl / cnsn / to / json / test / CnSnToJsonWithAugmentTest.java
1 package org.opendaylight.controller.sal.restconf.impl.cnsn.to.json.test;
2
3 import static org.junit.Assert.assertNotNull;
4 import static org.junit.Assert.assertTrue;
5
6 import java.io.IOException;
7
8 import javax.ws.rs.WebApplicationException;
9
10 import org.junit.BeforeClass;
11 import org.junit.Test;
12 import org.opendaylight.controller.sal.rest.impl.StructuredDataToJsonProvider;
13 import org.opendaylight.controller.sal.rest.impl.XmlToCompositeNodeProvider;
14 import org.opendaylight.controller.sal.restconf.impl.test.TestUtils;
15 import org.opendaylight.controller.sal.restconf.impl.test.YangAndXmlAndDataSchemaLoader;
16 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
17
18 public class CnSnToJsonWithAugmentTest extends YangAndXmlAndDataSchemaLoader {
19
20     @BeforeClass
21     public static void initialize() {
22         dataLoad("/cnsn-to-json/augmentation", 5, "yang", "cont");
23     }
24
25     /**
26      * Test of json output when as input are specified composite node with empty
27      * data + YANG file
28      */
29     @Test
30     public void augmentedElementsToJson() {
31         CompositeNode compositeNode = TestUtils.readInputToCnSn("/cnsn-to-json/augmentation/xml/data.xml",
32                 XmlToCompositeNodeProvider.INSTANCE);
33         TestUtils.normalizeCompositeNode(compositeNode, modules, searchedModuleName + ":" + searchedDataSchemaName);
34
35         String jsonOutput = null;
36         try {
37             jsonOutput = TestUtils.writeCompNodeWithSchemaContextToOutput(compositeNode, modules, dataSchemaNode,
38                     StructuredDataToJsonProvider.INSTANCE);
39         } catch (WebApplicationException | IOException e) {
40         }
41         assertNotNull(jsonOutput);
42
43         assertTrue(jsonOutput.contains("\"augment-leaf:lf2\": \"lf2\""));
44         assertTrue(jsonOutput.contains("\"augment-container:cont1\": {"));
45         assertTrue(jsonOutput.contains("\"augment-container:lf11\": \"lf11\""));
46         assertTrue(jsonOutput.contains("\"augment-list:lst1\": ["));
47         assertTrue(jsonOutput.contains("\"augment-list:lf11\": \"lf1_1\""));
48         assertTrue(jsonOutput.contains("\"augment-list:lf11\": \"lf1_2\""));
49         assertTrue(jsonOutput.contains("\"augment-leaflist:lflst1\": ["));
50     }
51 }