SHARE
TWEET

Untitled

a guest Jun 25th, 2019 92 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @RunWith(SpringRunner.class)
  2. @SpringBootTest
  3. public class MyTestClass {
  4.  
  5.  
  6.     @IfProfileValue(name = "os.name", values = {"Linux"})
  7.     @Test
  8.     public void testMe() {
  9.      // will run only in linux, otherwise
  10.      // won't even try to load an
  11.      // application context
  12.     ....
  13.     }
  14.   }
  15.      
  16. public class VPNConnectivityProfileValueSource implements ProfileValueSource {
  17.  
  18.   private String vpnEnabled = "true";
  19.   public VPNConnectivityProfileValueSource () {
  20.      // no spring context is available here
  21.      ClassPathResource resource = new ClassPathResource("vpn-config.properties");
  22.  
  23.      if (resource.exists()) {
  24.           // read the VPN address,
  25.           //  
  26.           //this.testProps = PropertiesLoaderUtils.loadProperties(resource);
  27.           // invoke your utility, check the connectivity, etc.
  28.           this.vpnEnabled = ...
  29.      }
  30.  
  31. }
  32.  
  33.   @Override
  34.   public String get(String key) {
  35.     // this is important method,
  36.     if(key.equals("vpn.enabled") {
  37.        return this.vpnEnabled;  
  38.     }
  39.     else return System.getProperty(key);
  40.   }
  41. }
  42.      
  43. @RunWith(SpringRunner.class)
  44. @SpringBootTest
  45. @ProfileValueSourceConfiguration(VPNConnectivityProfileValueSource.class)
  46. @IfProfileValue(name = "vpn.enabled", value = "true")
  47. public class MyTestClass {
  48.  
  49.    @Test
  50.    public void testMe() {
  51.      ....
  52.    }
  53. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top