Merge "Bug 9092: revert to org.json temporarily"
[netconf.git] / restconf / sal-rest-connector / src / test / java / org / opendaylight / controller / sal / restconf / impl / json / to / nn / test / JsonLeafrefToNnTest.java
1 /*
2  * Copyright (c) 2014 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 package org.opendaylight.controller.sal.restconf.impl.json.to.nn.test;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertTrue;
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.controller.sal.rest.impl.test.providers.AbstractBodyReaderTest;
18 import org.opendaylight.netconf.sal.rest.impl.JsonNormalizedNodeBodyReader;
19 import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
20 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodes;
21 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
22
23 public class JsonLeafrefToNnTest extends AbstractBodyReaderTest {
24
25     private final JsonNormalizedNodeBodyReader jsonBodyReader;
26     private static SchemaContext schemaContext;
27
28     public JsonLeafrefToNnTest() throws NoSuchFieldException, SecurityException {
29         super();
30         this.jsonBodyReader = new JsonNormalizedNodeBodyReader();
31     }
32
33     @BeforeClass
34     public static void initialize() {
35         schemaContext = schemaContextLoader("/json-to-nn/leafref",
36                 schemaContext);
37         CONTROLLER_CONTEXT.setSchemas(schemaContext);
38     }
39
40     @Test
41     public void jsonIdentityrefToNormalizeNode() throws Exception {
42
43         final String uri = "leafref-module:cont";
44         mockBodyReader(uri, this.jsonBodyReader, false);
45         final InputStream inputStream = this.getClass().getResourceAsStream(
46                 "/json-to-nn/leafref/json/data.json");
47
48         final NormalizedNodeContext normalizedNodeContext = this.jsonBodyReader.readFrom(
49                 null, null, null, this.mediaType, null, inputStream);
50
51         assertEquals("cont", normalizedNodeContext.getData().getNodeType()
52                 .getLocalName());
53         final String dataTree = NormalizedNodes.toStringTree(normalizedNodeContext
54                 .getData());
55         assertTrue(dataTree.contains("lf2 121"));
56     }
57
58     @Override
59     protected MediaType getMediaType() {
60         return null;
61     }
62
63 }