169d8062e52f770927b02394ceb2a576835733a6
[netconf.git] / restconf / restconf-nb-bierman02 / 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
13 import java.io.ByteArrayOutputStream;
14 import java.io.File;
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.NormalizedNodeContext;
22 import org.opendaylight.netconf.sal.rest.impl.NormalizedNodeXmlBodyWriter;
23 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
24 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
25
26 public class TestXmlBodyWriter extends AbstractBodyReaderTest {
27
28     private final NormalizedNodeXmlBodyWriter xmlBodyWriter;
29     private static EffectiveModelContext schemaContext;
30
31     public TestXmlBodyWriter() {
32         super(schemaContext, null);
33         this.xmlBodyWriter = new NormalizedNodeXmlBodyWriter();
34     }
35
36     @Override
37     protected MediaType getMediaType() {
38         return new MediaType(MediaType.APPLICATION_XML, null);
39     }
40
41     @BeforeClass
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.parseYangFiles(testFiles);
46     }
47
48     @Test
49     public void rpcModuleInputTest() throws Exception {
50         final String uri = "invoke-rpc-module:rpc-test";
51         final String pathToInputFile = "/invoke-rpc/xml/rpc-output.xml";
52         final NormalizedNodeContext nnContext = TestRestconfUtils
53                 .loadNormalizedContextFromXmlFile(pathToInputFile, uri, controllerContext);
54         final OutputStream output = new ByteArrayOutputStream();
55         this.xmlBodyWriter.writeTo(nnContext, null, null, null, this.mediaType, null, output);
56         assertTrue(output.toString().contains("lf-test"));
57     }
58 }