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;
12 import java.io.ByteArrayOutputStream;
13 import java.io.InputStream;
14 import java.io.OutputStream;
15 import javax.ws.rs.core.MediaType;
16 import org.junit.BeforeClass;
17 import org.junit.Test;
18 import org.opendaylight.controller.sal.rest.impl.JsonNormalizedNodeBodyReader;
19 import org.opendaylight.controller.sal.rest.impl.NormalizedNodeJsonBodyWriter;
20 import org.opendaylight.controller.sal.restconf.impl.NormalizedNodeContext;
21 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
25 * org.opendaylight.controller.sal.rest.impl.test.providers
29 * @author <a href="mailto:vdemcak@cisco.com">Vaclav Demcak</a>
31 * Created: Mar 12, 2015
33 public class TestJsonBodyWriter extends AbstractBodyReaderTest {
35 private final JsonNormalizedNodeBodyReader jsonBodyReader;
36 private final NormalizedNodeJsonBodyWriter jsonBodyWriter;
37 private static SchemaContext schemaContext;
39 public TestJsonBodyWriter () throws NoSuchFieldException, SecurityException {
41 jsonBodyWriter = new NormalizedNodeJsonBodyWriter();
42 jsonBodyReader = new JsonNormalizedNodeBodyReader();
46 MediaType getMediaType() {
47 return new MediaType(MediaType.APPLICATION_XML, null);
51 public static void initialization() throws NoSuchFieldException, SecurityException {
52 schemaContext = schemaContextLoader("/instanceidentifier/yang", schemaContext);
53 schemaContext = schemaContextLoader("/modules", schemaContext);
54 schemaContext = schemaContextLoader("/invoke-rpc", schemaContext);
55 controllerContext.setSchemas(schemaContext);
59 public void rpcModuleInputTest() throws Exception {
60 final String uri = "invoke-rpc-module:rpc-test";
61 mockBodyReader(uri, jsonBodyReader, true);
62 final InputStream inputStream = TestJsonBodyWriter.class
63 .getResourceAsStream("/invoke-rpc/json/rpc-output.json");
64 final NormalizedNodeContext returnValue = jsonBodyReader
65 .readFrom(null, null, null, mediaType, null, inputStream);
66 final OutputStream output = new ByteArrayOutputStream();
67 jsonBodyWriter.writeTo(returnValue, null, null, null, mediaType, null, output);
68 assertTrue(output.toString().contains("lf-test"));