Author: manik.surtani(a)jboss.com
Date: 2008-06-26 07:31:23 -0400 (Thu, 26 Jun 2008)
New Revision: 6053
Modified:
searchable/trunk/src/test/java/org/jboss/cache/search/QueryResultIteratorImplTest.java
Log:
Added a mock loader
Modified:
searchable/trunk/src/test/java/org/jboss/cache/search/QueryResultIteratorImplTest.java
===================================================================
---
searchable/trunk/src/test/java/org/jboss/cache/search/QueryResultIteratorImplTest.java 2008-06-26
11:18:41 UTC (rev 6052)
+++
searchable/trunk/src/test/java/org/jboss/cache/search/QueryResultIteratorImplTest.java 2008-06-26
11:31:23 UTC (rev 6053)
@@ -6,7 +6,9 @@
import org.testng.annotations.Test;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
/**
* @author Navin Surtani - navin(a)surtani.org
@@ -17,32 +19,48 @@
@Test
public class QueryResultIteratorImplTest
{
- CacheEntityLoader entityLoader;
- List<CacheEntityId> list;
+ List<CacheEntityId> ids;
+ Map<CacheEntityId, Object> dummyResults;
+ QueryResultIterator iterator;
@BeforeMethod
public void SetUp()
{
- list = new ArrayList();
- list.add(new CacheEntityId(Fqn.fromString("/a"), "key1"));
- list.add(new CacheEntityId(Fqn.fromString("/b"), "key2"));
- list.add(new CacheEntityId(Fqn.fromString("/c"), "key3"));
- list.add(new CacheEntityId(Fqn.fromString("/d"), "key4"));
- list.add(new CacheEntityId(Fqn.fromString("/e"), "key5"));
- list.add(new CacheEntityId(Fqn.fromString("/f"), "key6"));
- list.add(new CacheEntityId(Fqn.fromString("/g"), "key7"));
- list.add(new CacheEntityId(Fqn.fromString("/h"), "key8"));
- list.add(new CacheEntityId(Fqn.fromString("/i"), "key9"));
- list.add(new CacheEntityId(Fqn.fromString("/j"), "key10"));
+ // create a set of dummy cache entity IDs
+ ids = new ArrayList();
+ ids.add(new CacheEntityId(Fqn.fromString("/a"), "key1"));
+ ids.add(new CacheEntityId(Fqn.fromString("/b"), "key2"));
+ ids.add(new CacheEntityId(Fqn.fromString("/c"), "key3"));
+ ids.add(new CacheEntityId(Fqn.fromString("/d"), "key4"));
+ ids.add(new CacheEntityId(Fqn.fromString("/e"), "key5"));
+ ids.add(new CacheEntityId(Fqn.fromString("/f"), "key6"));
+ ids.add(new CacheEntityId(Fqn.fromString("/g"), "key7"));
+ ids.add(new CacheEntityId(Fqn.fromString("/h"), "key8"));
+ ids.add(new CacheEntityId(Fqn.fromString("/i"), "key9"));
+ ids.add(new CacheEntityId(Fqn.fromString("/j"), "key10"));
- QueryResultIteratorImpl iterator = new QueryResultIteratorImpl(list,
entityLoader);
+ // create some dummy data
+ dummyResults = new HashMap<CacheEntityId, Object>();
+ int counter = 0;
+ for (CacheEntityId id : ids)
+ {
+ // for each cache entity ID, create a dummy result that will be returned when
loading it.
+ dummyResults.put(id, "Result number " + counter);
+ }
+
+ // now create a dummy entity loader
+ CacheEntityLoader dummyLoader = new DummyEntityLoader(ids, dummyResults);
+
+ iterator = new QueryResultIteratorImpl(ids, dummyLoader);
}
@AfterMethod
public void tearDown()
{
- list = null;
+ ids = null;
+ dummyResults = null;
+ iterator = null;
}
public void jumpToResultTest(int index) throws IndexOutOfBoundsException
@@ -134,4 +152,38 @@
{
//To change body of implemented methods use File | Settings | File Templates.
}
+
+ public static class DummyEntityLoader extends CacheEntityLoader
+ {
+ private List<CacheEntityId> allKnownIds;
+ private Map<CacheEntityId, Object> dummyValues;
+
+ public DummyEntityLoader(List<CacheEntityId> allKnownIds,
Map<CacheEntityId, Object> dummyValues)
+ {
+ // use a null as a cache since we won't ever need to refer to the cache
+ super(null);
+
+ this.allKnownIds = allKnownIds;
+ this.dummyValues = dummyValues;
+ }
+
+ @Override
+ public List<Object> load(List<CacheEntityId> ids)
+ {
+ List<Object> resultsToReturn = new ArrayList<Object>(ids.size());
+ // iterate through the list of ids we are looking for
+ for (CacheEntityId id : ids)
+ {
+ resultsToReturn.add(dummyValues.get(id));
+ }
+
+ return resultsToReturn;
+ }
+
+ @Override
+ public Object load(CacheEntityId id)
+ {
+ return dummyValues.get(id);
+ }
+ }
}
Show replies by date