2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.controller.cluster.schema.provider.impl;
11 import static org.junit.Assert.assertArrayEquals;
12 import static org.junit.Assert.assertEquals;
14 import com.google.common.io.ByteSource;
15 import java.io.ByteArrayInputStream;
16 import java.io.ByteArrayOutputStream;
17 import java.io.IOException;
18 import java.io.ObjectInputStream;
19 import java.io.ObjectOutputStream;
20 import java.nio.charset.StandardCharsets;
21 import org.junit.Before;
22 import org.junit.Test;
23 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
24 import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
26 public class YangTextSourceSerializationProxyTest {
27 private YangTextSchemaSource schemaSource;
31 String source = "Test source.";
32 schemaSource = YangTextSchemaSource.delegateForByteSource(new SourceIdentifier("test", "2015-10-30"),
33 ByteSource.wrap(source.getBytes(StandardCharsets.UTF_8)));
38 public void serializeAndDeserializeProxy() throws ClassNotFoundException, IOException {
39 YangTextSchemaSourceSerializationProxy proxy = new YangTextSchemaSourceSerializationProxy(schemaSource);
40 ByteArrayOutputStream bos = new ByteArrayOutputStream();
41 ObjectOutputStream oos = new ObjectOutputStream(bos);
43 oos.writeObject(proxy);
45 final byte[] bytes = bos.toByteArray();
46 assertEquals(353, bytes.length);
48 ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bytes));
50 YangTextSchemaSourceSerializationProxy deserializedProxy =
51 (YangTextSchemaSourceSerializationProxy) ois.readObject();
53 assertEquals(deserializedProxy.getRepresentation().getIdentifier(), proxy.getRepresentation().getIdentifier());
54 assertArrayEquals(deserializedProxy.getRepresentation().read(), proxy.getRepresentation().read());
58 public void testProxyEqualsBackingYangTextSource() throws IOException {
59 YangTextSchemaSourceSerializationProxy serializationProxy =
60 new YangTextSchemaSourceSerializationProxy(schemaSource);
62 assertEquals(serializationProxy.getRepresentation().getIdentifier(), schemaSource.getIdentifier());
63 assertArrayEquals(serializationProxy.getRepresentation().read(), schemaSource.read());