Skip to content

Commit

Permalink
More @DirtiesContext for tests in core module
Browse files Browse the repository at this point in the history
Additional code style cleanups in the affected classes

# Conflicts:
#	spring-integration-core/src/test/java/org/springframework/integration/json/JsonPathTests.java

# Conflicts:
#	spring-integration-core/src/test/java/org/springframework/integration/aggregator/integration/MethodInvokingAggregatorReturningMessageTests.java
#	spring-integration-core/src/test/java/org/springframework/integration/gateway/GatewayWithHeaderAnnotationsTests.java
#	spring-integration-core/src/test/java/org/springframework/integration/router/config/DynamicExpressionRouterIntegrationTests.java
#	spring-integration-core/src/test/java/org/springframework/integration/router/config/RouterWithMappingTests.java
  • Loading branch information
artembilan committed Nov 15, 2024
1 parent 4a8eef8 commit 56d5624
Show file tree
Hide file tree
Showing 67 changed files with 433 additions and 456 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,17 +19,16 @@
import java.util.HashMap;
import java.util.Map;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.integration.IntegrationMessageHeaderAccessor;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.PollableChannel;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;

import static org.assertj.core.api.Assertions.assertThat;

Expand All @@ -39,8 +38,8 @@
* @author Oleg Zhurakousky
* @author Artem Bilan
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
@SpringJUnitConfig
@DirtiesContext
public class AggregatorExpressionIntegrationTests {

@Autowired
Expand All @@ -51,7 +50,7 @@ public class AggregatorExpressionIntegrationTests {
@Qualifier("output")
private PollableChannel output;

@Test//(timeout=5000)
@Test
public void testVanillaAggregation() {
for (int i = 0; i < 5; i++) {
Map<String, Object> headers = stubHeaders(i, 5, 1);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -38,6 +38,7 @@
import org.springframework.integration.support.MessageBuilder;
import org.springframework.messaging.Message;
import org.springframework.messaging.PollableChannel;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -47,6 +48,7 @@
* @author Artem Bilan
*/
@SpringJUnitConfig(classes = AnnotationAggregatorTests.TestConfiguration.class)
@DirtiesContext
public class AnnotationAggregatorTests {

@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,24 @@
import java.util.Collections;
import java.util.List;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.integration.channel.DirectChannel;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.messaging.Message;
import org.springframework.messaging.PollableChannel;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;

import static org.assertj.core.api.Assertions.assertThat;

/**
* @author Mark Fisher
* @author Artem Bilan
*/
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@SpringJUnitConfig
@DirtiesContext
public class MethodInvokingAggregatorReturningMessageTests {

@Autowired
Expand All @@ -52,8 +51,7 @@ public class MethodInvokingAggregatorReturningMessageTests {
@Autowired
PollableChannel defaultOutput;


@Test // INT-1107
@Test
public void messageReturningPojoAggregatorResultIsNotWrappedInAnotherMessage() {
List<String> payload = Collections.singletonList("test");
this.pojoInput.send(MessageBuilder.withPayload(payload).build());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,8 +16,7 @@

package org.springframework.integration.aggregator.integration;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
Expand All @@ -31,8 +30,7 @@
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;

import static org.assertj.core.api.Assertions.assertThat;

Expand All @@ -41,8 +39,7 @@
* @author David Liu
* @author Artem Bilan
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
@SpringJUnitConfig
@DirtiesContext
public class ResequencerIntegrationTests {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,37 @@

package org.springframework.integration.dispatcher;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import org.springframework.aop.framework.Advised;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;

import static org.assertj.core.api.Assertions.assertThat;

/**
* This test was influenced by INT-1483 where via registering TX Advisor
* in the BeanFactory while having <aop:config> resent resulted in
* TX Advisor being applied on all beans in AC
*
* @author Oleg Zhurakousky
* @author Gunnar Hillert
* @author Gary Russell
*
* This test was influenced by INT-1483 where by registering TX Advisor
* in the BeanFactory while having <aop:config> resent resulted in
* TX Advisor being applied on all beans in AC
* @author Artem Bilan
*/
@SpringJUnitConfig
@DirtiesContext
public class TransactionalPollerWithMixedAopConfigTests {

@Autowired
ApplicationContext applicationContext;

@Test
public void validateTransactionalProxyIsolationToThePollerOnly() {
ClassPathXmlApplicationContext context =
new ClassPathXmlApplicationContext("TransactionalPollerWithMixedAopConfig-context.xml", this.getClass());

assertThat(!(context.getBean("foo") instanceof Advised)).isTrue();
assertThat(!(context.getBean("inputChannel") instanceof Advised)).isTrue();
context.close();
assertThat(this.applicationContext.getBean("foo")).isNotInstanceOf(Advised.class);
assertThat(applicationContext.getBean("inputChannel")).isNotInstanceOf(Advised.class);
}

public static class SampleService {
Expand All @@ -54,9 +59,4 @@ public Foo(String value) {
}
}

// public static class SampleAdvice implements MethodInterceptor{
// public Object invoke(MethodInvocation invocation) throws Throwable {
// return invocation.proceed();
// }
// }
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,43 +16,48 @@

package org.springframework.integration.dispatcher;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.integration.gateway.RequestReplyExchanger;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.MessageDeliveryException;
import org.springframework.messaging.MessageHandler;
import org.springframework.messaging.SubscribableChannel;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;

import static org.assertj.core.api.Assertions.assertThat;

/**
* @author Oleg Zhurakousky
* @author Gunnar Hillert
* @author Gary Russell
*
* @author Artem Bilan
*/
@SpringJUnitConfig
@DirtiesContext
public class UnicastingDispatcherTests {

@SuppressWarnings("unchecked")
@Autowired
ApplicationContext applicationContext;

@Test
public void withInboundGatewayAsyncRequestChannelAndExplicitErrorChannel() throws Exception {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("unicasting-with-async.xml", this.getClass());
SubscribableChannel errorChannel = context.getBean("errorChannel", SubscribableChannel.class);
public void withInboundGatewayAsyncRequestChannelAndExplicitErrorChannel() {
SubscribableChannel errorChannel = this.applicationContext.getBean("errorChannel", SubscribableChannel.class);
MessageHandler errorHandler = message -> {
MessageChannel replyChannel = (MessageChannel) message.getHeaders().getReplyChannel();
assertThat(message.getPayload() instanceof MessageDeliveryException).isTrue();
replyChannel.send(new GenericMessage<String>("reply"));
replyChannel.send(new GenericMessage<>("reply"));
};
errorChannel.subscribe(errorHandler);

RequestReplyExchanger exchanger = context.getBean(RequestReplyExchanger.class);
Message<String> reply = (Message<String>) exchanger.exchange(new GenericMessage<String>("Hello"));
RequestReplyExchanger exchanger = this.applicationContext.getBean(RequestReplyExchanger.class);
Message<?> reply = exchanger.exchange(new GenericMessage<>("Hello"));
assertThat(reply.getPayload()).isEqualTo("reply");
context.close();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.springframework.integration.handler.LambdaMessageProcessor;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -48,6 +49,7 @@
* @since 5.0
*/
@SpringJUnitConfig
@DirtiesContext
public class LambdaMessageProcessorTests {

@Autowired
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2018-2022 the original author or authors.
* Copyright 2018-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,8 +16,7 @@

package org.springframework.integration.dsl.lifecycle;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanClassLoaderAware;
Expand All @@ -42,7 +41,7 @@
import org.springframework.integration.config.EnableIntegration;
import org.springframework.integration.dsl.IntegrationComponentSpec;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import org.springframework.util.StringValueResolver;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -52,7 +51,7 @@
*
* @since 5.0.7
*/
@RunWith(SpringRunner.class)
@SpringJUnitConfig
@DirtiesContext
public class IntegrationComponentSpecLifecycleTests {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2022 the original author or authors.
* Copyright 2017-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -20,8 +20,7 @@
import java.util.List;
import java.util.function.Consumer;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
Expand All @@ -34,7 +33,8 @@
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.MessageHandler;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;

import static org.assertj.core.api.Assertions.assertThat;

Expand All @@ -44,7 +44,8 @@
*
* @since 5.0
*/
@RunWith(SpringRunner.class)
@SpringJUnitConfig
@DirtiesContext
public class PublishSubscribeTests {

@Autowired
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 the original author or authors.
* Copyright 2019-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -27,6 +27,7 @@
import org.springframework.integration.config.EnableIntegration;
import org.springframework.integration.dsl.IntegrationFlow;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -39,6 +40,7 @@
*
*/
@SpringJUnitConfig
@DirtiesContext
public class NoFallbackAllowedTests {

@Test
Expand Down
Loading

0 comments on commit 56d5624

Please sign in to comment.