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

Admin static json mappings #21

Closed
phillee007 opened this issue Feb 9, 2017 · 13 comments
Closed

Admin static json mappings #21

phillee007 opened this issue Feb 9, 2017 · 13 comments
Assignees
Labels

Comments

@phillee007
Copy link
Contributor

phillee007 commented Feb 9, 2017

Hi there,

I've downloaded the source zip, built the solution, and created an /__admin/mappings/ folder under the bin/debug folder for the WireMock.Net.StandAlone project. In there, I copied the basic json file from http://wiremock.org/docs/stubbing/ (as shown at the end) and named it test.json. I then ran the standalone project from the command line (after adding Newtonsoft.Json reference and restoring Nuget packages). The console runner shows the server is now listening on port 9090.

When I tried to browse to http://localhost:9090/some/thing it said "No mapping found", and also when I browse to http://localhost:9090/__admin/mappings it returned an empty array. Is it loading up the static json file mappings?

Thanks,
Phil

{
"request": {
"method": "GET",
"url": "/some/thing"
},
"response": {
"status": 200,
"body": "Hello world!",
"headers": {
"Content-Type": "text/plain"
}
}
}

@StefH
Copy link
Collaborator

StefH commented Feb 10, 2017

WireMock.Net.StandAlone
There should be no need for Newtonsoft.Json; I did fix the app.config

StefH added a commit that referenced this issue Feb 10, 2017
@StefH StefH self-assigned this Feb 10, 2017
@StefH StefH added the feature label Feb 10, 2017
@StefH
Copy link
Collaborator

StefH commented Feb 10, 2017

Static Mappings using a json file is not yet implemented. I'll build this in some time using this thread for updates.

@StefH
Copy link
Collaborator

StefH commented Feb 10, 2017

Support added.

See example project on how to use this.

@phillee007
Copy link
Contributor Author

phillee007 commented Feb 10, 2017 via email

StefH added a commit that referenced this issue Feb 10, 2017
StefH added a commit that referenced this issue Feb 12, 2017
@StefH
Copy link
Collaborator

StefH commented Feb 13, 2017

Did you have time to verify this?

@StefH
Copy link
Collaborator

StefH commented Mar 4, 2017

@phillee007 Is it working fine?

@phillee007
Copy link
Contributor Author

finally got a chance to test this!

To answer your question: yes and no...

Yes it can read mappings files that are named using a guid, however, we find it useful to actually use meaningful file names, as we're generating a whole heap of static mappings based on log files from real requests/responses from our external api. E.g. customer_get_123.json vs asdfdsafsaf234324.json

Is it possible for the static mappings reader to just read all .json files in the directory rather than forcing them to use a guid? Maybe add an optional filename property to the Mapping class so we can specify that if/when calling the admin api to add mappings at runtime too?

Thanks,
Phil

@StefH
Copy link
Collaborator

StefH commented Mar 15, 2017

Good point.

I will add support for all .json files and add a title to the mapping which will be used as filename if present.

StefH added a commit that referenced this issue Mar 15, 2017
@StefH
Copy link
Collaborator

StefH commented Mar 15, 2017

OK. I've added a "Title" as property. Can you please get the latest code and test if this works for you ?

StefH added a commit that referenced this issue Mar 20, 2017
StefH added a commit that referenced this issue Mar 20, 2017
@StefH
Copy link
Collaborator

StefH commented Apr 14, 2017

Were you able to test the latest code?

@phillee007
Copy link
Contributor Author

Good news - I got to test this at last and it does work! Will raise another issue regarding the path matching and full urls separately

@phillee007
Copy link
Contributor Author

Actually, scratch that comment re raising another issue. I see you've already added in the extra function to convert a relative url to the fully qualified url so that matcher works :-)

E.g. If the request has something like this:
...
Url": {
"Matchers": [
{
"Name": "WildcardMatcher",
"Pattern": "products/123456"
}
]
},
...

When I was using the earlier version of wiremock.net, it required me to have the fully-qualified url in the Pattern otherwise it wouldn't find the match when I requested http://myserver:9090/products/123456. E.g.

...
"Pattern": "http://myserver:9090/products/123456"
...

However, I see now that I can just specify the relative url and it works as per the regular WireMock documentation.

Great work!!! We're now ready to use this fairly heavily so will let you know if we hit any other issues

@StefH
Copy link
Collaborator

StefH commented Apr 28, 2017

Thanks. Please open new issues in case you encounter something.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants