2 * Copyright (c) 2015 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
9 package org.opendaylight.controller.sal.rest.impl.test.providers;
11 import static org.junit.Assert.assertTrue;
13 import java.io.ByteArrayOutputStream;
14 import java.io.InputStream;
15 import java.io.OutputStream;
17 import javax.ws.rs.core.MediaType;
19 import org.junit.BeforeClass;
20 import org.junit.Test;
21 import org.opendaylight.controller.sal.rest.impl.JsonNormalizedNodeBodyReader;
22 import org.opendaylight.controller.sal.rest.impl.NormalizedNodeJsonBodyWriter;
23 import org.opendaylight.controller.sal.restconf.impl.NormalizedNodeContext;
24 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
27 * sal-rest-connector org.opendaylight.controller.sal.rest.impl.test.providers
31 * @author <a href="mailto:vdemcak@cisco.com">Vaclav Demcak</a>
33 * Created: Mar 12, 2015
35 public class TestJsonBodyWriter extends AbstractBodyReaderTest {
37 private final JsonNormalizedNodeBodyReader jsonBodyReader;
38 private final NormalizedNodeJsonBodyWriter jsonBodyWriter;
39 private static SchemaContext schemaContext;
41 public TestJsonBodyWriter() throws NoSuchFieldException, SecurityException {
43 jsonBodyWriter = new NormalizedNodeJsonBodyWriter();
44 jsonBodyReader = new JsonNormalizedNodeBodyReader();
48 protected MediaType getMediaType() {
49 return new MediaType(MediaType.APPLICATION_XML, null);
53 public static void initialization() throws NoSuchFieldException,
55 schemaContext = schemaContextLoader("/instanceidentifier/yang",
57 schemaContext = schemaContextLoader("/modules", schemaContext);
58 schemaContext = schemaContextLoader("/invoke-rpc", schemaContext);
59 controllerContext.setSchemas(schemaContext);
63 public void rpcModuleInputTest() throws Exception {
64 final String uri = "invoke-rpc-module:rpc-test";
65 mockBodyReader(uri, jsonBodyReader, true);
66 final InputStream inputStream = TestJsonBodyWriter.class
67 .getResourceAsStream("/invoke-rpc/json/rpc-output.json");
68 final NormalizedNodeContext returnValue = jsonBodyReader.readFrom(null,
69 null, null, mediaType, null, inputStream);
70 final OutputStream output = new ByteArrayOutputStream();
71 jsonBodyWriter.writeTo(returnValue, null, null, null, mediaType, null,
73 assertTrue(output.toString().contains("lf-test"));