d97b246dc0aa3070133cde1019151ccca6f887b2
[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.assertNotNull;
11 import static org.junit.Assert.assertTrue;
12
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.NormalizedNodeContext;
23 import org.opendaylight.netconf.sal.rest.impl.NormalizedNodeJsonBodyWriter;
24 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
25
26 @Deprecated
27 public class NnToJsonWithAugmentTest extends AbstractBodyReaderTest {
28
29     private static EffectiveModelContext schemaContext;
30     private final NormalizedNodeJsonBodyWriter xmlBodyWriter;
31
32     public NnToJsonWithAugmentTest() {
33         super(schemaContext, null);
34         xmlBodyWriter = new NormalizedNodeJsonBodyWriter();
35     }
36
37     @BeforeClass
38     public static void initialize() {
39         schemaContext = schemaContextLoader("/nn-to-json/augmentation", schemaContext);
40     }
41
42     @Test
43     public void augmentedElementsToJson() throws WebApplicationException,
44             IOException {
45         final String uri = "yang:cont";
46         final String pathToInputFile = "/nn-to-json/augmentation/xml/data.xml";
47
48         final NormalizedNodeContext testNN = TestRestconfUtils
49                 .loadNormalizedContextFromXmlFile(pathToInputFile, uri, controllerContext);
50
51         final OutputStream output = new ByteArrayOutputStream();
52         xmlBodyWriter
53                 .writeTo(testNN, null, null, null, mediaType, null, output);
54         final String jsonOutput = output.toString();
55
56         assertNotNull(jsonOutput);
57         assertTrue(jsonOutput.contains("\"cont1\"" + ":" + '{'));
58         assertTrue(jsonOutput.contains("\"lf11\"" + ":" + "\"lf11\""));
59         assertTrue(jsonOutput.contains("\"lst1\"" + ":" + '['));
60         assertTrue(jsonOutput.contains("\"lf11\"" + ":" + "\"lf1_1\""));
61         assertTrue(jsonOutput.contains("\"lf11\"" + ":" + "\"lf1_2\""));
62         assertTrue(jsonOutput.contains("\"lflst1\"" + ":" + "["));
63         assertTrue(jsonOutput.contains("\"lf2\"" + ":" + "\"lf2\""));
64     }
65
66     @Override
67     protected MediaType getMediaType() {
68         return new MediaType(MediaType.APPLICATION_XML, null);
69     }
70 }