-
-
Notifications
You must be signed in to change notification settings - Fork 481
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Enhancements] Some enhancements for Pact-JVM #330
Comments
These are all great ideas. Just a question on the |
Yes that was my idea El 15 oct. 2016 7:46 a. m., "Ronald Holshausen" [email protected]
|
I have been thinking about If you agree in this change I can provide the PR as well. Meanwhile I sent #331 to review with the other changes. |
Issue #330 Implementing several minimal features in PactDsl
One option for the number matcher, is to use the number format strings (NumberFormat class) to verify the number's string form matches the format pattern. This is how the date matches work. |
Hi look I have created this method: /**
* Attribute that must match the regular expression
* @param name attribute name
* @param regex regular expression
* @param number example number to use for generated bodies
*/
public PactDslJsonBody numberMatcher(String name, String regex, Number number) {
NumberFormat formatter = NumberFormat.getInstance();
String value = formatter.format(number);
if (!value.matches(regex)) {
throw new InvalidMatcherException(EXAMPLE + value + "\" does not match regular expression \"" +
regex + "\"");
}
body.put(name, number);
matchers.put(matcherKey(name), regexp(regex));
return this;
} Then is there any modification I need to do in consumer or in producer side? I get lost when I enter to Scala classes :) |
I was thinking of using the number format pattern (actually DecimalFormat) to verify the number, similar to the date and time ones. e.g.: DslPart body = new PactDslJsonBody()
.numberMatcher("salary", "#0.00")
.date("dob", "MM/dd/yyyy") but I'm not sure that it has any real value. |
Just coming back to this issue. The numberMatcher code above will work. Can we get this implemented? |
Closing this as you can use regular expressions with numbers |
Hello, today I have seen some minor things to improve how users write Pact contracts, I will enumerate here, so we can discuss, the ones we think it would be great to implement, I will open an issue separately and I will provide a PR.
All the enhancements are in
DSLPart
elements:.headers(String... headers)
so instead of having to create a separateMap
, you can do something like.headers("content-type", "application/json")
.numberMatcher()
method like it happens withstringMatcher
.body(java.util.Consumer<>)
method. Now users can only use JSONObject, Document or String, but if we create a functional method then users wil be able to use lambda to for example transform Jackson POJO to String or JSR 364 JsonObject.toJson
method that allows users to set Json as string using single quotes, so avoiding having to skip over and over again the (") char. https://github.com/arquillian-testing-microservices/game-service/blob/contract-tests/src/test/java/org/arquillian/microservices/gameservice/AgeCheckerConsumer.java#L82As I said I can provide a PR for each of one.
The text was updated successfully, but these errors were encountered: