1 package test.tuigwaa;
2
3 import java.sql.SQLException;
4 import java.util.Iterator;
5 import java.util.List;
6 import java.util.Properties;
7
8 import javax.sql.DataSource;
9
10 import junit.extensions.TestSetup;
11 import junit.framework.Test;
12 import junit.framework.TestCase;
13 import junit.framework.TestSuite;
14
15 import org.seasar.framework.container.S2Container;
16 import org.seasar.framework.container.factory.SingletonS2ContainerFactory;
17 import org.seasar.tuigwaa.cms.ContentsStoreService;
18 import org.seasar.tuigwaa.cms.core.PageImpl;
19 import org.seasar.tuigwaa.cms.core.Resource;
20 import org.seasar.tuigwaa.cms.core.ResourceImpl;
21 import org.seasar.tuigwaa.security.DirectoryService;
22 import org.seasar.tuigwaa.system.BackupDto;
23 import org.seasar.tuigwaa.system.Constants;
24 import org.seasar.tuigwaa.system.SiteService;
25 import org.seasar.tuigwaa.util.TgwContext;
26
27 import com.isenshi.util.extlib.HSQLDBUtil;
28
29 /***
30 * @author nishioka
31 */
32 public class SlideTest extends TestCase {
33
34 private ContentsStoreService storeService_;
35
36
37
38 public static Test suite() {
39 TestSetup setup = new TestSetup(new TestSuite(SlideTest.class)) {
40
41 public void setUp() {
42
43
44
45 SingletonS2ContainerFactory.init();
46
47 S2Container container = SingletonS2ContainerFactory.getContainer();
48 container.getComponent(DirectoryService.class);
49
50 TgwContext.setAdmin();
51 ContentsStoreService storeService = (ContentsStoreService) container
52 .getComponent(ContentsStoreService.class);
53 try {
54
55 if (storeService.isExistResource("junit", "", false)) {
56 storeService.delete("junit", "");
57 }
58 if (storeService.isExistResource("junit", "", false)) {
59 storeService.delete("junit", "");
60 }
61 storeService.createFolder("junit", "");
62 System.out.println("Creating .....");
63 } catch (Exception e) {
64 e.printStackTrace();
65 fail();
66 }
67 }
68
69 public void tearDown() {
70 S2Container container = SingletonS2ContainerFactory
71 .getContainer();
72 ContentsStoreService storeService = (ContentsStoreService) container
73 .getComponent(ContentsStoreService.class);
74 try {
75
76 if (storeService.isExistResource("junit", "", false)) {
77 storeService.delete("junit" , "");
78 }
79
80 System.out.println("Deleting .....");
81 } catch (Exception e) {
82 e.printStackTrace();
83 fail();
84 }
85 DataSource dataSource = (DataSource) SingletonS2ContainerFactory
86 .getContainer().getComponent(DataSource.class);
87 try {
88 HSQLDBUtil.shutdown(dataSource);
89 } catch (SQLException e) {
90
91 e.printStackTrace();
92 }
93 }
94 };
95
96 return setup;
97 }
98
99 public void setUp() {
100 S2Container container = SingletonS2ContainerFactory.getContainer();
101 storeService_ = (ContentsStoreService) container
102 .getComponent(ContentsStoreService.class);
103 }
104
105 public void testCreateContent() {
106 try {
107 Resource resource = new ResourceImpl("junit", "test", Constants.CONTENTTYPE_WIKI);
108 Resource resource2 = new ResourceImpl("junit", "test2", Constants.CONTENTTYPE_WIKI);
109 Resource resource3 = new ResourceImpl("junit", "test3", Constants.CONTENTTYPE_WIKI);
110 Resource resource5 = new ResourceImpl("junit", "test5", Constants.CONTENTTYPE_WIKI);
111
112
113 storeService_.createPage(new PageImpl(resource, "test is a test"));
114
115 storeService_.createPage(new PageImpl(resource2,"that is a test"));
116
117 storeService_.createPage(new PageImpl(resource3,"that is a test"));
118
119 storeService_.createPage(new PageImpl(resource5, "test"));
120
121 Iterator itr = storeService_.search("junit", "test")
122 .iterator();
123
124 int i = 0;
125
126 while (itr.hasNext()) {
127 i++;
128 Object obj = itr.next();
129 System.out.println(obj);
130 }
131
132 assertEquals(4, i);
133
134 } catch (Exception e) {
135 e.printStackTrace();
136 fail();
137 }
138
139 }
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181 public void testLatestContent() {
182
183
184
185 try {
186 List list = storeService_.getLatestContents("junit", 30);
187 assertNotNull(list);
188 } catch (Exception e) {
189 e.printStackTrace();
190 fail();
191 }
192
193 }
194
195 public void testBackup() {
196 S2Container container = SingletonS2ContainerFactory.getContainer();
197 SiteService siteService = (SiteService)container.getComponent(SiteService.class);
198
199 try {
200
201 BackupDto dto = new BackupDto();
202 siteService.backup("junit",dto);
203
204
205
206
207
208
209
210
211 siteService.restore("junit",dto);
212
213
214 List list = storeService_.getPageList("junit", "");
215
216 for (Iterator i = list.iterator(); i.hasNext();) {
217 System.out.println(i.next());
218 }
219
220 } catch (Exception e) {
221 e.printStackTrace();
222 fail();
223 }
224 }
225
226 public void testHidden() {
227 try {
228 Properties props = new Properties();
229 props.put("hidden","true");
230 props.put("trackback","hogehoge");
231
232 System.out.println("properties updated...");
233 storeService_.setProperty("junit", "", props);
234 } catch (Exception e) {
235 e.printStackTrace();
236 fail();
237 }
238
239 }
240
241 public void testSecurity() {
242
243
244 try {
245
246
247
248
249
250
251 } catch (Exception e) {
252 e.printStackTrace();
253 fail();
254 }
255 }
256
257 }