Comments (7)
That's the way I understand it too: basically, switching the regex to "literal" is like replacing it with a simple String.equals, which is not ideal because it's quite useful to be able to only look for patterns instead of an exact match.
I think I need to look at regex syntax again to find a way to write that body request in a way that won't be mistaken as an incorrect regex syntax. Will keep you posted.
from httpmocker.
@nnobelis Correction has been published in 1.3. Let me know if you have any further requests.
from httpmocker.
Thanks for the feedback. You're right that recorded scenarios should work with as little clean up as possible (although a minimum is probably always needed because ALL request parameters will be recorded, including some that might be dynamic or constantly changing like authentication tokens for a connected API for instance). As for your suggestion about using RegexOption.LITERAL, could you help me what difference it would make? The doc is minimal on this field, and I'm not sure if it means that the expression will not be considered as an actual regex anymore but more like an exact string to match?
I'm going to look into it as quickly as possible.
from httpmocker.
Thanks a lot for the quick response.
As I understand, with RegexOption.LITERAL, the special characters in the string with be ignored and the full string will be used for an exact match : if you have .* in your string, these two characters will be matched.
The problem is that if you always use RegexOption.LITERAL, pattern matching in the body won't be possible any more.
I think the solution is in something like this : if you use RECORD, you get a body like before and it will be matched with RegexOption.LITERAL exactly.
But you can also specify bodyPattern which is indeed a pattern with normal RegEx matching. This bodyPattern takes precedence over body.
Something like that :
"request" : {
"method" : "POST",
"headers" : { },
"params" : { },
"body" : "{\"data\":{\"username\":\"XXX\",\"key\":\"XXX\",\"project_code\":\"Explorers_Helidon\"},\"action\":\"get_information\",\"group\":\"projects\"}",
"bodyPattern": ".*get_information.*"
},
But this is a breaking change for your users so you may want to do it "backwards" with bodyRaw for instance and body :)
"bodyRaw" : "{\"data\":{\"username\":\"XXX\",\"key\":\"XXX\",\"project_code\":\"Explorers_Helidon\"},\"action\":\"get_information\",\"group\":\"projects\"}",
"body": ".*get_information.*"
from httpmocker.
Can't you just use Regex.escapeReplacement()
when serializing the body
to the recorded JSON file, so that any literal characters that have a special meaning in regex are escaped? Then it should work out of the box. However, I'd also rename the body
field to bodyRegex
in the same run to make the expected syntax explicit.
from httpmocker.
That's a good option. That's the kind of solution I'm planning to look into.
from httpmocker.
@nnobelis I've pushed a correction for your issue. I preferred keeping the current API. So request body is converted to a for an exact match regexp. Feel free to test it from develop if you want and make comments before I publish a new version.
from httpmocker.
Related Issues (18)
- Possible race condition in DynamicMockProvider
- Support for Ktor HTTP client
- Support for multiplatform
- Replace mockito in tests
- Update Doc for Ktor
- Query parameters should support doubles
- Set up automatic publish to MavenCentral
- Restore Dokka with multiplatform
- Add support for different JSON parrsing libs HOT 1
- How to Mock different request with different jsons HOT 8
- Record mode issue? HOT 3
- Allow custom RequestDescriptor.match(request: Request) handler HOT 3
- Automatic mocking
- Ability to mock request exception HOT 5
- Mock a specific API response HOT 11
- Ability to execute the chain with a new request in Mixed mode. HOT 4
- Add noop artifact for release builds
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from httpmocker.