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.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;
27 public class JsonLeafrefToNnTest extends AbstractBodyReaderTest {
29 private final JsonNormalizedNodeBodyReader jsonBodyReader;
30 private static SchemaContext schemaContext;
32 public JsonLeafrefToNnTest() throws NoSuchFieldException, SecurityException {
34 jsonBodyReader = new JsonNormalizedNodeBodyReader();
38 public static void initialize() {
39 schemaContext = schemaContextLoader("/json-to-nn/leafref",
41 controllerContext.setSchemas(schemaContext);
45 public void jsonIdentityrefToNormalizeNode() throws NoSuchFieldException,
46 SecurityException, IllegalArgumentException,
47 IllegalAccessException, WebApplicationException, IOException {
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");
54 NormalizedNodeContext normalizedNodeContext = jsonBodyReader.readFrom(
55 null, null, null, mediaType, null, inputStream);
57 assertEquals("cont", normalizedNodeContext.getData().getNodeType()
59 String dataTree = NormalizedNodes.toStringTree(normalizedNodeContext
61 assertTrue(dataTree.contains("lf2 121"));
65 protected MediaType getMediaType() {
66 // TODO Auto-generated method stub