Announcement Announcement Module
Collapse
No announcement yet.
How to TestNG tests a @PreAuthorize annotation and its spring EL specified by a sprin Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to TestNG tests a @PreAuthorize annotation and its spring EL specified by a sprin

    I've defined this method in my Spring MVC Controller

    Code:
    @PreAuthorize("isAuthenticated() and hasPermission(#request, 'CREATE_REQUISITION')")
        @RequestMapping(method = RequestMethod.POST, value = "/trade/createrequisition")
        public @ResponseBody
        void createRequisition(@RequestBody CreateRequisitionRO[] request,
                @RequestHeader("validateOnly") boolean validateOnly) {
    .....
    }
    Then in my TestNG test I'd like to call this method and ensure that the PreAuthorize condition is verified. when I call this method in a normal way (not testing), the PreAuthorize is verified.

    If it's possible, how to test this annotation in a TestNG test and how to catch the exception if it throws one ?

    Best Regards

    I am new to spring forum so please correct me when go wrong when creating new thread.
    Last edited by Rob Winch; Mar 21st, 2013, 12:09 PM. Reason: code formatting

  • #2
    How are you creating your Spring Controller? You should have Spring Test create the controller and inject it into your test. If that doesn't help can you post your test code?

    PS: It helps to ensure you format code, config, logs, etc with the code tag (i.e. the # button)

    Comment

    Working...
    X