@Test public void lastModified() { ZonedDateTime now = ZonedDateTime.now(); Mono<ServerResponse> result = ServerResponse.ok().lastModified(now).build(); Long expected = now.toInstant().toEpochMilli() / 1000; StepVerifier.create(result) .expectNextMatches(response -> expected.equals(response.headers().getLastModified() / 1000)) .expectComplete() .verify(); }
@Test public void lastModified() { ZonedDateTime now = ZonedDateTime.now(); String body = "foo"; Mono<EntityResponse<String>> result = EntityResponse.fromObject(body).lastModified(now).build(); Long expected = now.toInstant().toEpochMilli() / 1000; StepVerifier.create(result) .expectNextMatches(response -> expected.equals(response.headers().getLastModified() / 1000)) .expectComplete() .verify(); }
@Test public void modelAttributesConventions() { Set<String> model = Collections.singleton("bar"); Mono<RenderingResponse> result = RenderingResponse.create("foo") .modelAttributes(model).build(); StepVerifier.create(result) .expectNextMatches(response -> "bar".equals(response.model().get("string"))) .expectComplete() .verify(); }
@Test public void cacheControlTag() { Mono<ServerResponse> result = ServerResponse.ok().cacheControl(CacheControl.noCache()).build(); StepVerifier.create(result) .expectNextMatches(response -> "no-cache".equals(response.headers().getCacheControl())) .expectComplete() .verify(); }
@Test public void contentType() { Mono<ServerResponse> result = ServerResponse.ok().contentType(MediaType.APPLICATION_JSON).build(); StepVerifier.create(result) .expectNextMatches(response -> MediaType.APPLICATION_JSON.equals(response.headers().getContentType())) .expectComplete() .verify(); }
@Test public void badRequest() { Mono<ServerResponse> result = ServerResponse.badRequest().build(); StepVerifier.create(result) .expectNextMatches(response -> HttpStatus.BAD_REQUEST.equals(response.statusCode())) .expectComplete() .verify(); }
@Test public void status() { Mono<ServerResponse> result = ServerResponse.status(HttpStatus.CREATED).build(); StepVerifier.create(result) .expectNextMatches(response -> HttpStatus.CREATED.equals(response.statusCode())) .expectComplete() .verify(); }
@Test public void varyBy() { String body = "foo"; Mono<EntityResponse<String>> result = EntityResponse.fromObject(body).varyBy("foo").build(); List<String> expected = Collections.singletonList("foo"); StepVerifier.create(result) .expectNextMatches(response -> expected.equals(response.headers().getVary())) .expectComplete() .verify(); }
@Test public void create() { String name = "foo"; Mono<RenderingResponse> result = RenderingResponse.create(name).build(); StepVerifier.create(result) .expectNextMatches(response -> name.equals(response.name())) .expectComplete() .verify(); }
@Test public void varyBy() { Mono<ServerResponse> result = ServerResponse.ok().varyBy("foo").build(); List<String> expected = Collections.singletonList("foo"); StepVerifier.create(result) .expectNextMatches(response -> expected.equals(response.headers().getVary())) .expectComplete() .verify(); }
@Test public void etag() { String body = "foo"; Mono<EntityResponse<String>> result = EntityResponse.fromObject(body).eTag("foo").build(); StepVerifier.create(result) .expectNextMatches(response -> "\"foo\"".equals(response.headers().getETag())) .expectComplete() .verify(); }
@Test public void contentType() { String body = "foo"; Mono<EntityResponse<String>> result = EntityResponse.fromObject(body).contentType(MediaType.APPLICATION_JSON).build(); StepVerifier.create(result) .expectNextMatches(response -> MediaType.APPLICATION_JSON.equals(response.headers().getContentType())) .expectComplete() .verify(); }
@Test public void allow() { String body = "foo"; Mono<EntityResponse<String>> result = EntityResponse.fromObject(body).allow(HttpMethod.GET).build(); Set<HttpMethod> expected = EnumSet.of(HttpMethod.GET); StepVerifier.create(result) .expectNextMatches(response -> expected.equals(response.headers().getAllow())) .expectComplete() .verify(); }
@Test public void modelAttributeConventions() { Mono<RenderingResponse> result = RenderingResponse.create("foo") .modelAttribute("bar").build(); StepVerifier.create(result) .expectNextMatches(response -> "bar".equals(response.model().get("string"))) .expectComplete() .verify(); }
@Test public void unprocessableEntity() { Mono<ServerResponse> result = ServerResponse.unprocessableEntity().build(); StepVerifier.create(result) .expectNextMatches(response -> HttpStatus.UNPROCESSABLE_ENTITY.equals(response.statusCode())) .expectComplete() .verify(); }
@Test public void notFound() { Mono<ServerResponse> result = ServerResponse.notFound().build(); StepVerifier.create(result) .expectNextMatches(response -> HttpStatus.NOT_FOUND.equals(response.statusCode())) .expectComplete() .verify(); }
@Test public void noContent() { Mono<ServerResponse> result = ServerResponse.noContent().build(); StepVerifier.create(result) .expectNextMatches(response -> HttpStatus.NO_CONTENT.equals(response.statusCode())) .expectComplete() .verify(); }
@Test public void ok() { Mono<ServerResponse> result = ServerResponse.ok().build(); StepVerifier.create(result) .expectNextMatches(response -> HttpStatus.OK.equals(response.statusCode())) .expectComplete() .verify(); }
@Test public void cacheControlTag() { String body = "foo"; Mono<EntityResponse<String>> result = EntityResponse.fromObject(body).cacheControl(CacheControl.noCache()).build(); StepVerifier.create(result) .expectNextMatches(response -> "no-cache".equals(response.headers().getCacheControl())) .expectComplete() .verify(); }
@Test public void contentLength() { String body = "foo"; Mono<EntityResponse<String>> result = EntityResponse.fromObject(body).contentLength(42).build(); StepVerifier.create(result) .expectNextMatches(response -> Long.valueOf(42).equals(response.headers().getContentLength())) .expectComplete() .verify(); }