1
2
3
4 package org.melati.login.test;
5
6 import org.melati.Melati;
7 import org.melati.MelatiConfig;
8 import org.melati.PoemContext;
9 import org.melati.login.AccessHandler;
10 import org.melati.poem.AccessPoemException;
11 import org.melati.poem.Capability;
12 import org.melati.poem.test.PoemTestCase;
13 import org.melati.template.AttributeMarkupLanguage;
14 import org.melati.template.MarkupLanguage;
15 import org.melati.template.TemplateContext;
16 import org.melati.template.TemplateEngine;
17 import org.melati.util.MelatiStringWriter;
18
19
20
21
22
23 public abstract class AccessHandlerTestAbstract extends PoemTestCase {
24
25
26 protected AccessHandler it = null;
27
28 protected static MelatiConfig mc = null;
29 protected static TemplateEngine templateEngine = null;
30 protected static MarkupLanguage ml = null;
31 protected static AttributeMarkupLanguage aml = null;
32 protected static Melati m = null;
33
34
35
36
37
38 public AccessHandlerTestAbstract(String name) {
39 super(name);
40 }
41
42
43
44
45 protected void setUp()
46 throws Exception {
47 super.setUp();
48 setAccessHandler();
49 melatiConfig();
50 templateEngine = mc.getTemplateEngine();
51 if (templateEngine != null)
52 templateEngine.init(mc);
53 else fail();
54 m = new Melati(mc, new MelatiStringWriter());
55 m.setTemplateEngine(templateEngine);
56 assertNotNull(m.getTemplateEngine());
57 TemplateContext templateContext =
58 templateEngine.getTemplateContext();
59 m.setTemplateContext(templateContext);
60 PoemContext poemContext = new PoemContext();
61 poemContext.setLogicalDatabase("melatijunit");
62 m.setPoemContext(poemContext);
63
64 }
65
66 protected void tearDown() throws Exception {
67 super.tearDown();
68 }
69
70
71
72
73 public abstract void setAccessHandler();
74
75 protected void melatiConfig() {
76 mc = new MelatiConfig();
77 }
78
79
80
81
82
83
84 public void testHandleAccessException() throws Exception {
85 AccessPoemException ape = new AccessPoemException(
86 getDb().getUserTable().guestUser(), new Capability("Cool"));
87 it.handleAccessException(m, ape);
88 }
89
90
91
92
93
94
95 public void testBuildRequest() throws Exception {
96 it.buildRequest(m);
97 }
98
99
100
101
102 public void testEstablishUser() {
103 it.establishUser(m);
104 assertEquals("Melati database administrator",m.getUser().displayString());
105 }
106
107
108 }