From a8b3d3ca600cd032ddfca71585304c1dbc25377c Mon Sep 17 00:00:00 2001 From: "burcu.akkaya" Date: Mon, 2 Oct 2023 10:19:45 +0300 Subject: [PATCH 1/8] A Stubmapping can be removed by ID #2393 --- .../java/com/github/tomakehurst/wiremock/WireMockServer.java | 3 ++- .../java/com/github/tomakehurst/wiremock/client/WireMock.java | 4 +++- .../java/com/github/tomakehurst/wiremock/junit/Stubbing.java | 2 ++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/github/tomakehurst/wiremock/WireMockServer.java b/src/main/java/com/github/tomakehurst/wiremock/WireMockServer.java index 9505d79bc9..711c0ec8ad 100644 --- a/src/main/java/com/github/tomakehurst/wiremock/WireMockServer.java +++ b/src/main/java/com/github/tomakehurst/wiremock/WireMockServer.java @@ -258,7 +258,8 @@ public void removeStub(MappingBuilder mappingBuilder) { public void removeStub(StubMapping stubMapping) { client.removeStubMapping(stubMapping); } - + @Override + public void removeStub(UUID id) { client.removeStubMapping(id); } @Override public List getStubMappings() { return client.allStubMappings().getMappings(); diff --git a/src/main/java/com/github/tomakehurst/wiremock/client/WireMock.java b/src/main/java/com/github/tomakehurst/wiremock/client/WireMock.java index 4b14e82ea3..afca9f1473 100644 --- a/src/main/java/com/github/tomakehurst/wiremock/client/WireMock.java +++ b/src/main/java/com/github/tomakehurst/wiremock/client/WireMock.java @@ -457,7 +457,9 @@ public void removeStubMapping(MappingBuilder mappingBuilder) { public void removeStubMapping(StubMapping stubMapping) { admin.removeStubMapping(stubMapping); } - + public void removeStubMapping(UUID id) { + admin.removeStubMapping(id); + } public ListStubMappingsResult allStubMappings() { return admin.listAllStubMappings(); } diff --git a/src/main/java/com/github/tomakehurst/wiremock/junit/Stubbing.java b/src/main/java/com/github/tomakehurst/wiremock/junit/Stubbing.java index 88bd79821b..52ffa2b5e7 100644 --- a/src/main/java/com/github/tomakehurst/wiremock/junit/Stubbing.java +++ b/src/main/java/com/github/tomakehurst/wiremock/junit/Stubbing.java @@ -38,6 +38,8 @@ public interface Stubbing { void removeStub(StubMapping mappingBuilder); + void removeStub(UUID id); + List getStubMappings(); StubMapping getSingleStubMapping(UUID id); From 85c2f70984a465717333b6d1de972ecbbbce02a0 Mon Sep 17 00:00:00 2001 From: "burcu.akkaya" Date: Tue, 3 Oct 2023 08:28:01 +0300 Subject: [PATCH 2/8] acceptance tests are added --- .../tomakehurst/wiremock/client/WireMock.java | 4 ++ .../RemoveStubMappingAcceptanceTest.java | 50 +++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/src/main/java/com/github/tomakehurst/wiremock/client/WireMock.java b/src/main/java/com/github/tomakehurst/wiremock/client/WireMock.java index afca9f1473..feee3bdcb9 100644 --- a/src/main/java/com/github/tomakehurst/wiremock/client/WireMock.java +++ b/src/main/java/com/github/tomakehurst/wiremock/client/WireMock.java @@ -146,6 +146,10 @@ public static void removeStub(StubMapping stubMapping) { defaultInstance.get().removeStubMapping(stubMapping); } + public static void removeStub(UUID id) { + defaultInstance.get().removeStubMapping(id); + } + public static ListStubMappingsResult listAllStubMappings() { return defaultInstance.get().allStubMappings(); } diff --git a/src/test/java/com/github/tomakehurst/wiremock/RemoveStubMappingAcceptanceTest.java b/src/test/java/com/github/tomakehurst/wiremock/RemoveStubMappingAcceptanceTest.java index 6da969cdcf..979df49bdf 100644 --- a/src/test/java/com/github/tomakehurst/wiremock/RemoveStubMappingAcceptanceTest.java +++ b/src/test/java/com/github/tomakehurst/wiremock/RemoveStubMappingAcceptanceTest.java @@ -135,6 +135,56 @@ public void removeStubThatDoesNotExists() { assertThat(getMatchingStubCount("/stb-1", "/stb-2"), is(2)); } + @Test + public void removeStubWithUUIDThatExists() { + + UUID id1 = UUID.randomUUID(); + + stubFor(get(urlEqualTo("/stub-1")).withId(id1).willReturn(aResponse().withBody("Stub-1-Body"))); + + assertThat(testClient.get("/stub-1").content(), is("Stub-1-Body")); + + UUID id2 = UUID.randomUUID(); + stubFor(get(urlEqualTo("/stub-2")).withId(id2).willReturn(aResponse().withBody("Stub-2-Body"))); + + assertThat(testClient.get("/stub-2").content(), is("Stub-2-Body")); + + assertThat(getMatchingStubCount("/stub-1", "/stub-2"), is(2)); + + removeStub(id2); + + assertThat(getMatchingStubCount("/stub-1", "/stub-2"), is(1)); + + removeStub(id2); + + assertThat(getMatchingStubCount("/stub-1", "/stub-2"), is(0)); + } + + @Test + public void removeStubWithUUIDThatDoesNotExists() { + + UUID id1 = UUID.randomUUID(); + + stubFor(get(urlEqualTo("/stb-1")).withId(id1).willReturn(aResponse().withBody("Stb-1-Body"))); + + assertThat(testClient.get("/stb-1").content(), is("Stb-1-Body")); + + UUID id2 = UUID.randomUUID(); + stubFor(get(urlEqualTo("/stb-2")).withId(id2).willReturn(aResponse().withBody("Stb-2-Body"))); + + assertThat(testClient.get("/stb-2").content(), is("Stb-2-Body")); + + assertThat(getMatchingStubCount("/stb-1", "/stb-2"), is(2)); + + UUID id3 = UUID.randomUUID(); + get(urlEqualTo("/stb-3")).withId(id3).willReturn(aResponse().withBody("Stb-3-Body")); + + removeStub(id3); + + assertThat(getMatchingStubCount("/stb-1", "/stb-2"), is(2)); + } + + private Predicate withAnyOf(final String... urls) { return mapping -> mapping.getRequest().getUrl() != null From 7ffd13d73d9c608a84b9ee432478cd4a623c124a Mon Sep 17 00:00:00 2001 From: "burcu.akkaya" Date: Tue, 3 Oct 2023 08:36:23 +0300 Subject: [PATCH 3/8] white space is removed --- .../tomakehurst/wiremock/RemoveStubMappingAcceptanceTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/java/com/github/tomakehurst/wiremock/RemoveStubMappingAcceptanceTest.java b/src/test/java/com/github/tomakehurst/wiremock/RemoveStubMappingAcceptanceTest.java index 979df49bdf..4fa16c9cf0 100644 --- a/src/test/java/com/github/tomakehurst/wiremock/RemoveStubMappingAcceptanceTest.java +++ b/src/test/java/com/github/tomakehurst/wiremock/RemoveStubMappingAcceptanceTest.java @@ -184,7 +184,6 @@ public void removeStubWithUUIDThatDoesNotExists() { assertThat(getMatchingStubCount("/stb-1", "/stb-2"), is(2)); } - private Predicate withAnyOf(final String... urls) { return mapping -> mapping.getRequest().getUrl() != null From acc36e5ab5e507e4fd38ebf788098dd1a6ca7db1 Mon Sep 17 00:00:00 2001 From: Burcu Akkaya <62480904+burcuakkayaa@users.noreply.github.com> Date: Tue, 3 Oct 2023 10:35:49 +0300 Subject: [PATCH 4/8] Update src/main/java/com/github/tomakehurst/wiremock/WireMockServer.java Co-authored-by: Oleg Nenashev --- .../java/com/github/tomakehurst/wiremock/WireMockServer.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/github/tomakehurst/wiremock/WireMockServer.java b/src/main/java/com/github/tomakehurst/wiremock/WireMockServer.java index 711c0ec8ad..99b7fef954 100644 --- a/src/main/java/com/github/tomakehurst/wiremock/WireMockServer.java +++ b/src/main/java/com/github/tomakehurst/wiremock/WireMockServer.java @@ -259,7 +259,10 @@ public void removeStub(StubMapping stubMapping) { client.removeStubMapping(stubMapping); } @Override - public void removeStub(UUID id) { client.removeStubMapping(id); } + public void removeStub(UUID id) { + client.removeStubMapping(id); + } + @Override public List getStubMappings() { return client.allStubMappings().getMappings(); From 648cdc38aad7ba50036d8a6a724b729bc4f26eab Mon Sep 17 00:00:00 2001 From: "burcu.akkaya" Date: Fri, 20 Oct 2023 09:03:58 +0300 Subject: [PATCH 5/8] CR findings are fixed --- .../wiremock/junit/DslWrapper.java | 5 ++++ .../RemoveStubMappingAcceptanceTest.java | 29 ++++--------------- 2 files changed, 10 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/github/tomakehurst/wiremock/junit/DslWrapper.java b/src/main/java/com/github/tomakehurst/wiremock/junit/DslWrapper.java index 73fcc4f933..3079ea7783 100644 --- a/src/main/java/com/github/tomakehurst/wiremock/junit/DslWrapper.java +++ b/src/main/java/com/github/tomakehurst/wiremock/junit/DslWrapper.java @@ -276,6 +276,11 @@ public void removeStub(StubMapping mappingBuilder) { stubbing.removeStub(mappingBuilder); } + @Override + public void removeStub(UUID id) { + stubbing.removeStub(id); + } + @Override public List getStubMappings() { return stubbing.getStubMappings(); diff --git a/src/test/java/com/github/tomakehurst/wiremock/RemoveStubMappingAcceptanceTest.java b/src/test/java/com/github/tomakehurst/wiremock/RemoveStubMappingAcceptanceTest.java index 4fa16c9cf0..45ec4ecfa0 100644 --- a/src/test/java/com/github/tomakehurst/wiremock/RemoveStubMappingAcceptanceTest.java +++ b/src/test/java/com/github/tomakehurst/wiremock/RemoveStubMappingAcceptanceTest.java @@ -144,20 +144,11 @@ public void removeStubWithUUIDThatExists() { assertThat(testClient.get("/stub-1").content(), is("Stub-1-Body")); - UUID id2 = UUID.randomUUID(); - stubFor(get(urlEqualTo("/stub-2")).withId(id2).willReturn(aResponse().withBody("Stub-2-Body"))); - - assertThat(testClient.get("/stub-2").content(), is("Stub-2-Body")); - - assertThat(getMatchingStubCount("/stub-1", "/stub-2"), is(2)); - - removeStub(id2); + assertThat(getMatchingStubCount("/stub-1", ""), is(1)); - assertThat(getMatchingStubCount("/stub-1", "/stub-2"), is(1)); + removeStub(id1); - removeStub(id2); - - assertThat(getMatchingStubCount("/stub-1", "/stub-2"), is(0)); + assertThat(getMatchingStubCount("/stub-1", ""), is(0)); } @Test @@ -169,19 +160,9 @@ public void removeStubWithUUIDThatDoesNotExists() { assertThat(testClient.get("/stb-1").content(), is("Stb-1-Body")); - UUID id2 = UUID.randomUUID(); - stubFor(get(urlEqualTo("/stb-2")).withId(id2).willReturn(aResponse().withBody("Stb-2-Body"))); - - assertThat(testClient.get("/stb-2").content(), is("Stb-2-Body")); - - assertThat(getMatchingStubCount("/stb-1", "/stb-2"), is(2)); - - UUID id3 = UUID.randomUUID(); - get(urlEqualTo("/stb-3")).withId(id3).willReturn(aResponse().withBody("Stb-3-Body")); + removeStub(id1); - removeStub(id3); - - assertThat(getMatchingStubCount("/stb-1", "/stb-2"), is(2)); + assertThat(getMatchingStubCount("/stb-1", ""), is(0)); } private Predicate withAnyOf(final String... urls) { From 9d731a0a3a95167962100549a1ac8761ea810cd7 Mon Sep 17 00:00:00 2001 From: Kirill Peshin Date: Sun, 3 Mar 2024 07:57:52 +0300 Subject: [PATCH 6/8] Replace net.jockx:littleproxy by JDK --- build.gradle | 6 ----- ...WireMockClientWithProxyAcceptanceTest.java | 24 +++++++++---------- ...WireMockClientWithProxyAcceptanceTest.java | 24 +++++++++---------- 3 files changed, 24 insertions(+), 30 deletions(-) diff --git a/build.gradle b/build.gradle index f89f32c8e2..0aea9ec199 100644 --- a/build.gradle +++ b/build.gradle @@ -129,12 +129,6 @@ dependencies { testRuntimeOnly "ch.qos.logback:logback-classic:1.4.14" testRuntimeOnly files('src/test/resources/classpath file source/classpathfiles.zip', 'src/test/resources/classpath-filesource.jar') - testImplementation ('net.jockx:littleproxy:1.1.3') { - exclude group: 'com.google.guava', module: 'guava' - exclude group: 'org.apache.commons', module: 'commons-lang3' - exclude group: 'org.slf4j', module: 'slf4j-api' - exclude group: 'io.netty', module: 'netty-all' - } testImplementation "io.netty:netty-all:4.1.107.Final" testImplementation files('test-extension/test-extension.jar') diff --git a/src/test/java/com/github/tomakehurst/wiremock/WireMockClientWithProxyAcceptanceTest.java b/src/test/java/com/github/tomakehurst/wiremock/WireMockClientWithProxyAcceptanceTest.java index e6ca1beea0..a6a44347fe 100644 --- a/src/test/java/com/github/tomakehurst/wiremock/WireMockClientWithProxyAcceptanceTest.java +++ b/src/test/java/com/github/tomakehurst/wiremock/WireMockClientWithProxyAcceptanceTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011-2021 Thomas Akehurst + * Copyright (C) 2011-2024 Thomas Akehurst * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,28 +17,29 @@ import static com.github.tomakehurst.wiremock.client.WireMock.*; import static com.github.tomakehurst.wiremock.core.Options.DYNAMIC_PORT; +import static java.net.Proxy.Type.HTTP; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import com.github.tomakehurst.wiremock.client.WireMock; import com.github.tomakehurst.wiremock.testsupport.WireMockTestClient; +import java.net.InetSocketAddress; +import java.net.Proxy; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import org.littleshoot.proxy.HttpProxyServer; -import org.littleshoot.proxy.impl.DefaultHttpProxyServer; public class WireMockClientWithProxyAcceptanceTest { private static WireMockServer wireMockServer; private static WireMockTestClient testClient; - private static HttpProxyServer proxyServer; + private static Proxy proxyServer; @BeforeAll public static void init() { wireMockServer = new WireMockServer(DYNAMIC_PORT); wireMockServer.start(); - proxyServer = DefaultHttpProxyServer.bootstrap().withPort(0).start(); + proxyServer = new Proxy(HTTP, new InetSocketAddress("localhost", wireMockServer.port())); testClient = new WireMockTestClient(wireMockServer.port()); } @@ -46,17 +47,16 @@ public static void init() { @AfterAll public static void stopServer() { wireMockServer.stop(); - proxyServer.stop(); } @Test - public void supportsProxyingWithTheStaticClient() { + void supportsProxyingWithTheStaticClient() { WireMock.configureFor( "http", "localhost", wireMockServer.port(), - proxyServer.getListenAddress().getHostString(), - proxyServer.getListenAddress().getPort()); + ((InetSocketAddress) proxyServer.address()).getHostString(), + ((InetSocketAddress) proxyServer.address()).getPort()); givenThat(get(urlEqualTo("/my/new/resource")).willReturn(aResponse().withStatus(304))); @@ -64,7 +64,7 @@ public void supportsProxyingWithTheStaticClient() { } @Test - public void supportsProxyingWithTheInstanceClient() { + void supportsProxyingWithTheInstanceClient() { WireMock wireMock = WireMock.create() .scheme("http") @@ -72,8 +72,8 @@ public void supportsProxyingWithTheInstanceClient() { .port(wireMockServer.port()) .urlPathPrefix("") .hostHeader(null) - .proxyHost(proxyServer.getListenAddress().getHostString()) - .proxyPort(proxyServer.getListenAddress().getPort()) + .proxyHost(((InetSocketAddress) proxyServer.address()).getHostString()) + .proxyPort(((InetSocketAddress) proxyServer.address()).getPort()) .build(); wireMock.register( diff --git a/src/test/java/com/github/tomakehurst/wiremock/client/WireMockClientWithProxyAcceptanceTest.java b/src/test/java/com/github/tomakehurst/wiremock/client/WireMockClientWithProxyAcceptanceTest.java index e0b50f243e..25ae8836ea 100644 --- a/src/test/java/com/github/tomakehurst/wiremock/client/WireMockClientWithProxyAcceptanceTest.java +++ b/src/test/java/com/github/tomakehurst/wiremock/client/WireMockClientWithProxyAcceptanceTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011-2021 Thomas Akehurst + * Copyright (C) 2011-2024 Thomas Akehurst * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,28 +17,29 @@ import static com.github.tomakehurst.wiremock.client.WireMock.*; import static com.github.tomakehurst.wiremock.core.Options.DYNAMIC_PORT; +import static java.net.Proxy.Type.HTTP; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import com.github.tomakehurst.wiremock.WireMockServer; import com.github.tomakehurst.wiremock.testsupport.WireMockTestClient; +import java.net.InetSocketAddress; +import java.net.Proxy; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import org.littleshoot.proxy.HttpProxyServer; -import org.littleshoot.proxy.impl.DefaultHttpProxyServer; public class WireMockClientWithProxyAcceptanceTest { private static WireMockServer wireMockServer; private static WireMockTestClient testClient; - private static HttpProxyServer proxyServer; + private static Proxy proxyServer; @BeforeAll public static void init() { wireMockServer = new WireMockServer(DYNAMIC_PORT); wireMockServer.start(); - proxyServer = DefaultHttpProxyServer.bootstrap().withPort(0).start(); + proxyServer = new Proxy(HTTP, new InetSocketAddress("localhost", wireMockServer.port())); testClient = new WireMockTestClient(wireMockServer.port()); } @@ -46,17 +47,16 @@ public static void init() { @AfterAll public static void stopServer() { wireMockServer.stop(); - proxyServer.stop(); } @Test - public void supportsProxyingWithTheStaticClient() { + void supportsProxyingWithTheStaticClient() { WireMock.configureFor( "http", "localhost", wireMockServer.port(), - proxyServer.getListenAddress().getHostString(), - proxyServer.getListenAddress().getPort()); + ((InetSocketAddress) proxyServer.address()).getHostString(), + ((InetSocketAddress) proxyServer.address()).getPort()); givenThat(get(urlEqualTo("/my/new/resource")).willReturn(aResponse().withStatus(304))); @@ -64,7 +64,7 @@ public void supportsProxyingWithTheStaticClient() { } @Test - public void supportsProxyingWithTheInstanceClient() { + void supportsProxyingWithTheInstanceClient() { WireMock wireMock = WireMock.create() .scheme("http") @@ -72,8 +72,8 @@ public void supportsProxyingWithTheInstanceClient() { .port(wireMockServer.port()) .urlPathPrefix("") .hostHeader(null) - .proxyHost(proxyServer.getListenAddress().getHostString()) - .proxyPort(proxyServer.getListenAddress().getPort()) + .proxyHost(((InetSocketAddress) proxyServer.address()).getHostString()) + .proxyPort(((InetSocketAddress) proxyServer.address()).getPort()) .build(); wireMock.register( From 4faf9ad0392411b6aca6f2e73e9ed0e6dd5c1717 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 4 Mar 2024 04:27:19 +0000 Subject: [PATCH 7/8] Bump org.mockito:mockito-core from 5.10.0 to 5.11.0 Bumps [org.mockito:mockito-core](https://github.com/mockito/mockito) from 5.10.0 to 5.11.0. - [Release notes](https://github.com/mockito/mockito/releases) - [Commits](https://github.com/mockito/mockito/compare/v5.10.0...v5.11.0) --- updated-dependencies: - dependency-name: org.mockito:mockito-core dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index f89f32c8e2..3add9cbfa4 100644 --- a/build.gradle +++ b/build.gradle @@ -112,7 +112,7 @@ dependencies { testImplementation "org.hamcrest:hamcrest-core:2.2" testImplementation "org.hamcrest:hamcrest-library:2.2" - testImplementation 'org.mockito:mockito-core:5.10.0' + testImplementation 'org.mockito:mockito-core:5.11.0' testImplementation 'org.mockito:mockito-junit-jupiter:5.10.0' testImplementation "net.javacrumbs.json-unit:json-unit:$versions.jsonUnit" testImplementation "org.skyscreamer:jsonassert:1.2.3" From 39e9d02dfa83245cd82d5c180e780c99db9c2798 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 5 Mar 2024 10:16:21 +0000 Subject: [PATCH 8/8] Bump org.mockito:mockito-junit-jupiter from 5.10.0 to 5.11.0 Bumps [org.mockito:mockito-junit-jupiter](https://github.com/mockito/mockito) from 5.10.0 to 5.11.0. - [Release notes](https://github.com/mockito/mockito/releases) - [Commits](https://github.com/mockito/mockito/compare/v5.10.0...v5.11.0) --- updated-dependencies: - dependency-name: org.mockito:mockito-junit-jupiter dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 3add9cbfa4..91f7816086 100644 --- a/build.gradle +++ b/build.gradle @@ -113,7 +113,7 @@ dependencies { testImplementation "org.hamcrest:hamcrest-core:2.2" testImplementation "org.hamcrest:hamcrest-library:2.2" testImplementation 'org.mockito:mockito-core:5.11.0' - testImplementation 'org.mockito:mockito-junit-jupiter:5.10.0' + testImplementation 'org.mockito:mockito-junit-jupiter:5.11.0' testImplementation "net.javacrumbs.json-unit:json-unit:$versions.jsonUnit" testImplementation "org.skyscreamer:jsonassert:1.2.3" testImplementation 'com.toomuchcoding.jsonassert:jsonassert:0.8.0'