-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored WiremockCustomizer to take a CustomizationContext as argum…
…ent (#7) * Refactored WiremockCustomizer to take a CustomizationContext as argument - Introduced a parameter class CustomizationContext which additionally provides ExtensionContext and ParameterContext objects. This allows to implement more sophisticated setup logic based on the execution context. - Added WiremockCustomizer::customize(WireMockServer server, CustomizationContext ctx) as default method to keep backward compatibility. - Made WiremockCustomizer::customize(WireMockServer server) also a default method. This is to make sure, that only the necessary "customize" method needs be implemented on a WiremockCustomizer implementation (see TicketEndpoint). - Allow to throw an exception from WiremockCustomizer::customize - Added Unit-Tests - Updated dependencies and plugin versions where possible - Bumped version to 2.0.0-SNAPSHOT because the interface change * Fixed assertion * Use NoopWiremockCustomizer to test default methods (code coverage) * Pass correct replacement to exception message * Simplified tests - Use assertThrows where applicable - Inlined Executable where necessary - Simplified WiremockResolverUnitTest, removed tests which are already covered by integration test
- Loading branch information
1 parent
b571da6
commit dbebebb
Showing
14 changed files
with
486 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/main/java/ru/lanwen/wiremock/config/CustomizationContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package ru.lanwen.wiremock.config; | ||
|
||
import lombok.Builder; | ||
import lombok.Value; | ||
import lombok.experimental.NonFinal; | ||
import org.junit.jupiter.api.extension.ExtensionContext; | ||
import org.junit.jupiter.api.extension.ParameterContext; | ||
|
||
/** | ||
* @author SourcePond (Roland Hauser) | ||
*/ | ||
@Value | ||
@Builder | ||
@NonFinal | ||
public class CustomizationContext { | ||
ExtensionContext extensionContext; | ||
ParameterContext parameterContext; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package ru.lanwen.wiremock.ext; | ||
|
||
import com.github.tomakehurst.wiremock.WireMockServer; | ||
import org.junit.jupiter.api.extension.ParameterResolutionException; | ||
import ru.lanwen.wiremock.config.CustomizationContext; | ||
import ru.lanwen.wiremock.config.CustomizationContext.CustomizationContextBuilder; | ||
import ru.lanwen.wiremock.config.WiremockCustomizer; | ||
import ru.lanwen.wiremock.ext.WiremockResolver.Wiremock; | ||
|
||
import static java.lang.String.format; | ||
|
||
/** | ||
* @author SourcePond (Roland Hauser) | ||
*/ | ||
class WiremockFactory { | ||
|
||
public WireMockServer createServer(final Wiremock mockedServer) { | ||
try { | ||
return new WireMockServer(mockedServer.factory().newInstance().create()); | ||
} catch (ReflectiveOperationException e) { | ||
throw new ParameterResolutionException( | ||
format("Can't create config with given factory %s", mockedServer.factory()), | ||
e | ||
); | ||
} | ||
} | ||
|
||
public CustomizationContextBuilder createContextBuilder() { | ||
return CustomizationContext.builder(); | ||
} | ||
|
||
public WiremockCustomizer createCustomizer(final Wiremock mockedServer) { | ||
try { | ||
return mockedServer.customizer().newInstance(); | ||
} catch (ReflectiveOperationException e) { | ||
throw new ParameterResolutionException( | ||
format("Can't customize server with given customizer %s", mockedServer.customizer()), | ||
e | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/test/java/ru/lanwen/wiremock/config/DefaultWiremockConfigFactoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package ru.lanwen.wiremock.config; | ||
|
||
import com.github.tomakehurst.wiremock.common.Slf4jNotifier; | ||
import com.github.tomakehurst.wiremock.core.WireMockConfiguration; | ||
import org.junit.jupiter.api.Test; | ||
import ru.lanwen.wiremock.config.WiremockConfigFactory.DefaultWiremockConfigFactory; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
/** | ||
* @author SourcePond (Roland Hauser) | ||
*/ | ||
public class DefaultWiremockConfigFactoryTest { | ||
private DefaultWiremockConfigFactory factory = new DefaultWiremockConfigFactory(); | ||
|
||
@Test | ||
public void create() { | ||
WireMockConfiguration config = factory.create(); | ||
assertEquals(0, config.portNumber()); | ||
assertEquals(Slf4jNotifier.class, config.notifier().getClass()); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/test/java/ru/lanwen/wiremock/config/NoopWiremockCustomizerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package ru.lanwen.wiremock.config; | ||
|
||
import com.github.tomakehurst.wiremock.WireMockServer; | ||
import org.junit.jupiter.api.Test; | ||
import ru.lanwen.wiremock.config.WiremockCustomizer.NoopWiremockCustomizer; | ||
|
||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.verifyZeroInteractions; | ||
|
||
/** | ||
* @author SourcePond (Roland Hauser) | ||
*/ | ||
public class NoopWiremockCustomizerTest { | ||
private WireMockServer server = mock(WireMockServer.class); | ||
private CustomizationContext customizable = mock(CustomizationContext.class); | ||
private WiremockCustomizer customizer = new NoopWiremockCustomizer(); | ||
|
||
@Test | ||
public void customize() throws Exception { | ||
customizer.customize(server); | ||
verifyZeroInteractions(server, customizable); | ||
} | ||
|
||
@Test | ||
public void customizeWithContext() throws Exception { | ||
customizer.customize(server, customizable); | ||
verifyZeroInteractions(server, customizable); | ||
} | ||
} |
Oops, something went wrong.