Return-Path: Delivered-To: apmail-jakarta-jetspeed-dev-archive@www.apache.org Received: (qmail 84626 invoked from network); 2 Mar 2004 22:24:57 -0000 Received: from daedalus.apache.org (HELO mail.apache.org) (208.185.179.12) by minotaur-2.apache.org with SMTP; 2 Mar 2004 22:24:57 -0000 Received: (qmail 26337 invoked by uid 500); 2 Mar 2004 22:24:41 -0000 Delivered-To: apmail-jakarta-jetspeed-dev-archive@jakarta.apache.org Received: (qmail 26314 invoked by uid 500); 2 Mar 2004 22:24:41 -0000 Mailing-List: contact jetspeed-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jetspeed Developers List" Reply-To: "Jetspeed Developers List" Delivered-To: mailing list jetspeed-dev@jakarta.apache.org Received: (qmail 26287 invoked by uid 500); 2 Mar 2004 22:24:40 -0000 Received: (qmail 26265 invoked by uid 500); 2 Mar 2004 22:24:40 -0000 Received: (qmail 26258 invoked from network); 2 Mar 2004 22:24:39 -0000 Received: from unknown (HELO minotaur.apache.org) (209.237.227.194) by daedalus.apache.org with SMTP; 2 Mar 2004 22:24:39 -0000 Received: (qmail 84584 invoked by uid 1642); 2 Mar 2004 22:24:52 -0000 Date: 2 Mar 2004 22:24:52 -0000 Message-ID: <20040302222452.84583.qmail@minotaur.apache.org> From: weaver@apache.org To: jakarta-jetspeed-2-cvs@apache.org Subject: cvs commit: jakarta-jetspeed-2/components/persistence/src/test repository.xml repository_test.xml X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N weaver 2004/03/02 14:24:52 Modified: components/persistence/src/test/org/apache/jetspeed/components/persistence TestPersistenceContainer.java Added: components/persistence/src/test/org/apache/jetspeed/components/persistence B.java A.java components/persistence/src/test repository.xml repository_test.xml Log: Persistence testing Revision Changes Path 1.8 +77 -477 jakarta-jetspeed-2/components/persistence/src/test/org/apache/jetspeed/components/persistence/TestPersistenceContainer.java Index: TestPersistenceContainer.java =================================================================== RCS file: /home/cvs/jakarta-jetspeed-2/components/persistence/src/test/org/apache/jetspeed/components/persistence/TestPersistenceContainer.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- TestPersistenceContainer.java 1 Mar 2004 02:04:05 -0000 1.7 +++ TestPersistenceContainer.java 2 Mar 2004 22:24:51 -0000 1.8 @@ -54,10 +54,14 @@ package org.apache.jetspeed.components.persistence; import java.io.InputStreamReader; import java.io.Reader; +import java.util.ArrayList; import junit.framework.Test; import junit.framework.TestSuite; import org.apache.jetspeed.components.AbstractComponentAwareTestCase; import org.apache.jetspeed.components.ComponentManager; +import org.apache.jetspeed.components.persistence.store.Filter; +import org.apache.jetspeed.components.persistence.store.PersistenceStore; +import org.apache.jetspeed.components.persistence.store.PersistenceStoreContainer; import org.picocontainer.MutablePicoContainer; import org.picocontainer.defaults.DefaultPicoContainer; import org.picocontainer.defaults.ObjectReference; @@ -78,8 +82,9 @@ private ComponentManager persistenceCm; private ComponentManager rdbmsCm; private MutablePicoContainer rdbmsContainer; - private MutablePicoContainer persistenceContainer; + private PersistenceStoreContainer persistenceContainer; private DefaultPicoContainer parent; + private PersistenceStore store; /** @@ -103,474 +108,69 @@ assertNotNull(persistenceCm); } - - - // private static final String TEST_APP_1 = "test adding object"; - // private PersistenceStoreContainer pContainer; - // private ComponentManager cm; - // public static Test suite() - // { - // // All methods starting with "test" will be executed in the test suite. - // return new DatasourceEnabledTestSuite(TestPersistenceContainer.class); - // } - // - // /** - // * @param testName - // */ - // public TestPersistenceContainer(String testName) - // { - // super(testName); - // } - // public void testStartContainer() throws Exception - // { - // PersistenceStoreContainer pContainer = null; - // try - // { - // pContainer = getInstance(); - // PersistenceStore store = pContainer.getStoreForThread("jetspeed"); - // assertNotNull(store); - // } - // catch (RuntimeException e) - // { - // e.printStackTrace(); - // throw e; - // } - // finally - // { - // cm.killContainer(); - // } - // } - // public void testBasicPersistence() throws Exception - // { - // PersistenceStoreContainer pContainer = getInstance(); - // PersistenceStore store = pContainer.getStoreForThread("jetspeed"); - // assertNotNull(store); - // initTestObject(store); - // store.getTransaction().begin(); - // assertNotNull(getTestObject1(store)); - // store.getTransaction().commit(); - // } - // protected PersistenceStoreContainer getInstance() throws Exception - // { - // if (this.pContainer == null) - // { - // pContainer = (PersistenceStoreContainer) cm.getRootContainer(); - // } - // return pContainer; - // } - // protected void initTestObject(PersistenceStore store) throws Exception - // { - // try - // { - // store.getTransaction().begin(); - // MutablePortletApplication app = new PortletApplicationDefinitionImpl(); - // store.makePersistent(app); - // app.setName(TEST_APP_1); - // app.setVersion("1.0"); - // app.setDescription("This is a test from persistence layer"); - // // create a web application - // MutableWebApplication wad = new WebApplicationDefinitionImpl(); - // wad.addDescription(getEnglishLanguage().getLocale(), "This is an english - // desrcitpion"); - // wad.addDisplayName(getEnglishLanguage().getLocale(), "This is an english - // display name"); - // wad.setContextRoot("/test"); - // app.setWebApplicationDefinition(wad); - // - // // Create some Portlets - // PortletDefinitionComposite pdc = new PortletDefinitionImpl(); - // pdc.setClassName("com.bogus.Class1"); - // pdc.setName("Portlet 1"); - // PortletDefinitionComposite pdc2 = new PortletDefinitionImpl(); - // pdc2.setClassName("com.bogus.Class2"); - // pdc2.setName("Portlet 2"); - // app.addPortletDefinition(pdc); - // app.addPortletDefinition(pdc2); - // store.getTransaction().commit(); - // } - // catch (Exception e) - // { - // store.getTransaction().rollback(); - // store.close(); - // throw e; - // } - // } - // protected Language getEnglishLanguage() - // { - // MutableLanguage lang = new LanguageImpl(); - // lang.setTitle("Portlet Title"); - // lang.setShortTitle("Portlet Short Title"); - // lang.setLocale(Locale.ENGLISH); - // return lang; - // } - // protected void destroyTestObject(PersistenceStore store) throws - // Exception - // { - // try - // { - // store.getTransaction().begin(); - // Filter c = store.newFilter(); - // c.addEqualTo("name", TEST_APP_1); - // Object query = store.newQuery(PortletApplicationDefinitionImpl.class, - // c); - // Collection removeUs = store.getCollectionByQuery(query); - // Iterator itr = removeUs.iterator(); - // while (itr.hasNext()) - // { - // store.deletePersistent(itr.next()); - // } - // store.getTransaction().commit(); - // } - // catch (Exception e) - // { - // store.getTransaction().rollback(); - // throw e; - // } - // } - // protected PortletApplicationDefinitionImpl - // getTestObject1(PersistenceStore store) - // { - // Filter c = store.newFilter(); - // c.addEqualTo("name", TEST_APP_1); - // Object obj = - // store.getObjectByQuery(store.newQuery(PortletApplicationDefinitionImpl.class, - // c)); - // return (PortletApplicationDefinitionImpl) obj; - // } - // - // /** - // * @see junit.framework.TestCase#setUp() - // */ - // protected void setUp() throws Exception - // { - // super.setUp(); - // Map oms = new HashMap(); - // oms.put("pluto.om", "../../portal/src/webapp/WEB-INF/conf/pluto.om"); - // if (!OMHelper.isInitialized()) - // { - // OMHelper helper = new OMHelper(oms); - // helper.start(); - // } - // - // Reader composition = new - // InputStreamReader(Thread.currentThread().getContextClassLoader() - // .getResourceAsStream( - // "org/apache/jetspeed/containers/persistence.container.groovy")); - // cm = new ComponentManager(composition, ComponentManager.GROOVY); - // cm.getRootContainer(); - // destroyTestObject(getInstance().getStore("jetspeed")); - // } - // - // /** - // * @see junit.framework.TestCase#tearDown() - // */ - // protected void tearDown() throws Exception - // { - // destroyTestObject(getInstance().getStore("jetspeed")); - // super.tearDown(); - // } - - // public void testAdd2atATime() throws TransactionStateException - // { - // MutablePortletApplication app1 = new PortletApplicationDefinitionImpl(); - // - // try - // { - // plugin.beginTransaction(); - // - // plugin.prepareForUpdate(app1); - // app1.setName("This is app 1 of 2"); - // app1.setVersion("1.0"); - // app1.setDescription("This is app 1 of 2"); - // app1.setApplicationIdentifier("app1of2"); - // - // MutablePortletApplication app2 = new PortletApplicationDefinitionImpl(); - // plugin.prepareForUpdate(app2); - // app2.setName("This is app 2 of 2"); - // app2.setVersion("1.0"); - // app2.setDescription("This is app 2 of 2"); - // app1.setApplicationIdentifier("app2of2"); - // - // plugin.commitTransaction(); - // } - // catch (TransactionStateException e) - // { - // try - // { - // plugin.rollbackTransaction(); - // } - // catch (TransactionStateException e1) - // { - // // TODO Auto-generated catch block - // e1.printStackTrace(); - // } - // // TODO Auto-generated catch block - // e.printStackTrace(); - // throw e; - // } - // - // } - // - // - // public void testAddingLangaugeToPortlet() throws Exception - // { - // - // - // try - // { - // initTestObject(); - // MutablePortletApplication app = getTestObject1(); - // plugin.beginTransaction(); - // plugin.prepareForUpdate(app); - // - // Language english = getEnglishLanguage(); - // assertNotNull(english); - // - // PortletDefinitionComposite pdc = (PortletDefinitionComposite) - // app.getPortletDefinitionByName("Portlet 1"); - // plugin.prepareForUpdate(pdc); - // pdc.addLanguage(english); - // - // plugin.commitTransaction(); - // } - // catch (TransactionStateException e) - // { - // try - // { - // plugin.rollbackTransaction(); - // } - // catch (TransactionStateException e1) - // { - // e1.printStackTrace(); - // throw e1; - // } - // e.printStackTrace(); - // throw e; - // } - // - // } - // - // - // public void testAddObject() - // { - // initTestObject(); - // MutablePortletApplication app = getTestObject1(); - // assertNotNull(app); - // WebApplicationDefinition wad = app.getWebApplicationDefinition(); - // assertNotNull(wad); - // assertTrue(app.getPortletDefinitions().size() == 2); - // - // PortletDefinition pd = app.getPortletDefinitionByName("Portlet 1"); - // assertNotNull(pd); - // } - // - // - // public void testDefaultPlugin() - // { - // - // assertNotNull(plugin); - // } - // - // - // public void testDelete() throws TransactionStateException - // { - // initTestObject(); - // - // PortletApplicationDefinitionImpl app = getTestObject1(); - // - // assertNotNull(app); - // - // - // - // try - // { - // plugin.beginTransaction(); - // plugin.prepareForDelete(app); - // plugin.commitTransaction(); - // - // app = getTestObject1(); - // - // assertNull(app); - // } - // catch (TransactionStateException e) - // { - // try - // { - // plugin.rollbackTransaction(); - // } - // catch (TransactionStateException e1) - // { - // - // e1.printStackTrace(); - // } - // - // e.printStackTrace(); - // throw e; - // } - // } - // - // - // public void testDeleteByQuery() - // { - // initTestObject(); - // - // PortletApplicationDefinitionImpl app = getTestObject1(); - // - // assertNotNull(app); - // - // - // LookupCriteria c = plugin.newLookupCriteria(); - // c.addEqualTo("name", TEST_APP_1); - // Object query = - // plugin.generateQuery(PortletApplicationDefinitionImpl.class, c); - // plugin.deleteByQuery(query); - // - // app = getTestObject1(); - // - // assertNull(app); - // } - // - // - // public void testExtents() - // { - // // PersistencePlugin plugin = getService().getPlugin("jetspeed-test"); - // // Object query = - // // plugin.generateQuery(Application.class, new SimpleCriteria()); - // // Collection extent = - // // plugin.getCollectionByQuery(Application.class, query); - // // assertNotNull(extent); - // // assertTrue(extent.size() > 0); - // // Iterator itr = extent.iterator(); - // // while (itr.hasNext()) - // // { - // // Application app = (Application) itr.next(); - // // System.out.println("Application Name: " + app.getName()); - // // } - // - // } - // - // - // public void testGet2atATime() throws TransactionStateException - // { - // - // LookupCriteria lc1 = plugin.newLookupCriteria(); - // lc1.addEqualTo("name", "This is app 1 of 2"); - // MutablePortletApplication app1 = - // (MutablePortletApplication) plugin.getObjectByQuery( - // PortletApplicationDefinitionImpl.class, - // plugin.generateQuery(PortletApplicationDefinitionImpl.class, lc1)); - // - // assertNotNull("Could not retrieve test app 1 from the db", app1); - // try - // { - // plugin.beginTransaction(); - // plugin.prepareForDelete(app1); - // - // LookupCriteria lc2 = plugin.newLookupCriteria(); - // lc2.addEqualTo("name", "This is app 2 of 2"); - // MutablePortletApplication app2 = - // (MutablePortletApplication) plugin.getObjectByQuery( - // PortletApplicationDefinitionImpl.class, - // plugin.generateQuery(PortletApplicationDefinitionImpl.class, lc2)); - // assertNotNull("Could not retrieve test app 2 from the db", app2); - // plugin.prepareForDelete(app2); - // plugin.commitTransaction(); - // } - // catch (TransactionStateException e) - // { - // try - // { - // plugin.rollbackTransaction(); - // } - // catch (TransactionStateException e1) - // { - // e1.printStackTrace(); - // } - // - // e.printStackTrace(); - // throw e; - // } - // } - // - // - // /** - // * @see - // org.apache.jetspeed.test.JetspeedTest#overrideProperties(org.apache.commons.configuration.Configuration) - // */ - //// public void overrideProperties(Configuration properties) - //// { - //// super.overrideProperties(properties); - //// } - // - // public void testInit() throws Exception - // { - // assertNotNull(getService()); - // } - // - // - // public void testSingleObjectByCollection() - // { - // // PersistencePlugin plugin = getService().getPlugin("jetspeed-test"); - // // SimpleCriteria crit = new SimpleCriteria(); - // // crit.addComparsion("name", "demo", SimpleCriteria.EQUAL); - // // Object query = plugin.generateQuery(Application.class, crit); - // // Collection extent = - // // plugin.getCollectionByQuery(Application.class, query); - // // assertNotNull(extent); - // // assertTrue(extent.size() == 1); - // // Application app = - // // (Application) extent.toArray()[0]; - // // System.out.println("Only Application Name: " + app.getName()); - // } - // - // - // public void testUpdate() throws Exception - // { - // initTestObject(); - // - // - // - // PortletApplicationDefinitionImpl app; - // try - // { - // app = getTestObject1(); - // - // assertNotNull(app); - // plugin.beginTransaction(); - // plugin.prepareForUpdate(app); - // - // String version = app.getVersion(); - // - // app.setVersion("5.5.5"); - // - // MutableWebApplication wac = (MutableWebApplication) - // app.getWebApplicationDefinition(); - // - // wac.setContextRoot("/root/changed"); - // - // plugin.commitTransaction(); - // } - // catch (Exception e) - // { - // plugin.rollbackTransaction(); - // e.printStackTrace(); - // throw e; - // } - // - // app = getTestObject1(); - // - // assertNotNull(app); - // - // assertTrue(app.getVersion().equals("5.5.5")); - // String cRoot = app.getWebApplicationDefinition().getContextRoot(); - // - // assertTrue(cRoot.equals("/root/changed")); - // } - - - - - + public void test001() throws Exception + { + try + { + assertNotNull(store); + store.getTransaction().begin(); + A a = new A(); + a.setName("A1"); + ArrayList bList = new ArrayList(2); + B b1 = new B(); + b1.setName("B1"); + B b2 = new B(); + b2.setName("B2"); + bList.add(b1); + bList.add(b2); + a.setBList(bList); + store.makePersistent(a); + store.getTransaction().commit(); + + //assertNotNull(b1.getA()); + //assertNotNull(b2.getA()); + + store.getTransaction().begin(); + store.invalidate(b1); + store.invalidate(b2); + store.invalidate(a); + store.getTransaction().commit(); + + Filter filter = store.newFilter(); + filter.addEqualTo("name", "A1"); + store.getTransaction().begin(); + try + { + a = (A) store.getObjectByQuery(store.newQuery(A.class, filter)); + assertNotNull(a); + assertEquals(2, a.getBList().size()); + } + finally + { + store.getTransaction().commit(); + } + try + { + store.getTransaction().begin(); + Filter b1f = store.newFilter(); + b1f.addEqualTo("name", "B1"); + b1 = (B) store.getObjectByQuery(store.newQuery(B.class, b1f)); + assertNotNull(b1); + assertNotNull(b1.getA()); + } + finally + { + store.getTransaction().commit(); + } + } + finally + { + Filter af = store.newFilter(); + store.getTransaction().begin(); + store.deleteAll(store.newQuery(A.class, af)); + store.getTransaction().commit(); + } + } /* * (non-Javadoc) @@ -580,14 +180,13 @@ protected void setUp() throws Exception { super.setUp(); - ClassLoader cl = Thread.currentThread().getContextClassLoader(); Reader rdbmsScript = new InputStreamReader(cl - .getResourceAsStream("org/apache/jetspeed/containers/rdbms.container.groovy")); + .getResourceAsStream("org/apache/jetspeed/containers/rdbms.container.groovy")); Reader persistenceScript = new InputStreamReader(cl - .getResourceAsStream("org/apache/jetspeed/containers/persistence.container.groovy")); + .getResourceAsStream("org/apache/jetspeed/containers/persistence.container.groovy")); rdbmsCm = new ComponentManager(rdbmsScript, ComponentManager.GROOVY); - persistenceCm = new ComponentManager(persistenceScript, ComponentManager.GROOVY); + persistenceCm = new ComponentManager(persistenceScript, ComponentManager.GROOVY); ObjectReference parentRef = new SimpleReference(); ObjectReference rdbmsRef = new SimpleReference(); ObjectReference persistenceRef = new SimpleReference(); @@ -595,15 +194,16 @@ rdbmsCm.getContainerBuilder().buildContainer(rdbmsRef, parentRef, "TEST_PERSISTENCE"); persistenceCm.getContainerBuilder().buildContainer(persistenceRef, parentRef, "TEST_PERSISTENCE"); rdbmsContainer = (MutablePicoContainer) rdbmsRef.get(); - persistenceContainer = (MutablePicoContainer) persistenceRef.get(); - + persistenceContainer = (PersistenceStoreContainer) persistenceRef.get(); + store = persistenceContainer.getStoreForThread("jetspeed"); } protected void tearDown() throws Exception - { + { // parent.stop(); + rdbmsContainer.stop(); - persistenceContainer.stop(); + ((MutablePicoContainer) persistenceContainer).stop(); super.tearDown(); } } 1.1 jakarta-jetspeed-2/components/persistence/src/test/org/apache/jetspeed/components/persistence/B.java Index: B.java =================================================================== /* * Created on Mar 2, 2004 * * To change the template for this generated file go to * Window - Preferences - Java - Code Generation - Code and Comments */ package org.apache.jetspeed.components.persistence; /** *

