Why are my tests not triggering my filter?

问题: I have following Problem. My tests are running allways positive even when the HttpHeaders.AUTHORIZATION headder has a wrong token. In theory it should fail because I have a...

问题:

I have following Problem. My tests are running allways positive even when the HttpHeaders.AUTHORIZATION headder has a wrong token. In theory it should fail because I have a filter that checks the token. My Jax-RS program is working perfectly in the browser or using a httpclient like postman. So I have to generate a token first and then use that token to run the HTTP commands otherwise it will return the statuscode 401. I think that my configuration is wrong and the Testframework is running the tests without triggering the filter. I never worked with Jax-RS before and I have no Idea how to fix that...

public class GamesTest extends JerseyTest{


@Override
protected Application configure() {
    return new ResourceConfig(Games.class).register(new AbstractBinder() {
        protected void configure() {
            bind(GamesXMLDB.class).to(MyGameDBInterfaceDB.class).in(Singleton.class);
            bind(UserXMLDB.class).to(MyUserInterfaceDB.class).in(Singleton.class);
        }
    });
}   


@Test
public void getWithoutTokenTest() {
    Response response = target("/games").request().header(HttpHeaders.AUTHORIZATION, "").get();
    assertEquals(200, response.getStatus());
}

}


回答1:

I'm an idiot I had to add the filter.class to the ResourceConfig. I thought this was not needed as it would find the filter via the annotation.

  • 发表于 2019-01-22 16:22
  • 阅读 ( 176 )
  • 分类:网络文章

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除