Add more serialization assertions
[controller.git] / opendaylight / md-sal / cds-access-api / src / test / java / org / opendaylight / controller / cluster / access / concepts / FrontendTypeTest.java
1 /*
2  * Copyright (c) 2017 Pantheon Technologies s.r.o. 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.access.concepts;
9
10 import static org.junit.Assert.assertEquals;
11
12 import java.io.ByteArrayInputStream;
13 import java.io.ByteArrayOutputStream;
14 import java.io.DataInputStream;
15 import java.io.DataOutputStream;
16 import org.junit.Assert;
17 import org.junit.Test;
18
19 public class FrontendTypeTest extends AbstractIdentifierTest<FrontendType> {
20
21     @Override
22     FrontendType object() {
23         return FrontendType.forName("type-1");
24     }
25
26     @Override
27     FrontendType differentObject() {
28         return FrontendType.forName("type-2");
29     }
30
31     @Override
32     FrontendType equalObject() {
33         return FrontendType.forName("type-1");
34     }
35
36     @Override
37     int expectedSize() {
38         return 104;
39     }
40
41     @Test
42     public void testWriteToReadFrom() throws Exception {
43         final FrontendType type = FrontendType.forName("type");
44         final ByteArrayOutputStream baos = new ByteArrayOutputStream();
45         final DataOutputStream dos = new DataOutputStream(baos);
46         type.writeTo(dos);
47
48         final byte[] bytes = baos.toByteArray();
49         assertEquals(8, bytes.length);
50         final FrontendType read = FrontendType.readFrom(new DataInputStream(new ByteArrayInputStream(bytes)));
51         Assert.assertEquals(type, read);
52     }
53
54     @Test
55     public void testCompareTo() {
56         Assert.assertTrue(object().compareTo(equalObject()) == 0);
57         Assert.assertTrue(object().compareTo(differentObject()) < 0);
58     }
59 }