01: /*
02: * Copyright 2005-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
05: * in compliance with the License. You may obtain a copy of the License at
06: *
07: * http://www.apache.org/licenses/LICENSE-2.0
08: *
09: * Unless required by applicable law or agreed to in writing, software distributed under the License
10: * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11: * or implied. See the License for the specific language governing permissions and limitations under
12: * the License.
13: */
14:
15: package org.strecks.navigate.spring;
16:
17: import static org.testng.Assert.assertEquals;
18: import static org.testng.Assert.fail;
19:
20: import org.strecks.exceptions.ApplicationConfigurationException;
21: import org.strecks.navigate.NavigationHandler;
22: import org.strecks.navigate.NavigationHandlerFactory;
23: import org.strecks.navigate.NavigationHolder;
24: import org.strecks.navigate.factory.IdentityNavigationHandlerFactory;
25: import org.strecks.navigate.internal.BeanNavigationReader;
26: import org.strecks.navigate.spring.impl.ActionWithDuffSpringNavigation;
27: import org.strecks.navigate.spring.impl.ActionWithSpringResolverNavigation;
28: import org.strecks.navigate.spring.impl.ActionWithSpringViewNavigation;
29: import org.testng.annotations.BeforeMethod;
30: import org.testng.annotations.Test;
31:
32: public class TestSpringNavigationReader {
33:
34: private BeanNavigationReader navigationReader;
35:
36: @BeforeMethod
37: public void setUp() {
38: navigationReader = new BeanNavigationReader();
39: }
40:
41: @Test
42: public void testResolverNavigationReader() {
43: SpringViewNavigationHandler h = getAndTestHandler(ActionWithSpringResolverNavigation.class);
44: assert h.isUseResolver();
45: assertEquals(h.getName(), "resolver_name");
46: assert h.getLocaleResolver() instanceof StrecksLocaleResolver;
47: }
48:
49: @Test
50: public void testViewNavigationReader() {
51: SpringViewNavigationHandler h = getAndTestHandler(ActionWithSpringViewNavigation.class);
52: assert !h.isUseResolver();
53: assert null == h.getName();
54: assert h.getLocaleResolver() instanceof StrecksLocaleResolver;
55: }
56:
57: private SpringViewNavigationHandler getAndTestHandler(Class clazz) {
58: navigationReader.readAnnotations(clazz);
59: NavigationHolder navigationHolder = navigationReader
60: .getNavigationHolder();
61: NavigationHandlerFactory factory = navigationHolder
62: .getFactory();
63: assert factory instanceof IdentityNavigationHandlerFactory;
64:
65: NavigationHandler navigationHandler = factory
66: .getNavigationHandler(null, null);
67: assert navigationHandler instanceof SpringViewNavigationHandler;
68:
69: SpringViewNavigationHandler h = (SpringViewNavigationHandler) navigationHandler;
70: return h;
71: }
72:
73: @Test
74: public void testIllegalMethodName() {
75:
76: try {
77: navigationReader
78: .readAnnotations(ActionWithDuffSpringNavigation.class);
79: fail();
80: } catch (ApplicationConfigurationException e) {
81: assertEquals(
82: e.getMessage(),
83: "Method getResult() in class "
84: + "org.strecks.navigate.spring.impl.ActionWithDuffSpringNavigation "
85: + "must return object of type org.springframework.web.servlet.ModelAndView");
86: }
87: }
88:
89: }
|