Bug 2358 - Remove tests json to cnsn and add tests json to nn
[controller.git] / opendaylight / md-sal / sal-rest-connector / 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.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 JsonIdentityrefToNnTest extends AbstractBodyReaderTest {
28
29     private final JsonNormalizedNodeBodyReader jsonBodyReader;
30     private static SchemaContext schemaContext;
31
32     public JsonIdentityrefToNnTest() throws NoSuchFieldException,
33             SecurityException {
34         super();
35         jsonBodyReader = new JsonNormalizedNodeBodyReader();
36     }
37
38     @BeforeClass
39     public static void initialize() {
40         schemaContext = schemaContextLoader("/json-to-nn/identityref",
41                 schemaContext);
42         controllerContext.setSchemas(schemaContext);
43     }
44
45     @Test
46     public void jsonIdentityrefToNn() throws NoSuchFieldException,
47             SecurityException, IllegalArgumentException,
48             IllegalAccessException, WebApplicationException, IOException {
49
50         String uri = "identityref-module:cont";
51         mockBodyReader(uri, jsonBodyReader, false);
52         InputStream inputStream = this.getClass().getResourceAsStream(
53                 "/json-to-nn/identityref/json/data.json");
54
55         NormalizedNodeContext normalizedNodeContext = jsonBodyReader.readFrom(
56                 null, null, null, mediaType, null, inputStream);
57
58         assertEquals("cont", normalizedNodeContext.getData().getNodeType()
59                 .getLocalName());
60
61         String dataTree = NormalizedNodes.toStringTree(normalizedNodeContext
62                 .getData());
63
64         assertTrue(dataTree.contains("cont1"));
65         assertTrue(dataTree
66                 .contains("lf11 (identity:module?revision=2013-12-02)iden"));
67         assertTrue(dataTree
68                 .contains("lf12 (identityref:module?revision=2013-12-02)iden_local"));
69         assertTrue(dataTree
70                 .contains("lf13 (identityref:module?revision=2013-12-02)iden_local"));
71         assertTrue(dataTree
72                 .contains("lf14 (identity:module?revision=2013-12-02)iden"));
73     }
74
75     @Override
76     protected MediaType getMediaType() {
77         // TODO Auto-generated method stub
78         return null;
79     }
80
81 }