玩SecureSocial-开发人员环境和单元测试 [英] Play securesocial - developer environment and unit testing

查看:58
本文介绍了玩SecureSocial-开发人员环境和单元测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用安全社交模块在Play 2应用程序中进行身份验证.

We are using securesocial module for authentication in Play 2 application.

关于此模块,我有两个问题.

I have two questions concerning this module.

首先,有一种简便的方法可以在开发环境中禁用授权检查,最好不要注释所有@SecureSocial.SecuredAction批注.

Firstly, is there an easy way to disable the authorization checking in out development environment, preferably w/o commenting all @SecureSocial.SecuredAction annotations.

第二,在Java中使用securesocial的单元测试方法的首选方法是什么?例如,我在控制器中调用了ctx().args.get(SecureSocial.USER_KEY);以获取身份.如果要对该方法进行单元测试,如何模拟该身份?还是安全的社交网站有一些实用程序类可以帮助进行单元测试?

Secondly, what is the preferred way to unit test methods that use securesocial in Java? For example I have a call to ctx().args.get(SecureSocial.USER_KEY); in controller for getting the identity. If I would want to unit test this method, how can I mock out this identity? Or maybe secure social has some utility classes that can help unit testing?

推荐答案

我们决定在控制器中创建方法getUser,然后在单元测试中使用

We decided to create method getUser in our controller and then in unit-tests we are using http://www.javassist.org/ library to remove securesocial annotations and also to change return value of getUser to some mock that is created in test classes.

这篇关于玩SecureSocial-开发人员环境和单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