@GwtIncompatible // java.time.Duration public void testTimeToLive_setTwice_duration() { CacheBuilder<Object, Object> builder = CacheBuilder.newBuilder().expireAfterWrite(java.time.Duration.ofSeconds(3600)); try { // even to the same value is not allowed builder.expireAfterWrite(java.time.Duration.ofSeconds(3600)); fail(); } catch (IllegalStateException expected) { } }
@GwtIncompatible // java.time.Duration public void testTimeToIdle_setTwice_duration() { CacheBuilder<Object, Object> builder = CacheBuilder.newBuilder().expireAfterAccess(java.time.Duration.ofSeconds(3600)); try { // even to the same value is not allowed builder.expireAfterAccess(java.time.Duration.ofSeconds(3600)); fail(); } catch (IllegalStateException expected) { } }
@GetMapping(path = "/spr16869", produces = MediaType.TEXT_EVENT_STREAM_VALUE) Flux<String> sseFlux() { return Flux.interval(Duration.ofSeconds(1)).take(3) .map(aLong -> String.format("event%d", aLong)); } }
@GwtIncompatible // java.time.Duration public void testTimeToLive_negative_duration() { CacheBuilder<Object, Object> builder = CacheBuilder.newBuilder(); try { builder.expireAfterWrite(java.time.Duration.ofSeconds(-1)); fail(); } catch (IllegalArgumentException expected) { } }
@GwtIncompatible // java.time.Duration public void testTimeToIdle_negative_duration() { CacheBuilder<Object, Object> builder = CacheBuilder.newBuilder(); try { builder.expireAfterAccess(java.time.Duration.ofSeconds(-1)); fail(); } catch (IllegalArgumentException expected) { } }
@GwtIncompatible // java.time.Duration public void testRefresh_setTwice_duration() { CacheBuilder<Object, Object> builder = CacheBuilder.newBuilder().refreshAfterWrite(java.time.Duration.ofSeconds(3600)); try { // even to the same value is not allowed builder.refreshAfterWrite(java.time.Duration.ofSeconds(3600)); fail(); } catch (IllegalStateException expected) { } }
@After public void shutDown() throws InterruptedException { waitForDataBufferRelease(Duration.ofSeconds(2)); this.factory.destroy(); }
@SuppressWarnings("unchecked") private <T> T resolveValue(MethodParameter param, String body) { ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.post("/path").body(body)); Mono<Object> result = this.resolver.readBody(param, true, new BindingContext(), exchange); Object value = result.block(Duration.ofSeconds(5)); assertNotNull(value); assertTrue("Unexpected return value type: " + value, param.getParameterType().isAssignableFrom(value.getClass())); //no inspection unchecked return (T) value; }
@Test // SPR-12894 public void useDefaultContentType() throws Exception { Resource body = new ClassPathResource("logo.png", getClass()); MethodParameter type = on(TestController.class).resolveReturnType(Resource.class); this.resultHandler.writeBody(body, type, this.exchange).block(Duration.ofSeconds(5)); assertEquals("image/png", this.exchange.getResponse().getHeaders().getFirst("Content-Type")); }
@Test public void handleAnnotatedException() { Throwable ex = new CustomException(); this.handler.handle(this.exchange, ex).block(Duration.ofSeconds(5)); assertEquals(HttpStatus.I_AM_A_TEAPOT, this.exchange.getResponse().getStatusCode()); }
@Test // SPR-13318 public void jacksonTypeWithSubTypeOfListElement() throws Exception { MethodParameter returnType = on(TestController.class).resolveReturnType(List.class, Identifiable.class); List<SimpleBean> body = Arrays.asList(new SimpleBean(123L, "foo"), new SimpleBean(456L, "bar")); this.resultHandler.writeBody(body, returnType, this.exchange).block(Duration.ofSeconds(5)); assertEquals(APPLICATION_JSON_UTF8, this.exchange.getResponse().getHeaders().getContentType()); assertResponseBody("[{\"id\":123,\"name\":\"foo\"},{\"id\":456,\"name\":\"bar\"}]"); }
@SuppressWarnings("unchecked") private <T> HttpEntity<T> resolveValueWithEmptyBody(ResolvableType type) { ServerWebExchange exchange = MockServerWebExchange.from(post("/path")); MethodParameter param = this.testMethod.arg(type); Mono<Object> result = this.resolver.resolveArgument(param, new BindingContext(), exchange); HttpEntity<String> httpEntity = (HttpEntity<String>) result.block(Duration.ofSeconds(5)); assertEquals(exchange.getRequest().getHeaders(), httpEntity.getHeaders()); return (HttpEntity<T>) httpEntity; }
@Test public void testBindingWithQueryParams() throws Exception { String url = "/path?spouse=someValue&spouse.name=test"; ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.post(url)); this.binder.bind(exchange).block(Duration.ofSeconds(5)); assertNotNull(this.testBean.getSpouse()); assertEquals("test", this.testBean.getSpouse().getName()); }
@Test public void readResourcePosition() throws Exception { Flux<DataBuffer> flux = DataBufferUtils.read(this.resource, 9, this.bufferFactory, 3); StepVerifier.create(flux) .consumeNextWith(stringConsumer("qux")) .expectComplete() .verify(Duration.ofSeconds(5)); }
@Test // SPR-13318 public void jacksonTypeWithSubType() throws Exception { SimpleBean body = new SimpleBean(123L, "foo"); MethodParameter type = on(TestController.class).resolveReturnType(Identifiable.class); this.resultHandler.writeBody(body, type, this.exchange).block(Duration.ofSeconds(5)); assertEquals(APPLICATION_JSON_UTF8, this.exchange.getResponse().getHeaders().getContentType()); assertResponseBody("{\"id\":123,\"name\":\"foo\"}"); }
@Test // SPR-17482 public void bodyToMonoVoidWithoutContentType() { this.server.enqueue(new MockResponse() .setResponseCode(HttpStatus.ACCEPTED.value()) .setChunkedBody("{\"foo\" : \"123\", \"baz\" : \"456\", \"baz\" : \"456\"}", 5)); Mono<Map<String, String>> mono = this.webClient.get() .uri("/sample").accept(MediaType.APPLICATION_JSON) .retrieve() .bodyToMono(new ParameterizedTypeReference<Map<String, String>>() {}); StepVerifier.create(mono).expectError(UnsupportedMediaTypeException.class).verify(Duration.ofSeconds(3)); assertEquals(1, this.server.getRequestCount()); }
private void verifyReadData(Flux<DataBuffer> buffers) { StepVerifier.create(buffers) .consumeNextWith(stringConsumer("foo")) .consumeNextWith(stringConsumer("bar")) .consumeNextWith(stringConsumer("baz")) .consumeNextWith(stringConsumer("qux")) .expectComplete() .verify(Duration.ofSeconds(3)); }
@Test public void maxAge0() { assertEquals("id=1fWa; Max-Age=0; Expires=Thu, 1 Jan 1970 00:00:00 GMT", ResponseCookie.from("id", "1fWa").maxAge(Duration.ofSeconds(0)).build().toString()); assertEquals("id=1fWa; Max-Age=0; Expires=Thu, 1 Jan 1970 00:00:00 GMT", ResponseCookie.from("id", "1fWa").maxAge(0).build().toString()); }
@Test public void takeUntilByteCount() { Flux<DataBuffer> result = DataBufferUtils.takeUntilByteCount( Flux.just(stringBuffer("foo"), stringBuffer("bar")), 5L); StepVerifier.create(result) .consumeNextWith(stringConsumer("foo")) .consumeNextWith(stringConsumer("ba")) .expectComplete() .verify(Duration.ofSeconds(5)); }