【问题标题】:Play 2 Java, play-authenticate and Eclipse JUnit tests玩 2 个 Java、play-authenticate 和 Eclipse JUnit 测试
【发布时间】:2012-10-22 07:03:43
【问题描述】:

我有一个带有 play-authenticate 的新 Play 2 项目。我为 REST API 编写了一些简单的测试用例。测试在控制台上顺利通过,但我无法让其中一些在 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);
    }
  });
}

此示例在控制台上正常通过,但在 Eclipse 中失败,响应错误代码为 500。看起来应用程序设置不正确(例如,我自己的 AuthProvider 未找到)。有没有人设法让这样的测试在 Eclipse 中工作?

【问题讨论】:

    标签: eclipse junit playframework-2.0 play-authenticate


    【解决方案1】:

    终于解决了。诀窍是使用自定义配置创建 FakeApplicatio。在我的情况下,设置是这样的:

    @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);
            }
        });
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-13
      • 1970-01-01
      • 2011-04-04
      相关资源
      最近更新 更多