.withNodeIdentifier(new NodeIdentifier(SchemaContext.NAME)).withChild(toasterNode).build();
nnout.writeNormalizedNode(toasterContainer);
- NormalizedNodeDataInput nnin = NormalizedNodeInputOutput.newDataInput(ByteStreams.newDataInput(
- bos.toByteArray()));
+ final byte[] bytes = bos.toByteArray();
+ assertEquals(1049950, bytes.length);
- NormalizedNode<?,?> node = nnin.readNormalizedNode();
+ NormalizedNodeDataInput nnin = NormalizedNodeInputOutput.newDataInput(ByteStreams.newDataInput(bytes));
+
+ NormalizedNode<?, ?> node = nnin.readNormalizedNode();
Assert.assertEquals(testContainer, node);
node = nnin.readNormalizedNode();
nnout.writeYangInstanceIdentifier(path);
- NormalizedNodeDataInput nnin = NormalizedNodeInputOutput.newDataInput(ByteStreams.newDataInput(
- bos.toByteArray()));
+ final byte[] bytes = bos.toByteArray();
+ assertEquals(161, bytes.length);
+
+ NormalizedNodeDataInput nnin = NormalizedNodeInputOutput.newDataInput(ByteStreams.newDataInput(bytes));
YangInstanceIdentifier newPath = nnin.readYangInstanceIdentifier();
Assert.assertEquals(path, newPath);
@Test
public void testNormalizedNodeAndYangInstanceIdentifierStreaming() throws IOException {
- ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
NormalizedNodeDataOutput writer = NormalizedNodeInputOutput.newDataOutput(
- ByteStreams.newDataOutput(byteArrayOutputStream));
+ ByteStreams.newDataOutput(bos));
NormalizedNode<?, ?> testContainer = TestModel.createBaseTestContainerBuilder().build();
writer.writeNormalizedNode(testContainer);
writer.writeYangInstanceIdentifier(path);
- NormalizedNodeDataInput reader = NormalizedNodeInputOutput.newDataInput(
- ByteStreams.newDataInput(byteArrayOutputStream.toByteArray()));
+ final byte[] bytes = bos.toByteArray();
+ assertEquals(1163, bytes.length);
+
+ NormalizedNodeDataInput reader = NormalizedNodeInputOutput.newDataInput(ByteStreams.newDataInput(bytes));
NormalizedNode<?,?> node = reader.readNormalizedNode();
Assert.assertEquals(testContainer, node);
@Test(expected = InvalidNormalizedNodeStreamException.class, timeout = 10000)
public void testInvalidNormalizedNodeStream() throws IOException {
- byte[] invalidBytes = {1,2,3};
+ byte[] invalidBytes = {1, 2, 3};
NormalizedNodeDataInput reader = NormalizedNodeInputOutput.newDataInput(
ByteStreams.newDataInput(invalidBytes));
nnout.writeNormalizedNode(anyXmlContainer);
- NormalizedNodeDataInput nnin = NormalizedNodeInputOutput.newDataInput(ByteStreams.newDataInput(
- bos.toByteArray()));
+ final byte[] bytes = bos.toByteArray();
+ assertEquals(235, bytes.length);
+
+ NormalizedNodeDataInput nnin = NormalizedNodeInputOutput.newDataInput(ByteStreams.newDataInput(bytes));
ContainerNode deserialized = (ContainerNode)nnin.readNormalizedNode();
nnout.writeSchemaPath(expected);
}
- NormalizedNodeDataInput nnin = NormalizedNodeInputOutput.newDataInput(ByteStreams.newDataInput(
- bos.toByteArray()));
+ final byte[] bytes = bos.toByteArray();
+ assertEquals(100, bytes.length);
+
+ NormalizedNodeDataInput nnin = NormalizedNodeInputOutput.newDataInput(ByteStreams.newDataInput(bytes));
assertEquals(expected, nnin.readSchemaPath());
}
nnout.writePathArgument(expected);
}
- NormalizedNodeDataInput nnin = NormalizedNodeInputOutput.newDataInput(ByteStreams.newDataInput(
- bos.toByteArray()));
+ final byte[] bytes = bos.toByteArray();
+ assertEquals(105, bytes.length);
+
+ NormalizedNodeDataInput nnin = NormalizedNodeInputOutput.newDataInput(ByteStreams.newDataInput(bytes));
assertEquals(expected, nnin.readPathArgument());
}
*/
package org.opendaylight.controller.cluster.datastore.node.utils.stream;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
import com.google.common.collect.ImmutableSet;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import javax.xml.transform.dom.DOMSource;
import org.custommonkey.xmlunit.Diff;
import org.custommonkey.xmlunit.XMLUnit;
-import org.junit.Assert;
import org.junit.Test;
import org.opendaylight.yangtools.util.xml.UntrustedXML;
import org.opendaylight.yangtools.yang.common.QName;
public void testSerializeDeserializeNodes() throws IOException {
final NormalizedNode<?, ?> normalizedNode = createNormalizedNode();
final byte[] bytes = serializeNormalizedNode(normalizedNode);
- Assert.assertEquals(normalizedNode, deserializeNormalizedNode(bytes));
+ assertEquals(10774, bytes.length);
+ assertEquals(normalizedNode, deserializeNormalizedNode(bytes));
}
@Test
.withValue(new DOMSource(parse))
.build();
final byte[] bytes = serializeNormalizedNode(anyXmlNode);
+ assertEquals(115, bytes.length);
final NormalizedNode<?, ?> deserialized = deserializeNormalizedNode(bytes);
final DOMSource value = (DOMSource) deserialized.getValue();
final Diff diff = XMLUnit.compareXML((Document) anyXmlNode.getValue().getNode(),
value.getNode().getOwnerDocument());
- Assert.assertTrue(diff.toString(), diff.similar());
+ assertTrue(diff.toString(), diff.similar());
}
@Test
.node(leafSetId("leafSer1", "leafSetValue1"))
.build();
SerializationUtils.writePath(out, path);
+
+ final byte[] bytes = bos.toByteArray();
+ assertEquals(150, bytes.length);
+
final YangInstanceIdentifier deserialized =
- SerializationUtils.readPath(new DataInputStream(new ByteArrayInputStream(bos.toByteArray())));
- Assert.assertEquals(path, deserialized);
+ SerializationUtils.readPath(new DataInputStream(new ByteArrayInputStream(bytes)));
+ assertEquals(path, deserialized);
}
@Test
final NormalizedNode<?, ?> node = createNormalizedNode();
final YangInstanceIdentifier path = YangInstanceIdentifier.create(id("container1"));
SerializationUtils.writeNodeAndPath(out, path, node);
- final DataInputStream in = new DataInputStream(new ByteArrayInputStream(bos.toByteArray()));
+
+ final byte[] bytes = bos.toByteArray();
+ assertEquals(10783, bytes.length);
+
+ final DataInputStream in = new DataInputStream(new ByteArrayInputStream(bytes));
final AtomicBoolean applierCalled = new AtomicBoolean(false);
SerializationUtils.readNodeAndPath(in, applierCalled, (instance, deserializedPath, deserializedNode) -> {
- Assert.assertEquals(path, deserializedPath);
- Assert.assertEquals(node, deserializedNode);
+ assertEquals(path, deserializedPath);
+ assertEquals(node, deserializedNode);
applierCalled.set(true);
});
- Assert.assertTrue(applierCalled.get());
+ assertTrue(applierCalled.get());
}
- private static NormalizedNode<?, ?> deserializeNormalizedNode(final byte [] bytes) throws IOException {
+ private static NormalizedNode<?, ?> deserializeNormalizedNode(final byte[] bytes) throws IOException {
return SerializationUtils.readNormalizedNode(new DataInputStream(new ByteArrayInputStream(bytes))).get();
}
@Test
- public void serializeAndDesrializeProxy() throws ClassNotFoundException, IOException {
+ public void serializeAndDeserializeProxy() throws ClassNotFoundException, IOException {
YangTextSchemaSourceSerializationProxy proxy = new YangTextSchemaSourceSerializationProxy(schemaSource);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject(proxy);
- ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bos.toByteArray()));
+ final byte[] bytes = bos.toByteArray();
+ assertEquals(353, bytes.length);
+
+ ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bytes));
YangTextSchemaSourceSerializationProxy deserializedProxy =
(YangTextSchemaSourceSerializationProxy) ois.readObject();