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.api.source.SourceIdentifier;
21 import org.opendaylight.yangtools.yang.model.api.source.YangTextSource;
22 import org.opendaylight.yangtools.yang.model.spi.source.DelegatedYangTextSource;
24 public class YangTextSourceSerializationProxyTest {
25 private YangTextSource schemaSource;
29 schemaSource = new DelegatedYangTextSource(new SourceIdentifier("test", "2015-10-30"),
30 CharSource.wrap("Test source."));
34 public void serializeAndDeserializeProxy() throws ClassNotFoundException, IOException {
35 final var proxy = new YangTextSchemaSourceSerializationProxy(schemaSource);
36 ByteArrayOutputStream bos = new ByteArrayOutputStream();
37 ObjectOutputStream oos = new ObjectOutputStream(bos);
39 oos.writeObject(proxy);
41 final byte[] bytes = bos.toByteArray();
42 assertEquals(323, bytes.length);
44 ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bytes));
46 final var deserializedProxy = (YangTextSchemaSourceSerializationProxy) ois.readObject();
48 assertEquals(deserializedProxy.getRepresentation().sourceId(), proxy.getRepresentation().sourceId());
49 assertEquals(deserializedProxy.getRepresentation().read(), proxy.getRepresentation().read());
53 public void testProxyEqualsBackingYangTextSource() throws IOException {
54 final var serializationProxy = new YangTextSchemaSourceSerializationProxy(schemaSource);
56 assertEquals(serializationProxy.getRepresentation().sourceId(), schemaSource.sourceId());
57 assertEquals(serializationProxy.getRepresentation().read(), schemaSource.read());