@Author: Thiago Carreira
@License: Apache 2
Foram implementados duas interfaces:
- uma conjunto de Funções para Request Assíncronos com assinatura:
Function<RestSpecs, HttpResponse> asyncRequestGET = (specs) ->
(HttpResponse) Try.of(() ->
specs.getBaseClient().sendAsync(
requestGET.apply(specs),
specs.getResponseBodyHandler()
).get()
).getOrNull();
- um conjunto de Funções, uma para cada método, de assinatura similar, porém, Síncronas:
Function<RestSpecs, HttpResponse> syncResquestGET = (specs) ->
Try.of(() ->
specs.getBaseClient().send(requestGET.apply(specs), specs.getResponseBodyHandler())
).getOrNull();
Um teste fazendo uso dessa função tem o seguinte formato:
@Tag("Function")
@DisplayName("Aplicando Function")
@Test
void testFunction(){
AtomicReference<HttpResponse> response = new AtomicReference<>();
response.lazySet(Lazy.val(()-> syncRequestPost.apply(restSpecs()), HttpResponse.class));
assertAll("valida dia feliz",
() -> assertNotNull(response.get()),
() -> assertNotNull(response.get().headers().firstValue("x-access-token"))
);
}
assertAll("valida dia feliz",
() -> assertNotNull(response.get()),
() -> assertNotNull(response.get().headers().firstValue("x-access-token")));
}
Para executar testes com uma tag específica, por exemplo 'auth', execute via terminal: gradle clean test -Dtag="auth"
.
Consulte a documentação oficial do Junit5 para maiores informações.