WireMock-Net / WireMock.Net

WireMock.Net is a flexible product for stubbing and mocking web HTTP responses using advanced request matching and response templating. Based on the functionality from http://WireMock.org, but extended with more functionality.
Apache License 2.0
1.41k stars 209 forks source link

Why WireMock.net is not compatible with stubs from WireMock.org #491

Closed Ppiwow closed 3 years ago

Ppiwow commented 4 years ago

Hi,

We wanted to use stubs generated for WireMock.org (spirng contract testing). It seems that they are incompatible or we are using it in wrong way.

Example from WireMock.net: https://github.com/bredah/csharp-wiremock/blob/master/NetCore.2.2/Mock/__admin/mappings/example.json

Example of stub for WireMock.org:

{
  "id" : "f34b38df-059b-401d-a391-2c7e1b21258d",
  "request" : {
    "url" : "/api/Customers",
    "method" : "GET",
    "headers" : {
      "Content-Type" : {
        "equalTo" : "application/json"
      }
    }
  },
  "response" : {
    "status" : 200,
    "body" : "[{\"firstName\":\"Stub1\",\"lastName\":\"Kowalski\"},{\"firstName\":\"Stub2\",\"lastName\":\"Kowalski\"},{\"firstName\":\"Stub3\",\"lastName\":\"Nowak\"},{\"firstName\":\"Stub4\",\"lastName\":\"Nowak\"}]",
    "headers" : {
      "Content-Type" : "application/json; charset=utf-8"
    },
    "transformers" : [ "response-template" ]
  },
  "uuid" : "f34b38df-059b-401d-a391-2c7e1b21258d"
}

Do you have any converter?

StefH commented 4 years ago

Hello @Ppiwow,

I'm sorry for the confusion, this project does indeed use a different JSON mapping file. The mappings are similar as idea, but the content differs.

See this youtube for some info: https://youtu.be/IJa6DyJOxzk?t=436

StefH commented 4 years ago

@Ppiwow Does this answer your question, or do you need more help?

Ppiwow commented 4 years ago

yes, but decission is really strange. standarization... specially if you were copying idea you could decide to make it compatible... this is json so easy to be compatible

StefH commented 3 years ago

Hello @Ppiwow, I understand your statement, however when starting this project, I already had to deviate from some concepts from WireMock.Java so that resulted in another JSON Mapping file.

Maybe I'll create a converter some day, but not planned for short time.

rodrigoramos commented 3 years ago

Hi there! I have same problem here. We're creating a project which contains more than .NET technology (Python and Java) and it has been difficult to share those mappings across the projects.

Actually, that might invalidate the use of this marvelous tool at all.

Is it possible to help to create some kind of "importer" or something like the converter that you mentioned above?

StefH commented 3 years ago

@Ppiwow and @rodrigoramos Can you help me by providing the model (Java) and the JSON file which the current wiremock.org uses?

And what would preferred?

(Note that a 100% match will never be possible...)

rodrigoramos commented 3 years ago

Hi @StefH! Thanks for your answer. IMO, I'd preferred an "import/read" capability.

I cannot share exactly the models that I'm working on (company's policy) but I can share some samples that I created in order to understand the Playback/Recording functionality.

GET Sample

{
  "id" : "ef53ea56-f118-4b3a-8c69-a9484851d99a",
  "name" : "weatherforecast",
  "request" : {
    "url" : "/WeatherForecast",
    "method" : "GET"
  },
  "response" : {
    "status" : 200,
    "body" : "[{\"date\":\"2021-09-09T20:44:48.0992639-03:00\",\"temperatureC\":51,\"temperatureF\":123,\"summary\":\"Hot\"},{\"date\":\"2021-09-10T20:44:48.0992692-03:00\",\"temperatureC\":34,\"temperatureF\":93,\"summary\":\"Mild\"},{\"date\":\"2021-09-11T20:44:48.0992696-03:00\",\"temperatureC\":43,\"temperatureF\":109,\"summary\":\"Sweltering\"},{\"date\":\"2021-09-12T20:44:48.0992698-03:00\",\"temperatureC\":46,\"temperatureF\":114,\"summary\":\"Cool\"},{\"date\":\"2021-09-13T20:44:48.0992701-03:00\",\"temperatureC\":3,\"temperatureF\":37,\"summary\":\"Freezing\"}]",
    "headers" : {
      "Date" : "Wed, 08 Sep 2021 23:44:47 GMT",
      "Content-Type" : "application/json; charset=utf-8",
      "Server" : "Kestrel"
    }
  },
  "uuid" : "ef53ea56-f118-4b3a-8c69-a9484851d99a",
  "persistent" : true,
  "insertionIndex" : 1
}

POST Sample

{
  "id" : "365dd908-dc67-4f27-9e41-15d908206d81",
  "name" : "weatherforecast_register-city",
  "request" : {
    "url" : "/WeatherForecast/register-city",
    "method" : "POST",
    "bodyPatterns" : [ {
      "equalToJson" : "{ \"cityName\": \"São Paulo\", \"cityCode\": 5001 }",
      "ignoreArrayOrder" : true,
      "ignoreExtraElements" : true
    } ]
  },
  "response" : {
    "status" : 200,
    "headers" : {
      "Date" : "Wed, 08 Sep 2021 23:48:33 GMT",
      "Server" : "Kestrel"
    }
  },
  "uuid" : "365dd908-dc67-4f27-9e41-15d908206d81",
  "persistent" : true,
  "insertionIndex" : 4
}
StefH commented 3 years ago

@rodrigoramos Something like ImportWireMockOrg(string path) as public method on WireMockServer?

StefH commented 3 years ago

@rodrigoramos & @Ppiwow I've create a preview version WireMock.1.4.21-preview-04-ci-15384 which has an extra method to import 1 json file.

https://github.com/WireMock-Net/WireMock.Net/wiki/MyGet-preview-versions

In the next days, I'll add more logic and unittests. And if you encounter issues, please write tehse here.

StefH commented 3 years ago

https://github.com/WireMock-Net/WireMock.Net/pull/631

StefH commented 3 years ago

Some compatibility has been added.

You can now post Create a new single WireMock.org stub mapping or an array from WireMock.org mappings to /__admin/mappings/wiremock.org

Please try this functionality and create a new issue in case you miss something.

A new version will be released shortly.

rodrigoramos commented 3 years ago

Thank you so much.

Em qui., 16 de set. de 2021 09:37, Stef Heyenrath @.***> escreveu:

Some compatibility has been added.

You can now post Create a new single WireMock.org stub mapping or an array from WireMock.org mappings to /__admin/mappings/wiremock.org

Please try this functionality and create a new issue in case you miss something.

A new version will be released shortly.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/WireMock-Net/WireMock.Net/issues/491#issuecomment-920863274, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAL64CMXKTC4YACXHAYY7KDUCHQHBANCNFSM4PCFIUQQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.