Skip to content

Commit

Permalink
Test Refactor (YamlServletProfileInitializerTests)
Browse files Browse the repository at this point in the history
- Should cleanup the Log Configuration

[#162794188] https://www.pivotaltracker.com/story/show/162794188
  • Loading branch information
joshuatcasey authored and andrewedstrom committed Mar 18, 2019
1 parent c369774 commit cf1ac78
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.cloudfoundry.identity.uaa.impl.config;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.LoggerContext;
import org.junit.jupiter.api.extension.AfterAllCallback;
import org.junit.jupiter.api.extension.BeforeAllCallback;
import org.junit.jupiter.api.extension.ExtensionContext;

import java.net.URI;

public class LoggerContextCleanupExtension implements BeforeAllCallback, AfterAllCallback {

private URI configLocation = null;

@Override
public void beforeAll(ExtensionContext context) {
LoggerContext loggerContext = (LoggerContext) LogManager.getContext(false);
configLocation = loggerContext.getConfigLocation();
}

@Override
public void afterAll(ExtensionContext context) {
LoggerContext loggerContext = (LoggerContext) LogManager.getContext(false);
loggerContext.setConfigLocation(configLocation);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.springframework.core.env.StandardEnvironment;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.security.web.session.HttpSessionEventPublisher;
import org.springframework.util.Log4jConfigurer;
import org.springframework.web.context.ConfigurableWebApplicationContext;
import org.springframework.web.context.support.StandardServletEnvironment;

Expand All @@ -27,6 +26,7 @@

@ExtendWith(PollutionPreventionExtension.class)
@ExtendWith(SpringProfileCleanupExtension.class)
@ExtendWith(LoggerContextCleanupExtension.class)
class YamlServletProfileInitializerTests {

private YamlServletProfileInitializer initializer;
Expand Down Expand Up @@ -57,11 +57,10 @@ void setup() {
}

@AfterEach
void cleanup() throws Exception {
void cleanup() {
System.clearProperty("APPLICATION_CONFIG_URL");
System.clearProperty("LOG_FILE");
System.clearProperty("LOG_PATH");
Log4jConfigurer.initLogging("classpath:log4j.properties");
}

@Test
Expand Down

0 comments on commit cf1ac78

Please sign in to comment.