次の問題があります。HttpHeaders.AUTHORIZATION ヘッダーに間違ったトークンがある場合でも、私のテストは常に肯定的に実行されています。トークンをチェックするフィルターがあるため、理論的には失敗するはずです。私の Jax-RS プログラムは、ブラウザまたは postman のような httpclient を使用して完全に動作しています。したがって、最初にトークンを生成し、そのトークンを使用して HTTP コマンドを実行する必要があります。そうしないと、ステータスコード 401 が返されます。構成が間違っていて、Testframework がフィルターをトリガーせずにテストを実行していると思います。以前に Jax-RS を使用したことがなく、それを修正する方法がわかりません...
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());
}
}