Bug 3866: Support for Restconf HTTP Patch
[netconf.git] / opendaylight / restconf / sal-rest-connector / src / test / java / org / opendaylight / controller / sal / rest / impl / test / providers / TestXmlPATCHBodyReader.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 java.io.InputStream;
12 import javax.ws.rs.core.MediaType;
13 import org.junit.BeforeClass;
14 import org.junit.Test;
15 import org.opendaylight.netconf.sal.rest.impl.XmlToPATCHBodyReader;
16 import org.opendaylight.netconf.sal.restconf.impl.PATCHContext;
17 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
18
19 public class TestXmlPATCHBodyReader extends AbstractBodyReaderTest {
20
21     private final XmlToPATCHBodyReader xmlPATCHBodyReader;
22     private static SchemaContext schemaContext;
23
24     public TestXmlPATCHBodyReader() throws NoSuchFieldException, SecurityException {
25         super();
26         xmlPATCHBodyReader = new XmlToPATCHBodyReader();
27     }
28
29     @Override
30     protected MediaType getMediaType() {
31         return new MediaType(MediaType.APPLICATION_XML, null);
32     }
33
34     @BeforeClass
35     public static void initialization() throws NoSuchFieldException, SecurityException {
36         schemaContext = schemaContextLoader("/instanceidentifier/yang", schemaContext);
37         controllerContext.setSchemas(schemaContext);
38     }
39
40     @Test
41     public void moduleDataTest() throws Exception {
42         final String uri = "instance-identifier-patch-module:patch-cont/my-list1/leaf1";
43         mockBodyReader(uri, xmlPATCHBodyReader, false);
44         final InputStream inputStream = TestXmlBodyReader.class
45                 .getResourceAsStream("/instanceidentifier/xml/xmlPATCHdata.xml");
46         final PATCHContext returnValue = xmlPATCHBodyReader
47                 .readFrom(null, null, null, mediaType, null, inputStream);
48         checkPATCHContext(returnValue);
49     }
50 }