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