2 * Copyright (c) 2016 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
8 package org.opendaylight.controller.cluster.access;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertThrows;
12 import static org.junit.Assert.assertTrue;
13 import static org.opendaylight.controller.cluster.access.ABIVersion.POTASSIUM;
14 import static org.opendaylight.controller.cluster.access.ABIVersion.TEST_FUTURE_VERSION;
15 import static org.opendaylight.controller.cluster.access.ABIVersion.TEST_PAST_VERSION;
17 import com.google.common.io.ByteArrayDataOutput;
18 import com.google.common.io.ByteStreams;
19 import java.io.IOException;
20 import org.junit.Test;
22 public class ABIVersionTest {
24 public void testInvalidVersions() {
25 assertTrue(TEST_PAST_VERSION.compareTo(TEST_FUTURE_VERSION) < 0);
26 assertTrue(TEST_PAST_VERSION.compareTo(POTASSIUM) < 0);
27 assertTrue(TEST_FUTURE_VERSION.compareTo(POTASSIUM) > 0);
31 public void testMagnesiumVersion() throws Exception {
32 assertEquals((short)10, POTASSIUM.shortValue());
33 assertEquals(POTASSIUM, ABIVersion.valueOf(POTASSIUM.shortValue()));
34 assertEquals(POTASSIUM, ABIVersion.readFrom(ByteStreams.newDataInput(writeVersion(POTASSIUM))));
38 public void testInvalidPastVersion() {
39 assertThrows(PastVersionException.class, () -> ABIVersion.valueOf(TEST_PAST_VERSION.shortValue()));
43 public void testInvalidFutureVersion() {
44 assertThrows(FutureVersionException.class, () -> ABIVersion.valueOf(TEST_FUTURE_VERSION.shortValue()));
47 private static byte[] writeVersion(final ABIVersion version) {
48 final ByteArrayDataOutput bado = ByteStreams.newDataOutput();
49 bado.writeShort(version.shortValue());
50 return bado.toByteArray();
54 public void testBadRead() {
55 final var in = ByteStreams.newDataInput(writeVersion(TEST_PAST_VERSION));
56 assertThrows(IOException.class, () -> ABIVersion.readFrom(in));