Unit tests for Request derived classes
[controller.git] / opendaylight / md-sal / cds-access-api / src / test / java / org / opendaylight / controller / cluster / access / commands / ConnectClientRequestTest.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.commands;
9
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.AbstractRequestProxy;
15 import org.opendaylight.controller.cluster.access.concepts.AbstractRequestTest;
16 import org.opendaylight.controller.cluster.access.concepts.ClientIdentifier;
17 import org.opendaylight.controller.cluster.access.concepts.FrontendIdentifier;
18 import org.opendaylight.controller.cluster.access.concepts.FrontendType;
19 import org.opendaylight.controller.cluster.access.concepts.MemberName;
20 import org.opendaylight.controller.cluster.access.concepts.RequestException;
21
22 public class ConnectClientRequestTest extends AbstractRequestTest<ConnectClientRequest> {
23     private static final FrontendIdentifier FRONTEND_IDENTIFIER = FrontendIdentifier.create(
24             MemberName.forName("member"), FrontendType.forName("frontend"));
25     private static final ClientIdentifier CLIENT_IDENTIFIER = ClientIdentifier.create(FRONTEND_IDENTIFIER, 0);
26
27     private static final ABIVersion MIN_VERSION = ABIVersion.TEST_PAST_VERSION;
28     private static final ABIVersion MAX_VERSION = ABIVersion.TEST_FUTURE_VERSION;
29
30     private static final ConnectClientRequest OBJECT = new ConnectClientRequest(
31             CLIENT_IDENTIFIER, 0, ACTOR_REF, MIN_VERSION, MAX_VERSION);
32
33     @Override
34     protected ConnectClientRequest object() {
35         return OBJECT;
36     }
37
38     @Test
39     public void getMinVersion() throws Exception {
40         Assert.assertEquals(MIN_VERSION, OBJECT.getMinVersion());
41     }
42
43     @Test
44     public void getMaxVersion() throws Exception {
45         Assert.assertEquals(MAX_VERSION, OBJECT.getMaxVersion());
46     }
47
48     @Test
49     public void toRequestFailure() throws Exception {
50         final RequestException exception = new DeadTransactionException(0);
51         final ConnectClientFailure failure = OBJECT.toRequestFailure(exception);
52         Assert.assertNotNull(failure);
53     }
54
55     @Test
56     public void externalizableProxy() throws Exception {
57         final AbstractRequestProxy<ClientIdentifier, ConnectClientRequest> proxy = OBJECT.externalizableProxy(
58                 ABIVersion.current());
59         Assert.assertNotNull(proxy);
60     }
61
62     @Test
63     public void cloneAsVersion() throws Exception {
64         final ConnectClientRequest clone = OBJECT.cloneAsVersion(ABIVersion.BORON);
65         Assert.assertNotNull(clone);
66         Assert.assertEquals(ABIVersion.BORON, clone.getVersion());
67     }
68
69     @Test
70     public void addToStringAttributes() throws Exception {
71         final MoreObjects.ToStringHelper result = OBJECT.addToStringAttributes(MoreObjects.toStringHelper(OBJECT));
72         Assert.assertTrue(result.toString().contains("minVersion=" + MIN_VERSION));
73         Assert.assertTrue(result.toString().contains("maxVersion=" + MAX_VERSION));
74     }
75 }