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 / TestJsonPATCHBodyReader.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 javax.ws.rs.core.MediaType.APPLICATION_JSON;
12
13 import java.io.InputStream;
14 import javax.ws.rs.core.MediaType;
15 import org.junit.BeforeClass;
16 import org.junit.Test;
17 import org.opendaylight.netconf.sal.rest.impl.JsonToPATCHBodyReader;
18 import org.opendaylight.netconf.sal.restconf.impl.PATCHContext;
19 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
20
21 public class TestJsonPATCHBodyReader extends AbstractBodyReaderTest {
22
23     private final JsonToPATCHBodyReader jsonPATCHBodyReader;
24     private static SchemaContext schemaContext;
25
26     public TestJsonPATCHBodyReader() throws NoSuchFieldException, SecurityException {
27         super();
28         jsonPATCHBodyReader = new JsonToPATCHBodyReader();
29     }
30
31     @Override
32     protected MediaType getMediaType() {
33         return new MediaType(APPLICATION_JSON, null);
34     }
35
36     @BeforeClass
37     public static void initialization() {
38         schemaContext = schemaContextLoader("/instanceidentifier/yang", schemaContext);
39         controllerContext.setSchemas(schemaContext);
40     }
41
42     @Test
43     public void modulePATCHDataTest() throws Exception {
44         final String uri = "instance-identifier-patch-module:patch-cont/my-list1/leaf1";
45         mockBodyReader(uri, jsonPATCHBodyReader, false);
46
47         final InputStream inputStream = TestJsonBodyReader.class
48                 .getResourceAsStream("/instanceidentifier/json/jsonPATCHdata.json");
49
50         final PATCHContext returnValue = jsonPATCHBodyReader
51                 .readFrom(null, null, null, mediaType, null, inputStream);
52         checkPATCHContext(returnValue);
53     }
54 }