[Javamatch-cvs] javamatch/src/net/sourceforge/javamatch/engine/test ExtentMock.java,NONE,1.1 JDOMatc
Status: Pre-Alpha
Brought to you by:
iterson
From: Walter v. I. <it...@us...> - 2004-09-20 08:26:03
|
Update of /cvsroot/javamatch/javamatch/src/net/sourceforge/javamatch/engine/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2618/src/net/sourceforge/javamatch/engine/test Modified Files: TestAll.java Added Files: ExtentMock.java JDOMatchEngineTest.java PersistenceManagerMock.java Log Message: Added (unoptimized) JDO implementation --- NEW FILE: JDOMatchEngineTest.java --- /* JavaMatch: Matching engine for Java runtime data structures * Copyright (C) 2004 Walter van Iterson * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ package net.sourceforge.javamatch.engine.test; import java.util.*; import javax.jdo.*; import junit.framework.*; import net.sourceforge.javamatch.engine.*; import net.sourceforge.javamatch.query.*; import net.sourceforge.javamatch.query.test.*; /** * Class JDOMatchEngineTest tests the JDOMatchEngine functionality */ public class JDOMatchEngineTest extends TestCase { public JDOMatchEngineTest(String name) { super(name); } public void testCreateNullPersistenceManager() { try { new JDOMatchEngine(null); fail("Shouldn't be ableto create JDOMatchEngine with null persistence manager"); } catch (NullPointerException npe) { // should occur } } public void testUnusedObjectsAreEvicted() { PersistenceManagerMock persistenceManager = new PersistenceManagerMock(); JDOMatchEngine matchEngine = new JDOMatchEngine(persistenceManager); MatchResult matchResult = new MatchResult(matchEngine); matchResult.setMaxNumResultItems(1); matchResult.addResultItem(new Object(), 0.2f); Object object = new Object(); persistenceManager.expectEvict(object); matchResult.addResultItem(object, 0.1f); persistenceManager.validate(); } public void testNullExtent() { PersistenceManagerMock persistenceManager = new PersistenceManagerMock(); JDOMatchEngine matchEngine = new JDOMatchEngine(persistenceManager); try { matchEngine.executeQuery(new ConstantMatch(3f), (Extent)null); fail("Shouldn't be able to execute query with null extent"); } catch (NullPointerException npe) { // should occur } catch (MatchException me) { fail("unable to match"); } } public void testIteratorsClosed() { PersistenceManagerMock persistenceManager = new PersistenceManagerMock(); JDOMatchEngine matchEngine = new JDOMatchEngine(persistenceManager); ExtentMock extent = new ExtentMock(); extent.expectClose(); extent.expectClose(); try { matchEngine.executeQuery(new ConstantMatch(3f), extent); } catch (NullPointerException npe) { // should occur extent.validate(); } catch (MatchException me) { fail("unable to match"); } } } Index: TestAll.java =================================================================== RCS file: /cvsroot/javamatch/javamatch/src/net/sourceforge/javamatch/engine/test/TestAll.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** TestAll.java 3 Sep 2004 08:21:22 -0000 1.1.1.1 --- TestAll.java 20 Sep 2004 08:25:46 -0000 1.2 *************** *** 36,39 **** --- 36,40 ---- suite.addTestSuite(MatchEngineTest.class); suite.addTestSuite(MatchResultTest.class); + suite.addTestSuite(JDOMatchEngineTest.class); // ... and others return suite; --- NEW FILE: ExtentMock.java --- /* JavaMatch: Matching engine for Java runtime data structures * Copyright (C) 2004 Walter van Iterson * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ package net.sourceforge.javamatch.engine.test; import java.util.*; import javax.jdo.*; import net.sourceforge.javamatch.test.*; public class ExtentMock extends ExpectationList implements Extent { public void expectClose() { expect("close"); } public Iterator iterator() { return null; } public boolean hasSubclasses() { return false; } public Class getCandidateClass() { return null; } public PersistenceManager getPersistenceManager() { return null; } public void closeAll() {} public void close(Iterator i) { encounter("close"); } } --- NEW FILE: PersistenceManagerMock.java --- /* JavaMatch: Matching engine for Java runtime data structures * Copyright (C) 2004 Walter van Iterson * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ package net.sourceforge.javamatch.engine.test; import java.util.*; import javax.jdo.*; import net.sourceforge.javamatch.test.*; public class PersistenceManagerMock extends ExpectationList implements PersistenceManager { public void expectEvict(Object objectToEvict) { expect("evict: " + objectToEvict); } public void evict(Object objectToEvict) { encounter("evict: " + objectToEvict); } public boolean isClosed() { return false; } public void close() {} public Transaction currentTransaction() { return null; } public void evictAll(Object[] os) {} public void evictAll(Collection c) {} public void evictAll() {} public void refresh(Object o) {} public void refreshAll(Object[] os) {} public void refreshAll(Collection c) {} public void refreshAll() {} public Query newQuery() { return null; } public Query newQuery(Object o) { return null; } public Query newQuery(String s, Object o) { return null; } public Query newQuery(Class c) { return null; } public Query newQuery(Extent e) { return null; } public Query newQuery(Class cl, Collection co) { return null; } public Query newQuery(Class c, String s) { return null; } public Query newQuery(Class cl, Collection co, String s) { return null; } public Query newQuery(Extent e, String s) { return null; } public Extent getExtent(Class s, boolean b) { return null; } public Object getObjectById(Object o, boolean b) { return null; } public Object getObjectId(Object o) { return null; } public Object getTransactionalObjectId(Object o) { return null; } public Object newObjectIdInstance(Class c, String s) { return null; } public void makePersistent(Object o) {} public void makePersistentAll(Object[] os) {} public void makePersistentAll(Collection c) {} public void deletePersistent(Object o) {} public void deletePersistentAll(Object[] os) {} public void deletePersistentAll(Collection c) {} public void makeTransient(Object o) {} public void makeTransientAll(Object[] os) {} public void makeTransientAll(Collection c) {} public void makeTransactional(Object o) {} public void makeTransactionalAll(Object[] os) {} public void makeTransactionalAll(Collection c) {} public void makeNontransactional(Object o) {} public void makeNontransactionalAll(Object[] os) {} public void makeNontransactionalAll(Collection c) {} public void retrieve(Object o) {} public void retrieveAll(Collection c) {} public void retrieveAll(Collection c, boolean b) {} public void retrieveAll(Object[] o) {} public void retrieveAll(Object[] os, boolean b) {} public void setUserObject(Object o) {} public Object getUserObject() { return null; } public PersistenceManagerFactory getPersistenceManagerFactory() { return null; } public Class getObjectIdClass(Class c) { return null; } public void setMultithreaded(boolean b) {} public boolean getMultithreaded() { return false; } public void setIgnoreCache(boolean b) {} public boolean getIgnoreCache() { return false; } } |