И я использую smallrye-mutiny для разработки своих API-интерфейсов REST.Проблема заключается в том, что при запуске теста RestAssured пытается сериализовать Uni и выдает следующее исключение, сообщающее, что не удалось найти сериализатор для типа Uni. :
Код: Выделить всё
Caused by:
com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of
`io.smallrye.mutiny.Uni` (no Creators, like default constructor, exist): abstract types either
need to be mapped to concrete types, have custom deserializer, or contain additional type
information
at [Source: (String)
{
"header":{
"statusCode":"99-9999",
"statusDescription":"com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class io.smallrye.mutiny.operators.uni.builders.UniCreateFromKnownItem and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS)"
}
}
; line: 1, column: 1]
Мой уровень обслуживания:
Код: Выделить всё
import io.smallrye.mutiny.Uni;
@ApplicationScoped
public class AccountOpeningServiceImpl implements AccountOpeningService {
@Override
public Uni getRandomNumber(GetRandomNumberRequestApi requestApi) {
Uni numberUni = Uni.createFrom().item(() -> GetRandomNumberResponseApi.builder().number(10).build()))
return numberUni;
}
Код: Выделить всё
import io.smallrye.mutiny.Uni;
@Path("")
public class AccountOpeningController {
@Inject
AccountOpeningService accountOpeningService;
@POST
@Path("/random-number")
public Uni getRandomNumber(@Valid GetRandomNumberRequestApi requestApi) {
return accountOpeningService.getRandomNumber(requestApi);
}
Код: Выделить всё
@QuarkusTest
public class AccountOpeningControllerTest {
@InjectMock
AccountOpeningService accountOpeningService;
@Inject
MockUtil mockUtil;
@Test
void getRandomNumber() throws IOException {
GetRandomNumberRequestApi requestApi = mockUtil.getMock("Get_Random_Number_Request.json",
GetRandomNumberRequestApi.class);
GetRandomNumberResponseApi responseApi = mockUtil.getMock("Get_Random_Number_Response.json",
GetRandomNumberResponseApi.class);
when(accountOpeningService.getRandomNumber(requestApi)).thenReturn(Uni.createFrom().item(responseApi));
Uni response = given()
.contentType(MediaType.APPLICATION_JSON)
.body(requestApi)
.when()
.post("/get-random-number")
.then()
.statusCode(200)
.extract()
.as(new TypeRef() {
});
GetRandomNumberResponseApi actualResponse = response.subscribe()
.withSubscriber(UniAssertSubscriber.create())
.assertCompleted()
.getItem();
Assertions.assertEquals(responseApi, actualResponse);
}
Подробнее здесь: https://stackoverflow.com/questions/780 ... estassured