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;
15 import java.io.OutputStream;
16 import java.util.Collection;
18 import javax.ws.rs.core.MediaType;
20 import org.junit.BeforeClass;
21 import org.junit.Test;
22 import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils;
23 import org.opendaylight.netconf.sal.rest.impl.NormalizedNodeXmlBodyWriter;
24 import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
25 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
28 * sal-rest-connector org.opendaylight.controller.sal.rest.impl.test.providers
32 * @author <a href="mailto:vdemcak@cisco.com">Vaclav Demcak</a>
34 * Created: Mar 12, 2015
36 public class TestXmlBodyWriter extends AbstractBodyReaderTest {
38 private final NormalizedNodeXmlBodyWriter xmlBodyWriter;
39 private static SchemaContext schemaContext;
41 public TestXmlBodyWriter() throws NoSuchFieldException, SecurityException {
43 xmlBodyWriter = new NormalizedNodeXmlBodyWriter();
47 protected MediaType getMediaType() {
48 return new MediaType(MediaType.APPLICATION_XML, null);
52 public static void initialization() throws Exception {
53 Collection<File> testFiles = TestRestconfUtils.loadFiles("/instanceidentifier/yang");
54 testFiles.addAll(TestRestconfUtils.loadFiles("/modules"));
55 testFiles.addAll(TestRestconfUtils.loadFiles("/invoke-rpc"));
56 schemaContext = TestRestconfUtils.parseYangSources(testFiles);
57 controllerContext.setSchemas(schemaContext);
61 public void rpcModuleInputTest() throws Exception {
62 final String uri = "invoke-rpc-module:rpc-test";
63 final String pathToInputFile = "/invoke-rpc/xml/rpc-output.xml";
64 final NormalizedNodeContext nnContext = TestRestconfUtils
65 .loadNormalizedContextFromXmlFile(pathToInputFile, uri);
66 final OutputStream output = new ByteArrayOutputStream();
67 xmlBodyWriter.writeTo(nnContext, null, null, null, mediaType, null,
69 assertTrue(output.toString().contains("lf-test"));