Remote yang text source provider implementation
[controller.git] / opendaylight / md-sal / sal-clustering-commons / src / test / java / org / opendaylight / controller / cluster / schema / repository / 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
9 package org.opendaylight.controller.cluster.schema.repository.impl;
10
11 import static org.junit.Assert.assertArrayEquals;
12 import static org.junit.Assert.assertEquals;
13
14 import com.google.common.base.Charsets;
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 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;
25
26 public class YangTextSourceSerializationProxyTest {
27
28     private YangTextSchemaSource schemaSource;
29
30     @Before
31     public void setUp() {
32         String source = "Test source.";
33         schemaSource = YangTextSchemaSource.delegateForByteSource(
34                 new SourceIdentifier("test", "2015-10-30"), ByteSource.wrap(source.getBytes(Charsets.UTF_8)));
35     }
36
37
38     @Test
39     public void serializeAndDesrializeProxy() throws ClassNotFoundException, IOException {
40         YangTextSchemaSourceSerializationProxy proxy = new YangTextSchemaSourceSerializationProxy(schemaSource);
41         ByteArrayOutputStream bos = new ByteArrayOutputStream();
42         ObjectOutputStream oos = new ObjectOutputStream(bos);
43
44         oos.writeObject(proxy);
45
46         ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bos.toByteArray()));
47
48         YangTextSchemaSourceSerializationProxy deserializedProxy =  (YangTextSchemaSourceSerializationProxy) ois.readObject();
49
50         assertEquals(deserializedProxy.getRepresentation().getIdentifier(), proxy.getRepresentation().getIdentifier());
51         assertArrayEquals(deserializedProxy.getRepresentation().read(), proxy.getRepresentation().read());
52     }
53
54     @Test
55     public void testProxyEqualsBackingYangTextSource() throws IOException {
56         YangTextSchemaSourceSerializationProxy serializationProxy = new YangTextSchemaSourceSerializationProxy(schemaSource);
57
58         assertEquals(serializationProxy.getRepresentation().getIdentifier(), schemaSource.getIdentifier());
59         assertArrayEquals(serializationProxy.getRepresentation().read(), schemaSource.read());
60     }
61 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.