Randomize wiremock port Avoid unwanted interactions between tests by randomizing the wiremock server port when possible. Change-Id: I17cb7280755d73b92b9bdde4240bf6c517c77f2e
diff --git a/src/test/java/com/ericsson/gerrit/plugins/evictcache/Constants.java b/src/test/java/com/ericsson/gerrit/plugins/evictcache/Constants.java index f7ba16c..ce6d933 100644 --- a/src/test/java/com/ericsson/gerrit/plugins/evictcache/Constants.java +++ b/src/test/java/com/ericsson/gerrit/plugins/evictcache/Constants.java
@@ -19,7 +19,6 @@ private Constants() { } - static final String URL = "http://localhost:18888"; static final String ENDPOINT_BASE = "/plugins/evict-cache/gerrit/evict/"; static final String PROJECT_LIST = "project_list"; static final String ACCOUNTS = "accounts"; @@ -27,6 +26,4 @@ static final String GROUPS_BYINCLUDE = "groups_byinclude"; static final String GROUPS_MEMBERS = "groups_members"; static final String DEFAULT = "projects"; - - static final int PORT = 18888; }
diff --git a/src/test/java/com/ericsson/gerrit/plugins/evictcache/EvictCacheIT.java b/src/test/java/com/ericsson/gerrit/plugins/evictcache/EvictCacheIT.java index 2e71d2f..a6d61cb 100644 --- a/src/test/java/com/ericsson/gerrit/plugins/evictcache/EvictCacheIT.java +++ b/src/test/java/com/ericsson/gerrit/plugins/evictcache/EvictCacheIT.java
@@ -46,12 +46,14 @@ httpModule = "com.ericsson.gerrit.plugins.evictcache.HttpModule" ) public class EvictCacheIT extends LightweightPluginDaemonTest { + private static final int PORT = 18888; + private static final String URL = "http://localhost:" + PORT; @Rule - public WireMockRule wireMockRule = new WireMockRule(Constants.PORT); + public WireMockRule wireMockRule = new WireMockRule(PORT); @Test - @GerritConfig(name = "plugin.evict-cache.url", value = Constants.URL) + @GerritConfig(name = "plugin.evict-cache.url", value = URL) @GerritConfig(name = "plugin.evict-cache.user", value = "admin") public void flushAndSendPost() throws Exception { final String flushRequest =
diff --git a/src/test/java/com/ericsson/gerrit/plugins/evictcache/HttpSessionTest.java b/src/test/java/com/ericsson/gerrit/plugins/evictcache/HttpSessionTest.java index f45e52d..cb03159 100644 --- a/src/test/java/com/ericsson/gerrit/plugins/evictcache/HttpSessionTest.java +++ b/src/test/java/com/ericsson/gerrit/plugins/evictcache/HttpSessionTest.java
@@ -54,12 +54,13 @@ private HttpSession httpSession; @Rule - public WireMockRule wireMockRule = new WireMockRule(Constants.PORT); + public WireMockRule wireMockRule = new WireMockRule(0); @Before public void setUp() throws Exception { + String url = "http://localhost:" + wireMockRule.port(); Configuration cfg = mock(Configuration.class); - when(cfg.getUrl()).thenReturn(Constants.URL); + when(cfg.getUrl()).thenReturn(url); when(cfg.getUser()).thenReturn("user"); when(cfg.getPassword()).thenReturn("pass"); when(cfg.getMaxTries()).thenReturn(MAX_TRIES); @@ -68,7 +69,7 @@ when(cfg.getRetryInterval()).thenReturn(RETRY_INTERVAL); httpSession = - new HttpSession(new HttpClientProvider(cfg).get(), Constants.URL); + new HttpSession(new HttpClientProvider(cfg).get(), url); } @Test