*/
package org.opendaylight.controller.cluster.access.commands;
+import static java.util.Objects.requireNonNull;
+import static org.junit.Assert.assertEquals;
+
import org.apache.commons.lang.SerializationUtils;
-import org.junit.Assert;
+import org.eclipse.jdt.annotation.NonNull;
import org.junit.Test;
+import org.opendaylight.controller.cluster.access.ABIVersion;
import org.opendaylight.controller.cluster.access.concepts.ClientIdentifier;
import org.opendaylight.controller.cluster.access.concepts.FrontendIdentifier;
import org.opendaylight.controller.cluster.access.concepts.FrontendType;
import org.opendaylight.controller.cluster.access.concepts.RequestSuccess;
public abstract class AbstractRequestSuccessTest<T extends RequestSuccess<?, T>> {
-
private static final FrontendIdentifier FRONTEND_IDENTIFIER = FrontendIdentifier.create(
MemberName.forName("test"), FrontendType.forName("one"));
protected static final ClientIdentifier CLIENT_IDENTIFIER = ClientIdentifier.create(FRONTEND_IDENTIFIER, 0);
- protected static final LocalHistoryIdentifier HISTORY_IDENTIFIER = new LocalHistoryIdentifier(
- CLIENT_IDENTIFIER, 0);
+ protected static final LocalHistoryIdentifier HISTORY_IDENTIFIER = new LocalHistoryIdentifier(CLIENT_IDENTIFIER, 0);
+
+ private final @NonNull T object;
+ private final int expectedSize;
+ private final int legacySize;
- protected abstract T object();
+ protected AbstractRequestSuccessTest(final T object, final int expectedSize, final int legacySize) {
+ this.object = requireNonNull(object);
+ this.expectedSize = expectedSize;
+ this.legacySize = legacySize;
+ }
- @SuppressWarnings("unchecked")
@Test
public void serializationTest() {
- final Object deserialize = SerializationUtils.clone(object());
+ final var bytes = SerializationUtils.serialize(object);
+ assertEquals(expectedSize, bytes.length);
+ assertEquals(legacySize, SerializationUtils.serialize(object.toVersion(ABIVersion.MAGNESIUM)).length);
+
+ @SuppressWarnings("unchecked")
+ final var deserialize = (T) SerializationUtils.deserialize(bytes);
- Assert.assertEquals(object().getTarget(), ((T) deserialize).getTarget());
- Assert.assertEquals(object().getVersion(), ((T) deserialize).getVersion());
- Assert.assertEquals(object().getSequence(), ((T) deserialize).getSequence());
+ assertEquals(object.getTarget(), deserialize.getTarget());
+ assertEquals(object.getVersion(), deserialize.getVersion());
+ assertEquals(object.getSequence(), deserialize.getSequence());
doAdditionalAssertions(deserialize);
}
- protected abstract void doAdditionalAssertions(Object deserialize);
+ protected void doAdditionalAssertions(final T deserialize) {
+ // No-op by default
+ }
}