b3a45bd970e021605bc283a441ea4d456aca6817
[netconf.git] / opendaylight / restconf / sal-rest-connector / src / test / java / org / opendaylight / controller / sal / rest / impl / test / providers / TestXmlBodyWriter.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.OutputStream;
15
16 import javax.ws.rs.core.MediaType;
17
18 import org.junit.BeforeClass;
19 import org.junit.Test;
20 import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils;
21 import org.opendaylight.netconf.sal.rest.impl.NormalizedNodeXmlBodyWriter;
22 import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
23 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
24
25 /**
26  * sal-rest-connector org.opendaylight.controller.sal.rest.impl.test.providers
27  *
28  *
29  *
30  * @author <a href="mailto:vdemcak@cisco.com">Vaclav Demcak</a>
31  *
32  *         Created: Mar 12, 2015
33  */
34 public class TestXmlBodyWriter extends AbstractBodyReaderTest {
35
36     private final NormalizedNodeXmlBodyWriter xmlBodyWriter;
37     private static SchemaContext schemaContext;
38
39     public TestXmlBodyWriter() throws NoSuchFieldException, SecurityException {
40         super();
41         xmlBodyWriter = new NormalizedNodeXmlBodyWriter();
42     }
43
44     @Override
45     protected MediaType getMediaType() {
46         return new MediaType(MediaType.APPLICATION_XML, null);
47     }
48
49     @BeforeClass
50     public static void initialization() throws NoSuchFieldException,
51             SecurityException {
52         schemaContext = schemaContextLoader("/instanceidentifier/yang",
53                 schemaContext);
54         schemaContext = schemaContextLoader("/modules", schemaContext);
55         schemaContext = schemaContextLoader("/invoke-rpc", schemaContext);
56         controllerContext.setSchemas(schemaContext);
57     }
58
59     @Test
60     public void rpcModuleInputTest() throws Exception {
61         final String uri = "invoke-rpc-module:rpc-test";
62         final String pathToInputFile = "/invoke-rpc/xml/rpc-output.xml";
63         final NormalizedNodeContext nnContext = TestRestconfUtils
64                 .loadNormalizedContextFromXmlFile(pathToInputFile, uri);
65         final OutputStream output = new ByteArrayOutputStream();
66         xmlBodyWriter.writeTo(nnContext, null, null, null, mediaType, null,
67                 output);
68         assertTrue(output.toString().contains("lf-test"));
69     }
70 }