Skip to content
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

Closed
3 of 4 tasks
lordofthejars opened this issue Oct 14, 2016 · 8 comments
Closed
3 of 4 tasks

[Enhancements] Some enhancements for Pact-JVM #330

lordofthejars opened this issue Oct 14, 2016 · 8 comments

Comments

@lordofthejars
Copy link
Contributor

lordofthejars commented Oct 14, 2016

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:

As I said I can provide a PR for each of one.

@uglyog
Copy link
Member

uglyog commented Oct 15, 2016

These are all great ideas.

Just a question on the .numberMatcher(). Would the behaviour be to convert the number to a string and then match with a regex?

@lordofthejars
Copy link
Contributor Author

Yes that was my idea

El 15 oct. 2016 7:46 a. m., "Ronald Holshausen" [email protected]
escribió:

These are all great ideas.

Just a question on the .numberMatcher(). Would the behaviour be to
convert the number to a string and then match with a regex?


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#330 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/ABcmYfbup5vYRabExfyGebpVm3ZyQ_1Bks5q0Gi4gaJpZM4KW6f6
.

@lordofthejars
Copy link
Contributor Author

I have been thinking about numberMatch method and it is quite difficult and I think it will require some deep changes which I don't know if it has sense. Basically if we use the toString method to pass form Number to String then the problem is not very big, but I think this approach is a bit useless so we should think about adding a method so users can send how the conversion should be done. The problem comes in stub http server which also needs to know how the conversion should be done to validate what it is received. Currently matchers are stored in a map that contains the field where is applied and the regexp. This map should be changed to more complex object where you can set also how the ToString thing might happen.

If you agree in this change I can provide the PR as well. Meanwhile I sent #331 to review with the other changes.

uglyog pushed a commit that referenced this issue Oct 19, 2016
Issue #330 Implementing several minimal features in PactDsl
@uglyog
Copy link
Member

uglyog commented Oct 19, 2016

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.

@lordofthejars
Copy link
Contributor Author

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 :)

@uglyog
Copy link
Member

uglyog commented Oct 22, 2016

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.

@rholshausen
Copy link
Contributor

Just coming back to this issue. The numberMatcher code above will work. Can we get this implemented?

@uglyog
Copy link
Member

uglyog commented Aug 1, 2021

Closing this as you can use regular expressions with numbers

@uglyog uglyog closed this as completed Aug 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants