Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#265]: Validator to properly shutdown, so not to fail further invocations on the same JVM process. #266

Merged
merged 3 commits into from
May 21, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
import java.util.Optional;
import java.util.Properties;
import java.util.stream.Stream;

import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.Rollback;
import org.apache.commons.lang.StringUtils;
import org.dbunit.DatabaseUnitException;
Expand Down Expand Up @@ -53,12 +56,15 @@
import org.testcontainers.containers.MySQLContainer;
import ch.vorburger.exec.ManagedProcessException;

@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure if this annotation does anything because of how BaseContextSenstitiveTest is defined.

Copy link
Member Author

Choose a reason for hiding this comment

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

It actually does, as it forces the recreation of a new Spring application context on the next run. Also BaseContextSenstitiveTest extends AbstractJUnit4SpringContextTests which theoretically means being able to hook into the Spring context life-cycle.

public class ConfigurationTester extends DomainBaseModuleContextSensitiveTest {

protected static final Logger log = LoggerFactory.getLogger(ConfigurationTester.class);

private static MySQLContainer mysqlContainer = new MySQLContainer("mysql:5.7.31");

private static ConfigurableApplicationContext storedApplicationContext;

private String configDirPath;

private String cielFilePath;
Expand All @@ -74,6 +80,7 @@ public static void setupMySqlDb() throws IOException {
mysqlContainer.withPassword("");
mysqlContainer.withCommand("mysqld --character-set-server=utf8 --collation-server=utf8_general_ci");
mysqlContainer.start();

}

protected void setupDatabaseProps(Properties props) throws ManagedProcessException, URISyntaxException {
Expand Down Expand Up @@ -233,12 +240,15 @@ public void conclude() throws URISyntaxException {
}
Assert.assertThat(sb.toString(), Validator.errors, is(empty()));
super.getConnection();
storedApplicationContext = (ConfigurableApplicationContext) applicationContext;
}

@AfterClass
public static void tearDownAfterClass() throws Exception {
if (null != mysqlContainer) {
mysqlContainer.stop();
}
storedApplicationContext.close();
}

}
Loading