* B *

* * @author Scott T. Weaver * @version $ $ * */ public class B { private A a; private int aId; private int id; private String name; /** * @return Returns the a. */ public A getA() { return a; } /** * @param a The a to set. */ public void setA(A a) { this.a = a; } /** * @return Returns the id. */ public int getId() { return id; } /** * @param id The id to set. */ public void setId(int id) { this.id = id; } /** * @return Returns the name. */ public String getName() { return name; } /** * @param name The name to set. */ public void setName(String name) { this.name = name; } } 1.1 jakarta-jetspeed-2/components/persistence/src/test/org/apache/jetspeed/components/persistence/A.java Index: A.java =================================================================== /* * Created on Mar 2, 2004 * * To change the template for this generated file go to * Window - Preferences - Java - Code Generation - Code and Comments */ package org.apache.jetspeed.components.persistence; import java.util.Collection; /** *

* A *

* * @author Scott T. Weaver * @version $ $ * */ public class A { private Collection bList; private int id; private String name; /** * @return Returns the bList. */ public Collection getBList() { return bList; } /** * @param list The bList to set. */ public void setBList(Collection list) { bList = list; } /** * @return Returns the id. */ public int getId() { return id; } /** * @param id The id to set. */ public void setId(int id) { this.id = id; } /** * @return Returns the name. */ public String getName() { return name; } /** * @param name The name to set. */ public void setName(String name) { this.name = name; } } 1.1 jakarta-jetspeed-2/components/persistence/src/test/repository.xml Index: repository.xml =================================================================== ]> &database; &internal; &test; 1.1 jakarta-jetspeed-2/components/persistence/src/test/repository_test.xml Index: repository_test.xml =================================================================== --------------------------------------------------------------------- To unsubscribe, e-mail: jetspeed-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: jetspeed-dev-help@jakarta.apache.org