Package com.firefly.mvc.web

Examples of com.firefly.mvc.web.Resource$Result


public class TestResource {
 
  @Test
  public void testResource() throws NoSuchMethodException, SecurityException {
    IndexController controller = new IndexController();
    Resource resource = new Resource("utf-8");
    ControllerMetaInfo cm = new ControllerMetaInfo(controller,
        IndexController.class.getMethod("index4", HttpServletRequest.class, HttpServletResponse.class));
   
    resource.add("/user/id-?-?", cm);
    resource.add("/user/id-?-?/?", cm);
    resource.add("/user/add", cm);
    resource.add("/document/_?/?", cm);
   
    resource.add("/shop/fruit/apple/?", cm);
    resource.add("/shop/fruit/banana", cm);
    resource.add("/file/info.txt", cm);
   
    Result ret = resource.match("/user/id-3344-2222/55555");
    Assert.assertThat(ret.getParams().length, is(3));
    Assert.assertThat(ret.getParams()[1], is("2222"));
    Assert.assertThat(ret.getParams()[2], is("55555"));
   
    ret = resource.match("/shop/fruit/banana");
    Assert.assertThat(ret.getParams(), nullValue());
   
    ret = resource.match("/hello");
    Assert.assertThat(ret, nullValue());
   
    ret = resource.match("/file/info.txt");
    Assert.assertThat(ret, notNullValue());
   
    ret = resource.match("/document/_pengpeng");
    Assert.assertThat(ret, nullValue());
   
    Assert.assertThat(resource.getEncoding(), is("utf-8"));
  }
View Full Code Here


        DefaultActionMapper defaultActionMapper = new DefaultActionMapper();
        defaultActionMapper.setContainer(container);
        ActionMapping actionMapping = defaultActionMapper.getMapping(request, configManager);

        Result result = actionMapping.getResult();
        assertNotNull(result);
        assertTrue(result instanceof ServletRedirectResult);

        Mock invMock = new Mock(ActionInvocation.class);
        ActionInvocation inv = (ActionInvocation) invMock.proxy();
        ActionContext ctx = ActionContext.getContext();
        ctx.put(ServletActionContext.HTTP_REQUEST, request);
        StrutsMockHttpServletResponse response = new StrutsMockHttpServletResponse();
        ctx.put(ServletActionContext.HTTP_RESPONSE, response);
        invMock.expectAndReturn("getInvocationContext", ctx);
        invMock.expectAndReturn("getStack", ctx.getValueStack());
        result.execute(inv);
        assertEquals("http://www.google.com", response.getRedirectURL());
        //TODO: need to test location but there's noaccess to the property/method, unless we use reflection
    }
View Full Code Here

                request.setAttribute(ServletActionContext.STRUTS_VALUESTACK_KEY, stack);

                ActionContext savedContext = savedInvocation.getInvocationContext();
                savedContext.getContextMap().put(ServletActionContext.HTTP_REQUEST, request);
                savedContext.getContextMap().put(ServletActionContext.HTTP_RESPONSE, response);
                Result result = savedInvocation.getResult();

                if ((result != null) && (savedInvocation.getProxy().getExecuteResult())) {
                    synchronized (context) {
                        result.execute(savedInvocation);
                    }
                }

                // turn off execution of this invocations result
                invocation.getProxy().setExecuteResult(false);
View Full Code Here

        DefaultActionMapper defaultActionMapper = new DefaultActionMapper();
        defaultActionMapper.setContainer(container);
        ActionMapping actionMapping = defaultActionMapper.getMapping(request, configManager);

        Result result = actionMapping.getResult();
        assertNotNull(result);
        assertTrue(result instanceof ServletRedirectResult);

        Mock invMock = new Mock(ActionInvocation.class);
        ActionInvocation inv = (ActionInvocation) invMock.proxy();
        ActionContext ctx = ActionContext.getContext();
        ctx.put(ServletActionContext.HTTP_REQUEST, request);
        StrutsMockHttpServletResponse response = new StrutsMockHttpServletResponse();
        ctx.put(ServletActionContext.HTTP_RESPONSE, response);
        invMock.expectAndReturn("getInvocationContext", ctx);
        invMock.expectAndReturn("getStack", ctx.getValueStack());
        result.execute(inv);
        assertEquals("http://www.google.com", response.getRedirectURL());
        //TODO: need to test location but there's noaccess to the property/method, unless we use reflection
    }
View Full Code Here

     */
    protected void after(ActionInvocation invocation,
                         ValidationAware validationAware)
        throws Exception
    {
        Result result = invocation.getResult();

        if (result != null
            && (result instanceof ServletRedirectResult ||
                result instanceof ServletActionRedirectResult))
        {
View Full Code Here

        DefaultActionMapper defaultActionMapper = new DefaultActionMapper();
        defaultActionMapper.setContainer(container);
        ActionMapping actionMapping = defaultActionMapper.getMapping(request, configManager);

        Result result = actionMapping.getResult();
        assertNull(result);
    }
View Full Code Here

        DefaultActionMapper defaultActionMapper = new DefaultActionMapper();
        defaultActionMapper.setContainer(container);
        ActionMapping actionMapping = defaultActionMapper.getMapping(request, configManager);

        Result result = actionMapping.getResult();
        assertNull(result);
    }
View Full Code Here

        params.put("reject", "bad");
        ResultConfig config = new ResultConfig.Builder("struts", MyResult.class.getName()).addParams(params).build();
        Map<String, Object> context = new HashMap<String, Object>();

        // when
        Result result = builder.buildResult(config, context);

        // then
        assertEquals("ok", ((MyResult)result).getAccept());
        assertEquals("ok", ((MyResult)result).getReject());
    }
View Full Code Here

        this.reflectionProvider = reflectionProvider;
    }

    public Result buildResult(ResultConfig resultConfig, Map<String, Object> extraContext) throws Exception {
        String resultClassName = resultConfig.getClassName();
        Result result = null;

        if (resultClassName != null) {
            result = (Result) objectFactory.buildBean(resultClassName, extraContext);
            Map<String, String> params = resultConfig.getParams();
            if (params != null) {
View Full Code Here

        this.reflectionProvider = provider;
    }

    public Result buildResult(ResultConfig resultConfig, Map<String, Object> extraContext) throws Exception {
        String resultClassName = resultConfig.getClassName();
        Result result = null;

        if (resultClassName != null) {
            result = (Result) objectFactory.buildBean(resultClassName, extraContext);
            Map<String, String> params = resultConfig.getParams();
            if (params != null) {
View Full Code Here

TOP

Related Classes of com.firefly.mvc.web.Resource$Result

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.