Migrate netconf-netty-util to xmlunit-core
[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 package org.opendaylight.netconf.nettyutil.handler.exi;
9
10 import static org.junit.Assert.assertFalse;
11
12 import org.junit.Test;
13 import org.opendaylight.netconf.shaded.exificient.core.CodingMode;
14 import org.opendaylight.netconf.shaded.exificient.core.FidelityOptions;
15 import org.xmlunit.builder.DiffBuilder;
16
17 public class NetconfStartExiMessageTest {
18     @Test
19     public void testCreateEmpty() {
20         assertCreate("""
21               <rpc message-id="id" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
22               <start-exi xmlns="urn:ietf:params:xml:ns:netconf:exi:1.0">
23                 <alignment>bit-packed</alignment>
24               </start-exi>
25             </rpc>""", EXIParameters.empty());
26     }
27
28     @Test
29     public void testCreateFull() throws Exception {
30         final var fullOptions = FidelityOptions.createDefault();
31         fullOptions.setFidelity(FidelityOptions.FEATURE_LEXICAL_VALUE, true);
32         fullOptions.setFidelity(FidelityOptions.FEATURE_DTD, true);
33         fullOptions.setFidelity(FidelityOptions.FEATURE_COMMENT, true);
34         fullOptions.setFidelity(FidelityOptions.FEATURE_PREFIX, true);
35         fullOptions.setFidelity(FidelityOptions.FEATURE_PI, true);
36
37         assertCreate("""
38               <rpc message-id="id" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
39                 <start-exi xmlns="urn:ietf:params:xml:ns:netconf:exi:1.0">
40                   <alignment>byte-aligned</alignment>
41                   <fidelity>
42                     <comments/>
43                     <dtd/>
44                     <lexical-values/>
45                     <pis/>
46                     <prefixes/>
47                   </fidelity>
48                 </start-exi>
49               </rpc>""", new EXIParameters(CodingMode.BYTE_PACKED, fullOptions));
50     }
51
52     private static void assertCreate(final String control, final EXIParameters exiOptions) {
53         final var startExiMessage = NetconfStartExiMessageProvider.create(exiOptions, "id");
54
55         final var diff = DiffBuilder.compare(control)
56             .withTest(startExiMessage.getDocument())
57             .ignoreWhitespace()
58             .checkForIdentical()
59             .build();
60         assertFalse(diff.toString(), diff.hasDifferences());
61     }
62
63 }