2016-03-30 23 views
1

Jersey Test, Mockito, Junit ile test ettiğim REST web servisim var. Web hizmeti yöntemi başarıyla yürütüldüğünde, doğru yanıtı alırım. Geçersiz veriler durumunda, ExceptionMapper tarafından ele alınması gereken özel istisna atılır. Aynı yapı cevabını ancak farklı kodlarla döndürmelidir. ExceptionMapper, test ortamında iyi çalışır. Ancak sonra test yürütme günlükleri gösterir:Jersey testi - ExceptionMapper çağrılmadı

1 < 500 
1 < Connection: close 
1 < Content-Length: 1033 
1 < Content-Type: text/html;charset=ISO-8859-1 
1 < Date: Wed, 30 Mar 2016 11:55:37 GMT 

javax.ws.rs.InternalServerErrorException: HTTP 500 Request failed. 
at org.glassfish.jersey.client.JerseyInvocation.convertToException(JerseyInvocation.java:1020) 
at org.glassfish.jersey.client.JerseyInvocation.translate(JerseyInvocation.java:816) 
at org.glassfish.jersey.client.JerseyInvocation.access$700(JerseyInvocation.java:92) 

kullandığım:

<dependency> 
    <groupId>org.glassfish.jersey.test-framework.providers</groupId> 
    <artifactId>jersey-test-framework-provider-grizzly2</artifactId> 
    <version>2.22.2</version> 
</dependency> 
Test sınıfları ile genişlete- edilir alay hizmetin

Kısaltılmış sürümü:

public class MockedService extends JerseyTest { 

    @Override 
    public ResourceConfig configure() { 

     forceSet(TestProperties.CONTAINER_PORT, "8080"); 
     enable(TestProperties.LOG_TRAFFIC); 

     return new ResourceConfig().register(new Service()); 
    } 
} 

ExceptionMapper dan yanıt almak için nasıl ?

cevap

4

Hala mapper muhtemelen paket tarama veya sınıf yolu tarama ile, ya için taranır, Sende ExceptionMapper

return new ResourceConfig() 
     .register(new Service()) 
     .register(new YourMapper()); 

gerçek ortam kaydetmeniz gerekir.

İlgili konular