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.assertTrue;
11 import com.google.common.base.Preconditions;
12 import java.io.ByteArrayOutputStream;
13 import java.io.IOException;
14 import java.io.OutputStream;
15 import javax.ws.rs.WebApplicationException;
16 import javax.ws.rs.core.MediaType;
17 import org.junit.BeforeClass;
18 import org.junit.Test;
19 import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils;
20 import org.opendaylight.netconf.sal.rest.impl.NormalizedNodeJsonBodyWriter;
21 import org.opendaylight.controller.sal.rest.impl.test.providers.AbstractBodyReaderTest;
22 import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
23 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
25 public class NnToJsonWithAugmentTest extends AbstractBodyReaderTest {
27 private static SchemaContext schemaContext;
28 private final NormalizedNodeJsonBodyWriter xmlBodyWriter;
30 public NnToJsonWithAugmentTest() throws NoSuchFieldException,
33 xmlBodyWriter = new NormalizedNodeJsonBodyWriter();
37 public static void initialize() {
38 schemaContext = schemaContextLoader("/nn-to-json/augmentation",
40 controllerContext.setSchemas(schemaContext);
44 public void augmentedElementsToJson() throws WebApplicationException,
46 final String uri = "yang:cont";
47 final String pathToInputFile = "/nn-to-json/augmentation/xml/data.xml";
49 final NormalizedNodeContext testNN = TestRestconfUtils
50 .loadNormalizedContextFromXmlFile(pathToInputFile, uri);
52 final OutputStream output = new ByteArrayOutputStream();
54 .writeTo(testNN, null, null, null, mediaType, null, output);
55 final String jsonOutput = output.toString();
57 Preconditions.checkNotNull(jsonOutput);
59 assertTrue(jsonOutput.contains("\"cont1\"" + ":" + '{'));
60 assertTrue(jsonOutput.contains("\"lf11\"" + ":" + "\"lf11\""));
61 assertTrue(jsonOutput.contains("\"lst1\"" + ":" + '['));
62 assertTrue(jsonOutput.contains("\"lf11\"" + ":" + "\"lf1_1\""));
63 assertTrue(jsonOutput.contains("\"lf11\"" + ":" + "\"lf1_2\""));
64 assertTrue(jsonOutput.contains("\"lflst1\"" + ":" + "["));
65 assertTrue(jsonOutput.contains("\"lf2\"" + ":" + "\"lf2\""));
69 protected MediaType getMediaType() {
70 return new MediaType(MediaType.APPLICATION_XML, null);