|
| 1 | +package graphql.kickstart.servlet |
| 2 | + |
| 3 | +import com.fasterxml.jackson.databind.ObjectMapper |
| 4 | +import graphql.ExecutionResultImpl |
| 5 | +import graphql.kickstart.execution.GraphQLObjectMapper |
| 6 | +import org.codehaus.groovy.runtime.StringBufferWriter |
| 7 | +import spock.lang.Specification |
| 8 | +import spock.lang.Unroll |
| 9 | + |
| 10 | +import javax.servlet.http.HttpServletRequest |
| 11 | +import javax.servlet.http.HttpServletResponse |
| 12 | + |
| 13 | +class SingleQueryResponseWriterTest extends Specification { |
| 14 | + |
| 15 | + @Unroll |
| 16 | + def "should write utf8 results into the response with content #result"() { |
| 17 | + given: |
| 18 | + def graphQLObjectMapperMock = GraphQLObjectMapper.newBuilder().withObjectMapperProvider({ new ObjectMapper() }).build() |
| 19 | + graphQLObjectMapperMock.getJacksonMapper() >> new ObjectMapper() |
| 20 | + |
| 21 | + def requestMock = Mock(HttpServletRequest) |
| 22 | + def responseMock = Mock(HttpServletResponse) |
| 23 | + |
| 24 | + def responseContentBuffer = new StringBuffer() |
| 25 | + responseMock.getWriter() >> new PrintWriter(new StringBufferWriter(responseContentBuffer)) |
| 26 | + 1 * responseMock.setContentLength(expectedContentLenght) |
| 27 | + 1 * responseMock.setCharacterEncoding("UTF-8") |
| 28 | + |
| 29 | + expect: |
| 30 | + def writer = new SingleQueryResponseWriter(new ExecutionResultImpl(result, []), graphQLObjectMapperMock) |
| 31 | + writer.write(requestMock, responseMock) |
| 32 | + |
| 33 | + responseContentBuffer.toString() == expectedResponseContent |
| 34 | + |
| 35 | + where: |
| 36 | + result || expectedContentLenght | expectedResponseContent |
| 37 | + [testValue: "abcde"] || 30 | """{"data":{"testValue":"abcde"}}""" |
| 38 | + [testValue: "äöüüöß"] || 37 | """{"data":{"testValue":"äöüüöß"}}""" |
| 39 | + } |
| 40 | +} |
0 commit comments