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.netconf.nettyutil.handler.exi;
11 import static org.junit.Assert.assertEquals;
13 import java.util.Arrays;
14 import org.junit.Test;
15 import org.junit.runner.RunWith;
16 import org.junit.runners.Parameterized;
17 import org.opendaylight.controller.netconf.util.xml.XmlElement;
18 import org.opendaylight.controller.netconf.util.xml.XmlUtil;
19 import org.openexi.proc.common.AlignmentType;
20 import org.openexi.proc.common.EXIOptions;
22 @RunWith(Parameterized.class)
23 public class EXIParametersTest {
25 @Parameterized.Parameters
26 public static Iterable<Object[]> data() throws Exception {
27 final String noChangeXml =
28 "<start-exi xmlns=\"urn:ietf:params:xml:ns:netconf:exi:1.0\">\n" +
29 "<alignment>bit-packed</alignment>\n" +
33 final String fullOptionsXml =
34 "<start-exi xmlns=\"urn:ietf:params:xml:ns:netconf:exi:1.0\">\n" +
35 "<alignment>byte-aligned</alignment>\n" +
39 "<lexical-values/>\n" +
45 final EXIOptions fullOptions = new EXIOptions();
46 fullOptions.setAlignmentType(AlignmentType.byteAligned);
47 fullOptions.setPreserveLexicalValues(true);
48 fullOptions.setPreserveDTD(true);
49 fullOptions.setPreserveComments(true);
50 fullOptions.setPreserveNS(true);
51 fullOptions.setPreservePIs(true);
53 return Arrays.asList(new Object[][]{
54 {noChangeXml, new EXIOptions()},
55 {fullOptionsXml, fullOptions},
59 private final String sourceXml;
60 private final EXIOptions exiOptions;
62 public EXIParametersTest(final String sourceXml, final EXIOptions exiOptions) {
63 this.sourceXml = sourceXml;
64 this.exiOptions = exiOptions;
68 public void testFromXmlElement() throws Exception {
69 final EXIParameters opts =
70 EXIParameters.fromXmlElement(
71 XmlElement.fromDomElement(
72 XmlUtil.readXmlToElement(sourceXml)));
75 assertEquals(opts.getOptions().getAlignmentType(), exiOptions.getAlignmentType());
76 assertEquals(opts.getOptions().getPreserveComments(), exiOptions.getPreserveComments());
77 assertEquals(opts.getOptions().getPreserveLexicalValues(), exiOptions.getPreserveLexicalValues());
78 assertEquals(opts.getOptions().getPreserveNS(), exiOptions.getPreserveNS());
79 assertEquals(opts.getOptions().getPreserveDTD(), exiOptions.getPreserveDTD());
80 assertEquals(opts.getOptions().getPreserveNS(), exiOptions.getPreserveNS());