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