I have this simple OrderResource class that I would like to create unit tests for. I'm qusing Quarkus with Hibernate and Panache. What I don't understand is how do i get the function getOrders in my test? How can I mock the response without running this through a live system? I've currently added the quarkus-panache-mock dependency but i can't figure out how to mock the resource
Should the return values come from some service class? and then be injected into the test?
@Entity
public class Order extends PanacheEntity {
public Long id;
public String summary;
public String description;
}
@Path("orders")
public class OrderResource {
@GET
@Path("orders")
public String getAllOrders() {
return Order.listAll();
}
@POST
@Transactional
public Response create(Order order) {
order.persist();
return Response.created(URI.create("/orders/" + order.id)).build();
}
}
I tried creating a test like this:
@Test
public void testCreateOrder() {
OrderResource orderResource = new OrderResource();
System.out.println(orderResource.getAllOrders().get(0).name); //uses the live system
}
But this is not a unit test but rather an integration test since it takes data from the real database.
final String actual = new OrderResource().getOrders("foo"); assertThat(actual, is("orderId: foo"));
(or whatever framework you are using to write assertions) – Turing85