3 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
5 * This program and the accompanying materials are made available under the
6 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7 * and is available at http://www.eclipse.org/legal/epl-v10.html
11 package org.opendaylight.controller.cluster.datastore.node.utils.stream;
14 import org.apache.commons.lang.SerializationUtils;
15 import org.junit.Assert;
16 import org.junit.Test;
17 import org.opendaylight.controller.cluster.datastore.util.TestModel;
18 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
19 import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeWriter;
20 import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
22 import java.io.ByteArrayInputStream;
23 import java.io.ByteArrayOutputStream;
24 import java.io.IOException;
26 public class NormalizedNodeStreamReaderWriterTest {
28 final NormalizedNode<?, ?> input = TestModel.createTestContainer();
31 public void testNormalizedNodeStreamReaderWriter() throws IOException {
33 byte[] byteData = null;
35 try(ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
36 NormalizedNodeStreamWriter writer = new NormalizedNodeOutputStreamWriter(byteArrayOutputStream)) {
38 NormalizedNodeWriter normalizedNodeWriter = NormalizedNodeWriter.forStreamWriter(writer);
39 normalizedNodeWriter.write(input);
40 byteData = byteArrayOutputStream.toByteArray();
44 try(NormalizedNodeInputStreamReader reader = new NormalizedNodeInputStreamReader(
45 new ByteArrayInputStream(byteData))) {
47 NormalizedNode<?,?> node = reader.readNormalizedNode();
48 Assert.assertEquals(input, node);
54 public void testWithSerializable() {
55 SampleNormalizedNodeSerializable serializable = new SampleNormalizedNodeSerializable(input);
56 SampleNormalizedNodeSerializable clone = (SampleNormalizedNodeSerializable)SerializationUtils.clone(serializable);
58 Assert.assertEquals(input, clone.getInput());