Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @RunWith(SpringRunner.class)
- @SpringBootTest
- public class MyTestClass {
- @IfProfileValue(name = "os.name", values = {"Linux"})
- @Test
- public void testMe() {
- // will run only in linux, otherwise
- // won't even try to load an
- // application context
- ....
- }
- }
- public class VPNConnectivityProfileValueSource implements ProfileValueSource {
- private String vpnEnabled = "true";
- public VPNConnectivityProfileValueSource () {
- // no spring context is available here
- ClassPathResource resource = new ClassPathResource("vpn-config.properties");
- if (resource.exists()) {
- // read the VPN address,
- //
- //this.testProps = PropertiesLoaderUtils.loadProperties(resource);
- // invoke your utility, check the connectivity, etc.
- this.vpnEnabled = ...
- }
- }
- @Override
- public String get(String key) {
- // this is important method,
- if(key.equals("vpn.enabled") {
- return this.vpnEnabled;
- }
- else return System.getProperty(key);
- }
- }
- @RunWith(SpringRunner.class)
- @SpringBootTest
- @ProfileValueSourceConfiguration(VPNConnectivityProfileValueSource.class)
- @IfProfileValue(name = "vpn.enabled", value = "true")
- public class MyTestClass {
- @Test
- public void testMe() {
- ....
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement