summaryrefslogtreecommitdiffstats
path: root/netconf/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/nn/to/json/test/NnToJsonWithAugmentTest.java
blob: d97b246dc0aa3070133cde1019151ccca6f887b2 (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
59
60
61
62
63
64
65
66
67
68
69
70
/*
 * 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.nn.to.json.test;

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

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import org.junit.BeforeClass;
import org.junit.Test;
import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils;
import org.opendaylight.controller.sal.rest.impl.test.providers.AbstractBodyReaderTest;
import org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext;
import org.opendaylight.netconf.sal.rest.impl.NormalizedNodeJsonBodyWriter;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;

@Deprecated
public class NnToJsonWithAugmentTest extends AbstractBodyReaderTest {

    private static EffectiveModelContext schemaContext;
    private final NormalizedNodeJsonBodyWriter xmlBodyWriter;

    public NnToJsonWithAugmentTest() {
        super(schemaContext, null);
        xmlBodyWriter = new NormalizedNodeJsonBodyWriter();
    }

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

    @Test
    public void augmentedElementsToJson() throws WebApplicationException,
            IOException {
        final String uri = "yang:cont";
        final String pathToInputFile = "/nn-to-json/augmentation/xml/data.xml";

        final NormalizedNodeContext testNN = TestRestconfUtils
                .loadNormalizedContextFromXmlFile(pathToInputFile, uri, controllerContext);

        final OutputStream output = new ByteArrayOutputStream();
        xmlBodyWriter
                .writeTo(testNN, null, null, null, mediaType, null, output);
        final String jsonOutput = output.toString();

        assertNotNull(jsonOutput);
        assertTrue(jsonOutput.contains("\"cont1\"" + ":" + '{'));
        assertTrue(jsonOutput.contains("\"lf11\"" + ":" + "\"lf11\""));
        assertTrue(jsonOutput.contains("\"lst1\"" + ":" + '['));
        assertTrue(jsonOutput.contains("\"lf11\"" + ":" + "\"lf1_1\""));
        assertTrue(jsonOutput.contains("\"lf11\"" + ":" + "\"lf1_2\""));
        assertTrue(jsonOutput.contains("\"lflst1\"" + ":" + "["));
        assertTrue(jsonOutput.contains("\"lf2\"" + ":" + "\"lf2\""));
    }

    @Override
    protected MediaType getMediaType() {
        return new MediaType(MediaType.APPLICATION_XML, null);
    }
}