Skip to content

Commit

Permalink
chore: when generating JSON, sort the keys in the maps
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronald Holshausen committed Oct 1, 2020
1 parent 677cc2d commit 8d40c92
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Defect221Test {
@Test
@PactVerification('221_provider')
void runTest() {
assert '{"responsetest":true,"name":"harry","data":1234.0}' ==
assert '{"data":1234.0,"name":"harry","responsetest":true}' ==
Request.Put('http://localhost:8112/numbertest')
.addHeader('Accept', APPLICATION_JSON)
.bodyString('{"name": "harry","data": 1234.0 }', ContentType.APPLICATION_JSON)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class Defect342MultiTest {
assert Request.Put(mockProvider.url + '/numbertest')
.addHeader('Accept', 'application/json')
.bodyString('{"name": "harry","data": 1234.0 }', ContentType.APPLICATION_JSON)
.execute().returnContent().asString() == '{"responsetest":true,"name":"harry","data":1234.0}'
.execute().returnContent().asString() == '{"data":1234.0,"name":"harry","responsetest":true}'
}

@Pact(provider = 'multitest_provider', consumer = 'test_consumer')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class MultiTest {
assert Request.Put(mockServer.url + '/numbertest')
.addHeader('Accept', 'application/json')
.bodyString('{"name": "harry","data": 1234.0 }', ContentType.APPLICATION_JSON)
.execute().returnContent().asString() == '{"responsetest":true,"name":"harry","data":1234.0}'
.execute().returnContent().asString() == '{"data":1234.0,"name":"harry","responsetest":true}'
}

@Pact(provider = 'multitest_provider', consumer = 'test_consumer')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ class ProviderStateInjectedPactTest {
.bodyString(JsonOutput.toJson([userName: 'Test', userClass: 'Shoddy']), ContentType.APPLICATION_JSON)
.execute().returnResponse()
assert httpResponse.statusLine.statusCode == 200
assert httpResponse.entity.content.text == '{"userName":"Test","userId":100}'
assert httpResponse.entity.content.text == '{"userId":100,"userName":"Test"}'
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,6 @@ void testApi(MockServer mockServer) throws IOException {
HttpResponse httpResponse = Request.Get(mockServer.getUrl() + "/api/test/1234").execute().returnResponse();
assertThat(httpResponse.getStatusLine().getStatusCode(), is(equalTo(200)));
assertThat(IOUtils.toString(httpResponse.getEntity().getContent()),
is(equalTo("[{\"size\":1445211,\"name\":\"testId254\",\"id\":32432}]")));
is(equalTo("[{\"id\":32432,\"name\":\"testId254\",\"size\":1445211}]")));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ class PactBrokerClientSpec extends Specification {
newHalClient() >> halClient
}
def selectors = [ new ConsumerVersionSelector('DEV', true, null) ]
def json = '{"consumerVersionSelectors":[{"tag":"DEV","latest":true}]}'
def json = '{"consumerVersionSelectors":[{"latest":true,"tag":"DEV"}]}'
def jsonResult = JsonParser.INSTANCE.parseString('''
{
"_embedded": {
Expand Down Expand Up @@ -462,7 +462,7 @@ class PactBrokerClientSpec extends Specification {
newHalClient() >> halClient
}
def selectors = [ new ConsumerVersionSelector('DEV', true, null) ]
def json = '{"consumerVersionSelectors":[{"tag":"DEV","latest":true}]}'
def json = '{"consumerVersionSelectors":[{"latest":true,"tag":"DEV"}]}'
def jsonResult = JsonParser.INSTANCE.parseString('''
{
"_embedded": {
Expand All @@ -488,10 +488,8 @@ class PactBrokerClientSpec extends Specification {
newHalClient() >> halClient
}
def selectors = [ new ConsumerVersionSelector('DEV', true, null) ]
def json = '{"consumerVersionSelectors":[{"tag":"DEV","latest":true}],' +
'"providerVersionTags":[],' +
'"includePendingStatus":true,' +
'"includeWipPactsSince":"2020-24-06"}'
def json = '{"consumerVersionSelectors":[{"latest":true,"tag":"DEV"}],"includePendingStatus":true,' +
'"includeWipPactsSince":"2020-24-06","providerVersionTags":[]}'
def jsonResult = JsonParser.INSTANCE.parseString('''
{
"_embedded": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ sealed class JsonValue {
is True -> "true"
is False -> "false"
is Array -> "[${this.values.joinToString(",") { it.serialise() }}]"
is Object -> "{${this.entries.entries.joinToString(",") { "\"${it.key}\":" + it.value.serialise() }}}"
is Object -> "{${this.entries.entries.sortedBy { it.key }.joinToString(",") { "\"${it.key}\":" + it.value.serialise() }}}"
}
}

Expand Down

0 comments on commit 8d40c92

Please sign in to comment.