2
I created the following test to validate the registration but instead of returning 201 with the created resource is generating this generic error. My DAO is running on its own in a normal way (I created a listing address using it) Would you have any clue what it could be?
@Test
public void testAdicionaEspecie() {
Especie especie = new Especie();
especie.setDescricao("Especie Test");
Entity<Especie> entity = Entity.entity(especie, MediaType.APPLICATION_JSON);
System.out.println(entity);
Response response = targetVetweb.path("prontuario/especies")
.request()
.post(entity);
String locNovaEspecie = response.getHeaderString("Location");
System.out.println(response.getStatus());
assertTrue(response.getStatus() == 201);
assertTrue(!locNovaEspecie.isEmpty());
}
@Path("especies")
@POST
@Consumes(value = MediaType.APPLICATION_JSON)
public Response postEspecie(Especie especie) {
especieService.add(especie);
return Response.created(URI.create(uriResource.toString() + "/especies/" + especie.getEspecieId())).build();
}
@Override
public void add(Especie especie) {
animalDAO.salvarEspecie(especie);
}
I am using Wildfly 10. I discovered in debugging that it is failing with Transactionrequiredexception in the test classes. I entered the datasource in the Wildfly configuration and my ORM configuration file contains:
<jta-data-source>java:jboss/datasources/vetwebds</jta-data-source>
In other words, I imagine using jta to manage transactions, how do I make junit recognize this configuration and test my registration? I have tried using the Transactional annotation in the test but failed