Merge "Bug 9092: revert to org.json temporarily"
[netconf.git] / restconf / restconf-nb-bierman02 / src / test / java / org / opendaylight / controller / sal / restconf / impl / nn / to / json / test / NnToJsonWithAugmentTest.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.nn.to.json.test;
9
10 import static org.junit.Assert.assertTrue;
11
12 import com.google.common.base.Preconditions;
13 import java.io.ByteArrayOutputStream;
14 import java.io.IOException;
15 import java.io.OutputStream;
16 import javax.ws.rs.WebApplicationException;
17 import javax.ws.rs.core.MediaType;
18 import org.junit.BeforeClass;
19 import org.junit.Test;
20 import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils;
21 import org.opendaylight.controller.sal.rest.impl.test.providers.AbstractBodyReaderTest;
22 import org.opendaylight.netconf.sal.rest.impl.NormalizedNodeJsonBodyWriter;
23 import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
24 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
25
26 @Deprecated
27 public class NnToJsonWithAugmentTest extends AbstractBodyReaderTest {
28
29     private static SchemaContext schemaContext;
30     private final NormalizedNodeJsonBodyWriter xmlBodyWriter;
31
32     public NnToJsonWithAugmentTest() throws NoSuchFieldException,
33             SecurityException {
34         super();
35         xmlBodyWriter = new NormalizedNodeJsonBodyWriter();
36     }
37
38     @BeforeClass
39     public static void initialize() {
40         schemaContext = schemaContextLoader("/nn-to-json/augmentation",
41                 schemaContext);
42         CONTROLLER_CONTEXT.setSchemas(schemaContext);
43     }
44
45     @Test
46     public void augmentedElementsToJson() throws WebApplicationException,
47             IOException {
48         final String uri = "yang:cont";
49         final String pathToInputFile = "/nn-to-json/augmentation/xml/data.xml";
50
51         final NormalizedNodeContext testNN = TestRestconfUtils
52                 .loadNormalizedContextFromXmlFile(pathToInputFile, uri);
53
54         final OutputStream output = new ByteArrayOutputStream();
55         xmlBodyWriter
56                 .writeTo(testNN, null, null, null, mediaType, null, output);
57         final String jsonOutput = output.toString();
58
59         Preconditions.checkNotNull(jsonOutput);
60
61         assertTrue(jsonOutput.contains("\"cont1\"" + ":" + '{'));
62         assertTrue(jsonOutput.contains("\"lf11\"" + ":" + "\"lf11\""));
63         assertTrue(jsonOutput.contains("\"lst1\"" + ":" + '['));
64         assertTrue(jsonOutput.contains("\"lf11\"" + ":" + "\"lf1_1\""));
65         assertTrue(jsonOutput.contains("\"lf11\"" + ":" + "\"lf1_2\""));
66         assertTrue(jsonOutput.contains("\"lflst1\"" + ":" + "["));
67         assertTrue(jsonOutput.contains("\"lf2\"" + ":" + "\"lf2\""));
68     }
69
70     @Override
71     protected MediaType getMediaType() {
72         return new MediaType(MediaType.APPLICATION_XML, null);
73     }
74 }