01: package org.vraptor.url;
02:
03: import org.jmock.Mock;
04: import org.vraptor.AbstractTest;
05: import org.vraptor.LogicException;
06: import org.vraptor.annotations.Remotable;
07: import org.vraptor.component.ComponentNotFoundException;
08: import org.vraptor.component.LogicMethod;
09: import org.vraptor.component.LogicNotFoundException;
10: import org.vraptor.test.MockedRequest;
11: import org.vraptor.view.RemoteViewManager;
12: import org.vraptor.view.ViewManager;
13:
14: /**
15: * Tests the default url dealer.
16: *
17: * @author Guilherme Silveira
18: */
19: public class DefaultViewLocatorTest extends AbstractTest {
20:
21: private ViewLocator manager;
22: private Mock mockedViewManager;
23: private ViewManager viewManager;
24: private LogicMethod remotableMethod;
25:
26: public static class MyType {
27: @Remotable
28: public void method() {
29: }
30: }
31:
32: @Override
33: protected void setUp() throws Exception {
34: super .setUp();
35: mockedViewManager = mock(ViewManager.class);
36: remotableMethod = createComponentType(MyType.class).getLogic(
37: "method");
38: viewManager = (ViewManager) mockedViewManager.proxy();
39: manager = new DefaultViewLocator();
40: }
41:
42: public void testFindsJSONURLViewType() throws InvalidURLException,
43: LogicNotFoundException, ComponentNotFoundException,
44: LogicException {
45: assertEquals(RemoteViewManager.class, locateViewManager(
46: "/a.b.ajax.logic").getClass());
47: mockedViewManager.verify();
48: }
49:
50: public void testFindsXMLURLViewType() throws InvalidURLException,
51: LogicNotFoundException, ComponentNotFoundException,
52: LogicException {
53: assertEquals(RemoteViewManager.class, locateViewManager(
54: "/a.b.xml.logic").getClass());
55: mockedViewManager.verify();
56: }
57:
58: public void testDoesntFindURLViewType() throws InvalidURLException,
59: LogicNotFoundException, ComponentNotFoundException,
60: LogicException {
61: assertEquals(viewManager, locateViewManager("/a.b.logic"));
62: mockedViewManager.verify();
63: }
64:
65: public void testFindsNullURLViewType() throws InvalidURLException,
66: LogicNotFoundException, ComponentNotFoundException,
67: LogicException {
68: assertEquals(viewManager, locateViewManager("/a.b.logic"));
69: mockedViewManager.verify();
70: }
71:
72: private ViewManager locateViewManager(String uri)
73: throws InvalidURLException, LogicNotFoundException,
74: ComponentNotFoundException, LogicException {
75: return manager.locate(new MockedRequest(uri, createSession()),
76: remotableMethod, viewManager);
77: }
78:
79: }
|