Merge "Netconf-cli compilable and included in project"
[controller.git] / opendaylight / netconf / netconf-netty-util / src / test / java / org / opendaylight / controller / netconf / nettyutil / handler / exi / EXIParametersTest.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.controller.netconf.nettyutil.handler.exi;
10
11 import static org.junit.Assert.assertEquals;
12
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;
21
22 @RunWith(Parameterized.class)
23 public class EXIParametersTest {
24
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" +
30                 "</start-exi>\n";
31
32
33         final String fullOptionsXml =
34                 "<start-exi xmlns=\"urn:ietf:params:xml:ns:netconf:exi:1.0\">\n" +
35                 "<alignment>byte-aligned</alignment>\n" +
36                 "<fidelity>\n" +
37                 "<comments/>\n" +
38                 "<dtd/>\n" +
39                 "<lexical-values/>\n" +
40                 "<pis/>\n" +
41                 "<prefixes/>\n" +
42                 "</fidelity>\n" +
43                 "</start-exi>\n";
44
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);
52
53         return Arrays.asList(new Object[][]{
54             {noChangeXml, new EXIOptions()},
55             {fullOptionsXml, fullOptions},
56         });
57     }
58
59     private final String sourceXml;
60     private final EXIOptions exiOptions;
61
62     public EXIParametersTest(final String sourceXml, final EXIOptions exiOptions) {
63         this.sourceXml = sourceXml;
64         this.exiOptions = exiOptions;
65     }
66
67     @Test
68     public void testFromXmlElement() throws Exception {
69         final EXIParameters opts =
70                 EXIParameters.fromXmlElement(
71                         XmlElement.fromDomElement(
72                                 XmlUtil.readXmlToElement(sourceXml)));
73
74
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());
81     }
82 }