Remove NetconfMessageConstants 86/101886/4
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 28 Jul 2022 20:43:57 +0000 (22:43 +0200)
committerRobert Varga <nite@hq.sk>
Fri, 29 Jul 2022 07:04:37 +0000 (07:04 +0000)
MessageParts are really something related to FramingMechanism, without
much further value. Get rid of it by moving interesting constants to
FramingMechanism.

Change-Id: I1e92dbc771876a53c12e8f60f4beed35de747529
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
netconf/netconf-impl/src/test/java/org/opendaylight/netconf/impl/MessageParserTest.java
netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/handler/MessageParts.java
netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/messages/FramingMechanism.java
netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/messages/NetconfMessageConstants.java [deleted file]

index 82c42dcb29fa59c0c9022737f087f92878a9b185..88f4f1133726a3e8877fab7ccc3be161a5048b81 100644 (file)
@@ -32,7 +32,6 @@ import org.opendaylight.netconf.nettyutil.handler.NetconfEOMAggregator;
 import org.opendaylight.netconf.nettyutil.handler.NetconfMessageToXMLEncoder;
 import org.opendaylight.netconf.nettyutil.handler.NetconfXMLToMessageDecoder;
 import org.opendaylight.netconf.util.messages.FramingMechanism;
-import org.opendaylight.netconf.util.messages.NetconfMessageConstants;
 import org.opendaylight.netconf.util.test.XmlFileLoader;
 
 public class MessageParserTest {
@@ -41,7 +40,7 @@ public class MessageParserTest {
 
     @Before
     public void setUp() throws Exception {
-        this.msg = XmlFileLoader.xmlFileToNetconfMessage("netconfMessages/getConfig.xml");
+        msg = XmlFileLoader.xmlFileToNetconfMessage("netconfMessages/getConfig.xml");
     }
 
     @Test
@@ -53,7 +52,7 @@ public class MessageParserTest {
                 new NetconfChunkAggregator(),
                 new NetconfXMLToMessageDecoder());
 
-        testChunkChannel.writeOutbound(this.msg);
+        testChunkChannel.writeOutbound(msg);
         Queue<Object> messages = testChunkChannel.outboundMessages();
         assertFalse(messages.isEmpty());
 
@@ -67,7 +66,7 @@ public class MessageParserTest {
             chunkCount++;
         }
 
-        byte[] endOfChunkBytes = NetconfMessageConstants.END_OF_CHUNK.getBytes(StandardCharsets.UTF_8);
+        byte[] endOfChunkBytes = FramingMechanism.CHUNK_END_STR.getBytes(StandardCharsets.US_ASCII);
         for (int i = 1; i <= chunkCount; i++) {
             ByteBuf recievedOutbound = (ByteBuf) messages.poll();
             int exptHeaderLength = ChunkedFramingMechanismEncoder.DEFAULT_CHUNK_SIZE;
@@ -78,8 +77,7 @@ public class MessageParserTest {
                 assertArrayEquals(endOfChunkBytes, eom);
             }
 
-            byte[] header = new byte[String.valueOf(exptHeaderLength).length()
-                    + NetconfMessageConstants.MIN_HEADER_LENGTH - 1];
+            byte[] header = new byte[String.valueOf(exptHeaderLength).length() + 3];
             recievedOutbound.getBytes(0, header);
             assertEquals(exptHeaderLength, getHeaderLength(header));
 
@@ -90,7 +88,7 @@ public class MessageParserTest {
         NetconfMessage receivedMessage = testChunkChannel.readInbound();
         assertNotNull(receivedMessage);
         XMLUnit.setIgnoreWhitespace(true);
-        assertXMLEqual(this.msg.getDocument(), receivedMessage.getDocument());
+        assertXMLEqual(msg.getDocument(), receivedMessage.getDocument());
     }
 
     @Test
@@ -99,10 +97,10 @@ public class MessageParserTest {
                 FramingMechanismHandlerFactory.createHandler(FramingMechanism.EOM),
                 new NetconfMessageToXMLEncoder(), new NetconfEOMAggregator(), new NetconfXMLToMessageDecoder());
 
-        testChunkChannel.writeOutbound(this.msg);
+        testChunkChannel.writeOutbound(msg);
         ByteBuf recievedOutbound = testChunkChannel.readOutbound();
 
-        byte[] endOfMsgBytes = NetconfMessageConstants.END_OF_MESSAGE.getBytes(StandardCharsets.UTF_8);
+        byte[] endOfMsgBytes = FramingMechanism.EOM_STR.getBytes(StandardCharsets.US_ASCII);
         byte[] eom = new byte[endOfMsgBytes.length];
         recievedOutbound.getBytes(recievedOutbound.readableBytes() - endOfMsgBytes.length, eom);
         assertArrayEquals(endOfMsgBytes, eom);
@@ -111,7 +109,7 @@ public class MessageParserTest {
         NetconfMessage receivedMessage = testChunkChannel.readInbound();
         assertNotNull(receivedMessage);
         XMLUnit.setIgnoreWhitespace(true);
-        assertXMLEqual(this.msg.getDocument(), receivedMessage.getDocument());
+        assertXMLEqual(msg.getDocument(), receivedMessage.getDocument());
     }
 
     private static long getHeaderLength(final byte[] bytes) {
index fb21b7f8c2a956d545062e42ef75aa3d1deee04a..2921a84796dc995b907a73700c422e315fc62e1c 100644 (file)
@@ -12,7 +12,7 @@ import java.nio.CharBuffer;
 import java.nio.charset.CharacterCodingException;
 import java.nio.charset.CodingErrorAction;
 import java.nio.charset.StandardCharsets;
-import org.opendaylight.netconf.util.messages.NetconfMessageConstants;
+import org.opendaylight.netconf.util.messages.FramingMechanism;
 
 /**
  * netconf message part constants as bytes.
@@ -20,9 +20,9 @@ import org.opendaylight.netconf.util.messages.NetconfMessageConstants;
  * @author Thomas Pantelis
  */
 final class MessageParts {
-    static final byte[] END_OF_MESSAGE = asciiBytes(NetconfMessageConstants.END_OF_MESSAGE);
-    static final byte[] START_OF_CHUNK = asciiBytes(NetconfMessageConstants.START_OF_CHUNK);
-    static final byte[] END_OF_CHUNK = asciiBytes(NetconfMessageConstants.END_OF_CHUNK);
+    static final byte[] END_OF_MESSAGE = asciiBytes(FramingMechanism.EOM_STR);
+    static final byte[] START_OF_CHUNK = asciiBytes(FramingMechanism.CHUNK_START_STR);
+    static final byte[] END_OF_CHUNK = asciiBytes(FramingMechanism.CHUNK_END_STR);
 
     private MessageParts() {
         // Hidden on purpose
index ae7d7472e94217191d0b8303ed4f5707a96c32ae..3d5680cbda56ddf126c2057bf7bb2dc7262a1d54 100644 (file)
@@ -5,26 +5,36 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.netconf.util.messages;
 
+import org.eclipse.jdt.annotation.NonNullByDefault;
+
 /**
  * Known NETCONF framing mechanisms.
  */
+@NonNullByDefault
 public enum FramingMechanism {
     /**
-     * Chunked framing mechanism.
-     *
-     * @see <a href="http://tools.ietf.org/html/rfc6242#section-4.2">Chunked
-     *      framing mechanism</a>
+     * Chunk framing mechanism, as defined in
+     * <a href="https://tools.ietf.org/html/rfc6242#section-4.2">RFC6242 Section 4.2</a>.
      */
     CHUNK,
     /**
-     * End-of-Message framing mechanism.
-     *
-     * @see <a
-     *      href="http://tools.ietf.org/html/rfc6242#section-4.3">End-of-message
-     *      framing mechanism</a>
+     * End-of-Message framing mechanism, as defined in
+     * <a href="https://tools.ietf.org/html/rfc6242#section-4.3">RFC6242 Section 4.3</a>.
+     */
+    EOM;
+
+    /**
+     * String literal for a start of chunk, i.e. {@code LF HASH} part of {@code chunk} ABNF.
+     */
+    public static final String CHUNK_START_STR = "\n#";
+    /**
+     * String representing the end of a chunk, i.e. the {@code LF HASH HASH LF} production {@code end-of-chunks} ABNF.
+     */
+    public static final String CHUNK_END_STR = "\n##\n";
+    /**
+     * String representing the End-Of-Message delimiter.
      */
-    EOM
+    public static final String EOM_STR = "]]>]]>";
 }
diff --git a/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/messages/NetconfMessageConstants.java b/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/messages/NetconfMessageConstants.java
deleted file mode 100644 (file)
index db23875..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.netconf.util.messages;
-
-import org.eclipse.jdt.annotation.NonNullByDefault;
-
-@NonNullByDefault
-public final class NetconfMessageConstants {
-    /**
-     * The NETCONF 1.0 old-style message separator. This is framing mechanism is used by default.
-     */
-    public static final String END_OF_MESSAGE = "]]>]]>";
-
-    // bytes
-    @Deprecated(since = "3.0.6", forRemoval = true)
-    public static final int MIN_HEADER_LENGTH = 4;
-
-    // bytes
-    @Deprecated(since = "3.0.6", forRemoval = true)
-    public static final int MAX_HEADER_LENGTH = 13;
-
-    public static final String START_OF_CHUNK = "\n#";
-    public static final String END_OF_CHUNK = "\n##\n";
-
-    private NetconfMessageConstants() {
-        // Hidden on purpose
-    }
-}