Add 'features/protocol-framework/' from commit 'cb42405784db97d0ce2c5991d12a89b46d185949'
[netconf.git] / netconf / netconf-netty-util / src / test / java / org / opendaylight / netconf / nettyutil / handler / exi / NetconfStartExiMessageTest.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.netconf.nettyutil.handler.exi;
10
11 import static org.junit.Assert.assertTrue;
12
13 import java.util.Arrays;
14 import org.custommonkey.xmlunit.Diff;
15 import org.custommonkey.xmlunit.XMLUnit;
16 import org.junit.Test;
17 import org.junit.runner.RunWith;
18 import org.junit.runners.Parameterized;
19 import org.openexi.proc.common.AlignmentType;
20 import org.openexi.proc.common.EXIOptions;
21
22 @RunWith(Parameterized.class)
23 public class NetconfStartExiMessageTest {
24
25     @Parameterized.Parameters
26     public static Iterable<Object[]> data() throws Exception {
27         final String noChangeXml = "<rpc xmlns:ns0=\"urn:ietf:params:xml:ns:netconf:base:1.0\" "
28                 + "ns0:message-id=\"id\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n"
29                 + "<start-exi xmlns=\"urn:ietf:params:xml:ns:netconf:exi:1.0\">\n"
30                 + "<alignment>bit-packed</alignment>\n"
31                 + "</start-exi>\n"
32                 + "</rpc>";
33
34
35         final String fullOptionsXml = "<rpc xmlns:ns0=\"urn:ietf:params:xml:ns:netconf:base:1.0\" "
36                 + "ns0:message-id=\"id\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n"
37                 + "<start-exi xmlns=\"urn:ietf:params:xml:ns:netconf:exi:1.0\">\n"
38                 + "<alignment>byte-aligned</alignment>\n"
39                 + "<fidelity>\n"
40                 + "<comments/>\n"
41                 + "<dtd/>\n"
42                 + "<lexical-values/>\n"
43                 + "<pis/>\n"
44                 + "<prefixes/>\n"
45                 + "</fidelity>\n"
46                 + "</start-exi>\n"
47                 + "</rpc>";
48
49         final EXIOptions fullOptions = new EXIOptions();
50         fullOptions.setAlignmentType(AlignmentType.byteAligned);
51         fullOptions.setPreserveLexicalValues(true);
52         fullOptions.setPreserveDTD(true);
53         fullOptions.setPreserveComments(true);
54         fullOptions.setPreserveNS(true);
55         fullOptions.setPreservePIs(true);
56
57         return Arrays.asList(new Object[][]{
58             {noChangeXml, new EXIOptions()},
59             {fullOptionsXml, fullOptions},
60         });
61     }
62
63     private final String controlXml;
64     private final EXIOptions exiOptions;
65
66     public NetconfStartExiMessageTest(final String controlXml, final EXIOptions exiOptions) {
67         this.controlXml = controlXml;
68         this.exiOptions = exiOptions;
69     }
70
71     @Test
72     public void testCreate() throws Exception {
73         final NetconfStartExiMessage startExiMessage = NetconfStartExiMessage.create(exiOptions, "id");
74
75         XMLUnit.setIgnoreWhitespace(true);
76         XMLUnit.setIgnoreAttributeOrder(true);
77         final Diff diff = XMLUnit.compareXML(XMLUnit.buildControlDocument(controlXml), startExiMessage.getDocument());
78         assertTrue(diff.toString(), diff.similar());
79     }
80 }