Fix raw type warnings
[controller.git] / opendaylight / md-sal / sal-clustering-commons / src / test / java / org / opendaylight / controller / cluster / datastore / node / utils / stream / NormalizedNodeStreamReaderWriterTest.java
index 6dbb0f8e64e7ec143fa54d993c1c802353601702..9803df937a721ce3d41d6b9bf12941852601e3ed 100644 (file)
@@ -8,19 +8,18 @@
 
 package org.opendaylight.controller.cluster.datastore.node.utils.stream;
 
-import java.io.ByteArrayInputStream;
+import com.google.common.io.ByteStreams;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import org.apache.commons.lang.SerializationUtils;
 import org.junit.Assert;
 import org.junit.Test;
 import org.opendaylight.controller.cluster.datastore.node.NormalizedNodeToNodeCodec;
-import org.opendaylight.controller.cluster.datastore.util.InstanceIdentifierUtils;
 import org.opendaylight.controller.cluster.datastore.util.TestModel;
-import org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionMessages;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue;
 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
 import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
@@ -36,7 +35,8 @@ public class NormalizedNodeStreamReaderWriterTest {
     public void testNormalizedNodeStreaming() throws IOException {
 
         ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
-        NormalizedNodeOutputStreamWriter writer = new NormalizedNodeOutputStreamWriter(byteArrayOutputStream);
+        NormalizedNodeOutputStreamWriter writer = new NormalizedNodeOutputStreamWriter(
+            ByteStreams.newDataOutput(byteArrayOutputStream));
 
         NormalizedNode<?, ?> testContainer = createTestContainer();
         writer.writeNormalizedNode(testContainer);
@@ -56,7 +56,7 @@ public class NormalizedNodeStreamReaderWriterTest {
         writer.writeNormalizedNode(toasterContainer);
 
         NormalizedNodeInputStreamReader reader = new NormalizedNodeInputStreamReader(
-                new ByteArrayInputStream(byteArrayOutputStream.toByteArray()));
+            ByteStreams.newDataInput(byteArrayOutputStream.toByteArray()));
 
         NormalizedNode<?,?> node = reader.readNormalizedNode();
         Assert.assertEquals(testContainer, node);
@@ -70,26 +70,23 @@ public class NormalizedNodeStreamReaderWriterTest {
     private static NormalizedNode<?, ?> createTestContainer() {
         byte[] bytes1 = {1,2,3};
         LeafSetEntryNode<Object> entry1 = ImmutableLeafSetEntryNodeBuilder.create().withNodeIdentifier(
-                new YangInstanceIdentifier.NodeWithValue(TestModel.BINARY_LEAF_LIST_QNAME, bytes1)).
-                withValue(bytes1).build();
+                new NodeWithValue<>(TestModel.BINARY_LEAF_LIST_QNAME, bytes1)).withValue(bytes1).build();
 
         byte[] bytes2 = {};
         LeafSetEntryNode<Object> entry2 = ImmutableLeafSetEntryNodeBuilder.create().withNodeIdentifier(
-                new YangInstanceIdentifier.NodeWithValue(TestModel.BINARY_LEAF_LIST_QNAME, bytes2)).
-                withValue(bytes2).build();
+                new NodeWithValue<>(TestModel.BINARY_LEAF_LIST_QNAME, bytes2)).withValue(bytes2).build();
 
         LeafSetEntryNode<Object> entry3 = ImmutableLeafSetEntryNodeBuilder.create().withNodeIdentifier(
-                new YangInstanceIdentifier.NodeWithValue(TestModel.BINARY_LEAF_LIST_QNAME, null)).
-                withValue(null).build();
+                new NodeWithValue<>(TestModel.BINARY_LEAF_LIST_QNAME, null)).withValue(null).build();
 
 
         return TestModel.createBaseTestContainerBuilder().
                 withChild(ImmutableLeafSetNodeBuilder.create().withNodeIdentifier(
-                        new YangInstanceIdentifier.NodeIdentifier(TestModel.BINARY_LEAF_LIST_QNAME)).
+                        new NodeIdentifier(TestModel.BINARY_LEAF_LIST_QNAME)).
                         withChild(entry1).withChild(entry2).withChild(entry3).build()).
                 withChild(ImmutableNodes.leafNode(TestModel.SOME_BINARY_DATA_QNAME, new byte[]{1,2,3,4})).
                 withChild(Builders.orderedMapBuilder().
-                      withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.ORDERED_LIST_QNAME)).
+                      withNodeIdentifier(new NodeIdentifier(TestModel.ORDERED_LIST_QNAME)).
                       withChild(ImmutableNodes.mapEntry(TestModel.ORDERED_LIST_ENTRY_QNAME,
                               TestModel.ID_QNAME, 11)).build()).
                 build();
