summaryrefslogtreecommitdiffstats
path: root/netconf/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/json/to/nn/test/JsonLeafrefToNnTest.java
blob: 19bba7b5c97dd834b36158e626e966b578d69238 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
 * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 */
package org.opendaylight.controller.sal.restconf.impl.json.to.nn.test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.io.InputStream;
import javax.ws.rs.core.MediaType;
import org.junit.BeforeClass;
import org.junit.Test;
import org.opendaylight.controller.sal.rest.impl.test.providers.AbstractBodyReaderTest;
import org.opendaylight.netconf.sal.rest.impl.JsonNormalizedNodeBodyReader;
import org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodes;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;

public class JsonLeafrefToNnTest extends AbstractBodyReaderTest {

    private final JsonNormalizedNodeBodyReader jsonBodyReader;
    private static EffectiveModelContext schemaContext;

    public JsonLeafrefToNnTest() {
        super(schemaContext, null);
        this.jsonBodyReader = new JsonNormalizedNodeBodyReader(controllerContext);
    }

    @BeforeClass
    public static void initialize() {
        schemaContext = schemaContextLoader("/json-to-nn/leafref", schemaContext);
    }

    @Test
    public void jsonIdentityrefToNormalizeNode() throws Exception {

        final String uri = "leafref-module:cont";
        mockBodyReader(uri, this.jsonBodyReader, false);
        final InputStream inputStream = this.getClass().getResourceAsStream(
                "/json-to-nn/leafref/json/data.json");

        final NormalizedNodeContext normalizedNodeContext = this.jsonBodyReader.readFrom(
                null, null, null, this.mediaType, null, inputStream);

        assertEquals("cont", normalizedNodeContext.getData().getIdentifier().getNodeType().getLocalName());
        final String dataTree = NormalizedNodes.toStringTree(normalizedNodeContext.getData());
        assertTrue(dataTree.contains("lf2 121"));
    }

    @Override
    protected MediaType getMediaType() {
        return null;
    }
}