2 Replies Latest reply on Apr 11, 2011 5:25 AM by tyshan.tyshanchn.gmail.com

    how can I create Test for s:hasPermission

    tyshan.tyshanchn.gmail.com
      Hi

      How can I create a test for restrict in *.page.xml?

      in viewDialplan.page.xml
      <?xml version="1.0" encoding="UTF-8"?>
      <page xmlns="http://jboss.com/products/seam/pages" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://jboss.com/products/seam/pages http://jboss.com/products/seam/pages-2.1.xsd"
              no-conversation-view-id="/home.xhtml" login-required="true"
              view-id="/dialplan/viewDialplan.xhtml">

              <restrict>#{s:hasPermission('dialPlan', 'view')}</restrict>
          <begin-conversation join="true" flush-mode="manual"/>
             
      </page>

      How can I create a unit test for this in

      @Test(alwaysRun = true)
              public void testViewDRPlanWithRoleCallManager() throws Exception {

                      new FacesRequest("/dialplan/viewDialplan.xhtml") {

                              @Override
                              protected void afterRequest() {
                                      super.afterRequest();
                                      System.out.println("aferRequest");
                                      assert Pages.instance().getPage(Pages.getCurrentViewId())
                                                      .isRestricted();
                              }

                      }.run();
                   }

      I will get an exception:

      FAILED: testViewDRPlanWithRoleCallManager
      java.lang.IllegalStateException: No active application context
              at org.jboss.seam.navigation.Pages.instance(Pages.java:664)
              at


      Is there any way for this?


      Thanks in advance


      Tyshan
        • 1. Re: how can I create Test for s:hasPermission
          tyshan.tyshanchn.gmail.com


          failed when use such codes as follows:



          @Override
                         protected void beforeRequest(){
                              super.beforeRequest();
                              
                              try {


                                   Identity.instance().checkPermission(dialPlan,
                                             view);
                                   
                              } catch (AuthorizationException e) {
                                   System.out.println(e.getMessage());
                                   assert false;
                              }
                         }


          Is there any good way for checking a permission,which is defined in the rules.



          Best regards



          Tyshan

          • 2. Re: how can I create Test for s:hasPermission
            tyshan.tyshanchn.gmail.com
            hi

            I got the answer

            use Identity.instance().checkPermission("#{}");

            it will work.


            Tysha