Nikita Karpuk
05/09/2023, 6:00 PMwiremock-testcontainers-java
and would like to validate it with you
Current API
private final Map<String, Extension> extensions = new HashMap<>();
WireMockContainer withExtension(String id, Collection<String> classNames, Collection<File> jars)
WireMockContainer withExtension(String id, Collection<String> classNames, File jarDirectory)
WireMockContainer withExtension(String id, String className)
example of usage
.withExtension("Webhook",
Collections.singleton("org.wiremock.webhooks.Webhooks"),
Collections.singleton(Paths.get("target", "test-wiremock-extension", "wiremock-webhooks-extension-2.35.0.jar").toFile()))
.withExtension("JSON Body Transformer",
Collections.singleton("com.ninecookies.wiremock.extensions.JsonBodyTransformer"),
Collections.singleton(Paths.get("target", "test-wiremock-extension", "wiremock-extensions-0.4.1-jar-with-dependencies.jar").toFile()));
Problem:
• Field id
brings confusion, it forces developers to create random string literal for each method invocation, since this id
has no influence on behavior - values will be very random (absence of control / validation)
• We store extention details className
and jar
as a value in HashMap<ID, Extention>
, so we are not able to utilize Collections benefits like check for uniqueness (HashSet)
• Even if developer mixed classNames with wrong jars
withExtnetion("ExtA", "JarB").withExtention("ExtB", "JarA")
it will work
Improvement Options:
Option 1
private final Set<String> extensionClassNames = new LinkedHashSet<>();
private final Set<File> extensionJars = new LinkedHashSet<>();
WireMockContainer withExtension(Collection<String> classNames, File jar)
WireMockContainer withExtension(Collection<String> classNames, Collection<File> jars);
WireMockContainer withExtension(Collection<String> classNames, Path jarDirectory)
Benefits:
• Store all extensionJars in a LinkedHashSet to preserve an order and keep only unique values
• Store all extensionClassNames in a LinkedHashSet to preserve an order and keep only unique value
• all params for --extention
will be stored in one collection extensionClassNames
- easy to build cli command for docker
• all params for /var/wiremock/extentions
will be stored in one collection extensionJars
- easy to build cli command for docker
• Allow developer to organize and keep related Jars and classNames in one method
Problem:
• Even if developer mixed classNames with wrong jars
withExtnetion("ExtA", "JarB").withExtention("ExtB", "JarA")
it will work
Option 2
private final Set<String> extensionClassNames = new LinkedHashSet<>();
private final Set<File> extensionJars = new LinkedHashSet<>();
WireMockContainer withExtensionFile(Collection<String> classNames)
WireMockContainer withExtensionClass(Collection<File> jars);
Benefits:
• Store all extensionJars in a LinkedHashSet to preserve an order and keep only unique values
• Store all extensionClassNames in a LinkedHashSet to preserve an order and keep only unique value
• all params for --extention
will be stored in one collection extensionClassNames
- easy to build cli command for docker
• all params for /var/wiremock/extentions
will be stored in one collection extensionJars
- easy to build cli command for docker
• Very straignt forward apiOleg Nenashev
05/10/2023, 11:03 AMNikita Karpuk
05/12/2023, 7:30 PMOleg Nenashev
05/12/2023, 7:34 PMNikita Karpuk
05/12/2023, 7:36 PMOleg Nenashev
05/12/2023, 7:37 PMNikita Karpuk
05/12/2023, 7:38 PMorg.wiremock.webhooks.Webhooks
into doker image since it belongs to same organization but for other third party extensions it could be complicatedOleg Nenashev
05/12/2023, 7:40 PM