Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
olegz committed Jun 22, 2023
1 parent 3103dc6 commit 55be671
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,10 @@ public void write(int b) throws IOException {
}
}

@Override
public void flush() throws IOException {
flushBuffer();
}

@Override
public void close()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ public void initServletAppTest(String reqType) {
handler = new LambdaHandler(type);
}

@MethodSource("data")
@ParameterizedTest
void asyncRequest(String reqType) {
initServletAppTest(reqType);
AwsProxyRequestBuilder req = new AwsProxyRequestBuilder("/async", "POST")
.json()
.body("{\"name\":\"bob\"}");
AwsProxyResponse resp = handler.handleRequest(req, lambdaContext);
assertEquals("{\"name\":\"BOB\"}", resp.getBody());
}

@MethodSource("data")
@ParameterizedTest
void helloRequest_respondsWithSingleMessage(String reqType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
import org.springframework.http.ResponseEntity;
import org.springframework.validation.Errors;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.async.DeferredResult;
import org.springframework.web.server.ResponseStatusException;

import jakarta.validation.Valid;
import reactor.core.publisher.Mono;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

Expand All @@ -18,6 +22,22 @@ public class MessageController {
public static final String UTF8_RESPONSE = "öüäß фрыцшщ";
public static final String EX_MESSAGE = "404 exception message";


@RequestMapping(path="/hi", method=RequestMethod.GET, produces = {"text/plain"})
public Mono<String> hi() {
return Mono.just(HELLO_MESSAGE);
}

@SuppressWarnings({ "unchecked", "rawtypes" })
@RequestMapping(path = "/async", method = RequestMethod.POST)
@ResponseBody
public DeferredResult<Map<String, String>> asyncResult(@RequestBody Map<String, String> value) {
DeferredResult result = new DeferredResult<>();
result.setResult(Collections.singletonMap("name", value.get("name").toUpperCase()));
return result;
}


@RequestMapping(path="/hello", method=RequestMethod.GET, produces = {"text/plain"})
public String hello() {
return HELLO_MESSAGE;
Expand Down

0 comments on commit 55be671

Please sign in to comment.