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.OutputStream;
16 import javax.ws.rs.core.MediaType;
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;
26 * sal-rest-connector org.opendaylight.controller.sal.rest.impl.test.providers
30 * @author <a href="mailto:vdemcak@cisco.com">Vaclav Demcak</a>
32 * Created: Mar 12, 2015
34 public class TestXmlBodyWriter extends AbstractBodyReaderTest {
36 private final NormalizedNodeXmlBodyWriter xmlBodyWriter;
37 private static SchemaContext schemaContext;
39 public TestXmlBodyWriter() throws NoSuchFieldException, SecurityException {
41 xmlBodyWriter = new NormalizedNodeXmlBodyWriter();
45 protected MediaType getMediaType() {
46 return new MediaType(MediaType.APPLICATION_XML, null);
50 public static void initialization() throws NoSuchFieldException,
52 schemaContext = schemaContextLoader("/instanceidentifier/yang",
54 schemaContext = schemaContextLoader("/modules", schemaContext);
55 schemaContext = schemaContextLoader("/invoke-rpc", schemaContext);
56 controllerContext.setSchemas(schemaContext);
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,
68 assertTrue(output.toString().contains("lf-test"));