-
FEATURED COMPONENTS
First time here? Check out the FAQ!
1) there are multiple options using just spring configuration:
disable spring security conditionally when Zats classes are on the classpath (indicating a test run):
in this example the java config in WebSecurityConfig.java can be disabled just like this
@Configuration
@EnableWebSecurity
@ConditionalOnMissingClass("org.zkoss.zats.mimic.Zats") //Disable security during Zats tests
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
...
@Override
protected void configure(HttpSecurity http) throws Exception {
use a spring profile to disable the config explicitely
@Configuration
@EnableWebSecurity
@Profile("!test") //Disable security during test
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
...
@Override
protected void configure(HttpSecurity http) throws Exception {
There are multiple ways of activating a spring profile ... e.g. using a system variable
SPRING_PROFILES_ACTIVE=test mvn clean test
2) for your test properties
Another benefit of profiles in spring boot is the automatic loading based on the convention application-[profile].properties
so when activating the test
profile you can add your overriding properties into an application-test.properties
3) what you didn't ask (maybe it's helpful)
It may also be possible to test your application using ZATS with security activated, as in this example test case: SecurePageTest.java - it performs a login, and follows redirects during a test.
Asked: 2020-04-16 08:21:17 +0800
Seen: 9 times
Last updated: Apr 16 '20