2 * Copyright (c) 2017 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
9 package org.opendaylight.yangtools.yang.data.codec.gson;
11 import static org.junit.Assert.assertNotNull;
12 import static org.opendaylight.yangtools.yang.data.codec.gson.TestUtils.loadTextFile;
14 import com.google.gson.stream.JsonReader;
15 import java.io.IOException;
16 import java.io.StringReader;
17 import java.net.URISyntaxException;
18 import org.junit.Ignore;
19 import org.junit.Test;
20 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
21 import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
22 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNormalizedNodeStreamWriter;
23 import org.opendaylight.yangtools.yang.data.impl.schema.NormalizedNodeResult;
24 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
25 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
27 public class Bug8083Test {
29 @Ignore("Instance-identifier codec has to be modified according to the RFC7951 to correctly parse this.")
31 public void testRFC7951InstanceIdentifierPath() throws IOException, URISyntaxException {
32 final SchemaContext schemaContext = YangParserTestUtils.parseYangResourceDirectory("/bug8083/yang/");
33 final String inputJson = loadTextFile("/bug8083/json/foo.json");
36 final NormalizedNodeResult result = new NormalizedNodeResult();
37 final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
38 final JsonParserStream jsonParser = JsonParserStream.create(streamWriter,
39 JSONCodecFactorySupplier.RFC7951.getShared(schemaContext));
40 jsonParser.parse(new JsonReader(new StringReader(inputJson)));
41 final NormalizedNode<?, ?> transformedInput = result.getResult();
42 assertNotNull(transformedInput);
46 public void testInstanceIdentifierPathWithEmptyListKey() throws IOException, URISyntaxException {
47 final SchemaContext schemaContext = YangParserTestUtils.parseYangResource("/bug8083/yang/baz.yang");
48 final String inputJson = loadTextFile("/bug8083/json/baz.json");
51 final NormalizedNodeResult result = new NormalizedNodeResult();
52 final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
53 final JsonParserStream jsonParser = JsonParserStream.create(streamWriter,
54 JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02.getShared(schemaContext));
55 jsonParser.parse(new JsonReader(new StringReader(inputJson)));
56 final NormalizedNode<?, ?> transformedInput = result.getResult();
57 assertNotNull(transformedInput);
61 public void testInstanceIdentifierPathWithIdentityrefListKey() throws IOException, URISyntaxException {
62 final SchemaContext schemaContext = YangParserTestUtils.parseYangResource("/bug8083/yang/zab.yang");
63 final String inputJson = loadTextFile("/bug8083/json/zab.json");
66 final NormalizedNodeResult result = new NormalizedNodeResult();
67 final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
68 final JsonParserStream jsonParser = JsonParserStream.create(streamWriter,
69 JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02.getShared(schemaContext));
70 jsonParser.parse(new JsonReader(new StringReader(inputJson)));
71 final NormalizedNode<?, ?> transformedInput = result.getResult();
72 assertNotNull(transformedInput);
76 public void testInstanceIdentifierPathWithInstanceIdentifierListKey() throws IOException, URISyntaxException {
77 final SchemaContext schemaContext = YangParserTestUtils.parseYangResource("/bug8083/yang/foobar.yang");
78 final String inputJson = loadTextFile("/bug8083/json/foobar.json");
81 final NormalizedNodeResult result = new NormalizedNodeResult();
82 final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
83 final JsonParserStream jsonParser = JsonParserStream.create(streamWriter,
84 JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02.getShared(schemaContext));
85 jsonParser.parse(new JsonReader(new StringReader(inputJson)));
86 final NormalizedNode<?, ?> transformedInput = result.getResult();
87 assertNotNull(transformedInput);