Merge "Bug 1125: Added regression test"
[controller.git] / opendaylight / md-sal / sal-rest-connector / src / test / java / org / opendaylight / controller / sal / restconf / impl / cnsn / to / json / test / CnSnToJsonWithAugmentTest.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.sal.restconf.impl.cnsn.to.json.test;
9
10 import static org.junit.Assert.assertNotNull;
11 import static org.junit.Assert.assertTrue;
12 import static org.opendaylight.controller.sal.restconf.impl.test.TestUtils.containsStringData;
13
14 import java.io.IOException;
15 import javax.ws.rs.WebApplicationException;
16 import org.junit.BeforeClass;
17 import org.junit.Test;
18 import org.opendaylight.controller.sal.rest.impl.StructuredDataToJsonProvider;
19 import org.opendaylight.controller.sal.rest.impl.XmlToCompositeNodeProvider;
20 import org.opendaylight.controller.sal.restconf.impl.test.TestUtils;
21 import org.opendaylight.controller.sal.restconf.impl.test.YangAndXmlAndDataSchemaLoader;
22 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
23
24 public class CnSnToJsonWithAugmentTest extends YangAndXmlAndDataSchemaLoader {
25
26     @BeforeClass
27     public static void initialize() {
28         dataLoad("/cnsn-to-json/augmentation", 5, "yang", "cont");
29     }
30
31     /**
32      * Test of json output when as input are specified composite node with empty data + YANG file
33      */
34     @Test
35     public void augmentedElementsToJson() {
36         CompositeNode compositeNode = TestUtils.readInputToCnSn("/cnsn-to-json/augmentation/xml/data.xml",
37                 XmlToCompositeNodeProvider.INSTANCE);
38         TestUtils.normalizeCompositeNode(compositeNode, modules, searchedModuleName + ":" + searchedDataSchemaName);
39
40         String jsonOutput = null;
41         try {
42             jsonOutput = TestUtils.writeCompNodeWithSchemaContextToOutput(compositeNode, modules, dataSchemaNode,
43                     StructuredDataToJsonProvider.INSTANCE);
44         } catch (WebApplicationException | IOException e) {
45         }
46         assertNotNull(jsonOutput);
47
48         assertTrue(containsStringData(jsonOutput, "\"augment-leaf:lf2\"", ":", "\"lf2\""));
49         assertTrue(containsStringData(jsonOutput, "\"augment-container:cont1\"", ":", "\\{"));
50         assertTrue(containsStringData(jsonOutput, "\"augment-container:lf11\"", ":", "\"lf11\""));
51         assertTrue(containsStringData(jsonOutput, "\"augment-list:lst1\"", ":", "\\["));
52         assertTrue(containsStringData(jsonOutput, "\"augment-list:lf11\"", ":", "\"lf1_1\""));
53         assertTrue(containsStringData(jsonOutput, "\"augment-list:lf11\"", ":", "\"lf1_2\""));
54         assertTrue(containsStringData(jsonOutput, "\"augment-leaflist:lflst1\"", ":", "\\["));
55     }
56 }