Skip to content

Commit

Permalink
fix: Add tests for generating URLs with null or empty query parameter…
Browse files Browse the repository at this point in the history
… values #1788
  • Loading branch information
rholshausen committed Apr 18, 2024
1 parent be1989d commit 9fea4e2
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 0 deletions.
Expand Up @@ -13,6 +13,7 @@ import org.springframework.web.reactive.function.server.RequestPredicates
import org.springframework.web.reactive.function.server.RouterFunction
import org.springframework.web.reactive.function.server.RouterFunctions
import org.springframework.web.reactive.function.server.ServerResponse
import spock.lang.Issue
import spock.lang.Specification

import java.nio.charset.StandardCharsets
Expand Down Expand Up @@ -98,4 +99,17 @@ class WebFluxTargetSpec extends Specification {
new V4Interaction.SynchronousMessages('test') | false
new V4Interaction.SynchronousHttp('test') | true
}

@Issue('#1788')
def 'query parameters with null and empty values'() {
given:
def pactRequest = new Request('GET', '/', ['A': ['', ''], 'B': [null, null]])
WebFluxTarget webFluxTarget = new WebFluxTarget(routerFunction)

when:
def request = webFluxTarget.requestUriString(pactRequest)

then:
request == '/?A=&A=&B&B'
}
}
Expand Up @@ -11,6 +11,7 @@ import org.springframework.web.reactive.function.server.RouterFunctions
import org.springframework.web.reactive.function.server.ServerRequest
import org.springframework.web.reactive.function.server.ServerResponse
import reactor.core.publisher.Mono
import spock.lang.Issue
import spock.lang.Specification

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

@Issue('#1788')
def 'query parameters with null and empty values'() {
given:
def pactRequest = new Request('GET', '/', ['A': ['', ''], 'B': [null, null]])

when:
def request = verifier.requestUriString(pactRequest)

then:
request == '/?A=&A=&B&B'
}
}
Expand Up @@ -11,6 +11,7 @@ import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.ResponseStatus
import org.springframework.web.bind.annotation.RestController
import spock.lang.Issue
import spock.lang.Specification

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

@Issue('#1788')
def 'query parameters with null and empty values'() {
given:
def pactRequest = new Request('GET', '/', ['A': ['', ''], 'B': [null, null]])

when:
def request = mockMvcTestTarget.requestUriString(pactRequest)

then:
request.query == 'A=&A=&B&B'
}

@RestController
static class TestResource {
@GetMapping(value = '/data', produces = 'application/json')
Expand Down
Expand Up @@ -789,4 +789,16 @@ class ProviderClientSpec extends Specification {
entity.content.text == '{"ä": "äbc"}'
entity.contentType == 'application/json; charset=UTF-8'
}

@Issue('#1788')
def 'query parameters with null and empty values'() {
given:
def pactRequest = new Request('GET', '/', ['A': ['', ''], 'B': [null, null]])

when:
def request = client.newRequest(pactRequest)

then:
request.uri.query == 'A=&A=&B&B'
}
}

0 comments on commit 9fea4e2

Please sign in to comment.