4 Replies Latest reply on May 29, 2007 4:33 AM by shane.bryzak

    Creating Mock for identity component

    andreigh.ts

      I am unable to mock the Identity component (so that I can bypass authentication and permission checking in testing).

      I am using SeamTest and in the FacesRequest I am calling my ping component:

      public class PingTest extends SeamTest {
      
       @Test(groups = { "dev" })
       public void test() throws Exception {
       new FacesRequest() {
       @Override
       protected void invokeApplication() {
       //call action methods here
       invokeMethod("#{ping.ping}");
       }
       }.run();
       }
      }
      


      ping is a Seam component that uses Restrict:

      @Stateless
      @Name("ping")
      @Restrict("#{identity.loggedIn}")
      public class PingAction implements Ping {
      ...
       public void ping() {
       ...
       }
      ...
      }
      


      I am trying to mock the identity component like this:

      @Name("identity")
      @Install(precedence=Install.MOCK)
      public class Identity extends org.jboss.seam.security.RuleBasedIdentity {
       public boolean isLoggedIn() {
       return true;
       }
      }
      


      When I run the tests it throws this exception:

      [testng] javax.el.ELException: java.lang.IllegalArgumentException: value of context variable is not an instance of the component bound to the context variable: identity
      [testng] at com.sun.el.parser.AstValue.invoke(AstValue.java:178)
      [testng] at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:286)
      [testng] at org.jboss.seam.util.UnifiedELMethodBinding.invoke(UnifiedELMethodBinding.java:36)
      [testng] at org.jboss.seam.actionparam.ActionParamBindingHelper.invokeTheExpression(ActionParamBindingHelper.java:58)
      [testng] at org.jboss.seam.actionparam.ActionParamMethodBinding.invoke(ActionParamMethodBinding.java:75)
      [testng] at org.jboss.seam.actionparam.ActionParamBindingHelper.invokeTheExpression(ActionParamBindingHelper.java:58)
      [testng] at org.jboss.seam.actionparam.ActionParamMethodBinding.invoke(ActionParamMethodBinding.java:75)
      [testng] at org.jboss.seam.mock.SeamTest$Request.invokeMethod(SeamTest.java:401)
      [testng] at com.ibx.ibxrequest.action.test.PingTest$FacesRequestTest.invokeApplication(PingTest.java:35)
      [testng] at org.jboss.seam.mock.SeamTest$Request.run(SeamTest.java:489)
      [testng] at com.ibx.ibxrequest.action.test.PingTest.test(PingTest.java:56)
      [testng] Caused by: java.lang.IllegalArgumentException: value of context variable is not an instance of the component bound to the context variable: iden
      tity
      [testng] at org.jboss.seam.Component.getInstance(Component.java:1655)
      [testng] at org.jboss.seam.Component.getInstance(Component.java:1610)
      [testng] at org.jboss.seam.Component.getInstance(Component.java:1604)
      [testng] at org.jboss.seam.jsf.SeamELResolver.getValue(SeamELResolver.java:49)
      [testng] at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:143)
      [testng] at com.sun.el.parser.AstIdentifier.getValue(AstIdentifier.java:73)
      [testng] at com.sun.el.parser.AstValue.getValue(AstValue.java:114)
      [testng] at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:195)
      [testng] at org.jboss.seam.util.UnifiedELValueBinding.getValue(UnifiedELValueBinding.java:34)
      [testng] at org.jboss.seam.security.Identity.evaluateExpression(Identity.java:506)
      [testng] at org.jboss.seam.security.Identity.checkRestriction(Identity.java:149)
      [testng] at org.jboss.seam.interceptors.SecurityInterceptor.aroundInvoke(SecurityInterceptor.java:35)
      [testng] at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:69)
      [testng] at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:103)
      [testng] at org.jboss.seam.intercept.ClientSideInterceptor.invoke(ClientSideInterceptor.java:50)
      [testng] at org.javassist.tmp.java.lang.Object_$$_javassist_0.ping(Object_$$_javassist_0.java)
      [testng] at com.sun.el.parser.AstValue.invoke(AstValue.java:174)
      [testng] ... 31 more
      [testng] ... Removed 25 stack frames

      Mocking my own components (for example ping) works very well, so I don't understand why this throws an exception...