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
8 package org.opendaylight.controller.cluster.schema.provider.impl;
10 import static org.junit.Assert.assertEquals;
12 import com.google.common.io.CharSource;
13 import java.io.ByteArrayInputStream;
14 import java.io.ByteArrayOutputStream;
15 import java.io.IOException;
16 import java.io.ObjectInputStream;
17 import java.io.ObjectOutputStream;
18 import org.junit.Before;
19 import org.junit.Test;
20 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
21 import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
23 public class YangTextSourceSerializationProxyTest {
24 private YangTextSchemaSource schemaSource;
28 schemaSource = YangTextSchemaSource.delegateForCharSource(new SourceIdentifier("test", "2015-10-30"),
29 CharSource.wrap("Test source."));
33 public void serializeAndDeserializeProxy() throws ClassNotFoundException, IOException {
34 YangTextSchemaSourceSerializationProxy proxy = new YangTextSchemaSourceSerializationProxy(schemaSource);
35 ByteArrayOutputStream bos = new ByteArrayOutputStream();
36 ObjectOutputStream oos = new ObjectOutputStream(bos);
38 oos.writeObject(proxy);
40 final byte[] bytes = bos.toByteArray();
41 assertEquals(333, bytes.length);
43 ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bytes));
45 YangTextSchemaSourceSerializationProxy deserializedProxy =
46 (YangTextSchemaSourceSerializationProxy) ois.readObject();
48 assertEquals(deserializedProxy.getRepresentation().getIdentifier(), proxy.getRepresentation().getIdentifier());
49 assertEquals(deserializedProxy.getRepresentation().read(), proxy.getRepresentation().read());
53 public void testProxyEqualsBackingYangTextSource() throws IOException {
54 YangTextSchemaSourceSerializationProxy serializationProxy =
55 new YangTextSchemaSourceSerializationProxy(schemaSource);
57 assertEquals(serializationProxy.getRepresentation().getIdentifier(), schemaSource.getIdentifier());
58 assertEquals(serializationProxy.getRepresentation().read(), schemaSource.read());