-
Notifications
You must be signed in to change notification settings - Fork 626
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JIRA: https://jira.spring.io/browse/AMQP-791 - refactor `BrokerRunning` JUnit4 `@Rule` so it can be invoked from an `ExecutionCondition`. - Add `@RabbitAvailable` annotation with queue list and auto-delete queues at the end of the class; purge them between tests. * Implement `ParameterResolver` to access the rule's connection factory. * Support CTOR Injection and `BrokerRunning` Injection - user might want to invoke methods such as `deleteQueues()`. * Patches omitted from previous commit * WIP - Spring * Polishing - PR Comments * Convert `RabbitTemplateMPPIntegrationTests` - JUnit5 * Remove bogus test * Docs + `@LongRunning` * Polishing - PR Comments
- Loading branch information
1 parent
48412b9
commit d73f4ff
Showing
15 changed files
with
840 additions
and
184 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
spring-rabbit-junit/src/main/java/org/springframework/amqp/rabbit/junit/LongRunning.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright 2017 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. | ||
* 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.springframework.amqp.rabbit.junit; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
import org.junit.jupiter.api.extension.ExtendWith; | ||
|
||
/** | ||
* Test classes annotated with this will not run if an environment variable or system | ||
* property (default {@code RUN_LONG_INTEGRATION_TESTS}) is not present or does not have | ||
* the value that {@link Boolean#parseBoolean(String)} evaluates to {@code true}. | ||
* | ||
* @author Gary Russell | ||
* @since 2.0.2 | ||
* | ||
*/ | ||
@ExtendWith(LongRunningIntegrationTestCondition.class) | ||
@Target({ ElementType.TYPE }) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Documented | ||
public @interface LongRunning { | ||
|
||
/** | ||
* The name of the variable/property used to determine whether long runnning tests | ||
* should run. | ||
* @return the name of the variable/property. | ||
*/ | ||
String value() default LongRunningIntegrationTest.RUN_LONG_INTEGRATION_TESTS; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
.../main/java/org/springframework/amqp/rabbit/junit/LongRunningIntegrationTestCondition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright 2017 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. | ||
* 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.springframework.amqp.rabbit.junit; | ||
|
||
import java.lang.reflect.AnnotatedElement; | ||
import java.util.Optional; | ||
|
||
import org.junit.jupiter.api.extension.ConditionEvaluationResult; | ||
import org.junit.jupiter.api.extension.ExecutionCondition; | ||
import org.junit.jupiter.api.extension.ExtensionContext; | ||
import org.junit.platform.commons.util.AnnotationUtils; | ||
|
||
import org.springframework.util.StringUtils; | ||
|
||
/** | ||
* {@link ExecutionCondition} to skip long running tests unless an environment | ||
* variable or property is set. | ||
* | ||
* @author Gary Russell | ||
* @since 2.0.2 | ||
* @see LongRunning | ||
*/ | ||
public class LongRunningIntegrationTestCondition implements ExecutionCondition { | ||
|
||
private static final ConditionEvaluationResult ENABLED = ConditionEvaluationResult.enabled( | ||
"@LongRunning is not present"); | ||
|
||
@Override | ||
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) { | ||
Optional<AnnotatedElement> element = context.getElement(); | ||
Optional<LongRunning> longRunning = AnnotationUtils.findAnnotation(element, LongRunning.class); | ||
if (longRunning.isPresent()) { | ||
String property = longRunning.get().value(); | ||
if (!StringUtils.hasText(property)) { | ||
property = LongRunningIntegrationTest.RUN_LONG_INTEGRATION_TESTS; | ||
} | ||
LongRunningIntegrationTest lrit = new LongRunningIntegrationTest(property); | ||
return lrit.isShouldRun() ? ConditionEvaluationResult.enabled("Long running tests must run") | ||
: ConditionEvaluationResult.disabled("Long running tests are skipped"); | ||
} | ||
return ENABLED; | ||
} | ||
|
||
} |
Oops, something went wrong.