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 akka.actor.ActorRef;
11 import akka.actor.ActorSystem;
12 import akka.actor.ExtendedActorSystem;
13 import akka.serialization.JavaSerializer;
14 import akka.testkit.TestProbe;
15 import com.google.common.base.MoreObjects;
16 import org.apache.commons.lang.SerializationUtils;
17 import org.junit.Assert;
18 import org.junit.Before;
19 import org.junit.Test;
21 public abstract class AbstractRequestTest<T extends Request<?, T>> {
22 private static final ActorSystem SYSTEM = ActorSystem.create("test");
23 protected static final ActorRef ACTOR_REF = TestProbe.apply(SYSTEM).ref();
25 protected abstract T object();
29 JavaSerializer.currentSystem().value_$eq((ExtendedActorSystem) SYSTEM);
33 public void getReplyToTest() {
34 Assert.assertEquals(ACTOR_REF, object().getReplyTo());
38 public void addToStringAttributesCommonTest() {
39 final MoreObjects.ToStringHelper result = object().addToStringAttributes(MoreObjects.toStringHelper(object()));
40 Assert.assertTrue(result.toString().contains("replyTo=" + ACTOR_REF));
43 @SuppressWarnings("unchecked")
45 public void serializationTest() {
46 final Object deserialize = SerializationUtils.clone(object());
48 Assert.assertEquals(object().getTarget(), ((T) deserialize).getTarget());
49 Assert.assertEquals(object().getVersion(), ((T) deserialize).getVersion());
50 Assert.assertEquals(object().getSequence(), ((T) deserialize).getSequence());
51 doAdditionalAssertions(deserialize);
54 protected abstract void doAdditionalAssertions(Object deserialize);