import akka.actor.ActorRef;
import akka.actor.ActorSystem;
+import akka.actor.ExtendedActorSystem;
+import akka.serialization.JavaSerializer;
import akka.testkit.TestProbe;
import com.google.common.base.MoreObjects;
+import org.apache.commons.lang.SerializationUtils;
import org.junit.Assert;
+import org.junit.Before;
import org.junit.Test;
-public abstract class AbstractRequestTest<T extends Request> {
+public abstract class AbstractRequestTest<T extends Request<?, ?>> {
private static final ActorSystem SYSTEM = ActorSystem.create("test");
protected static final ActorRef ACTOR_REF = TestProbe.apply(SYSTEM).ref();
protected abstract T object();
+ @Before
+ public void setUp() {
+ JavaSerializer.currentSystem().value_$eq((ExtendedActorSystem) SYSTEM);
+ }
+
@Test
- public void getReplyToTest() {}
+ public void getReplyToTest() {
+ Assert.assertEquals(ACTOR_REF, object().getReplyTo());
+ }
@Test
public void addToStringAttributesCommonTest() {
final MoreObjects.ToStringHelper result = object().addToStringAttributes(MoreObjects.toStringHelper(object()));
Assert.assertTrue(result.toString().contains("replyTo=" + ACTOR_REF));
}
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void serializationTest() {
+ final Object deserialize = SerializationUtils.clone(object());
+
+ Assert.assertEquals(object().getTarget(), ((T) deserialize).getTarget());
+ Assert.assertEquals(object().getVersion(), ((T) deserialize).getVersion());
+ Assert.assertEquals(object().getSequence(), ((T) deserialize).getSequence());
+ doAdditionalAssertions(deserialize);
+ }
+
+ protected abstract void doAdditionalAssertions(final Object deserialize);
}