Skip to content

Commit 9fea4e2

Browse files
committed
fix: Add tests for generating URLs with null or empty query parameter values #1788
1 parent be1989d commit 9fea4e2

File tree

4 files changed

+51
-0
lines changed

4 files changed

+51
-0
lines changed

provider/junit5spring/src/test/groovy/au/com/dius/pact/provider/spring/junit5/WebFluxTargetSpec.groovy

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import org.springframework.web.reactive.function.server.RequestPredicates
1313
import org.springframework.web.reactive.function.server.RouterFunction
1414
import org.springframework.web.reactive.function.server.RouterFunctions
1515
import org.springframework.web.reactive.function.server.ServerResponse
16+
import spock.lang.Issue
1617
import spock.lang.Specification
1718

1819
import java.nio.charset.StandardCharsets
@@ -98,4 +99,17 @@ class WebFluxTargetSpec extends Specification {
9899
new V4Interaction.SynchronousMessages('test') | false
99100
new V4Interaction.SynchronousHttp('test') | true
100101
}
102+
103+
@Issue('#1788')
104+
def 'query parameters with null and empty values'() {
105+
given:
106+
def pactRequest = new Request('GET', '/', ['A': ['', ''], 'B': [null, null]])
107+
WebFluxTarget webFluxTarget = new WebFluxTarget(routerFunction)
108+
109+
when:
110+
def request = webFluxTarget.requestUriString(pactRequest)
111+
112+
then:
113+
request == '/?A=&A=&B&B'
114+
}
101115
}

provider/spring/src/test/groovy/au/com/dius/pact/provider/spring/WebFluxProviderVerifierSpec.groovy

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import org.springframework.web.reactive.function.server.RouterFunctions
1111
import org.springframework.web.reactive.function.server.ServerRequest
1212
import org.springframework.web.reactive.function.server.ServerResponse
1313
import reactor.core.publisher.Mono
14+
import spock.lang.Issue
1415
import spock.lang.Specification
1516

1617
import static org.springframework.web.reactive.function.server.RequestPredicates.GET
@@ -96,4 +97,15 @@ class WebFluxProviderVerifierSpec extends Specification {
9697
new String(bytes)
9798
}
9899

100+
@Issue('#1788')
101+
def 'query parameters with null and empty values'() {
102+
given:
103+
def pactRequest = new Request('GET', '/', ['A': ['', ''], 'B': [null, null]])
104+
105+
when:
106+
def request = verifier.requestUriString(pactRequest)
107+
108+
then:
109+
request == '/?A=&A=&B&B'
110+
}
99111
}

provider/spring6/src/test/groovy/au/com/dius/pact/provider/spring/spring6/MockMvcTestTargetSpec.groovy

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import org.springframework.web.bind.annotation.GetMapping
1111
import org.springframework.web.bind.annotation.RequestParam
1212
import org.springframework.web.bind.annotation.ResponseStatus
1313
import org.springframework.web.bind.annotation.RestController
14+
import spock.lang.Issue
1415
import spock.lang.Specification
1516

1617
import java.nio.charset.StandardCharsets
@@ -123,6 +124,18 @@ class MockMvcTestTargetSpec extends Specification {
123124
responseMap.body.valueAsString() == 'Hello 1234'
124125
}
125126

127+
@Issue('#1788')
128+
def 'query parameters with null and empty values'() {
129+
given:
130+
def pactRequest = new Request('GET', '/', ['A': ['', ''], 'B': [null, null]])
131+
132+
when:
133+
def request = mockMvcTestTarget.requestUriString(pactRequest)
134+
135+
then:
136+
request.query == 'A=&A=&B&B'
137+
}
138+
126139
@RestController
127140
static class TestResource {
128141
@GetMapping(value = '/data', produces = 'application/json')

provider/src/test/groovy/au/com/dius/pact/provider/groovysupport/ProviderClientSpec.groovy

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -789,4 +789,16 @@ class ProviderClientSpec extends Specification {
789789
entity.content.text == '{"ä": "äbc"}'
790790
entity.contentType == 'application/json; charset=UTF-8'
791791
}
792+
793+
@Issue('#1788')
794+
def 'query parameters with null and empty values'() {
795+
given:
796+
def pactRequest = new Request('GET', '/', ['A': ['', ''], 'B': [null, null]])
797+
798+
when:
799+
def request = client.newRequest(pactRequest)
800+
801+
then:
802+
request.uri.query == 'A=&A=&B&B'
803+
}
792804
}

0 commit comments

Comments
 (0)