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.concepts;
10 import static org.hamcrest.CoreMatchers.containsString;
11 import static org.hamcrest.MatcherAssert.assertThat;
12 import static org.junit.Assert.assertEquals;
14 import akka.actor.ActorRef;
15 import akka.actor.ActorSystem;
16 import akka.actor.ExtendedActorSystem;
17 import akka.serialization.JavaSerializer;
18 import akka.testkit.TestProbe;
19 import com.google.common.base.MoreObjects;
20 import org.apache.commons.lang.SerializationUtils;
21 import org.junit.Before;
22 import org.junit.Test;
24 public abstract class AbstractRequestTest<T extends Request<?, T>> {
25 private static final ActorSystem SYSTEM = ActorSystem.create("test");
26 protected static final ActorRef ACTOR_REF = TestProbe.apply(SYSTEM).ref();
28 protected abstract T object();
32 JavaSerializer.currentSystem().value_$eq((ExtendedActorSystem) SYSTEM);
36 public void getReplyToTest() {
37 assertEquals(ACTOR_REF, object().getReplyTo());
41 public void addToStringAttributesCommonTest() {
42 final var result = object().addToStringAttributes(MoreObjects.toStringHelper(object()));
43 assertThat(result.toString(), containsString("replyTo=" + ACTOR_REF));
46 @SuppressWarnings("unchecked")
48 public void serializationTest() {
49 final Object deserialize = SerializationUtils.clone(object());
51 assertEquals(object().getTarget(), ((T) deserialize).getTarget());
52 assertEquals(object().getVersion(), ((T) deserialize).getVersion());
53 assertEquals(object().getSequence(), ((T) deserialize).getSequence());
54 doAdditionalAssertions(deserialize);
57 protected abstract void doAdditionalAssertions(Object deserialize);