I am trying to test my API in a Quarkus APP. My test setup is I define an object and persist it to the DB with a direct call to the service object. I then call the API and expect to get the object back, but I don't....
My test class setup is;
@QuarkusTest
@TestTransaction
@TestHTTPEndpoint(CompanyController.class)
public class CompanyControllerIntegrationTest {
@Inject
CompanyService service;
@ClassRule
private static PostgreSQLContainer<?> db = new PostgreSQLContainer<>("postgres:13.3-alpine")
.withDatabaseName("db")
.withUsername("user")
.withPassword("password");
@Test
void test_getCompanyThatExist() {
service.createCompany(createCompany());
given()
.when().get("/1")
.then().statusCode(200)
.body("size()", is(1));
}
private Company createCompany() {
Company company = new Company();
return company;
}
}
Controller endpoint is;
@GET
@Path("/{id}")
public Response getCompany(@PathParam("id") Long id) {
System.out.println("[CompanyController] Getting company with id - " + id);
Company company = service.getCompany(id);
System.out.println("[CompanyController] Company got was " + company);
return Response
.ok()
.entity(company)
.build();
Service call is;
public Company getCompany(Long id) {
Company company = repository.findById(id);
System.out.println("[CompanyService] Got company - " + company);
return company;
}
And the print outs, which really confuses me....
So the object is persisted with an ID of 1, but when I go to get the object with the ID of 1 its null. Any ideas why? As I am completely stumped at this stage.