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.restconf.common.context.NormalizedNodeContext;
23 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
24 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
26 public class TestXmlBodyWriter extends AbstractBodyReaderTest {
28 private final NormalizedNodeXmlBodyWriter xmlBodyWriter;
29 private static SchemaContext schemaContext;
31 public TestXmlBodyWriter() throws NoSuchFieldException, SecurityException {
33 this.xmlBodyWriter = new NormalizedNodeXmlBodyWriter();
37 protected MediaType getMediaType() {
38 return new MediaType(MediaType.APPLICATION_XML, null);
42 public static void initialization() throws Exception {
43 final Collection<File> testFiles = TestRestconfUtils.loadFiles("/instanceidentifier/yang");
44 testFiles.addAll(TestRestconfUtils.loadFiles("/invoke-rpc"));
45 schemaContext = YangParserTestUtils.parseYangSources(testFiles);
46 CONTROLLER_CONTEXT.setSchemas(schemaContext);
50 public void rpcModuleInputTest() throws Exception {
51 final String uri = "invoke-rpc-module:rpc-test";
52 final String pathToInputFile = "/invoke-rpc/xml/rpc-output.xml";
53 final NormalizedNodeContext nnContext = TestRestconfUtils
54 .loadNormalizedContextFromXmlFile(pathToInputFile, uri);
55 final OutputStream output = new ByteArrayOutputStream();
56 this.xmlBodyWriter.writeTo(nnContext, null, null, null, this.mediaType, null,
58 assertTrue(output.toString().contains("lf-test"));