Bug 6848 - repackage providers for jersey+create xml
[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 import java.io.InputStream;
13 import javax.ws.rs.core.MediaType;
14 import org.junit.BeforeClass;
15 import org.junit.Test;
16 import org.opendaylight.controller.sal.rest.impl.test.providers.AbstractBodyReaderTest;
17 import org.opendaylight.netconf.sal.rest.impl.JsonNormalizedNodeBodyReader;
18 import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
19 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodes;
20 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
21
22 public class JsonLeafrefToNnTest extends AbstractBodyReaderTest {
23
24     private final JsonNormalizedNodeBodyReader jsonBodyReader;
25     private static SchemaContext schemaContext;
26
27     public JsonLeafrefToNnTest() throws NoSuchFieldException, SecurityException {
28         super();
29         this.jsonBodyReader = new JsonNormalizedNodeBodyReader();
30     }
31
32     @BeforeClass
33     public static void initialize() {
34         schemaContext = schemaContextLoader("/json-to-nn/leafref",
35                 schemaContext);
36         controllerContext.setSchemas(schemaContext);
37     }
38
39     @Test
40     public void jsonIdentityrefToNormalizeNode() throws Exception {
41
42         final String uri = "leafref-module:cont";
43         mockBodyReader(uri, this.jsonBodyReader, false);
44         final InputStream inputStream = this.getClass().getResourceAsStream(
45                 "/json-to-nn/leafref/json/data.json");
46
47         final NormalizedNodeContext normalizedNodeContext = this.jsonBodyReader.readFrom(
48                 null, null, null, this.mediaType, null, inputStream);
49
50         assertEquals("cont", normalizedNodeContext.getData().getNodeType()
51                 .getLocalName());
52         final String dataTree = NormalizedNodes.toStringTree(normalizedNodeContext
53                 .getData());
54         assertTrue(dataTree.contains("lf2 121"));
55     }
56
57     @Override
58     protected MediaType getMediaType() {
59         return null;
60     }
61
62 }