Delete netconf
[controller.git] / opendaylight / md-sal / sal-rest-connector / src / test / java / org / opendaylight / controller / sal / rest / impl / test / providers / TestJsonBodyWriter.java
1 /**
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.controller.sal.rest.impl.test.providers;
10
11 import static org.junit.Assert.assertTrue;
12
13 import java.io.ByteArrayOutputStream;
14 import java.io.InputStream;
15 import java.io.OutputStream;
16
17 import javax.ws.rs.core.MediaType;
18
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;
25
26 /**
27  * sal-rest-connector org.opendaylight.controller.sal.rest.impl.test.providers
28  *
29  *
30  *
31  * @author <a href="mailto:vdemcak@cisco.com">Vaclav Demcak</a>
32  *
33  *         Created: Mar 12, 2015
34  */
35 public class TestJsonBodyWriter extends AbstractBodyReaderTest {
36
37     private final JsonNormalizedNodeBodyReader jsonBodyReader;
38     private final NormalizedNodeJsonBodyWriter jsonBodyWriter;
39     private static SchemaContext schemaContext;
40
41     public TestJsonBodyWriter() throws NoSuchFieldException, SecurityException {
42         super();
43         jsonBodyWriter = new NormalizedNodeJsonBodyWriter();
44         jsonBodyReader = new JsonNormalizedNodeBodyReader();
45     }
46
47     @Override
48     protected MediaType getMediaType() {
49         return new MediaType(MediaType.APPLICATION_XML, null);
50     }
51
52     @BeforeClass
53     public static void initialization() throws NoSuchFieldException,
54             SecurityException {
55         schemaContext = schemaContextLoader("/instanceidentifier/yang",
56                 schemaContext);
57         schemaContext = schemaContextLoader("/modules", schemaContext);
58         schemaContext = schemaContextLoader("/invoke-rpc", schemaContext);
59         controllerContext.setSchemas(schemaContext);
60     }
61
62     @Test
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,
72                 output);
73         assertTrue(output.toString().contains("lf-test"));
74     }
75 }