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;
17 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;
24 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
27 * sal-rest-connector org.opendaylight.controller.sal.rest.impl.test.providers
31 * @author <a href="mailto:vdemcak@cisco.com">Vaclav Demcak</a>
33 * Created: Mar 12, 2015
35 public class TestXmlBodyWriter extends AbstractBodyReaderTest {
37 private final NormalizedNodeXmlBodyWriter xmlBodyWriter;
38 private static SchemaContext schemaContext;
40 public TestXmlBodyWriter() throws NoSuchFieldException, SecurityException {
42 this.xmlBodyWriter = new NormalizedNodeXmlBodyWriter();
46 protected MediaType getMediaType() {
47 return new MediaType(MediaType.APPLICATION_XML, null);
51 public static void initialization() throws Exception {
52 final Collection<File> testFiles = TestRestconfUtils.loadFiles("/instanceidentifier/yang");
53 testFiles.addAll(TestRestconfUtils.loadFiles("/modules"));
54 testFiles.addAll(TestRestconfUtils.loadFiles("/invoke-rpc"));
55 schemaContext = YangParserTestUtils.parseYangSources(testFiles);
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 this.xmlBodyWriter.writeTo(nnContext, null, null, null, this.mediaType, null,
68 assertTrue(output.toString().contains("lf-test"));