1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.myfaces.tobago.internal.mock.faces;
21
22 import org.apache.myfaces.test.base.junit4.AbstractJsfTestCase;
23 import org.apache.myfaces.test.mock.MockFacesContext;
24 import org.apache.myfaces.test.mock.MockHttpServletRequest;
25 import org.apache.myfaces.tobago.component.ComponentTypes;
26 import org.apache.myfaces.tobago.component.UIButton;
27 import org.apache.myfaces.tobago.component.UICommand;
28 import org.apache.myfaces.tobago.component.UIIn;
29 import org.apache.myfaces.tobago.component.UILink;
30 import org.apache.myfaces.tobago.component.UIOut;
31 import org.apache.myfaces.tobago.component.UIPanel;
32 import org.apache.myfaces.tobago.component.UIPopup;
33 import org.apache.myfaces.tobago.component.UIViewRoot;
34 import org.apache.myfaces.tobago.config.TobagoConfig;
35 import org.apache.myfaces.tobago.context.ClientProperties;
36 import org.apache.myfaces.tobago.context.Theme;
37 import org.apache.myfaces.tobago.internal.config.TobagoConfigImpl;
38 import org.apache.myfaces.tobago.internal.context.ResourceManagerFactory;
39 import org.junit.After;
40 import org.junit.Before;
41 import org.slf4j.Logger;
42 import org.slf4j.LoggerFactory;
43
44 import java.util.Arrays;
45 import java.util.Collections;
46 import java.util.HashMap;
47 import java.util.Locale;
48 import java.util.Map;
49
50
51
52
53
54
55
56
57
58
59
60 public abstract class AbstractTobagoTestBase extends AbstractJsfTestCase {
61
62 private static final Logger LOG = LoggerFactory.getLogger(AbstractTobagoTestBase.class);
63
64
65
66
67 @Before
68 public void setUp() throws Exception {
69
70 super.setUp();
71
72
73
74 TobagoConfigImpl tobagoConfig = new TobagoConfigImpl();
75 Theme theme = new MockTheme("default", "Default Mock Theme", Collections.EMPTY_LIST);
76 Theme one = new MockTheme("one", "Mock Theme One", Arrays.asList(theme));
77 Map<String, Theme> availableThemes = new HashMap<String, Theme>();
78 availableThemes.put(theme.getName(), theme);
79 availableThemes.put(one.getName(), one);
80 tobagoConfig.setAvailableThemes(availableThemes);
81 tobagoConfig.resolveThemes();
82 tobagoConfig.initProjectState(servletContext);
83 tobagoConfig.initDefaultValidatorInfo();
84 servletContext.setAttribute(TobagoConfig.TOBAGO_CONFIG, tobagoConfig);
85
86 final ClientProperties clientProperties = new ClientProperties();
87 clientProperties.setTheme(one);
88 clientProperties.setLocale(Locale.ENGLISH);
89 session.setAttribute(ClientProperties.MANAGED_BEAN_NAME, clientProperties);
90
91
92 application.addComponent(ComponentTypes.IN, UIIn.class.getName());
93 application.addComponent(ComponentTypes.OUT, UIOut.class.getName());
94 application.addComponent(ComponentTypes.PANEL, UIPanel.class.getName());
95 application.addComponent("javax.faces.ViewRoot", UIViewRoot.class.getName());
96 application.addComponent("javax.faces.Command", javax.faces.component.UICommand.class.getName());
97 application.addComponent(ComponentTypes.COMMAND, UICommand.class.getName());
98 application.addComponent(ComponentTypes.LINK, UILink.class.getName());
99 application.addComponent(ComponentTypes.BUTTON, UIButton.class.getName());
100 application.addComponent(ComponentTypes.POPUP, UIPopup.class.getName());
101
102 try {
103 ResourceManagerFactory.init(servletContext, tobagoConfig);
104 } catch (AssertionError e) {
105
106 LOG.error("Todo: remove this hack", e);
107 }
108 }
109
110 @After
111 public void tearDown() throws Exception {
112 try {
113 ResourceManagerFactory.release(servletContext);
114 } catch (AssertionError e) {
115
116 LOG.error("Todo: remove this hack", e);
117 }
118
119 super.tearDown();
120 }
121
122 public MockFacesContext getFacesContext() {
123 return facesContext;
124 }
125
126 public MockHttpServletRequest getRequest() {
127 return request;
128 }
129 }