1 package org.melati.test;
2
3 import java.io.IOException;
4 import java.util.Locale;
5 import java.util.Vector;
6
7 import javax.servlet.http.HttpServletRequest;
8 import javax.servlet.http.HttpServletResponse;
9
10 import org.melati.Melati;
11 import org.melati.MelatiConfig;
12 import org.melati.PoemContext;
13 import org.melati.poem.Field;
14 import org.melati.template.webmacro.WebmacroTemplateEngine;
15 import org.melati.util.MelatiBugMelatiException;
16 import org.melati.util.MelatiStringWriter;
17 import org.melati.util.MelatiWriter;
18 import org.melati.servlet.test.MockHttpServletRequest;
19 import org.melati.servlet.test.MockHttpServletResponse;
20
21 import junit.framework.TestCase;
22
23
24
25
26
27
28
29 public class MelatiTest extends TestCase {
30
31
32
33
34
35 public MelatiTest(String name) {
36 super(name);
37 }
38
39
40
41
42 protected void setUp()
43 throws Exception {
44 super.setUp();
45 }
46
47
48
49
50 protected void tearDown()
51 throws Exception {
52 super.tearDown();
53 }
54
55 protected PoemContext poemContext() {
56 PoemContext it = new PoemContext();
57 return it;
58 }
59
60
61
62
63
64 public void testMelatiMelatiConfigHttpServletRequestHttpServletResponse() {
65
66 }
67
68
69
70
71 public void testMelatiMelatiConfigMelatiWriter() {
72
73 }
74
75
76
77
78 public void testGetRequest() {
79
80 }
81
82
83
84
85 public void testSetRequest() {
86
87 }
88
89
90
91
92 public void testGetResponse() {
93
94 }
95
96
97
98
99 public void testSetPoemContext() {
100
101 }
102
103
104
105
106 public void testLoadTableAndObject() {
107
108 }
109
110
111
112
113 public void testGetPoemContext() {
114
115 }
116
117
118
119
120 public void testGetDatabase() {
121
122 }
123
124
125
126
127 public void testGetKnownDatabaseNames() throws Exception {
128 MelatiConfig mc = null;
129 PoemContext pc = null;
130 Melati m = null;
131 mc = new MelatiConfig();
132 m = new Melati(mc, new MelatiStringWriter());
133 pc = poemContext();
134 m.setPoemContext(pc);
135 Vector<String> known = m.getKnownDatabaseNames();
136
137
138 pc.setLogicalDatabase("melatijunit");
139 m.setPoemContext(pc);
140 m.loadTableAndObject();
141 known = m.getKnownDatabaseNames();
142
143
144 assertTrue(known.size() > 0);
145 }
146
147
148
149
150 public void testGetTable() {
151
152 }
153
154
155
156
157 public void testGetObject() {
158
159 }
160
161
162
163
164 public void testGetMethod() {
165
166 }
167
168
169
170
171 public void testSetTemplateEngine() {
172
173 }
174
175
176
177
178 public void testGetTemplateEngine() {
179
180 }
181
182
183
184
185 public void testSetTemplateContext() {
186
187 }
188
189
190
191
192 public void testGetTemplateContext() {
193
194 }
195
196
197
198
199 public void testGetServletTemplateContext() {
200
201 }
202
203
204
205
206 public void testGetConfig() {
207
208 }
209
210
211
212
213 public void testGetPathInfoParts() {
214
215 }
216
217
218
219
220 public void testSetArguments() {
221
222 }
223
224
225
226
227 public void testGetArguments() throws Exception {
228 MelatiConfig mc = null;
229 Melati m = null;
230 mc = new MelatiConfig();
231 m = new Melati(mc, new MelatiStringWriter());
232 m.setPoemContext(poemContext());
233 assertNull(m.getArguments());
234 m.setArguments(new String[] {"hello", "world"});
235 assertEquals(2, m.getArguments().length);
236
237 }
238
239
240
241
242 public void testGetSession() {
243
244 }
245
246
247
248
249 public void testGetContextUtil() throws Exception {
250 MelatiConfig mc = null;
251 Melati m = null;
252 mc = new MelatiConfig();
253 m = new Melati(mc, new MelatiStringWriter());
254 m.setPoemContext(poemContext());
255 Object adminUtil = m.getContextUtil("org.melati.admin.AdminUtils");
256 assertTrue(adminUtil instanceof org.melati.admin.AdminUtils);
257 try {
258 m.getContextUtil("unknownClass");
259 fail("Should have bombed");
260 } catch (MelatiBugMelatiException e) {
261 e = null;
262 }
263 }
264
265
266
267
268
269
270 public void testGetLogoutURL() throws Exception {
271 MelatiConfig mc = new MelatiConfig();
272 Melati m = new Melati(mc, new MelatiStringWriter());
273 m.setPoemContext(poemContext());
274 MockHttpServletRequest req = new MockHttpServletRequest();
275 req.setRequestURI("");
276 m.setRequest(req);
277 assertEquals("/servletContext/mockServletPath/org.melati.login.Logout/null",m.getLogoutURL());
278 }
279
280
281
282
283
284 public void testGetLoginURL() throws Exception {
285 MelatiConfig mc = new MelatiConfig();
286 Melati m = new Melati(mc, new MelatiStringWriter());
287 m.setPoemContext(poemContext());
288 MockHttpServletRequest req = new MockHttpServletRequest();
289 req.setRequestURI("");
290 m.setRequest(req);
291 assertEquals("/servletContext/mockServletPath/org.melati.login.Login/null",m.getLoginURL());
292
293 }
294
295
296
297
298 public void testGetZoneURL() {
299
300 }
301
302
303
304
305
306
307 public void testGetServletURL() throws Exception {
308 MelatiConfig mc = new MelatiConfig();
309 Melati m = new Melati(mc, new MelatiStringWriter());
310 m.setPoemContext(poemContext());
311 MockHttpServletRequest req = new MockHttpServletRequest();
312 req.setRequestURI("/");
313 m.setRequest(req);
314 assertEquals("http://localhost/servletContext/mockServletPath/",m.getServletURL());
315 }
316
317
318
319 public void testGetRelativeZoneURL() {
320 MelatiConfig mc = new MelatiConfig();
321 Melati m = new Melati(mc, new MelatiStringWriter());
322 m.setPoemContext(poemContext());
323 MockHttpServletRequest req = new MockHttpServletRequest();
324 req.setRequestURI("/");
325 m.setRequest(req);
326 assertEquals("/servletContext/mockServletPath/",m.getRelativeZoneURL());
327 }
328
329
330
331 public void testGetJavascriptLibraryURL() {
332
333 }
334
335
336
337
338
339 public void testGetPoemLocale() throws Exception {
340 MelatiConfig mc = null;
341 Melati m = null;
342 mc = new MelatiConfig();
343 m = new Melati(mc, new MelatiStringWriter());
344 m.setPoemContext(poemContext());
345 assertEquals("en_GB", m.getPoemLocale().toString());
346 m.setRequest(new MockHttpServletRequest());
347 assertEquals("en_GB", m.getPoemLocale().toString());
348 MockHttpServletRequest msr = new MockHttpServletRequest();
349 msr.setHeader("Accept-Language","en-gb");
350 m.setRequest(msr);
351 assertEquals("en_GB", m.getPoemLocale().toString());
352 msr.setHeader("Accept-Language","not");
353 assertEquals("en_GB", m.getPoemLocale().toString());
354 msr.setLocale(new Locale("en-US"));
355 assertEquals("en-us", m.getPoemLocale().toString());
356
357
358 }
359
360
361
362
363 public void testEstablishCharsets() throws Exception {
364 MelatiConfig mc = new MelatiConfig();
365 Melati m = new Melati(mc, new MelatiStringWriter());
366 m.setPoemContext(poemContext());
367 MockHttpServletRequest mock = new MockHttpServletRequest();
368 mock.setHeader("Accept-Charset", "");
369 m.setRequest(mock);
370 m.establishCharsets();
371
372
373 mock.setHeader("Accept-Charset", "rubbish");
374 m.setRequest(mock);
375 m.establishCharsets();
376
377 mock.setHeader("Accept-Charset", "");
378 mock.setCharacterEncoding(null);
379 m.setRequest(mock);
380 m.establishCharsets();
381
382 }
383
384
385
386
387 public void testSetResponseContentType() {
388
389 }
390
391
392
393
394 public void testGetConentType() {
395
396 }
397
398
399
400 public void testSetMarkupLanguage() {
401
402 }
403
404
405
406
407 public void testGetMarkupLanguage() throws Exception {
408 MelatiConfig mc = new MelatiConfig();
409 Melati m = new Melati(mc, new MelatiStringWriter());
410 m.setPoemContext(poemContext());
411 assertEquals("html/en_GB", m.getMarkupLanguage().toString());
412 assertEquals("html_attr/en_GB", m.getMarkupLanguage().getAttr().toString());
413 }
414
415
416
417
418 public void testGetHTMLMarkupLanguage() throws Exception {
419 MelatiConfig mc = new MelatiConfig();
420 Melati m = new Melati(mc, new MelatiStringWriter());
421 m.setPoemContext(poemContext());
422 assertEquals("html/en_GB", m.getHTMLMarkupLanguage().toString());
423 assertEquals("html_attr/en_GB", m.getHTMLMarkupLanguage().getAttr().toString());
424
425 }
426
427
428
429
430 public void testSameURLWithStringString() throws Exception {
431 MelatiConfig mc = new MelatiConfig();
432 Melati m = new Melati(mc, new MelatiStringWriter());
433 m.setPoemContext(poemContext());
434 MockHttpServletRequest mock = new MockHttpServletRequest();
435 mock.setRequestURI("page");
436 m.setRequest(mock);
437
438 assertEquals("page?noodles=1", m.sameURLWith("noodles","1"));
439 assertEquals("page?noodles=1", m.sameURLWith("noodles"));
440 }
441
442
443
444
445 public void testSameURLWithString() {
446
447 }
448
449
450
451
452 public void testGetSameURL() {
453
454 }
455
456
457
458
459 public void testSetBufferingOff() throws Exception {
460 MelatiConfig mc = new MelatiConfig();
461 HttpServletRequest mockRequest = new MockHttpServletRequest();
462 HttpServletResponse mockResponse = new MockHttpServletResponse();
463 Melati m = new Melati(mc, mockRequest, mockResponse);
464 m.setPoemContext(poemContext());
465 m.setBufferingOff();
466 m.setFlushingOn();
467 MelatiWriter mw = m.getWriter();
468 m.setWriter(new MelatiStringWriter());
469 mw = m.getWriter();
470 try {
471 m.setBufferingOff();
472 fail("Should have blown up");
473 } catch (IOException e) {
474 e = null;
475 }
476 try {
477 m.setFlushingOn();
478 fail("Should have blown up");
479 } catch (IOException e) {
480 e = null;
481 }
482 mw.flush();
483 mw.close();
484 }
485
486
487
488
489 public void testSetFlushingOn() {
490
491 }
492
493
494
495
496 public void testGetURLQueryEncoding() throws Exception {
497 MelatiConfig mc = new MelatiConfig();
498 Melati m = new Melati(mc, new MelatiStringWriter());
499 m.setPoemContext(poemContext());
500 MockHttpServletRequest mock = new MockHttpServletRequest();
501 m.setRequest(mock);
502 assertEquals("ISO-8859-1", m.getURLQueryEncoding());
503 }
504
505
506
507
508 public void testUrlEncode() throws Exception {
509 MelatiConfig mc = new MelatiConfig();
510 Melati m = new Melati(mc, new MelatiStringWriter());
511 m.setPoemContext(poemContext());
512 MockHttpServletRequest mock = new MockHttpServletRequest();
513 m.setRequest(mock);
514 assertEquals("", m.urlEncode(""));
515 assertEquals("A+space+seperated+string", m.urlEncode("A space seperated string"));
516 mock.setCharacterEncoding("Unsupported Encoding");
517 m.setRequest(mock);
518 assertEquals("A space seperated string", m.urlEncode("A space seperated string"));
519 }
520
521
522
523
524 public void testGetEncoding() {
525
526 }
527
528
529
530
531 public void testGetWriter() {
532
533 }
534
535
536
537
538 public void testGetStringWriter() throws Exception {
539 MelatiConfig mc = new MelatiConfig();
540 Melati m = new Melati(mc, new MelatiStringWriter());
541 m.setPoemContext(poemContext());
542 MockHttpServletRequest mock = new MockHttpServletRequest();
543 m.setRequest(mock);
544 assertNull(m.getTemplateEngine());
545 assertTrue(m.getStringWriter() instanceof MelatiStringWriter);
546 }
547
548
549
550
551 public void testWrite() {
552
553 }
554
555
556
557
558
559 public void testSetVariableExceptionHandler() throws Exception {
560 }
561
562
563
564
565 public void testGetUser() throws Exception {
566 MelatiConfig mc = null;
567 Melati m = null;
568 mc = new MelatiConfig();
569 m = new Melati(mc, new MelatiStringWriter());
570 m.setPoemContext(poemContext());
571 assertNull(m.getUser());
572 }
573
574
575
576
577 public void testIsReferencePoemType() throws Exception {
578 MelatiConfig mc = null;
579 Melati m = null;
580 mc = new MelatiConfig();
581 m = new Melati(mc, new MelatiStringWriter());
582 m.setPoemContext(poemContext());
583 try {
584 m.isReferencePoemType(null);
585 fail("Should have blown up");
586 } catch (NullPointerException e) {
587 e = null;
588 }
589 }
590
591
592
593
594 public void testTemplateName() throws Exception {
595 MelatiConfig mc = null;
596 Melati m = null;
597 mc = new MelatiConfig();
598 m = new Melati(mc, new MelatiStringWriter());
599 m.setPoemContext(poemContext());
600 try {
601 m.templateName("");
602 fail("Should have blown up");
603 } catch (MelatiBugMelatiException e) {
604 e = null;
605 }
606
607 m.setTemplateEngine(new WebmacroTemplateEngine());
608
609 assertEquals("", m.templateName(""));
610 assertEquals("nonexistent", m.templateName("nonexistent"));
611 assertEquals("/org/melati/template/test/Templated.wm", m.templateName("org/melati/template/test/Templated"));
612
613 m.getTemplateEngine().addRoot("org/melati/template/test/");
614 assertEquals("/org/melati/template/test/Templated.wm", m.templateName("Templated"));
615 PoemContext pc = m.getPoemContext();
616 pc.setLogicalDatabase("melatijunit");
617 m.setPoemContext(pc);
618 assertEquals("/org/melati/template/test/melatijunit/Specialised.wm", m.templateName("Specialised"));
619
620
621 m.getTemplateEngine().addRoot("org/melati/template/test");
622 assertEquals("/org/melati/template/test/Templated.wm", m.templateName("Templated"));
623 assertEquals("/org/melati/template/test/melatijunit/Specialised.wm", m.templateName("Specialised"));
624
625 }
626
627
628 }