2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.sal.restconf.impl.nn.to.json.test;
10 import static org.junit.Assert.assertNotNull;
11 import static org.junit.Assert.assertTrue;
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;
27 public class NnToJsonWithAugmentTest extends AbstractBodyReaderTest {
29 private static EffectiveModelContext schemaContext;
30 private final NormalizedNodeJsonBodyWriter xmlBodyWriter;
32 public NnToJsonWithAugmentTest() {
33 super(schemaContext, null);
34 xmlBodyWriter = new NormalizedNodeJsonBodyWriter();
38 public static void initialize() {
39 schemaContext = schemaContextLoader("/nn-to-json/augmentation", schemaContext);
43 public void augmentedElementsToJson() throws WebApplicationException,
45 final String uri = "yang:cont";
46 final String pathToInputFile = "/nn-to-json/augmentation/xml/data.xml";
48 final NormalizedNodeContext testNN = TestRestconfUtils
49 .loadNormalizedContextFromXmlFile(pathToInputFile, uri, controllerContext);
51 final OutputStream output = new ByteArrayOutputStream();
53 .writeTo(testNN, null, null, null, mediaType, null, output);
54 final String jsonOutput = output.toString();
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\""));
67 protected MediaType getMediaType() {
68 return new MediaType(MediaType.APPLICATION_XML, null);