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 java.util.Objects.requireNonNull;
11 import static org.junit.jupiter.api.Assertions.assertEquals;
13 import org.apache.commons.lang.SerializationUtils;
14 import org.junit.Before;
15 import org.junit.Test;
17 public abstract class AbstractEnvelopeTest<E extends Envelope<?>> {
18 protected record EnvelopeDetails<E extends Envelope<?>>(E envelope, int expectedSize) {
22 private static final FrontendIdentifier FRONTEND =
23 new FrontendIdentifier(MemberName.forName("test"), FrontendIdentifierTest.ONE_FRONTEND_TYPE);
24 private static final ClientIdentifier CLIENT = new ClientIdentifier(FRONTEND, 0);
25 private static final LocalHistoryIdentifier HISTORY = new LocalHistoryIdentifier(CLIENT, 0);
26 protected static final TransactionIdentifier OBJECT = new TransactionIdentifier(HISTORY, 0);
29 private int expectedSize;
32 public void setUp() throws Exception {
33 final var details = createEnvelope();
34 envelope = requireNonNull(details.envelope);
35 expectedSize = details.expectedSize;
39 public void testProxySerializationDeserialization() {
40 final byte[] serializedBytes = SerializationUtils.serialize(envelope);
41 assertEquals(expectedSize, serializedBytes.length);
42 @SuppressWarnings("unchecked")
43 final E deserialize = (E) SerializationUtils.deserialize(serializedBytes);
44 checkDeserialized(deserialize);
47 private void checkDeserialized(final E deserializedEnvelope) {
48 assertEquals(envelope.getSessionId(), deserializedEnvelope.getSessionId());
49 assertEquals(envelope.getTxSequence(), deserializedEnvelope.getTxSequence());
50 final var expectedMessage = envelope.getMessage();
51 final var actualMessage = deserializedEnvelope.getMessage();
52 assertEquals(expectedMessage.getSequence(), actualMessage.getSequence());
53 assertEquals(expectedMessage.getTarget(), actualMessage.getTarget());
54 assertEquals(expectedMessage.getVersion(), actualMessage.getVersion());
55 assertEquals(expectedMessage.getClass(), actualMessage.getClass());
56 doAdditionalAssertions(envelope, deserializedEnvelope);
59 protected abstract EnvelopeDetails<E> createEnvelope();
61 protected abstract void doAdditionalAssertions(E envelope, E resolvedObject);