@@ -103,11 +100,11 @@ public class NormalizedNodeStreamReaderWriterTest {
 
         ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
         NormalizedNodeOutputStreamWriter writer =
-                new NormalizedNodeOutputStreamWriter(byteArrayOutputStream);
+                new NormalizedNodeOutputStreamWriter(ByteStreams.newDataOutput(byteArrayOutputStream));
         writer.writeYangInstanceIdentifier(path);
 
         NormalizedNodeInputStreamReader reader = new NormalizedNodeInputStreamReader(
-                new ByteArrayInputStream(byteArrayOutputStream.toByteArray()));
+            ByteStreams.newDataInput(byteArrayOutputStream.toByteArray()));
 
         YangInstanceIdentifier newPath = reader.readYangInstanceIdentifier();
         Assert.assertEquals(path, newPath);
@@ -119,7 +116,8 @@ public class NormalizedNodeStreamReaderWriterTest {
     public void testNormalizedNodeAndYangInstanceIdentifierStreaming() throws IOException {
 
         ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
-        NormalizedNodeOutputStreamWriter writer = new NormalizedNodeOutputStreamWriter(byteArrayOutputStream);
+        NormalizedNodeOutputStreamWriter writer = new NormalizedNodeOutputStreamWriter(
+            ByteStreams.newDataOutput(byteArrayOutputStream));
 
         NormalizedNode<?, ?> testContainer = TestModel.createBaseTestContainerBuilder().build();
         writer.writeNormalizedNode(testContainer);
@@ -131,7 +129,7 @@ public class NormalizedNodeStreamReaderWriterTest {
         writer.writeYangInstanceIdentifier(path);
 
         NormalizedNodeInputStreamReader reader = new NormalizedNodeInputStreamReader(
-                new ByteArrayInputStream(byteArrayOutputStream.toByteArray()));
+            ByteStreams.newDataInput(byteArrayOutputStream.toByteArray()));
 
         NormalizedNode<?,?> node = reader.readNormalizedNode();
         Assert.assertEquals(testContainer, node);
@@ -148,20 +146,16 @@ public class NormalizedNodeStreamReaderWriterTest {
                 TestModel.createBaseTestContainerBuilder().build()).getNormalizedNode().toByteArray();
 
         NormalizedNodeInputStreamReader reader = new NormalizedNodeInputStreamReader(
-                new ByteArrayInputStream(protobufBytes));
+            ByteStreams.newDataInput(protobufBytes));
 
         reader.readNormalizedNode();
     }
 
     @Test(expected=InvalidNormalizedNodeStreamException.class, timeout=10000)
     public void testInvalidYangInstanceIdentifierStream() throws IOException {
-        YangInstanceIdentifier path = YangInstanceIdentifier.builder(TestModel.TEST_PATH).build();
-
-        byte[] protobufBytes = ShardTransactionMessages.DeleteData.newBuilder().setInstanceIdentifierPathArguments(
-                InstanceIdentifierUtils.toSerializable(path)).build().toByteArray();
-
+        byte[] protobufBytes = {1,2,3};
         NormalizedNodeInputStreamReader reader = new NormalizedNodeInputStreamReader(
-                new ByteArrayInputStream(protobufBytes));
+            ByteStreams.newDataInput(protobufBytes));
 
         reader.readYangInstanceIdentifier();
     }
@@ -176,7 +170,7 @@ public class NormalizedNodeStreamReaderWriterTest {
 
     }
 
-    private String largeString(int pow){
+    private static String largeString(final int pow){
         String s = "X";
         for(int i=0;i<pow;i++){
             StringBuilder b = new StringBuilder();