Add FrontendTypeTest
[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 java.io.ByteArrayInputStream;
11 import java.io.ByteArrayOutputStream;
12 import java.io.DataInputStream;
13 import java.io.DataOutputStream;
14 import org.junit.Assert;
15 import org.junit.Test;
16
17 public class FrontendTypeTest extends AbstractIdentifierTest<FrontendType> {
18
19     @Override
20     FrontendType object() {
21         return FrontendType.forName("type-1");
22     }
23
24     @Override
25     FrontendType differentObject() {
26         return FrontendType.forName("type-2");
27     }
28
29     @Override
30     FrontendType equalObject() {
31         return FrontendType.forName("type-1");
32     }
33
34     @Test
35     public void testWriteToReadFrom() throws Exception {
36         final FrontendType type = FrontendType.forName("type");
37         final ByteArrayOutputStream baos = new ByteArrayOutputStream();
38         final DataOutputStream dos = new DataOutputStream(baos);
39         type.writeTo(dos);
40         final FrontendType read =
41                 FrontendType.readFrom(new DataInputStream(new ByteArrayInputStream(baos.toByteArray())));
42         Assert.assertEquals(type, read);
43     }
44
45     @Test
46     public void testCompareTo() throws Exception {
47         Assert.assertTrue(object().compareTo(equalObject()) == 0);
48         Assert.assertTrue(object().compareTo(differentObject()) < 0);
49     }
50 }