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.base.Optional;
15 import com.google.common.io.ByteSource;
16 import java.io.ByteArrayInputStream;
17 import java.io.ByteArrayOutputStream;
18 import java.io.IOException;
19 import java.io.ObjectInputStream;
20 import java.io.ObjectOutputStream;
21 import java.nio.charset.StandardCharsets;
22 import org.junit.Before;
23 import org.junit.Test;
24 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
25 import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
27 public class YangTextSourceSerializationProxyTest {
29 private YangTextSchemaSource schemaSource;
33 String source = "Test source.";
34 schemaSource = YangTextSchemaSource.delegateForByteSource(
35 SourceIdentifier.create("test", Optional.of("2015-10-30")),
36 ByteSource.wrap(source.getBytes(StandardCharsets.UTF_8)));
41 public void serializeAndDesrializeProxy() throws ClassNotFoundException, IOException {
42 YangTextSchemaSourceSerializationProxy proxy = new YangTextSchemaSourceSerializationProxy(schemaSource);
43 ByteArrayOutputStream bos = new ByteArrayOutputStream();
44 ObjectOutputStream oos = new ObjectOutputStream(bos);
46 oos.writeObject(proxy);
48 ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bos.toByteArray()));
50 YangTextSchemaSourceSerializationProxy deserializedProxy = (YangTextSchemaSourceSerializationProxy) ois.readObject();
52 assertEquals(deserializedProxy.getRepresentation().getIdentifier(), proxy.getRepresentation().getIdentifier());
53 assertArrayEquals(deserializedProxy.getRepresentation().read(), proxy.getRepresentation().read());
57 public void testProxyEqualsBackingYangTextSource() throws IOException {
58 YangTextSchemaSourceSerializationProxy serializationProxy = new YangTextSchemaSourceSerializationProxy(schemaSource);
60 assertEquals(serializationProxy.getRepresentation().getIdentifier(), schemaSource.getIdentifier());
61 assertArrayEquals(serializationProxy.getRepresentation().read(), schemaSource.read());