BUG-1521 Netconf-netty-util missing unit tests
[controller.git] / opendaylight / netconf / netconf-netty-util / src / test / java / org / opendaylight / controller / 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.controller.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\" ns0:message-id=\"id\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" +
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                 "</rpc>";
32
33
34         final String fullOptionsXml = "<rpc xmlns:ns0=\"urn:ietf:params:xml:ns:netconf:base:1.0\" ns0:message-id=\"id\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" +
35                 "<start-exi xmlns=\"urn:ietf:params:xml:ns:netconf:exi:1.0\">\n" +
36                 "<alignment>byte-aligned</alignment>\n" +
37                 "<fidelity>\n" +
38                 "<comments/>\n" +
39                 "<dtd/>\n" +
40                 "<lexical-values/>\n" +
41                 "<pis/>\n" +
42                 "<prefixes/>\n" +
43                 "</fidelity>\n" +
44                 "</start-exi>\n" +
45                 "</rpc>";
46
47         final EXIOptions fullOptions = new EXIOptions();
48         fullOptions.setAlignmentType(AlignmentType.byteAligned);
49         fullOptions.setPreserveLexicalValues(true);
50         fullOptions.setPreserveDTD(true);
51         fullOptions.setPreserveComments(true);
52         fullOptions.setPreserveNS(true);
53         fullOptions.setPreservePIs(true);
54
55         return Arrays.asList(new Object[][]{
56                 {noChangeXml, new EXIOptions()},
57                 {fullOptionsXml, fullOptions},
58         });
59     }
60
61     private final String controlXml;
62     private final EXIOptions exiOptions;
63
64     public NetconfStartExiMessageTest(final String controlXml, final EXIOptions exiOptions) {
65         this.controlXml = controlXml;
66         this.exiOptions = exiOptions;
67     }
68
69     @Test
70     public void testCreate() throws Exception {
71         final NetconfStartExiMessage startExiMessage = NetconfStartExiMessage.create(exiOptions, "id");
72
73         XMLUnit.setIgnoreWhitespace(true);
74         XMLUnit.setIgnoreAttributeOrder(true);
75         final Diff diff = XMLUnit.compareXML(XMLUnit.buildControlDocument(controlXml), startExiMessage.getDocument());
76         assertTrue(diff.toString(), diff.similar());
77     }
78 }