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;
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.restconf.common.context.NormalizedNodeContext;
24 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
27 public class NnToJsonWithAugmentTest extends AbstractBodyReaderTest {
29 private static SchemaContext schemaContext;
30 private final NormalizedNodeJsonBodyWriter xmlBodyWriter;
32 public NnToJsonWithAugmentTest() throws NoSuchFieldException,
35 xmlBodyWriter = new NormalizedNodeJsonBodyWriter();
39 public static void initialize() {
40 schemaContext = schemaContextLoader("/nn-to-json/augmentation",
42 CONTROLLER_CONTEXT.setSchemas(schemaContext);
46 public void augmentedElementsToJson() throws WebApplicationException,
48 final String uri = "yang:cont";
49 final String pathToInputFile = "/nn-to-json/augmentation/xml/data.xml";
51 final NormalizedNodeContext testNN = TestRestconfUtils
52 .loadNormalizedContextFromXmlFile(pathToInputFile, uri);
54 final OutputStream output = new ByteArrayOutputStream();
56 .writeTo(testNN, null, null, null, mediaType, null, output);
57 final String jsonOutput = output.toString();
59 Preconditions.checkNotNull(jsonOutput);
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\""));
71 protected MediaType getMediaType() {
72 return new MediaType(MediaType.APPLICATION_XML, null);