Fix followerDistributedDataStore tear down
[controller.git] / opendaylight / md-sal / sal-clustering-commons / src / test / java / org / opendaylight / controller / cluster / schema / provider / impl / YangTextSourceSerializationProxyTest.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.cluster.schema.provider.impl;
9
10 import static org.junit.Assert.assertEquals;
11
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;
23
24 public class YangTextSourceSerializationProxyTest {
25     private YangTextSource schemaSource;
26
27     @Before
28     public void setUp() {
29         schemaSource = new DelegatedYangTextSource(new SourceIdentifier("test", "2015-10-30"),
30             CharSource.wrap("Test source."));
31     }
32
33     @Test
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);
38
39         oos.writeObject(proxy);
40
41         final byte[] bytes = bos.toByteArray();
42         assertEquals(323, bytes.length);
43
44         ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bytes));
45
46         final var deserializedProxy = (YangTextSchemaSourceSerializationProxy) ois.readObject();
47
48         assertEquals(deserializedProxy.getRepresentation().sourceId(), proxy.getRepresentation().sourceId());
49         assertEquals(deserializedProxy.getRepresentation().read(), proxy.getRepresentation().read());
50     }
51
52     @Test
53     public void testProxyEqualsBackingYangTextSource() throws IOException {
54         final var serializationProxy = new YangTextSchemaSourceSerializationProxy(schemaSource);
55
56         assertEquals(serializationProxy.getRepresentation().sourceId(), schemaSource.sourceId());
57         assertEquals(serializationProxy.getRepresentation().read(), schemaSource.read());
58     }
59 }