Skip to content

Commit

Permalink
Introduce TestSerializer
Browse files Browse the repository at this point in the history
Introduce TestSerializer to be used for legacy tests.

#1917
  • Loading branch information
smcvb committed Sep 29, 2021
1 parent 7526eff commit 9d228e2
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@

package org.axonframework.commandhandling.model;

import com.thoughtworks.xstream.XStream;
import org.axonframework.serialization.SerializedObject;
import org.axonframework.serialization.SimpleSerializedObject;
import org.axonframework.serialization.json.JacksonSerializer;
import org.axonframework.serialization.xml.XStreamSerializer;
import org.axonframework.utils.TestSerializer;
import org.junit.jupiter.api.*;

import static org.junit.jupiter.api.Assertions.*;

/**
* Test whether the serialized form of the {@link org.axonframework.commandhandling.model.AggregateScopeDescriptor} can
* be deserialized into the {@link AggregateScopeDescriptor}, using the {@link XStreamSerializer} and
* {@link JacksonSerializer}.
* be deserialized into the {@link AggregateScopeDescriptor}, using the {@link XStreamSerializer} and {@link
* JacksonSerializer}.
*
* @author Steven van Beelen
*/
Expand All @@ -41,9 +41,7 @@ class AggregateScopeDescriptorTest {

@Test
void testXStreamSerializationOfOldAggregateScopeDescriptor() {
XStreamSerializer serializer = XStreamSerializer.builder()
.xStream(new XStream())
.build();
XStreamSerializer serializer = TestSerializer.xStreamSerializer();

String xmlSerializedScopeDescriptor =
"<org.axonframework.commandhandling.model.AggregateScopeDescriptor serialization=\"custom\">"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,20 @@

package org.axonframework.eventhandling.saga;

import com.thoughtworks.xstream.XStream;
import org.axonframework.modelling.saga.SagaScopeDescriptor;
import org.axonframework.serialization.SerializedObject;
import org.axonframework.serialization.SimpleSerializedObject;
import org.axonframework.serialization.json.JacksonSerializer;
import org.axonframework.serialization.xml.XStreamSerializer;
import org.axonframework.utils.TestSerializer;
import org.junit.jupiter.api.*;

import static org.junit.jupiter.api.Assertions.*;

/**
* Test whether the serialized form of the {@link org.axonframework.eventhandling.saga.SagaScopeDescriptor} can be
* deserialized into the {@link SagaScopeDescriptor}, using the {@link XStreamSerializer} and {@link JacksonSerializer}.
* deserialized into the {@link SagaScopeDescriptor}, using the {@link XStreamSerializer} and {@link
* JacksonSerializer}.
*
* @author Steven van Beelen
*/
Expand All @@ -41,9 +42,7 @@ class SagaScopeDescriptorTest {

@Test
void testXStreamSerializationOfOldSagaScopeDescriptor() {
XStreamSerializer serializer = XStreamSerializer.builder()
.xStream(new XStream())
.build();
XStreamSerializer serializer = TestSerializer.xStreamSerializer();

String xmlSerializedScopeDescriptor =
"<org.axonframework.eventhandling.saga.SagaScopeDescriptor>"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@

package org.axonframework.eventsourcing.eventstore;

import com.thoughtworks.xstream.XStream;
import org.axonframework.eventhandling.GapAwareTrackingToken;
import org.axonframework.serialization.SerializedObject;
import org.axonframework.serialization.SimpleSerializedObject;
import org.axonframework.serialization.json.JacksonSerializer;
import org.axonframework.serialization.xml.XStreamSerializer;
import org.axonframework.utils.TestSerializer;
import org.junit.jupiter.api.*;

import java.util.List;
Expand All @@ -33,8 +33,8 @@

/**
* Test whether the serialized form of the {@link org.axonframework.eventsourcing.eventstore.GapAwareTrackingToken} can
* be deserialized into the {@link GapAwareTrackingToken}, using the {@link XStreamSerializer} and
* {@link JacksonSerializer}.
* be deserialized into the {@link GapAwareTrackingToken}, using the {@link XStreamSerializer} and {@link
* JacksonSerializer}.
*
* @author Steven van Beelen
*/
Expand All @@ -47,9 +47,7 @@ class GapAwareTrackingTokenTest {

@Test
void testXStreamSerializationOfOldGapAwareTrackingToken() {
XStreamSerializer serializer = XStreamSerializer.builder()
.xStream(new XStream())
.build();
XStreamSerializer serializer = TestSerializer.xStreamSerializer();

String xmlSerializedGapAwareTrackingToken =
"<org.axonframework.eventsourcing.eventstore.GapAwareTrackingToken>"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@

package org.axonframework.eventsourcing.eventstore;

import com.thoughtworks.xstream.XStream;
import org.axonframework.eventhandling.GlobalSequenceTrackingToken;
import org.axonframework.serialization.SerializedObject;
import org.axonframework.serialization.SimpleSerializedObject;
import org.axonframework.serialization.json.JacksonSerializer;
import org.axonframework.serialization.xml.XStreamSerializer;
import org.axonframework.utils.TestSerializer;
import org.junit.jupiter.api.*;

import static org.junit.jupiter.api.Assertions.*;

/**
* Test whether the serialized form of the
* {@link org.axonframework.eventsourcing.eventstore.GlobalSequenceTrackingToken} can be deserialized into the
* {@link GlobalSequenceTrackingToken}, using the {@link XStreamSerializer} and {@link JacksonSerializer}.
* Test whether the serialized form of the {@link org.axonframework.eventsourcing.eventstore.GlobalSequenceTrackingToken}
* can be deserialized into the {@link GlobalSequenceTrackingToken}, using the {@link XStreamSerializer} and {@link
* JacksonSerializer}.
*
* @author Steven van Beelen
*/
Expand All @@ -41,9 +41,7 @@ class GlobalSequenceTrackingTokenTest {

@Test
void testXStreamSerializationOfOldGlobalSequenceTrackingToken() {
XStreamSerializer serializer = XStreamSerializer.builder()
.xStream(new XStream())
.build();
XStreamSerializer serializer = TestSerializer.xStreamSerializer();

String xmlSerializedGlobalSequenceTrackingToken =
"<org.axonframework.eventsourcing.eventstore.GlobalSequenceTrackingToken>"
Expand Down
44 changes: 44 additions & 0 deletions legacy/src/test/java/org/axonframework/utils/TestSerializer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (c) 2010-2021. Axon Framework
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.axonframework.utils;

import com.thoughtworks.xstream.XStream;
import org.axonframework.serialization.xml.CompactDriver;
import org.axonframework.serialization.xml.XStreamSerializer;

/**
* Utility providing {@link org.axonframework.serialization.Serializer} instances for testing.
*
* @author Steven van Beelen
*/
public abstract class TestSerializer {

private TestSerializer() {
// Test utility class
}

/**
* Return a {@link XStreamSerializer} using a default {@link XStream} instance with a {@link CompactDriver}.
*
* @return a {@link XStreamSerializer} using a default {@link XStream} instance with a {@link CompactDriver}
*/
public static XStreamSerializer xStreamSerializer() {
return XStreamSerializer.builder()
.xStream(new XStream(new CompactDriver()))
.build();
}
}

0 comments on commit 9d228e2

Please sign in to comment.