Package org.springmodules.validation.util

Examples of org.springmodules.validation.util.Switch


            protected String[] getValidationContextTokens(MethodInvocation methodInvocation) {
                return new String[] { "ctx1", "ctx2" };
            }
        };

        final Switch methodCalledSwitch = new Switch();

        MethodInvocation invocation = new MethodInvocation() {
            public Method getMethod() {
                return null;
            }

            public Object[] getArguments() {
                return new Object[0];
            }

            public Object proceed() throws Throwable {
                methodCalledSwitch.turnOn();
                assertNotNull(ValidationContextHolder.getValidationContext());
                assertTrue(DefaultValidationContext.class.isInstance(ValidationContextHolder.getValidationContext()));
                DefaultValidationContext context = (DefaultValidationContext)ValidationContextHolder.getValidationContext();
                String[] tokens = context.getTokens();
                assertNotNull(tokens);
                assertEquals(2, tokens.length);
                assertEquals("ctx1", tokens[0]);
                assertEquals("ctx2", tokens[1]);
                return "result";
            }

            public Object getThis() {
                return null;
            }

            public AccessibleObject getStaticPart() {
                return null;
            }
        };

        Object result = interceptor.invoke(invocation);

        assertTrue(methodCalledSwitch.isOn());
        assertEquals("result", result);
    }
View Full Code Here


        ValidationContextFilter filter = new ValidationContextFilter();
        filter.setValidationContextUrlMappings(mappings);

        filter.afterPropertiesSet();

        final Switch filterCallSwitch = new Switch();
        FilterChain filterChain = new FilterChain() {
            public void doFilter(ServletRequest req, ServletResponse res) {
                filterCallSwitch.turnOn();
                assertTrue(ValidationContextUtils.tokensSupportedByCurrentContext(new String[] { "ctx1", "ctx2" }));
                assertFalse(ValidationContextUtils.tokensSupportedByCurrentContext(new String[] { "ctx3" }));
            }
        };

        MockHttpServletRequest request = new MockHttpServletRequest("GET", "/user/test.html");
        MockHttpServletResponse response = new MockHttpServletResponse();
        filter.doFilterInternal(request, response, filterChain);

        assertTrue(filterCallSwitch.isOn()); // making sure the filter was called
    }
View Full Code Here

        ValidationContextFilter filter = new ValidationContextFilter();
        filter.setValidationContextUrlMappings(mappings);

        filter.afterPropertiesSet();

        final Switch filterCallSwitch = new Switch();
        FilterChain filterChain = new FilterChain() {
            public void doFilter(ServletRequest req, ServletResponse res) {
                filterCallSwitch.turnOn();
                assertFalse(ValidationContextUtils.tokensSupportedByCurrentContext(new String[] { "ctx1", "ctx2" }));
                assertTrue(DefaultValidationContext.class.isInstance(ValidationContextHolder.getValidationContext()));
                DefaultValidationContext context = (DefaultValidationContext)ValidationContextHolder.getValidationContext();
                assertEquals(0, context.getTokens().length);
            }
        };

        MockHttpServletRequest request = new MockHttpServletRequest("GET", "/user/test.html");
        MockHttpServletResponse response = new MockHttpServletResponse();
        filter.doFilterInternal(request, response, filterChain);

        assertTrue(filterCallSwitch.isOn()); // making sure the filter was called
    }
View Full Code Here

TOP

Related Classes of org.springmodules.validation.util.Switch

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.