2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.sal.restconf.impl.json.to.nn.test;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertTrue;
13 import java.io.IOException;
14 import java.io.InputStream;
16 import javax.ws.rs.WebApplicationException;
17 import javax.ws.rs.core.MediaType;
19 import org.junit.BeforeClass;
20 import org.junit.Test;
21 import org.opendaylight.netconf.sal.rest.impl.JsonNormalizedNodeBodyReader;
22 import org.opendaylight.controller.sal.rest.impl.test.providers.AbstractBodyReaderTest;
23 import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
24 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodes;
25 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
27 public class JsonIdentityrefToNnTest extends AbstractBodyReaderTest {
29 private final JsonNormalizedNodeBodyReader jsonBodyReader;
30 private static SchemaContext schemaContext;
32 public JsonIdentityrefToNnTest() throws NoSuchFieldException,
35 jsonBodyReader = new JsonNormalizedNodeBodyReader();
39 public static void initialize() {
40 schemaContext = schemaContextLoader("/json-to-nn/identityref",
42 controllerContext.setSchemas(schemaContext);
46 public void jsonIdentityrefToNn() throws NoSuchFieldException,
47 SecurityException, IllegalArgumentException,
48 IllegalAccessException, WebApplicationException, IOException {
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");
55 NormalizedNodeContext normalizedNodeContext = jsonBodyReader.readFrom(
56 null, null, null, mediaType, null, inputStream);
58 assertEquals("cont", normalizedNodeContext.getData().getNodeType()
61 String dataTree = NormalizedNodes.toStringTree(normalizedNodeContext
64 assertTrue(dataTree.contains("cont1"));
66 .contains("lf11 (identity:module?revision=2013-12-02)iden"));
68 .contains("lf12 (identityref:module?revision=2013-12-02)iden_local"));
70 .contains("lf13 (identityref:module?revision=2013-12-02)iden_local"));
72 .contains("lf14 (identity:module?revision=2013-12-02)iden"));
76 protected MediaType getMediaType() {
77 // TODO Auto-generated method stub