Skip to content
Merged

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
/*
* Copyright (c) 2010-2026. 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.integrationtests.testsuite;

import org.axonframework.common.annotation.Internal;
import org.axonframework.common.configuration.ApplicationConfigurer;
import org.axonframework.common.configuration.AxonConfiguration;
import org.axonframework.integrationtests.testsuite.infrastructure.TestInfrastructure;
import org.axonframework.messaging.commandhandling.gateway.CommandGateway;
import org.junit.jupiter.api.AfterEach;

import java.util.UUID;

/**
* Infrastructure-agnostic base class for all integration tests in this suite.
* <p>
* The specific backend (AxonServer, InMemory, Postgres, …) is supplied by leaf test classes through
* {@link #testInfrastructure()}.
* <p>
* Subclasses must implement:
* <ul>
* <li>{@link #testInfrastructure()} — return the infrastructure strategy to use</li>
* <li>{@link #applicationConfigurer()} — return the domain-specific {@link ApplicationConfigurer}</li>
* </ul>
* and must call {@link #startApp()} (typically from a {@code @BeforeEach} method) to start the Axon configuration.
*
* @author Mateusz Nowak
* @since 5.1.0
Comment thread
MateuszNaKodach marked this conversation as resolved.
*/
@Internal
public abstract class AbstractIntegrationTest {

protected CommandGateway commandGateway;
protected AxonConfiguration startedConfiguration;

/**
* Returns the {@link TestInfrastructure} for this test. Leaf classes typically return a {@code private static
* final} instance so the infrastructure wrapper (and any heavy resources it guards, such as a shared
* Testcontainer) is created once per leaf class:
* <pre>{@code
* private static final TestInfrastructure INFRASTRUCTURE = new AxonServerTestInfrastructure();
*
* @Override
* protected TestInfrastructure testInfrastructure() {
* return INFRASTRUCTURE;
* }
* }</pre>
*
* @return the infrastructure strategy to use for this test
*/
protected abstract TestInfrastructure testInfrastructure();

/**
* Returns the domain-specific {@link ApplicationConfigurer} for this test. Called from {@link #startApp()} each
* time the Axon configuration is started.
*
* @return the application configurer for this test
*/
protected abstract ApplicationConfigurer applicationConfigurer();

/**
* Shuts down the Axon configuration and releases infrastructure resources acquired during {@link #startApp()}.
* The infrastructure is only stopped when {@link #startApp()} actually completed, signalled by a non-null
* {@link #startedConfiguration}.
*/
@AfterEach
void tearDown() {
if (startedConfiguration == null) {
return;
}
try {
startedConfiguration.shutdown();
} finally {
testInfrastructure().stop();
}
}

/**
* Starts the Axon Framework application using the configured infrastructure and domain configurer.
* <p>
* Subclasses must call this method (directly or via {@code super.startApp()}) from a {@code @BeforeEach} method.
* The infrastructure's {@link TestInfrastructure#start()} is invoked first (idempotent), followed by building and
* starting the {@link AxonConfiguration}.
*/
protected void startApp() {
TestInfrastructure infra = testInfrastructure();
infra.start();
startedConfiguration = applicationConfigurer()
.componentRegistry(infra::configureInfrastructure)
.start();
commandGateway = startedConfiguration.getComponent(CommandGateway.class);
}

/**
* Purges persisted data via the current {@link TestInfrastructure}. Opt-in — only tests that require a clean
* initial state (e.g. event-replay tests) should call this method.
*/
protected void purgeData() {
testInfrastructure().purgeData();
}

/**
* Creates a unique ID string with the given {@code prefix}, suitable for use as an aggregate or entity identifier
* in tests.
*
* @param prefix a human-readable prefix for the generated ID
* @return a unique identifier string
*/
protected static String createId(String prefix) {
return prefix + "-" + UUID.randomUUID();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import org.axonframework.common.configuration.ApplicationConfigurer;
import org.axonframework.eventsourcing.configuration.EventSourcingConfigurer;
import org.axonframework.integrationtests.testsuite.AbstractAxonServerIT;
import org.axonframework.integrationtests.testsuite.AbstractIntegrationTest;
import org.axonframework.integrationtests.testsuite.administration.commands.AssignTaskCommand;
import org.axonframework.integrationtests.testsuite.administration.commands.ChangeEmailAddress;
import org.axonframework.integrationtests.testsuite.administration.commands.CompleteTaskCommand;
Expand All @@ -37,7 +37,7 @@
* Test suite for verifying polymorphic behavior of entities. Can be implemented by different test classes that verify
* different ways of building the {@link org.axonframework.modelling.entity.EntityCommandHandlingComponent}.
*/
public abstract class AbstractAdministrationIT extends AbstractAxonServerIT {
public abstract class AbstractAdministrationIT extends AbstractIntegrationTest {

private final CreateEmployee CREATE_EMPLOYEE_1_COMMAND = new CreateEmployee(
new PersonIdentifier(PersonType.EMPLOYEE, createId("employee")),
Expand All @@ -56,7 +56,7 @@ public void doStartApp() {
}

@Override
protected ApplicationConfigurer createConfigurer() {
protected ApplicationConfigurer applicationConfigurer() {
var configurer = EventSourcingConfigurer.create();
return testSuiteConfigurer(configurer);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (c) 2010-2026. 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.integrationtests.testsuite.administration;

import org.axonframework.integrationtests.testsuite.infrastructure.AxonServerTestInfrastructure;
import org.axonframework.integrationtests.testsuite.infrastructure.TestInfrastructure;

/**
* Runs {@link ImmutableBuilderEntityModelAdministrationIT} against a real Axon Server instance.
*/
public class ImmutableBuilderEntityModelAdministrationAxonServerIT
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to be curious, but you added the Axon Server variants for ease while moving I'd assume, right? I mean, they'll immediately be removed by #4412 that's following this PR.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I just wanted to check if it really works. Then we will remove and copy-paste to the Axoniq Framework.

extends ImmutableBuilderEntityModelAdministrationIT {

private static final TestInfrastructure INFRASTRUCTURE = new AxonServerTestInfrastructure();

@Override
protected TestInfrastructure testInfrastructure() {
return INFRASTRUCTURE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
/**
* Runs the administration test suite using the builders of {@link EntityMetamodel} and related classes.
*/
public class ImmutableBuilderEntityModelAdministrationIT extends AbstractAdministrationIT {
public abstract class ImmutableBuilderEntityModelAdministrationIT extends AbstractAdministrationIT {

EntityMetamodel<ImmutablePerson> buildEntityMetamodel(Configuration configuration,
EntityMetamodelBuilder<ImmutablePerson> builder) {
Expand Down
Loading
Loading