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
9 package org.opendaylight.controller.xml.codec;
11 import com.google.common.collect.Lists;
12 import com.google.common.io.ByteSource;
13 import java.io.IOException;
14 import java.io.InputStream;
15 import java.util.ArrayList;
16 import javax.xml.parsers.DocumentBuilderFactory;
17 import org.junit.Before;
18 import org.opendaylight.yangtools.yang.model.api.Module;
19 import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
20 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
21 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
22 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
23 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
25 // FIXME : CompositeNode is not avaliable anymore so fix the test to use NormalizedNodeContainer ASAP
26 public class XmlUtilsTest {
28 private static final DocumentBuilderFactory BUILDERFACTORY;
31 final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
32 factory.setNamespaceAware(true);
33 factory.setCoalescing(true);
34 factory.setIgnoringElementContentWhitespace(true);
35 factory.setIgnoringComments(true);
36 BUILDERFACTORY = factory;
39 private SchemaContext schemaContext;
40 private RpcDefinition testRpc;
42 public static final String XML_CONTENT = "<add-flow xmlns=\"urn:opendaylight:controller:rpc:test\"><input xmlns=\"urn:opendaylight:controller:rpc:test\">" +
44 "<flow xmlns:ltha=\"urn:opendaylight:controller:rpc:test\">/ltha:node/ltha:node1[ltha:id='3@java.lang.Short']</flow>" +
45 "</input></add-flow>";
48 public void setUp() throws Exception {
49 final ByteSource byteSource = new ByteSource() {
51 public InputStream openStream() throws IOException {
52 return XmlUtilsTest.this.getClass().getResourceAsStream("rpcTest.yang");
56 final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
57 final ArrayList<ByteSource> sources = Lists.newArrayList(byteSource);
61 schemaContext = reactor.buildEffective(sources);
62 } catch (ReactorException e) {
63 throw new RuntimeException("Unable to build schema context from " + sources, e);
66 final Module rpcTestModule = schemaContext.getModules().iterator().next();
67 testRpc = rpcTestModule.getRpcs().iterator().next();