public void testModelOnSession() throws Exception { inter.setScope("session"); inter.setName("king"); User user = new User(); user.setName("King George"); Map session = new HashMap(); ActionContext.getContext().setSession(session); ActionContext.getContext().getSession().put("king", user); ScopedModelDriven action = new MyUserScopedModelDrivenAction(); MockActionInvocation mai = new MockActionInvocation(); MockActionProxy map = new MockActionProxy(); ActionConfig ac = new ActionConfig.Builder("", "", "").build(); map.setConfig(ac); mai.setAction(action); mai.setProxy(map); inter.intercept(mai); inter.destroy(); assertNotNull(action.getModel()); assertNotNull(action.getScopeKey()); assertEquals("king", action.getScopeKey()); Object model = ActionContext.getContext().getSession().get(action.getScopeKey()); assertNotNull(model); assertTrue("Model should be an User object", model instanceof User); assertEquals("King George", ((User) model).getName()); }
public void testNoScopedModelAction() throws Exception { Action action = new SimpleAction(); MockActionInvocation mai = new MockActionInvocation(); MockActionProxy map = new MockActionProxy(); ActionConfig ac = new ActionConfig.Builder("", "", "").build(); map.setConfig(ac); mai.setAction(action); mai.setProxy(map); inter.intercept(mai); inter.destroy(); // nothing happends }
public void testResolveModel() throws Exception { ActionContext ctx = ActionContext.getContext(); ctx.setSession(new HashMap()); ObjectFactory factory = ObjectFactory.getObjectFactory(); Object obj = inter.resolveModel(factory, ctx, "java.lang.String", "request", "foo"); assertNotNull(obj); assertTrue(obj instanceof String); assertTrue(obj == ctx.get("foo")); obj = inter.resolveModel(factory, ctx, "java.lang.String", "session", "foo"); assertNotNull(obj); assertTrue(obj instanceof String); assertTrue(obj == ctx.getSession().get("foo")); obj = inter.resolveModel(factory, ctx, "java.lang.String", "session", "foo"); assertNotNull(obj); assertTrue(obj instanceof String); assertTrue(obj == ctx.getSession().get("foo")); }
public void testScopedModelDrivenAction() throws Exception { inter.setScope("request"); ScopedModelDriven action = new MyUserScopedModelDrivenAction(); MockActionInvocation mai = new MockActionInvocation(); MockActionProxy map = new MockActionProxy(); ActionConfig ac = new ActionConfig.Builder("", "", "").build(); map.setConfig(ac); mai.setAction(action); mai.setProxy(map); inter.intercept(mai); inter.destroy(); assertNotNull(action.getModel()); assertNotNull(action.getScopeKey()); assertEquals("com.opensymphony.xwork2.test.User", action.getScopeKey()); Object model = ActionContext.getContext().get(action.getScopeKey()); assertNotNull(model); assertTrue("Model should be an User object", model instanceof User); }
public void testModelAlreadySetOnAction() throws Exception { inter.setScope("request"); inter.setName("king"); User user = new User(); user.setName("King George"); ScopedModelDriven action = new MyUserScopedModelDrivenAction(); action.setModel(user); MockActionInvocation mai = new MockActionInvocation(); MockActionProxy map = new MockActionProxy(); ActionConfig ac = new ActionConfig.Builder("", "", "").build(); map.setConfig(ac); mai.setAction(action); mai.setProxy(map); inter.intercept(mai); inter.destroy(); assertNotNull(action.getModel()); assertNull(action.getScopeKey()); // no scope key as nothing happended }
/** Set up instance variables required by this test case. */ @Override public void setUp() throws Exception { super.setUp(); inter = new ScopedModelDrivenInterceptor(); inter.setObjectFactory(new ProxyObjectFactory()); }