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