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.assertTrue;
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;
22 @RunWith(Parameterized.class)
23 public class NetconfStartExiMessageTest {
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" +
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" +
40 "<lexical-values/>\n" +
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);
55 return Arrays.asList(new Object[][]{
56 {noChangeXml, new EXIOptions()},
57 {fullOptionsXml, fullOptions},
61 private final String controlXml;
62 private final EXIOptions exiOptions;
64 public NetconfStartExiMessageTest(final String controlXml, final EXIOptions exiOptions) {
65 this.controlXml = controlXml;
66 this.exiOptions = exiOptions;
70 public void testCreate() throws Exception {
71 final NetconfStartExiMessage startExiMessage = NetconfStartExiMessage.create(exiOptions, "id");
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());