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