Sal-rest-connector unit tests switch to new yang parser.
[netconf.git] / opendaylight / restconf / sal-rest-connector / 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
18 import javax.ws.rs.core.MediaType;
19
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;
26
27 /**
28  * sal-rest-connector org.opendaylight.controller.sal.rest.impl.test.providers
29  *
30  *
31  *
32  * @author <a href="mailto:vdemcak@cisco.com">Vaclav Demcak</a>
33  *
34  *         Created: Mar 12, 2015
35  */
36 public class TestXmlBodyWriter extends AbstractBodyReaderTest {
37
38     private final NormalizedNodeXmlBodyWriter xmlBodyWriter;
39     private static SchemaContext schemaContext;
40
41     public TestXmlBodyWriter() throws NoSuchFieldException, SecurityException {
42         super();
43         xmlBodyWriter = new NormalizedNodeXmlBodyWriter();
44     }
45
46     @Override
47     protected MediaType getMediaType() {
48         return new MediaType(MediaType.APPLICATION_XML, null);
49     }
50
51     @BeforeClass
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);
58     }
59
60     @Test
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,
68                 output);
69         assertTrue(output.toString().contains("lf-test"));
70     }
71 }