More test for improving of code coverage + 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.restconf.impl.test.TestUtils;
14 import org.opendaylight.controller.sal.restconf.impl.test.YangAndXmlAndDataSchemaLoader;
15 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
16
17 public class CnSnToJsonWithAugmentTest extends YangAndXmlAndDataSchemaLoader {
18
19     @BeforeClass
20     public static void initialize() {
21         dataLoad("/cnsn-to-json/augmentation", 5, "yang", "cont");
22     }
23
24     /**
25      * Test of json output when as input are specified composite node with empty
26      * data + YANG file
27      */
28     @Test
29     public void augmentedElementsToJson() {
30         CompositeNode compositeNode = TestUtils.loadCompositeNode("/cnsn-to-json/augmentation/xml/data.xml");
31         TestUtils.normalizeCompositeNode(compositeNode, modules, searchedModuleName + ":" + searchedDataSchemaName);
32
33         String jsonOutput = null;
34         try {
35             jsonOutput = TestUtils.writeCompNodeWithSchemaContextToOutput(compositeNode, modules, dataSchemaNode,
36                     StructuredDataToJsonProvider.INSTANCE);
37         } catch (WebApplicationException | IOException e) {
38         }
39         assertNotNull(jsonOutput);
40
41         assertTrue(jsonOutput.contains("\"augment-leaf:lf2\": \"lf2\""));
42         assertTrue(jsonOutput.contains("\"augment-container:cont1\": {"));
43         assertTrue(jsonOutput.contains("\"augment-container:lf11\": \"lf11\""));
44         assertTrue(jsonOutput.contains("\"augment-list:lst1\": ["));
45         assertTrue(jsonOutput.contains("\"augment-list:lf11\": \"lf1_1\""));
46         assertTrue(jsonOutput.contains("\"augment-list:lf11\": \"lf1_2\""));
47         assertTrue(jsonOutput.contains("\"augment-leaflist:lflst1\": ["));
48     }
49 }