Pergunta

I have a new Play 2 project with play-authenticate. I wrote some simple test cases for the REST API. Tests pass fine on the console but I cannot make some of them pass in Eclipse.

@Test
public void testWithoutAuth() {
  running(testServer(3333), new Runnable() {
    @Override
    public void run() {
        Response response = WS.url("http://localhost:3333/secretarea").get().get();
        assertThat(response.getStatus()).isEqualTo(FORBIDDEN);
    }
  });
}

This example passes fine on the console but in Eclipse fails with response error code 500. it looks like the application setup is not ok (e.g. my own AuthProvider not found). Has anyone managed to get such tests working in Eclipse?

Foi útil?

Solução

Finally sorted this out. The trick is to create FakeApplicatio with custom config. In my case the setup is like this:

@Test
public void testWithoutAuth() {
    List<String> plugins = new ArrayList<String>();
    plugins.add("be.objectify.deadbolt.DeadboltPlugin");
    plugins.add("service.MyUserServicePlugin");
    plugins.add("providers.MyUsernamePasswordAuthProvider");

    FakeApplication fa = fakeApplication(new HashMap<String,String>(), plugins);

    running(testServer(3333, fa), new Runnable() {
        @Override
        public void run() {
            Response response = WS.url("http://localhost:3333/secretarea").get().get();
            assertThat(response.getStatus()).isEqualTo(FORBIDDEN);
        }
    });
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top