1 16 17 package org.apache.jetspeed.services.registry; 18 19 import junit.framework.Test; 21 import junit.framework.TestSuite; 22 23 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 43 44 public class TestRegistryPersistence extends JetspeedTestCase { 45 46 51 public TestRegistryPersistence( String name ) { 52 super( name ); 53 } 54 55 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 73 public static Test suite() { 74 return new TestSuite( TestRegistryPersistence.class ); 76 } 77 78 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 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 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 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 } 152 153 157 private static TurbineConfig config = null; 158 159 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 System.out.println(StringUtils.stackTrace(e)); 174 } 175 } 176 } | Popular Tags |