f331c478391e5e46038109cc75c6444c2845b0b8
[netconf.git] / restconf / restconf-nb-bierman02 / src / test / java / org / opendaylight / controller / sal / restconf / impl / json / to / nn / test / JsonIdentityrefToNnTest.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.rest.impl.NormalizedNodeContext;
20 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodes;
21 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
22
23 public class JsonIdentityrefToNnTest extends AbstractBodyReaderTest {
24
25     private final JsonNormalizedNodeBodyReader jsonBodyReader;
26     private static EffectiveModelContext schemaContext;
27
28     public JsonIdentityrefToNnTest() {
29         super(schemaContext, null);
30         this.jsonBodyReader = new JsonNormalizedNodeBodyReader(controllerContext);
31     }
32
33     @BeforeClass
34     public static void initialize() {
35         schemaContext = schemaContextLoader("/json-to-nn/identityref", schemaContext);
36     }
37
38     @Test
39     public void jsonIdentityrefToNn() throws Exception {
40
41         final String uri = "identityref-module:cont";
42         mockBodyReader(uri, this.jsonBodyReader, false);
43         final InputStream inputStream = this.getClass().getResourceAsStream(
44                 "/json-to-nn/identityref/json/data.json");
45
46         final NormalizedNodeContext normalizedNodeContext = this.jsonBodyReader.readFrom(
47                 null, null, null, this.mediaType, null, inputStream);
48
49         assertEquals("cont", normalizedNodeContext.getData().getIdentifier().getNodeType().getLocalName());
50
51         final String dataTree = NormalizedNodes.toStringTree(normalizedNodeContext.getData());
52
53         assertTrue(dataTree.contains("cont1"));
54         assertTrue(dataTree
55                 .contains("lf11 (identity:module?revision=2013-12-02)iden"));
56         assertTrue(dataTree
57                 .contains("lf12 (identityref:module?revision=2013-12-02)iden_local"));
58         assertTrue(dataTree
59                 .contains("lf13 (identityref:module?revision=2013-12-02)iden_local"));
60         assertTrue(dataTree
61                 .contains("lf14 (identity:module?revision=2013-12-02)iden"));
62     }
63
64     @Override
65     protected MediaType getMediaType() {
66         return null;
67     }
68 }