This commit is contained in:
Stef Heyenrath
2018-08-08 11:05:27 +02:00
parent 5ee25fb1e7
commit 9e7d3b6d2d
3 changed files with 263 additions and 262 deletions

View File

@@ -3,14 +3,7 @@
"Title": "", "Title": "",
"Priority": 0, "Priority": 0,
"Request": { "Request": {
"Path": { "Path": "/proxy-google-test-post",
"Matchers": [
{
"Name": "WildcardMatcher",
"Pattern": "/proxy-google-test-post"
}
]
},
"Methods": [ "Methods": [
"post" "post"
], ],

View File

@@ -46,293 +46,293 @@ namespace WireMock.Net.ConsoleApplication
.WithHeader("Content-Type", "application/json") .WithHeader("Content-Type", "application/json")
.WithBody(@"{ ""result"": ""Contains x with FUNC 200""}")); .WithBody(@"{ ""result"": ""Contains x with FUNC 200""}"));
//server server
// .Given(Request.Create() .Given(Request.Create()
// .UsingGet() .UsingGet()
// .WithPath("/proxy-test-keep-alive") .WithPath("/proxy-test-keep-alive")
// ) )
// .RespondWith(Response.Create() .RespondWith(Response.Create()
// .WithHeader("Keep-Alive", "timeout=1, max=1") .WithHeader("Keep-Alive", "timeout=1, max=1")
// ); );
//server server
// .Given(Request.Create() .Given(Request.Create()
// .UsingGet() .UsingGet()
// .WithPath("/proxy-execute-keep-alive") .WithPath("/proxy-execute-keep-alive")
// ) )
// .RespondWith(Response.Create() .RespondWith(Response.Create()
// .WithProxy(new ProxyAndRecordSettings { Url = "http://localhost:9999", BlackListedHeaders = new[] { "Keep-Alive" } }) .WithProxy(new ProxyAndRecordSettings { Url = "http://localhost:9999", BlackListedHeaders = new[] { "Keep-Alive" } })
// .WithHeader("Keep-Alive-Test", "stef") .WithHeader("Keep-Alive-Test", "stef")
// ); );
//server server
// .Given(Request.Create() .Given(Request.Create()
// .WithPath("/xpath").UsingPost() .WithPath("/xpath").UsingPost()
// .WithBody(new XPathMatcher("/todo-list[count(todo-item) = 3]")) .WithBody(new XPathMatcher("/todo-list[count(todo-item) = 3]"))
// ) )
// .RespondWith(Response.Create().WithBody("XPathMatcher!")); .RespondWith(Response.Create().WithBody("XPathMatcher!"));
//server server
// .Given(Request .Given(Request
// .Create() .Create()
// .WithPath("/jsonthings") .WithPath("/jsonthings")
// .WithBody(new JsonPathMatcher("$.things[?(@.name == 'RequiredThing')]")) .WithBody(new JsonPathMatcher("$.things[?(@.name == 'RequiredThing')]"))
// .UsingPut()) .UsingPut())
// .RespondWith(Response.Create() .RespondWith(Response.Create()
// .WithBody(@"{ ""result"": ""JsonPathMatcher !!!""}")); .WithBody(@"{ ""result"": ""JsonPathMatcher !!!""}"));
//server server
// .Given(Request .Given(Request
// .Create() .Create()
// .WithPath("/jsonbodytest1") .WithPath("/jsonbodytest1")
// .WithBody(new JsonMatcher("{ \"x\": 42, \"s\": \"s\" }")) .WithBody(new JsonMatcher("{ \"x\": 42, \"s\": \"s\" }"))
// .UsingPost()) .UsingPost())
// .WithGuid("debaf408-3b23-4c04-9d18-ef1c020e79f2") .WithGuid("debaf408-3b23-4c04-9d18-ef1c020e79f2")
// .RespondWith(Response.Create() .RespondWith(Response.Create()
// .WithBody(@"{ ""result"": ""jsonbodytest1"" }")); .WithBody(@"{ ""result"": ""jsonbodytest1"" }"));
//server server
// .Given(Request .Given(Request
// .Create() .Create()
// .WithPath("/jsonbodytest2") .WithPath("/jsonbodytest2")
// .WithBody(new JsonMatcher(new { x = 42, s = "s" })) .WithBody(new JsonMatcher(new { x = 42, s = "s" }))
// .UsingPost()) .UsingPost())
// .WithGuid("debaf408-3b23-4c04-9d18-ef1c020e79f3") .WithGuid("debaf408-3b23-4c04-9d18-ef1c020e79f3")
// .RespondWith(Response.Create() .RespondWith(Response.Create()
// .WithBody(@"{ ""result"": ""jsonbodytest2"" }")); .WithBody(@"{ ""result"": ""jsonbodytest2"" }"));
//server server
// .Given(Request .Given(Request
// .Create() .Create()
// .WithPath(new WildcardMatcher("/navision/OData/Company('My Company')/School*", true)) .WithPath(new WildcardMatcher("/navision/OData/Company('My Company')/School*", true))
// .WithParam("$filter", "(substringof(Code, 'WA')") .WithParam("$filter", "(substringof(Code, 'WA')")
// .UsingGet()) .UsingGet())
// .RespondWith(Response.Create() .RespondWith(Response.Create()
// .WithHeader("Content-Type", "application/json") .WithHeader("Content-Type", "application/json")
// .WithBody(@"{ ""result"": ""odata""}")); .WithBody(@"{ ""result"": ""odata""}"));
//server server
// .Given(Request .Given(Request
// .Create() .Create()
// .WithPath(new WildcardMatcher("/param2", true)) .WithPath(new WildcardMatcher("/param2", true))
// .WithParam("key", "test") .WithParam("key", "test")
// .UsingGet()) .UsingGet())
// .RespondWith(Response.Create() .RespondWith(Response.Create()
// .WithHeader("Content-Type", "application/json") .WithHeader("Content-Type", "application/json")
// .WithBodyAsJson(new { result = "param2" })); .WithBodyAsJson(new { result = "param2" }));
//server server
// .Given(Request .Given(Request
// .Create() .Create()
// .WithPath(new WildcardMatcher("/param3", true)) .WithPath(new WildcardMatcher("/param3", true))
// .WithParam("key", new WildcardMatcher("t*")) .WithParam("key", new WildcardMatcher("t*"))
// .UsingGet()) .UsingGet())
// .RespondWith(Response.Create() .RespondWith(Response.Create()
// .WithHeader("Content-Type", "application/json") .WithHeader("Content-Type", "application/json")
// .WithBodyAsJson(new { result = "param3" })); .WithBodyAsJson(new { result = "param3" }));
//server server
// .Given(Request.Create().WithPath("/headers", "/headers_test").UsingPost().WithHeader("Content-Type", "application/json*")) .Given(Request.Create().WithPath("/headers", "/headers_test").UsingPost().WithHeader("Content-Type", "application/json*"))
// .RespondWith(Response.Create() .RespondWith(Response.Create()
// .WithStatusCode(201) .WithStatusCode(201)
// .WithHeader("Content-Type", "application/json") .WithHeader("Content-Type", "application/json")
// .WithBodyAsJson(new { result = "data:headers posted with 201" })); .WithBodyAsJson(new { result = "data:headers posted with 201" }));
//server server
// .Given(Request.Create().WithPath("/file").UsingGet()) .Given(Request.Create().WithPath("/file").UsingGet())
// .RespondWith(Response.Create() .RespondWith(Response.Create()
// .WithBodyFromFile(@"c:\temp\x.json", false) .WithBodyFromFile(@"c:\temp\x.json", false)
// ); );
//server server
// .Given(Request.Create().WithPath("/filecache").UsingGet()) .Given(Request.Create().WithPath("/filecache").UsingGet())
// .RespondWith(Response.Create() .RespondWith(Response.Create()
// .WithBodyFromFile(@"c:\temp\x.json") .WithBodyFromFile(@"c:\temp\x.json")
// ); );
//server server
// .Given(Request.Create().WithPath("/file_rel").UsingGet()) .Given(Request.Create().WithPath("/file_rel").UsingGet())
// .WithGuid("0000aaaa-fcf4-4256-a0d3-1c76e4862947") .WithGuid("0000aaaa-fcf4-4256-a0d3-1c76e4862947")
// .RespondWith(Response.Create() .RespondWith(Response.Create()
// .WithHeader("Content-Type", "application/xml") .WithHeader("Content-Type", "application/xml")
// .WithBodyFromFile("WireMock.Net.xml", false) .WithBodyFromFile("WireMock.Net.xml", false)
// ); );
//server server
// .Given(Request.Create().WithHeader("ProxyThis", "true") .Given(Request.Create().WithHeader("ProxyThis", "true")
// .UsingGet()) .UsingGet())
// .RespondWith(Response.Create() .RespondWith(Response.Create()
// .WithProxy("http://www.google.com") .WithProxy("http://www.google.com")
//); );
//server server
// .Given(Request.Create().WithPath("/bodyasbytes.png") .Given(Request.Create().WithPath("/bodyasbytes.png")
// .UsingGet()) .UsingGet())
// .RespondWith(Response.Create() .RespondWith(Response.Create()
// .WithHeader("Content-Type", "image/png") .WithHeader("Content-Type", "image/png")
// .WithBody(Convert.FromBase64String("iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAIAAAACUFjqAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAZdEVYdFNvZnR3YXJlAHBhaW50Lm5ldCA0LjAuMTczbp9jAAAAJ0lEQVQoU2NgUPuPD6Hz0RCEAtJoiAxpCCBXGgmRIo0TofORkdp/AMiMdRVnV6O0AAAAAElFTkSuQmCC")) .WithBody(Convert.FromBase64String("iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAIAAAACUFjqAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAZdEVYdFNvZnR3YXJlAHBhaW50Lm5ldCA0LjAuMTczbp9jAAAAJ0lEQVQoU2NgUPuPD6Hz0RCEAtJoiAxpCCBXGgmRIo0TofORkdp/AMiMdRVnV6O0AAAAAElFTkSuQmCC"))
// ); );
//server server
// .Given(Request.Create().WithPath("/oauth2/access").UsingPost().WithBody("grant_type=password;username=u;password=p")) .Given(Request.Create().WithPath("/oauth2/access").UsingPost().WithBody("grant_type=password;username=u;password=p"))
// .RespondWith(Response.Create() .RespondWith(Response.Create()
// .WithStatusCode(200) .WithStatusCode(200)
// .WithHeader("Content-Type", "application/json") .WithHeader("Content-Type", "application/json")
// .WithBodyAsJson(new { access_token = "AT", refresh_token = "RT" })); .WithBodyAsJson(new { access_token = "AT", refresh_token = "RT" }));
//server server
// .Given(Request.Create().WithPath("/helloworld").UsingGet().WithHeader("Authorization", new RegexMatcher("^(?i)Bearer AT$"))) .Given(Request.Create().WithPath("/helloworld").UsingGet().WithHeader("Authorization", new RegexMatcher("^(?i)Bearer AT$")))
// .RespondWith(Response.Create() .RespondWith(Response.Create()
// .WithStatusCode(200) .WithStatusCode(200)
// .WithBody("hi")); .WithBody("hi"));
//server server
// .Given(Request.Create().WithPath("/data").UsingPost().WithBody(b => b.Contains("e"))) .Given(Request.Create().WithPath("/data").UsingPost().WithBody(b => b.Contains("e")))
// .AtPriority(999) .AtPriority(999)
// .RespondWith(Response.Create() .RespondWith(Response.Create()
// .WithStatusCode(201) .WithStatusCode(201)
// .WithHeader("Content-Type", "application/json") .WithHeader("Content-Type", "application/json")
// .WithBodyAsJson(new { result = "data posted with FUNC 201" })); .WithBodyAsJson(new { result = "data posted with FUNC 201" }));
//server server
// .Given(Request.Create().WithPath("/json").UsingPost().WithBody(new JsonPathMatcher("$.things[?(@.name == 'RequiredThing')]"))) .Given(Request.Create().WithPath("/json").UsingPost().WithBody(new JsonPathMatcher("$.things[?(@.name == 'RequiredThing')]")))
// .RespondWith(Response.Create() .RespondWith(Response.Create()
// .WithStatusCode(201) .WithStatusCode(201)
// .WithHeader("Content-Type", "application/json") .WithHeader("Content-Type", "application/json")
// .WithBody(@"{ ""result"": ""json posted with 201""}")); .WithBody(@"{ ""result"": ""json posted with 201""}"));
//server server
// .Given(Request.Create().WithPath("/json2").UsingPost().WithBody("x")) .Given(Request.Create().WithPath("/json2").UsingPost().WithBody("x"))
// .RespondWith(Response.Create() .RespondWith(Response.Create()
// .WithStatusCode(201) .WithStatusCode(201)
// .WithHeader("Content-Type", "application/json") .WithHeader("Content-Type", "application/json")
// .WithBody(@"{ ""result"": ""json posted with x - 201""}")); .WithBody(@"{ ""result"": ""json posted with x - 201""}"));
//server server
// .Given(Request.Create().WithPath("/data").UsingDelete()) .Given(Request.Create().WithPath("/data").UsingDelete())
// .RespondWith(Response.Create() .RespondWith(Response.Create()
// .WithStatusCode(200) .WithStatusCode(200)
// .WithHeader("Content-Type", "application/json") .WithHeader("Content-Type", "application/json")
// .WithBody(@"{ ""result"": ""data deleted with 200""}")); .WithBody(@"{ ""result"": ""data deleted with 200""}"));
//server server
// .Given(Request.Create() .Given(Request.Create()
// .WithPath("/needs-a-key") .WithPath("/needs-a-key")
// .UsingGet() .UsingGet()
// .WithHeader("api-key", "*", MatchBehaviour.AcceptOnMatch) .WithHeader("api-key", "*", MatchBehaviour.AcceptOnMatch)
// .UsingAnyMethod()) .UsingAnyMethod())
// .RespondWith(Response.Create() .RespondWith(Response.Create()
// .WithStatusCode(HttpStatusCode.OK) .WithStatusCode(HttpStatusCode.OK)
// .WithBody(@"{ ""result"": ""api-key found""}")); .WithBody(@"{ ""result"": ""api-key found""}"));
//server server
// .Given(Request.Create() .Given(Request.Create()
// .WithPath("/needs-a-key") .WithPath("/needs-a-key")
// .UsingGet() .UsingGet()
// .WithHeader("api-key", "*", MatchBehaviour.RejectOnMatch) .WithHeader("api-key", "*", MatchBehaviour.RejectOnMatch)
// .UsingAnyMethod()) .UsingAnyMethod())
// .RespondWith(Response.Create() .RespondWith(Response.Create()
// .WithStatusCode(HttpStatusCode.Unauthorized) .WithStatusCode(HttpStatusCode.Unauthorized)
// .WithBody(@"{ ""result"": ""api-key missing""}")); .WithBody(@"{ ""result"": ""api-key missing""}"));
//server server
// .Given(Request.Create().WithPath("/nobody").UsingGet()) .Given(Request.Create().WithPath("/nobody").UsingGet())
// .RespondWith(Response.Create().WithDelay(TimeSpan.FromSeconds(1)) .RespondWith(Response.Create().WithDelay(TimeSpan.FromSeconds(1))
// .WithStatusCode(200)); .WithStatusCode(200));
//server server
// .Given(Request.Create().WithPath("/partial").UsingPost().WithBody(new SimMetricsMatcher(new[] { "cat", "dog" }))) .Given(Request.Create().WithPath("/partial").UsingPost().WithBody(new SimMetricsMatcher(new[] { "cat", "dog" })))
// .RespondWith(Response.Create().WithStatusCode(200).WithBody("partial = 200")); .RespondWith(Response.Create().WithStatusCode(200).WithBody("partial = 200"));
//// http://localhost:8080/trans?start=1000&stop=1&stop=2 // http://localhost:8080/trans?start=1000&stop=1&stop=2
//server server
// .Given(Request.Create().WithPath("/trans").UsingGet()) .Given(Request.Create().WithPath("/trans").UsingGet())
// .WithGuid("90356dba-b36c-469a-a17e-669cd84f1f05") .WithGuid("90356dba-b36c-469a-a17e-669cd84f1f05")
// .RespondWith(Response.Create() .RespondWith(Response.Create()
// .WithStatusCode(200) .WithStatusCode(200)
// .WithHeader("Content-Type", "application/json") .WithHeader("Content-Type", "application/json")
// .WithHeader("Transformed-Postman-Token", "token is {{request.headers.Postman-Token}}") .WithHeader("Transformed-Postman-Token", "token is {{request.headers.Postman-Token}}")
// .WithHeader("xyz_{{request.headers.Postman-Token}}", "token is {{request.headers.Postman-Token}}") .WithHeader("xyz_{{request.headers.Postman-Token}}", "token is {{request.headers.Postman-Token}}")
// .WithBody(@"{""msg"": ""Hello world CATCH-ALL on /*, {{request.path}}, bykey={{request.query.start}}, bykey={{request.query.stop}}, byidx0={{request.query.stop.[0]}}, byidx1={{request.query.stop.[1]}}"" }") .WithBody(@"{""msg"": ""Hello world CATCH-ALL on /*, {{request.path}}, bykey={{request.query.start}}, bykey={{request.query.stop}}, byidx0={{request.query.stop.[0]}}, byidx1={{request.query.stop.[1]}}"" }")
// .WithTransformer() .WithTransformer()
// .WithDelay(TimeSpan.FromMilliseconds(100)) .WithDelay(TimeSpan.FromMilliseconds(100))
// ); );
//server server
// .Given(Request.Create().WithPath("/jsonpathtestToken").UsingPost()) .Given(Request.Create().WithPath("/jsonpathtestToken").UsingPost())
// .RespondWith(Response.Create() .RespondWith(Response.Create()
// .WithHeader("Content-Type", "application/json") .WithHeader("Content-Type", "application/json")
// .WithBody("{{JsonPath.SelectToken request.body \"$.Manufacturers[?(@.Name == 'Acme Co')]\"}}") .WithBody("{{JsonPath.SelectToken request.body \"$.Manufacturers[?(@.Name == 'Acme Co')]\"}}")
// .WithTransformer() .WithTransformer()
// ); );
//server server
// .Given(Request.Create().WithPath("/zubinix").UsingPost()) .Given(Request.Create().WithPath("/zubinix").UsingPost())
// .RespondWith(Response.Create() .RespondWith(Response.Create()
// .WithHeader("Content-Type", "application/json") .WithHeader("Content-Type", "application/json")
// .WithBody("{ \"result\": \"{{JsonPath.SelectToken request.bodyAsJson \"username\"}}\" }") .WithBody("{ \"result\": \"{{JsonPath.SelectToken request.bodyAsJson \"username\"}}\" }")
// .WithTransformer() .WithTransformer()
// ); );
//server server
// .Given(Request.Create().WithPath("/zubinix2").UsingPost()) .Given(Request.Create().WithPath("/zubinix2").UsingPost())
// .RespondWith(Response.Create() .RespondWith(Response.Create()
// .WithHeader("Content-Type", "application/json") .WithHeader("Content-Type", "application/json")
// .WithBodyAsJson(new { path = "{{request.path}}", result = "{{JsonPath.SelectToken request.bodyAsJson \"username\"}}" }) .WithBodyAsJson(new { path = "{{request.path}}", result = "{{JsonPath.SelectToken request.bodyAsJson \"username\"}}" })
// .WithTransformer() .WithTransformer()
// ); );
//server server
// .Given(Request.Create().WithPath("/jsonpathtestTokenJson").UsingPost()) .Given(Request.Create().WithPath("/jsonpathtestTokenJson").UsingPost())
// .RespondWith(Response.Create() .RespondWith(Response.Create()
// .WithHeader("Content-Type", "application/json") .WithHeader("Content-Type", "application/json")
// .WithBodyAsJson(new { status = "OK", url = "{{request.url}}", transformed = "{{JsonPath.SelectToken request.body \"$.Manufacturers[?(@.Name == 'Acme Co')]\"}}" }) .WithBodyAsJson(new { status = "OK", url = "{{request.url}}", transformed = "{{JsonPath.SelectToken request.body \"$.Manufacturers[?(@.Name == 'Acme Co')]\"}}" })
// .WithTransformer() .WithTransformer()
// ); );
//server server
// .Given(Request.Create().WithPath("/jsonpathtestTokens").UsingPost()) .Given(Request.Create().WithPath("/jsonpathtestTokens").UsingPost())
// .RespondWith(Response.Create() .RespondWith(Response.Create()
// .WithHeader("Content-Type", "application/json") .WithHeader("Content-Type", "application/json")
// .WithBody("[{{#JsonPath.SelectTokens request.body \"$..Products[?(@.Price >= 50)].Name\"}} { \"idx\":{{id}}, \"value\":\"{{value}}\" }, {{/JsonPath.SelectTokens}} {} ]") .WithBody("[{{#JsonPath.SelectTokens request.body \"$..Products[?(@.Price >= 50)].Name\"}} { \"idx\":{{id}}, \"value\":\"{{value}}\" }, {{/JsonPath.SelectTokens}} {} ]")
// .WithTransformer() .WithTransformer()
// ); );
//server server
// .Given(Request.Create() .Given(Request.Create()
// .WithPath("/state1") .WithPath("/state1")
// .UsingGet()) .UsingGet())
// .InScenario("s1") .InScenario("s1")
// .WillSetStateTo("Test state 1") .WillSetStateTo("Test state 1")
// .RespondWith(Response.Create() .RespondWith(Response.Create()
// .WithBody("No state msg 1")); .WithBody("No state msg 1"));
//server server
// .Given(Request.Create() .Given(Request.Create()
// .WithPath("/foostate1") .WithPath("/foostate1")
// .UsingGet()) .UsingGet())
// .InScenario("s1") .InScenario("s1")
// .WhenStateIs("Test state 1") .WhenStateIs("Test state 1")
// .RespondWith(Response.Create() .RespondWith(Response.Create()
// .WithBody("Test state msg 1")); .WithBody("Test state msg 1"));
//server server
// .Given(Request.Create() .Given(Request.Create()
// .WithPath("/state2") .WithPath("/state2")
// .UsingGet()) .UsingGet())
// .InScenario("s2") .InScenario("s2")
// .WillSetStateTo("Test state 2") .WillSetStateTo("Test state 2")
// .RespondWith(Response.Create() .RespondWith(Response.Create()
// .WithBody("No state msg 2")); .WithBody("No state msg 2"));
//server server
// .Given(Request.Create() .Given(Request.Create()
// .WithPath("/foostate2") .WithPath("/foostate2")
// .UsingGet()) .UsingGet())
// .InScenario("s2") .InScenario("s2")
// .WhenStateIs("Test state 2") .WhenStateIs("Test state 2")
// .RespondWith(Response.Create() .RespondWith(Response.Create()
// .WithBody("Test state msg 2")); .WithBody("Test state msg 2"));
System.Console.WriteLine("Press any key to stop the server"); System.Console.WriteLine("Press any key to stop the server");
System.Console.ReadKey(); System.Console.ReadKey();

View File

@@ -121,7 +121,15 @@ namespace WireMock.Server
foreach (string filename in Directory.EnumerateFiles(folder).OrderBy(f => f)) foreach (string filename in Directory.EnumerateFiles(folder).OrderBy(f => f))
{ {
_logger.Info("Reading Static MappingFile : '{0}'", filename); _logger.Info("Reading Static MappingFile : '{0}'", filename);
ReadStaticMappingAndAddOrUpdate(filename);
try
{
ReadStaticMappingAndAddOrUpdate(filename);
}
catch
{
_logger.Error("Static MappingFile : '{0}' could not be read. This file will be skipped.", filename);
}
} }
} }