How to use junit to test jax rs on wildfly

2

I created the following test to validate the register but instead of returning 201 with the created resource is generating this generic error. My DAO is working alone in a normal way (I created a list 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'm using WildFly 10. I discovered in debugging that it is failing with TransactionRequiredException in the test classes. I inserted the datasource into the WildFly configuration and my ORM configuration file contains:

<jta-data-source>java:jboss/datasources/vetwebds</jta-data-source>

In other words, I imagine I'm using jta to manage transactions, how do I make junit recognize this configuration and test my registration? I have already tried using the Transactional annotation in the test but without success

    
asked by anonymous 11.06.2018 / 19:10

0 answers