1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.services.registry;
18
19
20 import junit.framework.Test;
21 import junit.framework.TestSuite;
22
23
24 import org.apache.jetspeed.test.JetspeedTestCase;
25 import org.apache.jetspeed.om.registry.base.*;
26
27 import ojb.broker.PersistenceBroker;
28 import ojb.broker.query.Query;
29 import ojb.broker.query.QueryByCriteria;
30 import ojb.broker.query.Criteria;
31
32 import org.apache.turbine.util.TurbineConfig;
33 import org.apache.turbine.util.StringUtils;
34
35 import org.apache.jetspeed.services.JetspeedDatabase;
36
37 /***
38 * TestRegistryPersistence
39 *
40 * @author <a href="taylor@apache.org">David Sean Taylor</a>
41 * @version $Id: TestRegistryPersistence.java,v 1.1 2004/04/07 22:02:42 jford Exp $
42 */
43
44 public class TestRegistryPersistence extends JetspeedTestCase {
45
46 /***
47 * Defines the testcase name for JUnit.
48 *
49 * @param name the testcase's name.
50 */
51 public TestRegistryPersistence( String name ) {
52 super( name );
53 }
54
55 /***
56 * Start the tests.
57 *
58 * @param args the arguments. Not used
59 */
60 public static void main(String args[]) {
61 junit.awtui.TestRunner.main( new String[] { TestRegistryPersistence.class.getName() } );
62 }
63
64 public void setup() {
65 System.out.println("Setup: Testing ObjectBridge");
66 }
67 /***
68 * Creates the test suite.
69 *
70 * @return a test suite (<code>TestSuite</code>) that includes all methods
71 * starting with "test"
72 */
73 public static Test suite() {
74
75 return new TestSuite( TestRegistryPersistence.class );
76 }
77
78 /***
79 *
80 *
81 * @throws Exception
82 */
83
84 public void testInsertUpdateDelete() throws Exception
85 {
86 PersistenceBroker pm = null;
87 try
88 {
89 pm = (PersistenceBroker) JetspeedDatabase.getPersistenceManager();
90
91 MediaTypeTest(pm);
92 SkinTest(pm);
93 }
94 catch (Throwable t)
95 {
96 t.printStackTrace();
97 }
98 }
99
100 void MediaTypeTest(PersistenceBroker pm) throws Exception
101 {
102
103 BaseMediaTypeEntry newEntry = new BaseMediaTypeEntry(0, "XHTML9", 0, "text.xhtml.9",
104 "Some Title", "Some Description", "Some Image", "SU");
105
106 pm.beginTransaction();
107 pm.store(newEntry);
108 pm.commitTransaction();
109
110
111 Criteria criteria = new Criteria();
112 criteria.addEqualTo("name", "XHTML9");
113 Query query = new QueryByCriteria(BaseMediaTypeEntry.class, criteria);
114 BaseMediaTypeEntry entry = (BaseMediaTypeEntry)pm.getObjectByQuery(query);
115 assertTrue(entry.getName().equals("XHTML9"));
116 System.out.println("id = " + entry.getId());
117 assertTrue(entry.getHidden() == false);
118 assertTrue(entry.getMimeType().equals("text.xhtml.9"));
119 assertTrue(entry.getMetaInfo().getTitle().equals("Some Title"));
120 assertTrue(entry.getDescription().equals("Some Description"));
121 assertTrue(entry.getMetaInfo().getImage().equals("Some Image"));
122 assertTrue(entry.getSecurity().getRole().equals("SU"));
123
124 entry.setHidden(true);
125 entry.setMimeType("text.xhtml.9.1");
126 entry.getMetaInfo().setTitle("New Title");
127 entry.setDescription("New Description");
128 entry.getSecurity().setRole("Dumb");
129
130 pm.beginTransaction();
131 pm.store(entry);
132 pm.commitTransaction();
133
134
135 pm.beginTransaction();
136 BaseMediaTypeEntry entry2 = (BaseMediaTypeEntry)pm.getObjectByQuery(query);
137 assertTrue(entry2.getHidden() == true);
138 assertTrue(entry2.getMimeType().equals("text.xhtml.9.1"));
139 assertTrue(entry2.getMetaInfo().getTitle().equals("New Title"));
140 assertTrue(entry2.getMetaInfo().getDescription().equals("New Description"));
141 assertTrue(entry2.getSecurity().getRole().equals("Dumb"));
142
143 pm.delete(entry2);
144 pm.commitTransaction();
145
146 }
147
148 void SkinTest(PersistenceBroker pm) throws Exception
149 {
150
151 }
152
153
154
155
156
157 private static TurbineConfig config = null;
158
159
160
161
162
163 static
164 {
165 try
166 {
167 config = new TurbineConfig( "webapp", "/WEB-INF/conf/TurbineResources.properties");
168 config.init();
169 }
170 catch (Exception e)
171 {
172
173 System.out.println(StringUtils.stackTrace(e));
174 }
175 }
176 }