2 * Copyright (c) 2017 Pantheon Technologies s.r.o. 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.commands;
10 import com.google.common.base.MoreObjects;
11 import org.junit.Assert;
12 import org.junit.Test;
13 import org.opendaylight.controller.cluster.access.ABIVersion;
14 import org.opendaylight.controller.cluster.access.concepts.AbstractRequestTest;
15 import org.opendaylight.controller.cluster.access.concepts.ClientIdentifier;
16 import org.opendaylight.controller.cluster.access.concepts.FrontendIdentifier;
17 import org.opendaylight.controller.cluster.access.concepts.FrontendType;
18 import org.opendaylight.controller.cluster.access.concepts.MemberName;
19 import org.opendaylight.controller.cluster.access.concepts.RequestException;
21 public class ConnectClientRequestTest extends AbstractRequestTest<ConnectClientRequest> {
22 private static final FrontendIdentifier FRONTEND_IDENTIFIER = FrontendIdentifier.create(
23 MemberName.forName("member"), FrontendType.forName("frontend"));
24 private static final ClientIdentifier CLIENT_IDENTIFIER = ClientIdentifier.create(FRONTEND_IDENTIFIER, 0);
26 private static final ABIVersion MIN_VERSION = ABIVersion.TEST_PAST_VERSION;
27 private static final ABIVersion MAX_VERSION = ABIVersion.TEST_FUTURE_VERSION;
29 private static final ConnectClientRequest OBJECT = new ConnectClientRequest(
30 CLIENT_IDENTIFIER, 0, ACTOR_REF, MIN_VERSION, MAX_VERSION);
33 protected ConnectClientRequest object() {
38 public void getMinVersionTest() throws Exception {
39 Assert.assertEquals(MIN_VERSION, OBJECT.getMinVersion());
43 public void getMaxVersionTest() throws Exception {
44 Assert.assertEquals(MAX_VERSION, OBJECT.getMaxVersion());
48 public void toRequestFailureTest() throws Exception {
49 final RequestException exception = new DeadTransactionException(0);
50 final ConnectClientFailure failure = OBJECT.toRequestFailure(exception);
51 Assert.assertNotNull(failure);
55 public void cloneAsVersionTest() throws Exception {
56 final ConnectClientRequest clone = OBJECT.cloneAsVersion(ABIVersion.BORON);
57 Assert.assertNotNull(clone);
58 Assert.assertEquals(ABIVersion.BORON, clone.getVersion());
62 public void addToStringAttributesTest() throws Exception {
63 final MoreObjects.ToStringHelper result = OBJECT.addToStringAttributes(MoreObjects.toStringHelper(OBJECT));
64 Assert.assertTrue(result.toString().contains("minVersion=" + MIN_VERSION));
65 Assert.assertTrue(result.toString().contains("maxVersion=" + MAX_VERSION));
69 protected void doAdditionalAssertions(final Object deserialize) {
70 Assert.assertTrue(deserialize instanceof ConnectClientRequest);
71 final ConnectClientRequest casted = (ConnectClientRequest) deserialize;
73 Assert.assertEquals(OBJECT.getMaxVersion(), casted.getMaxVersion());
74 Assert.assertEquals(OBJECT.getMinVersion(), casted.getMinVersion());
75 Assert.assertEquals(OBJECT.getReplyTo(), casted.getReplyTo());