/* * Copyright (c) 2017 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.yangtools.yang.data.codec.xml; import static org.junit.Assert.assertNotNull; import java.io.InputStream; import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamReader; import org.junit.Ignore; import org.junit.Test; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter; import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNormalizedNodeStreamWriter; import org.opendaylight.yangtools.yang.data.impl.schema.NormalizedNodeResult; import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode; import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; public class Bug8083Test { @Ignore("XMLEmptyCodec needs to be fixed first.") @Test public void testInstanceIdentifierPathWithEmptyListKey() throws Exception { final SchemaContext schemaContext = YangParserTestUtils.parseYangResource("/bug8083/yang/baz.yang"); final Module bazModule = schemaContext.getModules().iterator().next(); final ContainerSchemaNode topCont = (ContainerSchemaNode) bazModule.getDataChildByName( QName.create(bazModule.getQNameModule(), "top-cont")); assertNotNull(topCont); final InputStream resourceAsStream = Bug8083Test.class.getResourceAsStream("/bug8083/xml/baz.xml"); final XMLInputFactory factory = XMLInputFactory.newInstance(); final XMLStreamReader reader = factory.createXMLStreamReader(resourceAsStream); // deserialization final NormalizedNodeResult result = new NormalizedNodeResult(); final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result); final XmlParserStream xmlParser = XmlParserStream.create(streamWriter, schemaContext, topCont); xmlParser.parse(reader); final NormalizedNode transformedInput = result.getResult(); assertNotNull(transformedInput); } @Test public void testInstanceIdentifierPathWithIdentityrefListKey() throws Exception { final SchemaContext schemaContext = YangParserTestUtils.parseYangResource("/bug8083/yang/zab.yang"); final Module zabModule = schemaContext.getModules().iterator().next(); final ContainerSchemaNode topCont = (ContainerSchemaNode) zabModule.getDataChildByName( QName.create(zabModule.getQNameModule(), "top-cont")); assertNotNull(topCont); final InputStream resourceAsStream = Bug8083Test.class.getResourceAsStream("/bug8083/xml/zab.xml"); final XMLInputFactory factory = XMLInputFactory.newInstance(); final XMLStreamReader reader = factory.createXMLStreamReader(resourceAsStream); // deserialization final NormalizedNodeResult result = new NormalizedNodeResult(); final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result); final XmlParserStream xmlParser = XmlParserStream.create(streamWriter, schemaContext, topCont); xmlParser.parse(reader); final NormalizedNode transformedInput = result.getResult(); assertNotNull(transformedInput); } @Test public void testInstanceIdentifierPathWithInstanceIdentifierListKey() throws Exception { final SchemaContext schemaContext = YangParserTestUtils.parseYangResource("/bug8083/yang/foobar.yang"); final Module foobarModule = schemaContext.getModules().iterator().next(); final ContainerSchemaNode topCont = (ContainerSchemaNode) foobarModule.getDataChildByName( QName.create(foobarModule.getQNameModule(), "top-cont")); assertNotNull(topCont); final InputStream resourceAsStream = Bug8083Test.class.getResourceAsStream("/bug8083/xml/foobar.xml"); final XMLInputFactory factory = XMLInputFactory.newInstance(); final XMLStreamReader reader = factory.createXMLStreamReader(resourceAsStream); // deserialization final NormalizedNodeResult result = new NormalizedNodeResult(); final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result); final XmlParserStream xmlParser = XmlParserStream.create(streamWriter, schemaContext, topCont); xmlParser.parse(reader); final NormalizedNode transformedInput = result.getResult(); assertNotNull(transformedInput); } }