私は次のように注釈を付けているコントローラーメソッドを持っています:
@Secured(['ROLE_ADMIN'])
def save() {
... // code ommitted
}
管理者ユーザーのみが URL にアクセスできることを確認する単体テストを作成しようとしています。
def "Only the admin user should be able to invoke save"() {
given:
def user = createNonAdminUser() // let's pretend this method exists
controller.springSecurityService = Mock(SpringSecurityService)
controller.springSecurityService.currentUser >> user
when:
controller.save()
then:
view ==~ 'accessdenied'
}
ただし、返されるビューはsave
ビューであり、アクセスが拒否されたビューではありません。@Secured
注釈を完全にバイパスしているようです。@Secured
単体テストまたは統合テストからアノテーションをテストする方法はありますか?