Remove deprecated NetconfMessageHeader class 65/37065/1
authorAndrej Mak <andmak@cisco.com>
Mon, 4 Apr 2016 12:58:43 +0000 (14:58 +0200)
committerAndrej Mak <andmak@cisco.com>
Mon, 4 Apr 2016 12:58:43 +0000 (14:58 +0200)
Change-Id: Ia4a99e56f936bf7d52f343a1e38935b4b5eaad51
Signed-off-by: Andrej Mak <andmak@cisco.com>
netconf/netconf-impl/src/test/java/org/opendaylight/netconf/impl/MessageHeaderTest.java [deleted file]
netconf/netconf-impl/src/test/java/org/opendaylight/netconf/impl/MessageParserTest.java
netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/messages/NetconfMessageHeader.java [deleted file]
netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/messages/NetconfMessageHeaderTest.java [deleted file]

diff --git a/netconf/netconf-impl/src/test/java/org/opendaylight/netconf/impl/MessageHeaderTest.java b/netconf/netconf-impl/src/test/java/org/opendaylight/netconf/impl/MessageHeaderTest.java
deleted file mode 100644 (file)
index 40ab00c..0000000
+++ /dev/null
@@ -1,32 +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.impl;
-
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-
-import org.junit.Test;
-import org.opendaylight.netconf.util.messages.NetconfMessageHeader;
-
-@Deprecated
-public class MessageHeaderTest {
-    @Test
-    public void testFromBytes() {
-        final byte[] raw = new byte[] { (byte) 0x0a, (byte) 0x23, (byte) 0x35, (byte) 0x38, (byte) 0x0a };
-        NetconfMessageHeader header = NetconfMessageHeader.fromBytes(raw);
-        assertEquals(58, header.getLength());
-    }
-
-    @Test
-    public void testToBytes() {
-        NetconfMessageHeader header = new NetconfMessageHeader(123);
-        assertArrayEquals(new byte[] { (byte) 0x0a, (byte) 0x23, (byte) 0x31, (byte) 0x32, (byte) 0x33, (byte) 0x0a },
-                header.toBytes());
-    }
-}
index df34c45c5fc004f2f96b517fb1f7caaedbeff9fd..562d4a4ba993b4d307ca366e9e261a8f86f256a7 100644 (file)
@@ -15,12 +15,15 @@ import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
+import com.google.common.base.Charsets;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
 import io.netty.channel.embedded.EmbeddedChannel;
+import java.nio.ByteBuffer;
 import java.util.Queue;
 import org.junit.Before;
 import org.junit.Test;
+import org.opendaylight.netconf.api.NetconfMessage;
 import org.opendaylight.netconf.nettyutil.handler.ChunkedFramingMechanismEncoder;
 import org.opendaylight.netconf.nettyutil.handler.FramingMechanismHandlerFactory;
 import org.opendaylight.netconf.nettyutil.handler.NetconfChunkAggregator;
@@ -29,9 +32,7 @@ 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.messages.NetconfMessageHeader;
 import org.opendaylight.netconf.util.test.XmlFileLoader;
-import org.opendaylight.netconf.api.NetconfMessage;
 
 public class MessageParserTest {
 
@@ -78,8 +79,7 @@ public class MessageParserTest {
             byte[] header = new byte[String.valueOf(exptHeaderLength).length()
                     + NetconfMessageConstants.MIN_HEADER_LENGTH - 1];
             recievedOutbound.getBytes(0, header);
-            NetconfMessageHeader messageHeader = NetconfMessageHeader.fromBytes(header);
-            assertEquals(exptHeaderLength, messageHeader.getLength());
+            assertEquals(exptHeaderLength, getHeaderLength(header));
 
             testChunkChannel.writeInbound(recievedOutbound);
         }
@@ -108,4 +108,10 @@ public class MessageParserTest {
         assertNotNull(receivedMessage);
         assertXMLEqual(this.msg.getDocument(), receivedMessage.getDocument());
     }
+
+    private static long getHeaderLength(byte[] bytes) {
+        byte[] HEADER_START = new byte[] { (byte) 0x0a, (byte) 0x23 };
+        return Long.parseLong(Charsets.US_ASCII.decode(
+                ByteBuffer.wrap(bytes, HEADER_START.length, bytes.length - HEADER_START.length - 1)).toString());
+    }
 }
diff --git a/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/messages/NetconfMessageHeader.java b/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/messages/NetconfMessageHeader.java
deleted file mode 100644 (file)
index 8a425c2..0000000
+++ /dev/null
@@ -1,59 +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 com.google.common.base.Charsets;
-import com.google.common.base.Preconditions;
-import java.nio.ByteBuffer;
-
-/**
- * Netconf message header is used only when chunked framing mechanism is
- * supported. The header consists of only the length field.
- */
-@Deprecated
-public final class NetconfMessageHeader {
-    // \n#<length>\n
-    private static final byte[] HEADER_START = new byte[] { (byte) 0x0a, (byte) 0x23 };
-    private static final byte HEADER_END = (byte) 0x0a;
-    private final long length;
-
-    public NetconfMessageHeader(final long length) {
-        Preconditions.checkArgument(length < Integer.MAX_VALUE && length > 0);
-        this.length = length;
-    }
-
-    public byte[] toBytes() {
-        return toBytes(this.length);
-    }
-
-    // FIXME: improve precision to long
-    public int getLength() {
-        return (int) this.length;
-    }
-
-    public static NetconfMessageHeader fromBytes(final byte[] bytes) {
-        // the length is variable therefore bytes between headerBegin and
-        // headerEnd mark the length
-        // the length should be only numbers and therefore easily parsed with
-        // ASCII
-        long length = Long.parseLong(Charsets.US_ASCII.decode(
-                ByteBuffer.wrap(bytes, HEADER_START.length, bytes.length - HEADER_START.length - 1)).toString());
-
-        return new NetconfMessageHeader(length);
-    }
-
-    public static byte[] toBytes(final long length) {
-        final byte[] l = String.valueOf(length).getBytes(Charsets.US_ASCII);
-        final byte[] h = new byte[HEADER_START.length + l.length + 1];
-        System.arraycopy(HEADER_START, 0, h, 0, HEADER_START.length);
-        System.arraycopy(l, 0, h, HEADER_START.length, l.length);
-        System.arraycopy(new byte[] { HEADER_END }, 0, h, HEADER_START.length + l.length, 1);
-        return h;
-    }
-}
diff --git a/netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/messages/NetconfMessageHeaderTest.java b/netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/messages/NetconfMessageHeaderTest.java
deleted file mode 100644 (file)
index 1c09b95..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Copyright (c) 2014 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 static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-
-import com.google.common.base.Charsets;
-import org.junit.Test;
-
-@Deprecated
-public class NetconfMessageHeaderTest {
-    @Test
-    public void testGet() throws Exception {
-        NetconfMessageHeader header = new NetconfMessageHeader(10);
-        assertEquals(header.getLength(), 10);
-
-        byte[] expectedValue = "\n#10\n".getBytes(Charsets.US_ASCII);
-        assertArrayEquals(expectedValue, header.toBytes());
-    }
-}