Java Code Examples for org.springframework.test.context.TestContext#markApplicationContextDirty()

The following examples show how to use org.springframework.test.context.TestContext#markApplicationContextDirty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WireMockTestExecutionListener.java    From spring-cloud-contract with Apache License 2.0 6 votes vote down vote up
@Override
public void afterTestClass(TestContext testContext) {
	if (applicationContextBroken(testContext)
			|| wireMockConfigurationMissing(testContext)
			|| annotationMissing(testContext)) {
		return;
	}
	if (portIsFixed(testContext)) {
		if (log.isWarnEnabled()) {
			log.warn("You've used fixed ports for WireMock setup - "
					+ "will mark context as dirty. Please use random ports, as much "
					+ "as possible. Your tests will be faster and more reliable and this "
					+ "warning will go away");
		}
		testContext
				.markApplicationContextDirty(DirtiesContext.HierarchyMode.EXHAUSTIVE);
	}
	else {
		if (log.isDebugEnabled()) {
			log.debug(
					"Resetting mappings for the next test to restart them. That's necessary when"
							+ " reusing the same context with new servers running on random ports");
		}
		wireMockConfig(testContext).reRegisterServerWithResetMappings();
	}
}
 
Example 2
Source File: StubRunnerWireMockTestExecutionListener.java    From spring-cloud-contract with Apache License 2.0 6 votes vote down vote up
@Override
public void afterTestClass(TestContext testContext) {
	if (testContext.getTestClass()
			.getAnnotationsByType(AutoConfigureStubRunner.class).length == 0) {
		if (log.isDebugEnabled()) {
			log.debug("No @AutoConfigureStubRunner annotation found on ["
					+ testContext.getTestClass() + "]. Skipping");
		}
		return;
	}
	if (!WireMockHttpServerStub.SERVERS.isEmpty() && WireMockHttpServerStub.SERVERS
			.values().stream().noneMatch(p -> p.random)) {
		if (log.isWarnEnabled()) {
			log.warn("You've used fixed ports for WireMock setup - "
					+ "will mark context as dirty. Please use random ports, as much "
					+ "as possible. Your tests will be faster and more reliable and this "
					+ "warning will go away");
		}
		testContext
				.markApplicationContextDirty(DirtiesContext.HierarchyMode.EXHAUSTIVE);
	}
	// potential race condition
	WireMockHttpServerStub.SERVERS.clear();
}
 
Example 3
Source File: AbstractDirtiesContextTestExecutionListener.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * Mark the {@linkplain ApplicationContext application context} of the supplied
 * {@linkplain TestContext test context} as
 * {@linkplain TestContext#markApplicationContextDirty(DirtiesContext.HierarchyMode) dirty}
 * and set {@link DependencyInjectionTestExecutionListener#REINJECT_DEPENDENCIES_ATTRIBUTE
 * REINJECT_DEPENDENCIES_ATTRIBUTE} in the test context to {@code true}.
 * @param testContext the test context whose application context should
 * be marked as dirty
 * @param hierarchyMode the context cache clearing mode to be applied if the
 * context is part of a hierarchy; may be {@code null}
 * @since 3.2.2
 */
protected void dirtyContext(TestContext testContext, @Nullable HierarchyMode hierarchyMode) {
	testContext.markApplicationContextDirty(hierarchyMode);
	testContext.setAttribute(DependencyInjectionTestExecutionListener.REINJECT_DEPENDENCIES_ATTRIBUTE, Boolean.TRUE);
}
 
Example 4
Source File: AbstractDirtiesContextTestExecutionListener.java    From java-technology-stack with MIT License 2 votes vote down vote up
/**
 * Mark the {@linkplain ApplicationContext application context} of the supplied
 * {@linkplain TestContext test context} as
 * {@linkplain TestContext#markApplicationContextDirty(DirtiesContext.HierarchyMode) dirty}
 * and set {@link DependencyInjectionTestExecutionListener#REINJECT_DEPENDENCIES_ATTRIBUTE
 * REINJECT_DEPENDENCIES_ATTRIBUTE} in the test context to {@code true}.
 * @param testContext the test context whose application context should
 * be marked as dirty
 * @param hierarchyMode the context cache clearing mode to be applied if the
 * context is part of a hierarchy; may be {@code null}
 * @since 3.2.2
 */
protected void dirtyContext(TestContext testContext, @Nullable HierarchyMode hierarchyMode) {
	testContext.markApplicationContextDirty(hierarchyMode);
	testContext.setAttribute(DependencyInjectionTestExecutionListener.REINJECT_DEPENDENCIES_ATTRIBUTE, Boolean.TRUE);
}
 
Example 5
Source File: AbstractDirtiesContextTestExecutionListener.java    From spring4-understanding with Apache License 2.0 2 votes vote down vote up
/**
 * Mark the {@linkplain ApplicationContext application context} of the supplied
 * {@linkplain TestContext test context} as
 * {@linkplain TestContext#markApplicationContextDirty(DirtiesContext.HierarchyMode) dirty}
 * and set {@link DependencyInjectionTestExecutionListener#REINJECT_DEPENDENCIES_ATTRIBUTE
 * REINJECT_DEPENDENCIES_ATTRIBUTE} in the test context to {@code true}.
 * @param testContext the test context whose application context should
 * be marked as dirty
 * @param hierarchyMode the context cache clearing mode to be applied if the
 * context is part of a hierarchy; may be {@code null}
 * @since 3.2.2
 */
protected void dirtyContext(TestContext testContext, HierarchyMode hierarchyMode) {
	testContext.markApplicationContextDirty(hierarchyMode);
	testContext.setAttribute(DependencyInjectionTestExecutionListener.REINJECT_DEPENDENCIES_ATTRIBUTE, Boolean.TRUE);
}
 
Example 6
Source File: ReloadContextTestExecutionListener.java    From geomajas-project-server with GNU Affero General Public License v3.0 2 votes vote down vote up
/**
 * Marks the {@link ApplicationContext application context} of the supplied {@link TestContext test context} as
 * {@link TestContext#markApplicationContextDirty() dirty}, and sets the
 * {@link DependencyInjectionTestExecutionListener#REINJECT_DEPENDENCIES_ATTRIBUTE REINJECT_DEPENDENCIES_ATTRIBUTE}
 * in the test context to <code>true</code> .
 */
protected void reloadContext(TestContext testContext) {
	testContext.markApplicationContextDirty();
	testContext
			.setAttribute(DependencyInjectionTestExecutionListener.REINJECT_DEPENDENCIES_ATTRIBUTE, Boolean.TRUE);
}