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.commands;
10 import static java.util.Objects.requireNonNull;
11 import static org.junit.Assert.assertEquals;
13 import org.apache.commons.lang.SerializationUtils;
14 import org.eclipse.jdt.annotation.NonNull;
15 import org.junit.Test;
16 import org.opendaylight.controller.cluster.access.ABIVersion;
17 import org.opendaylight.controller.cluster.access.concepts.ClientIdentifier;
18 import org.opendaylight.controller.cluster.access.concepts.FrontendIdentifier;
19 import org.opendaylight.controller.cluster.access.concepts.FrontendType;
20 import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier;
21 import org.opendaylight.controller.cluster.access.concepts.MemberName;
22 import org.opendaylight.controller.cluster.access.concepts.RequestSuccess;
24 public abstract class AbstractRequestSuccessTest<T extends RequestSuccess<?, T>> {
25 private static final FrontendIdentifier FRONTEND_IDENTIFIER = FrontendIdentifier.create(
26 MemberName.forName("test"), FrontendType.forName("one"));
27 protected static final ClientIdentifier CLIENT_IDENTIFIER = ClientIdentifier.create(FRONTEND_IDENTIFIER, 0);
28 protected static final LocalHistoryIdentifier HISTORY_IDENTIFIER = new LocalHistoryIdentifier(CLIENT_IDENTIFIER, 0);
30 private final @NonNull T object;
31 private final int expectedSize;
32 private final int legacySize;
34 protected AbstractRequestSuccessTest(final T object, final int expectedSize, final int legacySize) {
35 this.object = requireNonNull(object);
36 this.expectedSize = expectedSize;
37 this.legacySize = legacySize;
41 public void serializationTest() {
42 final var bytes = SerializationUtils.serialize(object);
43 assertEquals(legacySize, bytes.length);
44 assertEquals(expectedSize, SerializationUtils.serialize(object.toVersion(ABIVersion.CHLORINE_SR2)).length);
46 @SuppressWarnings("unchecked")
47 final var deserialize = (T) SerializationUtils.deserialize(bytes);
49 assertEquals(object.getTarget(), deserialize.getTarget());
50 assertEquals(object.getVersion(), deserialize.getVersion());
51 assertEquals(object.getSequence(), deserialize.getSequence());
52 doAdditionalAssertions(deserialize);
55 protected void doAdditionalAssertions(final T deserialize) {