[infinispan-commits] Infinispan SVN: r503 - branches/ISPN-32/query/src/test/java/org/infinispan/query.

infinispan-commits at lists.jboss.org infinispan-commits at lists.jboss.org
Mon Jun 29 07:31:56 EDT 2009


Author: navssurtani
Date: 2009-06-29 07:31:56 -0400 (Mon, 29 Jun 2009)
New Revision: 503

Added:
   branches/ISPN-32/query/src/test/java/org/infinispan/query/BrokenAnnotationTest.java
   branches/ISPN-32/query/src/test/java/org/infinispan/query/BrokenDocumentId.java
   branches/ISPN-32/query/src/test/java/org/infinispan/query/BrokenProvided.java
   branches/ISPN-32/query/src/test/java/org/infinispan/query/CacheEntityIdTest.java
   branches/ISPN-32/query/src/test/java/org/infinispan/query/ClusteredCacheTest.java
   branches/ISPN-32/query/src/test/java/org/infinispan/query/IndexCleanUp.java
   branches/ISPN-32/query/src/test/java/org/infinispan/query/IndexingInTransaction.java
   branches/ISPN-32/query/src/test/java/org/infinispan/query/LazyQueryResultIteratorTest.java
   branches/ISPN-32/query/src/test/java/org/infinispan/query/LocalCacheProfilerTest.java
   branches/ISPN-32/query/src/test/java/org/infinispan/query/LocalCacheTest.java
   branches/ISPN-32/query/src/test/java/org/infinispan/query/LocalPOJOCacheTest.java
   branches/ISPN-32/query/src/test/java/org/infinispan/query/NodeModifiedTransactionContextTest.java
   branches/ISPN-32/query/src/test/java/org/infinispan/query/NodeRemovedTest.java
   branches/ISPN-32/query/src/test/java/org/infinispan/query/Person.java
   branches/ISPN-32/query/src/test/java/org/infinispan/query/QueryResultIteratorImplTest.java
   branches/ISPN-32/query/src/test/java/org/infinispan/query/SearchableCacheFactoryTest.java
   branches/ISPN-32/query/src/test/java/org/infinispan/query/SearchableCacheImplTest.java
   branches/ISPN-32/query/src/test/java/org/infinispan/query/TransformerTest.java
Log:
[ISPN-32] [Integrate Query API] Added classes into src/test

Added: branches/ISPN-32/query/src/test/java/org/infinispan/query/BrokenAnnotationTest.java
===================================================================
--- branches/ISPN-32/query/src/test/java/org/infinispan/query/BrokenAnnotationTest.java	                        (rev 0)
+++ branches/ISPN-32/query/src/test/java/org/infinispan/query/BrokenAnnotationTest.java	2009-06-29 11:31:56 UTC (rev 503)
@@ -0,0 +1,46 @@
+package org.jboss.cache.search.blackbox;
+
+import org.testng.annotations.Test;
+import org.jboss.cache.search.test.BrokenProvided;
+import org.jboss.cache.search.test.BrokenDocumentId;
+import org.jboss.cache.search.SearchableCache;
+import org.jboss.cache.search.SearchableCacheFactory;
+import org.jboss.cache.Cache;
+import org.jboss.cache.DefaultCacheFactory;
+
+/**
+ * This test is to try and create a searchable cache without the proper annotations used.
+ *
+ * @author Navin Surtani (<a href="mailto:nsurtani at redhat.com">nsurtani at redhat.com</a>)
+ */
+ at Test (groups = "functional")
+public class BrokenAnnotationTest
+{
+   @Test (expectedExceptions = IllegalArgumentException.class)
+   public void testProvided()
+   {
+      BrokenProvided provided = new BrokenProvided();
+      provided.setBoth("Cat", 5);
+
+      Cache cache = new DefaultCacheFactory().createCache();
+
+      SearchableCache searchable = new SearchableCacheFactory().createSearchableCache(cache, BrokenProvided.class);
+
+
+   }
+
+   @Test (expectedExceptions = IllegalArgumentException.class)
+   public void testDocumentId()
+   {
+      BrokenDocumentId provided = new BrokenDocumentId();
+      provided.setBoth("Cat", 5);
+
+      Cache cache = new DefaultCacheFactory().createCache();
+
+      SearchableCache searchable = new SearchableCacheFactory().createSearchableCache(cache, BrokenProvided.class);
+
+
+
+   }
+
+}

Added: branches/ISPN-32/query/src/test/java/org/infinispan/query/BrokenDocumentId.java
===================================================================
--- branches/ISPN-32/query/src/test/java/org/infinispan/query/BrokenDocumentId.java	                        (rev 0)
+++ branches/ISPN-32/query/src/test/java/org/infinispan/query/BrokenDocumentId.java	2009-06-29 11:31:56 UTC (rev 503)
@@ -0,0 +1,27 @@
+package org.jboss.cache.search.test;
+
+import org.hibernate.search.annotations.ProvidedId;
+import org.hibernate.search.annotations.Indexed;
+import org.hibernate.search.annotations.DocumentId;
+import org.hibernate.search.annotations.Field;
+
+/**
+ * @author Navin Surtani (<a href="mailto:nsurtani at redhat.com">nsurtani at redhat.com</a>)
+ */
+ at ProvidedId
+ at Indexed
+public class BrokenDocumentId
+{
+   @DocumentId
+   @Field
+   String name;
+
+   @Field
+   int age;
+
+   public void setBoth(String name, int age)
+   {
+      this.name = name;
+      this.age = age;
+   }
+}

Added: branches/ISPN-32/query/src/test/java/org/infinispan/query/BrokenProvided.java
===================================================================
--- branches/ISPN-32/query/src/test/java/org/infinispan/query/BrokenProvided.java	                        (rev 0)
+++ branches/ISPN-32/query/src/test/java/org/infinispan/query/BrokenProvided.java	2009-06-29 11:31:56 UTC (rev 503)
@@ -0,0 +1,26 @@
+package org.jboss.cache.search.test;
+
+import org.hibernate.search.annotations.Indexed;
+import org.hibernate.search.annotations.DocumentId;
+import org.hibernate.search.annotations.Field;
+
+/**
+ * @author Navin Surtani (<a href="mailto:nsurtani at redhat.com">nsurtani at redhat.com</a>)
+ */
+ at Indexed
+public class BrokenProvided
+{
+   @Field   
+   public String name;
+
+   @Field
+   public int age;
+
+   public void setBoth(String name, int age)
+   {
+      this.name = name;
+      this.age = age;
+
+   }
+
+}

Added: branches/ISPN-32/query/src/test/java/org/infinispan/query/CacheEntityIdTest.java
===================================================================
--- branches/ISPN-32/query/src/test/java/org/infinispan/query/CacheEntityIdTest.java	                        (rev 0)
+++ branches/ISPN-32/query/src/test/java/org/infinispan/query/CacheEntityIdTest.java	2009-06-29 11:31:56 UTC (rev 503)
@@ -0,0 +1,36 @@
+package org.jboss.cache.search;
+
+import org.testng.annotations.Test;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.search.CacheEntityId;
+
+/**
+ * @author Navin Surtani (<a href="mailto:nsurtani at redhat.com">nsurtani at redhat.com</a>)
+ */
+
+ at Test
+public class CacheEntityIdTest
+{
+
+   @Test (expectedExceptions = NullPointerException.class)
+   public void testNullFqn() throws InvalidKeyException
+   {
+      CacheEntityId nullFqn = new CacheEntityId(null, "key");
+   }
+
+
+   @Test (expectedExceptions = NullPointerException.class)
+   public void testNullKey() throws InvalidKeyException
+   {
+      CacheEntityId nullKey = new CacheEntityId(Fqn.fromString("/a/b/c"), null);
+   }
+
+   @Test (expectedExceptions = NullPointerException.class)
+   public void testNullDocId()
+   {
+      CacheEntityId nulldoc = new CacheEntityId(null);
+   }
+
+
+
+}

Added: branches/ISPN-32/query/src/test/java/org/infinispan/query/ClusteredCacheTest.java
===================================================================
--- branches/ISPN-32/query/src/test/java/org/infinispan/query/ClusteredCacheTest.java	                        (rev 0)
+++ branches/ISPN-32/query/src/test/java/org/infinispan/query/ClusteredCacheTest.java	2009-06-29 11:31:56 UTC (rev 503)
@@ -0,0 +1,230 @@
+package org.jboss.cache.search.blackbox;
+
+import org.apache.lucene.analysis.standard.StandardAnalyzer;
+import org.apache.lucene.queryParser.ParseException;
+import org.apache.lucene.queryParser.QueryParser;
+import org.apache.lucene.search.Query;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.Cache;
+import org.jboss.cache.DefaultCacheFactory;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.search.CacheQuery;
+import org.jboss.cache.search.SearchableCache;
+import org.jboss.cache.search.SearchableCacheFactory;
+import org.jboss.cache.search.helper.IndexCleanUp;
+import org.jboss.cache.search.test.Person;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import java.util.List;
+
+/**
+ * @author Navin Surtani (<a href="mailto:nsurtani at redhat.com">nsurtani at redhat.com</a>)
+ */
+ at Test(groups = "functional")
+public class ClusteredCacheTest
+{
+   Cache cache1, cache2;
+   SearchableCache searchableCache1, searchableCache2;
+   Person person1;
+   Person person2;
+   Person person3;
+   Person person4;
+   QueryParser queryParser;
+   Query luceneQuery;
+   CacheQuery cacheQuery;
+   List found;
+   String key1 = "Navin";
+   String key2 = "BigGoat";
+   String key3 = "MiniGoat";
+   private static final Log log = LogFactory.getLog(Person.class);
+
+
+
+   @BeforeMethod
+   public void setUp() throws CloneNotSupportedException
+   {
+      Configuration cacheCfg = new Configuration();
+      cacheCfg.setCacheMode(Configuration.CacheMode.REPL_SYNC);
+      cacheCfg.setFetchInMemoryState(false);
+      cache1 = new DefaultCacheFactory().createCache(cacheCfg.clone());
+      searchableCache1 = new SearchableCacheFactory().createSearchableCache(cache1, Person.class);
+
+      cache2 = new DefaultCacheFactory().createCache(cacheCfg.clone());
+      searchableCache2 = new SearchableCacheFactory().createSearchableCache(cache2, Person.class);
+
+      // wait until both caches are started and can see each other on the network.
+      long giveUpTime = System.currentTimeMillis() + (60 * 1000); // give up after 1 minute of waiting
+      boolean wait = true;
+      while (wait && System.currentTimeMillis() < giveUpTime)
+      {
+         wait = !((cache1.getMembers().size() == 2) && (cache2.getMembers().size() == 2));
+         // spin-lock
+         try
+         {
+            Thread.sleep(100);
+         }
+         catch (InterruptedException e)
+         {
+            // do nothing
+         }
+      }
+
+      if (wait)
+      {
+         // we still haven't got the cache views we want!!
+         throw new RuntimeException("Unable to initialise cluster!");
+      }
+
+
+      person1 = new Person();
+      person1.setName("Navin Surtani");
+      person1.setBlurb("Likes playing WoW");
+
+      person2 = new Person();
+      person2.setName("BigGoat");
+      person2.setBlurb("Eats grass");
+
+      person3 = new Person();
+      person3.setName("MiniGoat");
+      person3.setBlurb("Eats cheese");
+
+      //Put the 3 created objects in the searchableCache1.
+
+      searchableCache1.put(Fqn.fromString("/a/b/c"), key1, person1);
+      searchableCache1.put(Fqn.fromString("/a/b/d"), key2, person2);
+      searchableCache1.put(Fqn.fromString("/a/b/c"), key3, person3);
+
+
+   }
+
+   @AfterMethod
+   public void tearDown()
+   {
+      if (searchableCache1 != null) searchableCache1.stop();
+      if (searchableCache2 != null) searchableCache2.stop();
+
+      IndexCleanUp.cleanUpIndexes();
+
+   }
+
+   public void testSimple() throws ParseException
+   {
+      queryParser = new QueryParser("blurb", new StandardAnalyzer());
+      luceneQuery = queryParser.parse("playing");
+      cacheQuery = searchableCache2.createQuery(luceneQuery);
+
+      found = cacheQuery.list();
+
+      assert found.size() == 1;
+
+      if(found.get(0) == null)
+      {
+         if(log.isTraceEnabled()) log.warn("found.get(0) is null");
+         Person p1 = (Person) searchableCache2.get("/a/b/c", key1);
+                         http://wiki.jboss.org/wiki/JBossCacheSearchable
+         if(p1 == null)
+         {
+            if(log.isTraceEnabled()) log.warn("Person p1 is null in sc2 and cannot actually see the data of person1 in sc1");
+         }
+
+         else
+         {
+            if(log.isTraceEnabled()) log.trace("p1 name is  " + p1.getName());
+
+         }
+      }
+
+
+      assert found.get(0).equals(person1);
+
+   }
+
+   public void testModified() throws ParseException
+   {
+      queryParser = new QueryParser("blurb", new StandardAnalyzer());
+      luceneQuery = queryParser.parse("playing");
+      cacheQuery = searchableCache2.createQuery(luceneQuery);
+
+      found = cacheQuery.list();
+
+      assert found.size() == 1;
+      assert found.get(0).equals(person1);
+
+      person1.setBlurb("Likes pizza");
+      searchableCache1.put(Fqn.fromString("/a/b/c/"), "Navin", person1);
+
+
+      queryParser = new QueryParser("blurb", new StandardAnalyzer());
+      luceneQuery = queryParser.parse("pizza");
+      cacheQuery = searchableCache2.createQuery(luceneQuery);
+
+      found = cacheQuery.list();
+
+      assert found.size() == 1;
+      assert found.get(0).equals(person1);
+   }
+
+   public void testAdded() throws ParseException
+   {
+      queryParser = new QueryParser("blurb", new StandardAnalyzer());
+
+      luceneQuery = queryParser.parse("eats");
+      cacheQuery = searchableCache2.createQuery(luceneQuery);
+      found = cacheQuery.list();
+
+      System.out.println("found.size() is " + found.size());
+
+      assert found.size() == 2 : "Size of list should be 2";
+      assert found.contains(person2);
+      assert found.contains(person3);
+      assert !found.contains(person4) : "This should not contain object person4";
+
+      person4 = new Person();
+      person4.setName("Mighty Goat");
+      person4.setBlurb("Also eats grass");
+
+      searchableCache1.put(Fqn.fromString("/r/a/m/"), "Ram", person4);
+
+      luceneQuery = queryParser.parse("eats");
+      cacheQuery = searchableCache2.createQuery(luceneQuery);
+      found = cacheQuery.list();
+
+      assert found.size() == 3 : "Size of list should be 3";
+      assert found.contains(person2);
+      assert found.contains(person3);
+      assert found.contains(person4) : "This should now contain object person4";
+   }
+
+   public void testRemoved() throws ParseException
+   {
+      queryParser = new QueryParser("blurb", new StandardAnalyzer());
+      luceneQuery = queryParser.parse("eats");
+      cacheQuery = searchableCache2.createQuery(luceneQuery);
+      found = cacheQuery.list();
+
+      assert found.size() == 2;
+      assert found.contains(person2);
+      assert found.contains(person3) : "This should still contain object person3";
+
+      searchableCache1.remove(Fqn.fromString("/a/b/c/"), key3);
+
+      queryParser = new QueryParser("blurb", new StandardAnalyzer());
+      luceneQuery = queryParser.parse("eats");
+      cacheQuery = searchableCache2.createQuery(luceneQuery);
+      found = cacheQuery.list();
+
+      assert found.size() == 1;
+      assert found.contains(person2);
+      assert !found.contains(person3) : "The search should not return person3";
+
+
+   }
+
+
+}
+
+

Added: branches/ISPN-32/query/src/test/java/org/infinispan/query/IndexCleanUp.java
===================================================================
--- branches/ISPN-32/query/src/test/java/org/infinispan/query/IndexCleanUp.java	                        (rev 0)
+++ branches/ISPN-32/query/src/test/java/org/infinispan/query/IndexCleanUp.java	2009-06-29 11:31:56 UTC (rev 503)
@@ -0,0 +1,41 @@
+package org.jboss.cache.search.helper;
+
+import org.jboss.cache.search.test.Person;
+
+import java.io.File;
+
+/**
+ * @author Navin Surtani (<a href="mailto:nsurtani at redhat.com">nsurtani at redhat.com</a>)
+ */
+public class IndexCleanUp
+{
+
+   public static void cleanUpIndexes()
+   {
+      Class[] knownClasses = {Person.class};
+      for (Class c : knownClasses)
+      {
+         String dirName = c.getName();
+         File file = new File(dirName);
+         if (file.exists())
+         {
+            recursiveDelete(file);
+         }
+      }
+   }
+
+   private static void recursiveDelete(File f)
+   {
+      if (f.isDirectory())
+      {
+         File[] files = f.listFiles();
+         for (File file : files) recursiveDelete(file);
+      }
+      else
+      {
+         f.delete();
+      }
+   }
+
+}
+

Added: branches/ISPN-32/query/src/test/java/org/infinispan/query/IndexingInTransaction.java
===================================================================
--- branches/ISPN-32/query/src/test/java/org/infinispan/query/IndexingInTransaction.java	                        (rev 0)
+++ branches/ISPN-32/query/src/test/java/org/infinispan/query/IndexingInTransaction.java	2009-06-29 11:31:56 UTC (rev 503)
@@ -0,0 +1,202 @@
+package org.jboss.cache.search.blackbox;
+
+import org.apache.lucene.index.Term;
+import org.apache.lucene.search.BooleanClause;
+import org.apache.lucene.search.BooleanQuery;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.search.TermQuery;
+import org.hibernate.search.annotations.Field;
+import org.hibernate.search.annotations.Indexed;
+import org.hibernate.search.annotations.ProvidedId;
+import org.hibernate.search.annotations.Store;
+import org.jboss.cache.Cache;
+import org.jboss.cache.CacheFactory;
+import org.jboss.cache.CacheSPI;
+import org.jboss.cache.DefaultCacheFactory;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.Node;
+import org.jboss.cache.config.CacheLoaderConfig;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.loader.FileCacheLoaderConfig;
+import org.jboss.cache.search.SearchableCache;
+import org.jboss.cache.search.SearchableCacheFactory;
+import static org.testng.AssertJUnit.assertFalse;
+import static org.testng.AssertJUnit.assertTrue;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import java.io.Serializable;
+import java.util.List;
+import java.util.Properties;
+
+ at Test(groups = {"unit"}, sequential = true)
+public class IndexingInTransaction
+{
+
+   private static final Fqn fname = Fqn.fromString("blah");
+
+   private Cache coreCache;
+
+   private SearchableCache searchableCache;
+
+   Node node;
+
+   public IndexingInTransaction()
+   {
+      init();
+   }
+
+   @BeforeMethod
+   public void init()
+   {
+      CacheFactory factory = new DefaultCacheFactory();
+      Configuration c = new Configuration();
+      c.setInvocationBatchingEnabled(true);
+
+      CacheLoaderConfig clc = new CacheLoaderConfig();
+
+      FileCacheLoaderConfig fclc = new FileCacheLoaderConfig();
+      fclc.setAsync(false);
+      fclc.setFetchPersistentState(false);
+      fclc.setIgnoreModifications(false);
+      fclc.setPurgeOnStartup(true);
+      fclc.setLocation("/tmp/c1");
+
+      clc.addIndividualCacheLoaderConfig(fclc);
+      c.setCacheLoaderConfig(clc);
+
+      coreCache = factory.createCache(c, false);
+
+      SearchableCacheFactory f = new SearchableCacheFactory();
+      Properties p = new Properties();
+      p.put("hibernate.search.default.indexBase", "/tmp/c1idx");
+      p.put("hibernate.search.worker.batch_size", "1");
+      searchableCache = f.createSearchableCache(coreCache, p, Entity.class);
+      searchableCache.create();
+      searchableCache.start();
+      node = searchableCache.getRoot().addChild(fname);
+   }
+
+   @Test
+   public void testPutEntitiesWithoutTransaction()
+   {
+      for (int i = 1; i <= 10; i++)
+      {
+         Entity e = getEntity(i);
+         System.out.println("caching: " + e);
+         Node c = node.addChild(Fqn.fromString(e.getName()));
+         c.put("" + e.getId(), e);
+      }
+      assertFalse(searchableCache.createQuery(
+              Entity.searchByName("Name5")).list().isEmpty());
+   }
+
+   @Test
+   public void testPutEntitiesWithTransaction() throws Exception
+   {
+      ((CacheSPI) (coreCache)).getTransactionManager().begin();
+      for (int i = 15; i <= 15; i++)
+      {
+         Entity e = getEntity(i);
+         System.out.println("caching: " + e);
+         Node c = node.addChild(Fqn.fromString(e.getName()));
+         c.put("" + e.getId(), e);
+      }
+      ((CacheSPI) (coreCache)).getTransactionManager().commit();
+
+      assertFalse("there should be record for the name15",
+              searchableCache.createQuery(
+                      Entity.searchByName("Name15")).list().isEmpty());
+
+
+      searchableCache.removeNode(Fqn.fromString("Name15"));
+
+      List l = searchableCache.createQuery(Entity.searchByName("Name15")).list();
+      System.out.println(l.size());
+
+      System.out.println("Cache listeners are " + coreCache.getCacheListeners());
+      // bug: collection is not empty - there is null as there are inconsistencies in the indexes
+      assertTrue("there should be no record found", l.isEmpty());
+
+   }
+
+   Entity getEntity(long id)
+   {
+      return new Entity(id, "Name" + id, "Surname" + id, true);
+   }
+
+//    public static void main(String[] args) {
+//        IndexingInTransaction stb = new IndexingInTransaction();
+//        stb.init();
+//    }
+
+}
+
+ at ProvidedId
+ at Indexed
+class Entity implements Serializable
+{
+
+   public static final String IDX_NAME = "name";
+   public static final String IDX_SURNAME = "surname";
+
+   private long id;
+
+   @Field(store = Store.YES)
+   private String name;
+
+   @Field(store = Store.YES)
+   private String surname;
+
+   private boolean dead;
+
+   Entity(long id, String name, String surname, boolean dead)
+   {
+      this.id = id;
+      this.name = name;
+      this.surname = surname;
+      this.dead = dead;
+   }
+
+   public long getId()
+   {
+      return id;
+   }
+
+   public String getName()
+   {
+      return name;
+   }
+
+   public String getSurname()
+   {
+      return surname;
+   }
+
+   public boolean isDead()
+   {
+      return dead;
+   }
+
+   public static Query searchByName(String name)
+   {
+      BooleanQuery query = new BooleanQuery();
+      query.add(new TermQuery(
+              new Term(Entity.IDX_NAME,
+                      name.toLowerCase())),
+              BooleanClause.Occur.MUST);
+      return query;
+   }
+
+   @Override
+   public String toString()
+   {
+      return "Entity{" +
+              "id=" + id +
+              ", name='" + name + '\'' +
+              ", surname='" + surname + '\'' +
+              ", dead=" + dead +
+              '}';
+   }
+
+}
\ No newline at end of file

Added: branches/ISPN-32/query/src/test/java/org/infinispan/query/LazyQueryResultIteratorTest.java
===================================================================
--- branches/ISPN-32/query/src/test/java/org/infinispan/query/LazyQueryResultIteratorTest.java	                        (rev 0)
+++ branches/ISPN-32/query/src/test/java/org/infinispan/query/LazyQueryResultIteratorTest.java	2009-06-29 11:31:56 UTC (rev 503)
@@ -0,0 +1,285 @@
+package org.jboss.cache.search;
+
+import org.testng.annotations.*;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.queryParser.ParseException;
+import org.apache.lucene.queryParser.QueryParser;
+import org.apache.lucene.analysis.standard.StandardAnalyzer;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.Cache;
+import org.jboss.cache.DefaultCacheFactory;
+import org.jboss.cache.search.test.Person;
+import org.jboss.cache.search.helper.IndexCleanUp;
+
+
+/**
+ * @author Navin Surtani (<a href="mailto:nsurtani at redhat.com">nsurtani at redhat.com</a>)
+ */
+ at Test(groups = "functional")
+public class LazyQueryResultIteratorTest
+{
+   SearchableCache searchableCache;
+   QueryParser parser = null;
+   Query luceneQuery = null;
+   CacheQuery cacheQuery = null;
+   LazyQueryResultIterator iterator = null;
+   int fetchSize = 1;
+   Person person1, person2, person3, person4, person5, person6, person7, person8, person9, person10;
+   StringBuilder builder;
+
+
+   @BeforeTest
+   public void setUpBeforeTest() throws ParseException
+   {
+      Cache coreCache = new DefaultCacheFactory().createCache();
+      searchableCache = new SearchableCacheFactory().createSearchableCache(coreCache, Person.class);
+
+      person1 = new Person();
+      person2 = new Person();
+      person3 = new Person();
+      person4 = new Person();
+      person5 = new Person();
+      person6 = new Person();
+      person7 = new Person();
+      person8 = new Person();
+      person9 = new Person();
+      person10 = new Person();
+
+      person1.setBlurb("cat");
+      person2.setBlurb("cat");
+      person3.setBlurb("cat");
+      person4.setBlurb("cat");
+      person5.setBlurb("cat");
+      person6.setBlurb("cat");
+      person7.setBlurb("cat");
+      person8.setBlurb("cat");
+      person9.setBlurb("cat");
+      person10.setBlurb("cat");
+
+      searchableCache.put(Fqn.fromString("/a"), "key1", person1);
+      searchableCache.put(Fqn.fromString("/a"), "key2", person2);
+      searchableCache.put(Fqn.fromString("/a"), "key3", person3);
+      searchableCache.put(Fqn.fromString("/a"), "key4", person4);
+      searchableCache.put(Fqn.fromString("/a"), "key5", person5);
+      searchableCache.put(Fqn.fromString("/a"), "key6", person6);
+      searchableCache.put(Fqn.fromString("/a"), "key7", person7);
+      searchableCache.put(Fqn.fromString("/a"), "key8", person8);
+      searchableCache.put(Fqn.fromString("/a"), "key9", person9);
+      searchableCache.put(Fqn.fromString("/a"), "key10", person10);
+
+
+   }
+
+   @AfterTest
+   public void tearDownAfterTest()
+   {
+      IndexCleanUp.cleanUpIndexes();
+   }
+
+   @BeforeMethod
+   public void setUp() throws ParseException
+   {
+      parser = new QueryParser("blurb", new StandardAnalyzer());
+      luceneQuery = parser.parse("cat");
+      cacheQuery = searchableCache.createQuery(luceneQuery);
+      iterator = (LazyQueryResultIterator) cacheQuery.lazyIterator();
+
+   }
+
+
+   @AfterMethod
+   public void tearDown()
+   {
+      iterator = null;
+      parser = null;
+      luceneQuery = null;
+      cacheQuery = null;
+   }
+
+   public void testJumpToResult() throws IndexOutOfBoundsException
+   {
+      iterator.jumpToResult(0);
+      assert iterator.isFirst();
+
+      iterator.jumpToResult(1);
+      assert iterator.isAfterFirst();
+
+      iterator.jumpToResult(9);
+      assert iterator.isLast();
+
+      iterator.jumpToResult(8);
+      assert iterator.isBeforeLast();
+   }
+
+   public void testFirst()
+   {
+      assert iterator.isFirst() : "We should be pointing at the first element";
+      Object next = iterator.next();
+      assert next == person1;
+      assert !iterator.isFirst();
+
+      iterator.first();
+
+      assert iterator.isFirst() : "We should be pointing at the first element";
+      next = iterator.next();
+      assert next == person1;
+      assert !iterator.isFirst();
+
+   }
+
+   public void testLast()
+   {
+      //Jumps to the last element
+      iterator.last();
+
+      //Makes sure that the iterator is pointing at the last element.
+      assert iterator.isLast();
+
+      iterator.first();
+
+      //Check that the iterator is NOT pointing at the last element.
+      assert !iterator.isLast();
+   }
+
+   public void testAfterFirst()
+   {
+      //Jump to the second element.
+      iterator.afterFirst();
+
+      //Check this
+      assert iterator.isAfterFirst();
+
+      //Previous element in the list
+      Object previous = iterator.previous();
+
+      //Check that previous is the first element.
+      assert previous == person2;
+
+      //Make sure that the iterator isn't pointing at the second element.
+      assert !iterator.isAfterFirst();
+
+   }
+
+   public void testBeforeLast()
+   {
+      //Jump to the penultimate element.
+      iterator.beforeLast();
+
+      //Check this
+      assert iterator.isBeforeLast();
+
+      //Next element - which should be the last.
+      Object next = iterator.next();
+
+      //Check that next is the penultimate element.
+      assert next == person9;
+
+      //Make sure that the iterator is not pointing at the penultimate element.
+      assert !iterator.isBeforeLast();
+   }
+
+   public void testIsFirst()
+   {
+      iterator.first();
+      assert iterator.isFirst();
+
+      iterator.next();
+      assert !iterator.isFirst();
+   }
+
+   public void testIsLast()
+   {
+      iterator.last();
+      assert iterator.isLast();
+
+      iterator.previous();
+      assert !iterator.isLast();
+   }
+
+   public void testIsAfterFirst()
+   {
+      iterator.afterFirst();
+      assert iterator.isAfterFirst();
+
+      iterator.previous();
+      assert !iterator.isAfterFirst();
+   }
+
+   public void testIsBeforeLast()
+   {
+      iterator.beforeLast();
+      assert iterator.isBeforeLast();
+   }
+
+   public void testNextAndHasNext()
+   {
+      iterator.first();
+
+      // This is so that we can "rebuild" the keystring for the nextAndHasNext and the previousAndHasPrevious methods.
+      builder = new StringBuilder();
+
+      for (int i = 1; i <= 10; i++)
+      {
+         builder.delete(0, 4);      // In this case we know that there are 4 characters in this string. so each time we come into the loop we want to clear the builder.
+         builder.append("key");
+         builder.append(i);
+         String keyString = builder.toString();
+         Object expectedValue = searchableCache.get("/a", keyString);
+         assert iterator.hasNext(); // should have next as long as we are less than the number of elements.
+
+         Object next = iterator.next();
+
+         assert expectedValue == next; // tests next()
+     }
+      assert !iterator.hasNext(); // this should now NOT be true.
+   }
+
+   public void testPreviousAndHasPrevious()
+   {
+      iterator.last();
+
+      // This is so that we can "rebuild" the keystring for the nextAndHasNext and the previousAndHasPrevious methods.
+      builder = new StringBuilder();      
+
+      for (int i = 10; i >= 1; i--)
+      {
+         builder.delete(0, 5);      // In this case we know that there are 4 characters in this string. so each time we come into the loop we want to clear the builder.
+         builder.append("key");
+         builder.append(i);
+         String keyString = builder.toString();
+
+
+         Object expectedValue = searchableCache.get("/a", keyString);
+
+         assert iterator.hasPrevious(); // should have previous as long as we are less than the number of elements.
+
+         Object previous = iterator.previous();
+
+         assert expectedValue == previous; // tests previous()
+     }
+      assert !iterator.hasPrevious(); // this should now NOT be true.
+
+   }
+
+   public void testNextIndex()
+   {
+      iterator.first();
+      assert iterator.nextIndex() == 1;
+
+      iterator.last();
+      assert iterator.nextIndex() == 10; //Index will be the index of the last element + 1.
+
+   }
+
+   public void testPreviousIndex()
+   {
+      iterator.first();
+      assert iterator.previousIndex() == -1;
+
+      iterator.last();
+      assert iterator.previousIndex() == 8; //Index will be that of the last element - 1.
+   }
+
+}
+
+

Added: branches/ISPN-32/query/src/test/java/org/infinispan/query/LocalCacheProfilerTest.java
===================================================================
--- branches/ISPN-32/query/src/test/java/org/infinispan/query/LocalCacheProfilerTest.java	                        (rev 0)
+++ branches/ISPN-32/query/src/test/java/org/infinispan/query/LocalCacheProfilerTest.java	2009-06-29 11:31:56 UTC (rev 503)
@@ -0,0 +1,250 @@
+package org.jboss.cache.search.blackbox;
+
+import org.apache.lucene.analysis.standard.StandardAnalyzer;
+import org.apache.lucene.queryParser.ParseException;
+import org.apache.lucene.queryParser.QueryParser;
+import org.apache.lucene.queryParser.MultiFieldQueryParser;
+import org.apache.lucene.search.*;
+import org.apache.lucene.index.Term;
+import org.jboss.cache.Cache;
+import org.jboss.cache.DefaultCacheFactory;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.search.CacheQuery;
+import org.jboss.cache.search.QueryResultIterator;
+import org.jboss.cache.search.SearchableCache;
+import org.jboss.cache.search.SearchableCacheFactory;
+import org.jboss.cache.search.helper.IndexCleanUp;
+import org.jboss.cache.search.test.Person;
+import org.testng.annotations.*;
+
+import java.util.List;
+import java.util.Iterator;
+import java.io.File;
+
+/**
+ * @author Navin Surtani (<a href="mailto:nsurtani at redhat.com">nsurtani at redhat.com</a>)
+ */
+
+ at Test(groups = "functional", enabled = false)
+public class LocalCacheProfilerTest
+{
+   SearchableCache searchableCache;
+   Person person1;
+   Person person2;
+   Person person3;
+   Person person4;
+   Person person5;
+   Person person6;
+   QueryParser queryParser;
+   Query luceneQuery;
+   CacheQuery cacheQuery;
+   List found;
+   String key1 = "Navin";
+   String key2 = "BigGoat";
+   String key3 = "MiniGoat";
+
+   @BeforeTest
+   public void setUp()
+   {
+      Cache coreCache = new DefaultCacheFactory().createCache();
+      searchableCache = new SearchableCacheFactory().createSearchableCache(coreCache, Person.class);
+
+      person1 = new Person();
+      person1.setName("Navin Surtani");
+      person1.setBlurb("Likes playing WoW");
+
+      person2 = new Person();
+      person2.setName("Big Goat");
+      person2.setBlurb("Eats grass");
+
+      person3 = new Person();
+      person3.setName("Mini Goat");
+      person3.setBlurb("Eats cheese");
+
+      person5 = new Person();
+      person5.setName("Smelly Cat");
+      person5.setBlurb("Eats fish");
+
+      //Put the 3 created objects in the searchableCache.
+      searchableCache.put(Fqn.fromString("/a/b/c"), key1, person1);
+      searchableCache.put(Fqn.fromString("/a/b/d"), key2, person2);
+      searchableCache.put(Fqn.fromString("/a/b/c"), key3, person3);
+
+   }
+
+   @AfterTest
+   public void tearDown()
+   {
+      if (searchableCache != null) searchableCache.stop();
+      IndexCleanUp.cleanUpIndexes();
+   }
+
+   @Test (invocationCount = 200000, enabled = false)
+   public void testSimple() throws ParseException
+   {
+      queryParser = new QueryParser("blurb", new StandardAnalyzer());
+      luceneQuery = queryParser.parse("playing");
+      cacheQuery = searchableCache.createQuery(luceneQuery);
+
+      found = cacheQuery.list();
+
+      assert found.size() == 1;
+      assert found.get(0).equals(person1);
+   }
+
+   @Test (invocationCount = 200000, enabled = false)
+   public void testSimpleIterator() throws ParseException
+   {
+      queryParser = new QueryParser("blurb", new StandardAnalyzer());
+      luceneQuery = queryParser.parse("playing");
+      cacheQuery = searchableCache.createQuery(luceneQuery);
+
+      QueryResultIterator found = cacheQuery.iterator();
+
+      assert found.isFirst();
+      assert found.isLast();
+   }
+
+   @Test (invocationCount = 200000, enabled = false)
+   public void testMultipleResults() throws ParseException
+   {
+
+      queryParser = new QueryParser("name", new StandardAnalyzer());
+
+      luceneQuery = queryParser.parse("goat");
+      cacheQuery = searchableCache.createQuery(luceneQuery);
+      found = cacheQuery.list();
+
+      assert found.size() == 2;
+      assert found.get(0) == person2;
+      assert found.get(1) == person3;
+
+   }
+
+   @Test (invocationCount = 200000, enabled = false)
+   public void testModified() throws ParseException
+   {
+      queryParser = new QueryParser("blurb", new StandardAnalyzer());
+      luceneQuery = queryParser.parse("playing");
+      cacheQuery = searchableCache.createQuery(luceneQuery);
+
+      found = cacheQuery.list();
+
+      assert found.size() == 1;
+      assert found.get(0).equals(person1);
+
+      person1.setBlurb("Likes pizza");
+      searchableCache.put(Fqn.fromString("/a/b/c/"), key1, person1);
+
+      queryParser = new QueryParser("blurb", new StandardAnalyzer());
+      luceneQuery = queryParser.parse("pizza");
+      cacheQuery = searchableCache.createQuery(luceneQuery);
+
+      found = cacheQuery.list();
+
+      assert found.size() == 1;
+      assert found.get(0).equals(person1);
+   }
+
+   @Test (invocationCount = 200000, enabled = false)
+   public void testAdded() throws ParseException
+   {
+      queryParser = new QueryParser("name", new StandardAnalyzer());
+
+      luceneQuery = queryParser.parse("Goat");
+      cacheQuery = searchableCache.createQuery(luceneQuery);
+      found = cacheQuery.list();
+
+      assert found.size() == 2 : "Size of list should be 2";
+      assert found.contains(person2);
+      assert found.contains(person3);
+      assert !found.contains(person4) : "This should not contain object person4";
+
+      person4 = new Person();
+      person4.setName("Mighty Goat");
+      person4.setBlurb("Also eats grass");
+
+      searchableCache.put(Fqn.fromString("/r/a/m/"), "Ram", person4);
+
+      luceneQuery = queryParser.parse("Goat");
+      cacheQuery = searchableCache.createQuery(luceneQuery);
+      found = cacheQuery.list();
+
+      assert found.size() == 3 : "Size of list should be 3";
+      assert found.contains(person2);
+      assert found.contains(person3);
+      assert found.contains(person4) : "This should now contain object person4";
+   }
+
+   @Test (invocationCount = 200000, enabled = false)
+   public void testRemoved() throws ParseException
+   {
+      queryParser = new QueryParser("name", new StandardAnalyzer());
+
+      luceneQuery = queryParser.parse("Goat");
+      cacheQuery = searchableCache.createQuery(luceneQuery);
+      found = cacheQuery.list();
+
+      assert found.size() == 2;
+      assert found.contains(person2);
+      assert found.contains(person3) : "This should still contain object person3";
+
+      searchableCache.remove(Fqn.fromString("/a/b/c/"), key3);
+
+      luceneQuery = queryParser.parse("Goat");
+      cacheQuery = searchableCache.createQuery(luceneQuery);
+      found = cacheQuery.list();
+
+      assert found.size() == 1;
+      assert found.contains(person2);
+      assert !found.contains(person3) : "The search should not return person3";
+
+   }
+
+   @Test (invocationCount = 200000, enabled = false)
+   public void testSetSort() throws ParseException
+   {
+      person2.setAge(35);
+      person3.setAge(12);
+
+      Sort sort = new Sort("age");
+
+      queryParser = new QueryParser("name", new StandardAnalyzer());
+
+      luceneQuery = queryParser.parse("Goat");
+      cacheQuery = searchableCache.createQuery(luceneQuery);
+      found = cacheQuery.list();
+
+      assert found.size() == 2;
+
+      cacheQuery.setSort(sort);
+
+      found = cacheQuery.list();
+
+      assert found.size() == 2;
+      assert found.get(0).equals(person2);
+      assert found.get(1).equals(person3);
+   }
+
+   @Test (invocationCount = 200000, enabled = false)   
+   public void testSetFilter() throws ParseException
+   {
+      queryParser = new QueryParser("name", new StandardAnalyzer());
+
+      luceneQuery = queryParser.parse("goat");
+      cacheQuery = searchableCache.createQuery(luceneQuery);
+      found = cacheQuery.list();
+
+      assert found.size() == 2;
+
+      Filter filter = new PrefixFilter(new Term("blurb", "cheese"));
+
+      cacheQuery.setFilter(filter);
+
+      found = cacheQuery.list();
+
+      assert found.size() == 1;
+
+   }
+
+}

Added: branches/ISPN-32/query/src/test/java/org/infinispan/query/LocalCacheTest.java
===================================================================
--- branches/ISPN-32/query/src/test/java/org/infinispan/query/LocalCacheTest.java	                        (rev 0)
+++ branches/ISPN-32/query/src/test/java/org/infinispan/query/LocalCacheTest.java	2009-06-29 11:31:56 UTC (rev 503)
@@ -0,0 +1,256 @@
+package org.jboss.cache.search.blackbox;
+
+import org.apache.lucene.analysis.standard.StandardAnalyzer;
+import org.apache.lucene.queryParser.ParseException;
+import org.apache.lucene.queryParser.QueryParser;
+import org.apache.lucene.queryParser.MultiFieldQueryParser;
+import org.apache.lucene.search.*;
+import org.apache.lucene.index.Term;
+import org.jboss.cache.Cache;
+import org.jboss.cache.DefaultCacheFactory;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.search.CacheQuery;
+import org.jboss.cache.search.QueryResultIterator;
+import org.jboss.cache.search.SearchableCache;
+import org.jboss.cache.search.SearchableCacheFactory;
+import org.jboss.cache.search.helper.IndexCleanUp;
+import org.jboss.cache.search.test.Person;
+import org.testng.annotations.*;
+
+import java.util.List;
+import java.util.Iterator;
+import java.io.File;
+
+/**
+ * @author Navin Surtani (<a href="mailto:nsurtani at redhat.com">nsurtani at redhat.com</a>)
+ */
+
+ at Test(groups = "functional")
+public class LocalCacheTest
+{
+   SearchableCache searchableCache;
+   Person person1;
+   Person person2;
+   Person person3;
+   Person person4;
+   Person person5;
+   Person person6;
+   QueryParser queryParser;
+   Query luceneQuery;
+   CacheQuery cacheQuery;
+   List found;
+   String key1 = "Navin";
+   String key2 = "BigGoat";
+   String key3 = "MiniGoat";
+
+   @BeforeMethod
+   public void setUp()
+   {
+      Cache coreCache = new DefaultCacheFactory().createCache();
+      searchableCache = new SearchableCacheFactory().createSearchableCache(coreCache, Person.class);
+
+      person1 = new Person();
+      person1.setName("Navin Surtani");
+      person1.setBlurb("Likes playing WoW");
+
+      person2 = new Person();
+      person2.setName("Big Goat");
+      person2.setBlurb("Eats grass");
+
+      person3 = new Person();
+      person3.setName("Mini Goat");
+      person3.setBlurb("Eats cheese");
+
+      person5 = new Person();
+      person5.setName("Smelly Cat");
+      person5.setBlurb("Eats fish");
+
+      //Put the 3 created objects in the searchableCache.
+      searchableCache.put(Fqn.fromString("/a/b/c"), key1, person1);
+      searchableCache.put(Fqn.fromString("/a/b/d"), key2, person2);
+      searchableCache.put(Fqn.fromString("/a/b/c"), key3, person3);
+
+   }
+
+   @AfterMethod
+   public void tearDown()
+   {
+      if (searchableCache != null) searchableCache.stop();
+      IndexCleanUp.cleanUpIndexes();
+   }
+
+   public void testSimple() throws ParseException
+   {
+      queryParser = new QueryParser("blurb", new StandardAnalyzer());
+      luceneQuery = queryParser.parse("playing");
+      cacheQuery = searchableCache.createQuery(luceneQuery);
+
+      found = cacheQuery.list();
+
+      assert found.size() == 1;
+      assert found.get(0).equals(person1);
+   }
+
+   public void testSimpleIterator() throws ParseException
+   {
+      queryParser = new QueryParser("blurb", new StandardAnalyzer());
+      luceneQuery = queryParser.parse("playing");
+      cacheQuery = searchableCache.createQuery(luceneQuery);
+
+      QueryResultIterator found = cacheQuery.iterator();
+
+      assert found.isFirst();
+      assert found.isLast();
+   }
+
+   public void testMultipleResults() throws ParseException
+   {
+
+      queryParser = new QueryParser("name", new StandardAnalyzer());
+
+      luceneQuery = queryParser.parse("goat");
+      cacheQuery = searchableCache.createQuery(luceneQuery);
+      found = cacheQuery.list();
+
+      assert found.size() == 2;
+      assert found.get(0) == person2;
+      assert found.get(1) == person3;
+
+   }
+
+   public void testModified() throws ParseException
+   {
+      queryParser = new QueryParser("blurb", new StandardAnalyzer());
+      luceneQuery = queryParser.parse("playing");
+      cacheQuery = searchableCache.createQuery(luceneQuery);
+
+      found = cacheQuery.list();
+
+      assert found.size() == 1;
+      assert found.get(0).equals(person1);
+
+      person1.setBlurb("Likes pizza");
+      searchableCache.put(Fqn.fromString("/a/b/c/"), key1, person1);
+
+      queryParser = new QueryParser("blurb", new StandardAnalyzer());
+      luceneQuery = queryParser.parse("pizza");
+      cacheQuery = searchableCache.createQuery(luceneQuery);
+
+      found = cacheQuery.list();
+
+      assert found.size() == 1;
+      assert found.get(0).equals(person1);
+   }
+
+   public void testAdded() throws ParseException
+   {
+      queryParser = new QueryParser("name", new StandardAnalyzer());
+
+      luceneQuery = queryParser.parse("Goat");
+      cacheQuery = searchableCache.createQuery(luceneQuery);
+      found = cacheQuery.list();
+
+      assert found.size() == 2 : "Size of list should be 2";
+      assert found.contains(person2);
+      assert found.contains(person3);
+      assert !found.contains(person4) : "This should not contain object person4";
+
+      person4 = new Person();
+      person4.setName("Mighty Goat");
+      person4.setBlurb("Also eats grass");
+
+      searchableCache.put(Fqn.fromString("/r/a/m/"), "Ram", person4);
+
+      luceneQuery = queryParser.parse("Goat");
+      cacheQuery = searchableCache.createQuery(luceneQuery);
+      found = cacheQuery.list();
+
+      assert found.size() == 3 : "Size of list should be 3";
+      assert found.contains(person2);
+      assert found.contains(person3);
+      assert found.contains(person4) : "This should now contain object person4";
+   }
+
+   public void testRemoved() throws ParseException
+   {
+      queryParser = new QueryParser("name", new StandardAnalyzer());
+
+      luceneQuery = queryParser.parse("Goat");
+      cacheQuery = searchableCache.createQuery(luceneQuery);
+      found = cacheQuery.list();
+
+      assert found.size() == 2;
+      assert found.contains(person2);
+      assert found.contains(person3) : "This should still contain object person3";
+
+      searchableCache.remove(Fqn.fromString("/a/b/c/"), key3);
+
+      luceneQuery = queryParser.parse("Goat");
+      cacheQuery = searchableCache.createQuery(luceneQuery);
+      found = cacheQuery.list();
+
+      assert found.size() == 1;
+      assert found.contains(person2);
+      assert !found.contains(person3) : "The search should not return person3";
+
+
+   }
+
+   public void testSetSort() throws ParseException
+   {
+      person2.setAge(35);
+      person3.setAge(12);
+
+      Sort sort = new Sort("age");
+
+      queryParser = new QueryParser("name", new StandardAnalyzer());
+
+      luceneQuery = queryParser.parse("Goat");
+      cacheQuery = searchableCache.createQuery(luceneQuery);
+      found = cacheQuery.list();
+
+      assert found.size() == 2;
+
+      cacheQuery.setSort(sort);
+
+      found = cacheQuery.list();
+
+      assert found.size() == 2;
+      assert found.get(0).equals(person2);
+      assert found.get(1).equals(person3);
+   }
+
+   public void testSetFilter() throws ParseException
+   {
+      queryParser = new QueryParser("name", new StandardAnalyzer());
+
+      luceneQuery = queryParser.parse("goat");
+      cacheQuery = searchableCache.createQuery(luceneQuery);
+      found = cacheQuery.list();
+
+      assert found.size() == 2;
+
+      Filter filter = new PrefixFilter(new Term("blurb", "cheese"));
+
+      cacheQuery.setFilter(filter);
+
+      found = cacheQuery.list();
+
+      assert found.size() == 1;
+
+   }
+
+   public void testLazyIterator() throws ParseException
+   {
+      queryParser = new QueryParser("blurb", new StandardAnalyzer());
+      luceneQuery = queryParser.parse("playing");
+      cacheQuery = searchableCache.createQuery(luceneQuery);
+
+      QueryResultIterator found = cacheQuery.lazyIterator();
+
+      assert found.isFirst();
+      assert found.isLast();
+
+   }
+
+}

Added: branches/ISPN-32/query/src/test/java/org/infinispan/query/LocalPOJOCacheTest.java
===================================================================
--- branches/ISPN-32/query/src/test/java/org/infinispan/query/LocalPOJOCacheTest.java	                        (rev 0)
+++ branches/ISPN-32/query/src/test/java/org/infinispan/query/LocalPOJOCacheTest.java	2009-06-29 11:31:56 UTC (rev 503)
@@ -0,0 +1,213 @@
+package org.jboss.cache.search.blackbox;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.lucene.analysis.standard.StandardAnalyzer;
+import org.apache.lucene.queryParser.ParseException;
+import org.apache.lucene.queryParser.QueryParser;
+import org.apache.lucene.search.Query;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.pojo.PojoCache;
+import org.jboss.cache.pojo.PojoCacheFactory;
+import org.jboss.cache.search.CacheQuery;
+import org.jboss.cache.search.SearchableCache;
+import org.jboss.cache.search.SearchableCacheFactory;
+import org.jboss.cache.search.QueryResultIterator;
+import org.jboss.cache.search.helper.IndexCleanUp;
+import org.jboss.cache.search.test.Person;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import java.util.*;
+
+/**
+ * Same as LocalCacheTest except that you will use a POJO Cache instead and use pojoCache.attach() ad pojoCache.detach()
+ * instead of cache.put() and cache.remove().
+ * <p/>
+ *
+ * @author Navin Surtani (<a href="mailto:nsurtani at redhat.com">nsurtani at redhat.com</a>)
+ */
+
+ at Test(groups = "functional", enabled = false)
+public class LocalPOJOCacheTest
+{
+   SearchableCache searchableCache;
+   PojoCache pojo;
+   Person person1;
+   Person person2;
+   Person person3;
+   Person person4;
+   QueryParser queryParser;
+   Query luceneQuery;
+   CacheQuery cacheQuery;
+   List found;
+   private static final Log log = LogFactory.getLog(LocalPOJOCacheTest.class);
+
+
+   @BeforeMethod
+   public void setUp()
+   {
+      boolean toStart = false;
+      pojo = PojoCacheFactory.createCache(new Configuration(), toStart);
+      pojo.start(); // if toStart above is true, it will starts the cache automatically.
+      searchableCache = new SearchableCacheFactory().createSearchableCache(pojo, Person.class);
+
+      person1 = new Person();
+      person1.setName("Navin Surtani");
+      person1.setBlurb("Likes playing WoW");
+
+      person2 = new Person();
+      person2.setName("BigGoat");
+      person2.setBlurb("Eats grass");
+
+      person3 = new Person();
+      person3.setName("MiniGoat");
+      person3.setBlurb("Eats cheese");
+
+//      pojo.attach("/a", person1);
+//      pojo.attach("/b", person2);
+//      pojo.attach("/c", person3);
+
+
+   }
+
+   @AfterMethod
+   public void tearDown()
+   {
+      if (pojo != null) pojo.stop();
+      if (searchableCache != null) searchableCache.stop();
+      IndexCleanUp.cleanUpIndexes();
+   }
+
+   public void testSimple() throws ParseException
+   {
+      queryParser = new QueryParser("blurb", new StandardAnalyzer());
+      luceneQuery = queryParser.parse("eats");
+      cacheQuery = searchableCache.createQuery(luceneQuery);
+
+      found = cacheQuery.list();
+
+      assert found.size() == 2;
+   }
+
+   public void testMultipleResults() throws ParseException
+   {
+      queryParser = new QueryParser("blurb", new StandardAnalyzer());
+      luceneQuery = queryParser.parse("Eats");
+      cacheQuery = searchableCache.createQuery(luceneQuery);
+      found = cacheQuery.list();
+
+      System.out.println("size is " + found.size());
+      assert found.size() == 2;
+
+      System.out.println("object 0 is " + found.get(0));
+      System.out.println("object 1 is " + found.get(1));
+      assert !found.get(1).equals(person2);
+      assert !found.get(0).equals(person3);
+
+   }
+
+   public void testModified() throws ParseException
+   {
+      queryParser = new QueryParser("blurb", new StandardAnalyzer());
+      luceneQuery = queryParser.parse("playing");
+      cacheQuery = searchableCache.createQuery(luceneQuery);
+
+      found = cacheQuery.list();
+
+      assert found.size() == 1;
+//      assert found.get(0).equals(person1);
+
+      person1.setBlurb("Likes pizza");
+
+      pojo.attach(Fqn.fromString("/a/b/c/"), person1);
+
+      queryParser = new QueryParser("blurb", new StandardAnalyzer());
+      luceneQuery = queryParser.parse("pizza");
+      cacheQuery = searchableCache.createQuery(luceneQuery);
+
+      found = cacheQuery.list();
+
+      assert found.size() == 1;
+//      assert found.get(0).equals(person1);
+   }
+
+   public void testAdded() throws ParseException
+   {
+      queryParser = new QueryParser("blurb", new StandardAnalyzer());
+      luceneQuery = queryParser.parse("eats");
+      cacheQuery = searchableCache.createQuery(luceneQuery);
+      found = cacheQuery.list();
+
+      assert found.size() == 2 : "Size of list should be 2";
+      assert found.contains(person2);
+      assert found.contains(person3);
+      assert !found.contains(person4) : "This should not contain object person4";
+
+      person4 = new Person();
+      person4.setName("MightyGoat");
+      person4.setBlurb("Also eats grass");
+
+      pojo.attach(Fqn.fromString("/d/"), person4);
+
+      luceneQuery = queryParser.parse("eats");
+      cacheQuery = searchableCache.createQuery(luceneQuery);
+      found = cacheQuery.list();
+
+      assert found.size() == 3 : "Size of list should be 3";
+      assert found.contains(person2);
+      assert found.contains(person3);
+      assert found.contains(person4) : "This should now contain object person4";
+   }
+
+   public void testRemoved() throws ParseException
+   {
+      queryParser = new QueryParser("blurb", new StandardAnalyzer());
+      luceneQuery = queryParser.parse("eats");
+      cacheQuery = searchableCache.createQuery(luceneQuery);
+      found = cacheQuery.list();
+
+      assert found.size() == 2;
+      assert found.contains(person3);
+      assert found.contains(person2) : "This should still contain object person2";
+
+      pojo.detach("/b");
+
+      luceneQuery = queryParser.parse("eats");
+      cacheQuery = searchableCache.createQuery(luceneQuery);
+      found = cacheQuery.list();
+
+      assert found.size() == 1;
+      assert found.contains(person3);
+      assert !found.contains(person2) : "The search should not return person2";
+
+
+   }
+
+   public void testListAdded() throws ParseException
+   {
+      List<Person> objectsToAdd = new ArrayList<Person>();
+
+      objectsToAdd.add(person1);
+      objectsToAdd.add(person2);
+      objectsToAdd.add(person3);
+
+      pojo.attach(Fqn.fromString("/d"), objectsToAdd);
+
+      queryParser = new QueryParser("blurb", new StandardAnalyzer());
+      luceneQuery = queryParser.parse("eats");
+      cacheQuery = searchableCache.createQuery(luceneQuery);
+
+      found = cacheQuery.list();
+
+      System.out.println("Size of found is " + found.size());
+
+      System.out.println(pojo.find(Fqn.fromString("/d")));
+   }
+
+}
+
+
+

Added: branches/ISPN-32/query/src/test/java/org/infinispan/query/NodeModifiedTransactionContextTest.java
===================================================================
--- branches/ISPN-32/query/src/test/java/org/infinispan/query/NodeModifiedTransactionContextTest.java	                        (rev 0)
+++ branches/ISPN-32/query/src/test/java/org/infinispan/query/NodeModifiedTransactionContextTest.java	2009-06-29 11:31:56 UTC (rev 503)
@@ -0,0 +1,21 @@
+package org.jboss.cache.search;
+
+import org.testng.annotations.Test;
+
+/**
+ * @author Navin Surtani (<a href="mailto:nsurtani at redhat.com">nsurtani at redhat.com</a>)
+ */
+
+ at Test
+public class NodeModifiedTransactionContextTest
+{
+
+   @Test (expectedExceptions = NullPointerException.class)
+   public void nullConstuctor()
+   {
+      TransactionalEventTransactionContext nmtc = new TransactionalEventTransactionContext(null);
+   }
+
+
+
+}

Added: branches/ISPN-32/query/src/test/java/org/infinispan/query/NodeRemovedTest.java
===================================================================
--- branches/ISPN-32/query/src/test/java/org/infinispan/query/NodeRemovedTest.java	                        (rev 0)
+++ branches/ISPN-32/query/src/test/java/org/infinispan/query/NodeRemovedTest.java	2009-06-29 11:31:56 UTC (rev 503)
@@ -0,0 +1,88 @@
+package org.jboss.cache.search.blackbox;
+
+import org.apache.lucene.analysis.standard.StandardAnalyzer;
+import org.apache.lucene.queryParser.ParseException;
+import org.apache.lucene.queryParser.QueryParser;
+import org.apache.lucene.search.Query;
+import org.jboss.cache.Cache;
+import org.jboss.cache.CacheSPI;
+import org.jboss.cache.DefaultCacheFactory;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.search.SearchableCache;
+import org.jboss.cache.search.SearchableCacheFactory;
+import org.jboss.cache.search.test.Person;
+import org.jboss.cache.transaction.DummyTransactionManagerLookup;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import javax.transaction.TransactionManager;
+import java.util.List;
+
+/**
+ * @author Navin Surtani (<a href="mailto:nsurtani at redhat.com">nsurtani at redhat.com</a>)
+ */
+
+ at Test
+public class NodeRemovedTest
+{
+   Person p1 = new Person();
+   SearchableCache searchableCache;
+   TransactionManager tm;
+
+   @BeforeMethod
+   public void setUp()
+   {
+      p1.setName("Cat");
+      p1.setBlurb("Smelly");
+      p1.setAge(12);
+
+      Configuration cfg = new Configuration();
+      cfg.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
+      Cache cache = new DefaultCacheFactory().createCache(cfg, true);
+      tm = ((CacheSPI) cache).getTransactionManager();
+      searchableCache = new SearchableCacheFactory().createSearchableCache(cache, Person.class);
+
+   }
+
+   public void testRemoveNode() throws ParseException
+   {
+      searchableCache.put("/a", "key", p1);
+
+      QueryParser parser = new QueryParser("name", new StandardAnalyzer());
+      Query luceneQuery = parser.parse("cat");
+      List found = searchableCache.createQuery(luceneQuery, Person.class).list();
+
+      assert found.size() == 1;
+
+      searchableCache.removeNode("/a");
+
+      parser = new QueryParser("name", new StandardAnalyzer());
+      luceneQuery = parser.parse("cat");
+      found = searchableCache.createQuery(luceneQuery, Person.class).list();
+
+      assert found.size() == 0;
+   }
+
+   public void testRemoveNodeWithTx() throws Exception
+   {
+      tm.begin();
+      searchableCache.put("/a", "key", p1);
+      tm.commit();
+
+      QueryParser parser = new QueryParser("name", new StandardAnalyzer());
+      Query luceneQuery = parser.parse("cat");
+      List found = searchableCache.createQuery(luceneQuery, Person.class).list();
+
+      assert found.size() == 1;
+
+      tm.begin();
+      searchableCache.removeNode("/a");
+      tm.commit();
+
+      parser = new QueryParser("name", new StandardAnalyzer());
+      luceneQuery = parser.parse("cat");
+      found = searchableCache.createQuery(luceneQuery, Person.class).list();
+
+      assert found.size() == 0;
+   }
+}

Added: branches/ISPN-32/query/src/test/java/org/infinispan/query/Person.java
===================================================================
--- branches/ISPN-32/query/src/test/java/org/infinispan/query/Person.java	                        (rev 0)
+++ branches/ISPN-32/query/src/test/java/org/infinispan/query/Person.java	2009-06-29 11:31:56 UTC (rev 503)
@@ -0,0 +1,86 @@
+package org.jboss.cache.search.test;
+
+
+import org.hibernate.search.annotations.*;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.io.Serializable;
+
+/**
+ * @author Navin Surtani (<a href="mailto:nsurtani at redhat.com">nsurtani at redhat.com</a>)
+ */
+ at ProvidedId
+ at Indexed
+public class Person implements Serializable
+{
+   private static final Log log = LogFactory.getLog(Person.class);
+
+
+   @Field (store = Store.YES)
+   private String name;
+   @Field (store = Store.YES)
+   private String blurb;
+   @Field (store = Store.YES, index = Index.UN_TOKENIZED )
+   private int age;
+
+   public String getName()
+   {
+      return name;
+   }
+
+   public void setName(String name)
+   {
+      this.name = name;
+   }
+
+   public String getBlurb()
+   {
+      return blurb;
+   }
+
+   public void setBlurb(String blurb)
+   {
+      this.blurb = blurb;
+   }
+
+   public int getAge()
+   {
+      return age;
+   }
+
+   public void setAge(int age)
+   {
+      this.age = age;
+   }
+
+   public boolean equals(Object o)
+   {
+      if (this == o) return true;
+      if (o == null || getClass() != o.getClass()) return false;
+
+      Person person = (Person) o;
+
+      if (blurb != null ? !blurb.equals(person.blurb) : person.blurb != null) return false;
+      if (name != null ? !name.equals(person.name) : person.name != null) return false;
+
+      return true;
+   }
+
+   public int hashCode()
+   {
+      int result;
+      result = (name != null ? name.hashCode() : 0);
+      result = 31 * result + (blurb != null ? blurb.hashCode() : 0);
+      return result;
+   }
+
+
+   public String toString()
+   {
+      return "Person{" +
+              "name='" + name + '\'' +
+              ", blurb='" + blurb + '\'' +
+              '}';
+   }
+}

Added: branches/ISPN-32/query/src/test/java/org/infinispan/query/QueryResultIteratorImplTest.java
===================================================================
--- branches/ISPN-32/query/src/test/java/org/infinispan/query/QueryResultIteratorImplTest.java	                        (rev 0)
+++ branches/ISPN-32/query/src/test/java/org/infinispan/query/QueryResultIteratorImplTest.java	2009-06-29 11:31:56 UTC (rev 503)
@@ -0,0 +1,267 @@
+package org.jboss.cache.search;
+
+import org.jboss.cache.Fqn;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author Navin Surtani (<a href="mailto:nsurtani at redhat.com">nsurtani at redhat.com</a>)
+ *         <p/>
+ *         Test class for the QueryResultIteratorImpl
+ */
+
+ at Test(groups = "functional")
+public class QueryResultIteratorImplTest
+{
+   List<EntityId> ids;
+   Map<EntityId, Object> dummyResults;
+   QueryResultIterator iterator;
+   int fetchSize = 1;
+
+   @BeforeMethod
+   public void setUp() throws InvalidKeyException
+   {
+      // 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"));
+
+      // create some dummy data
+      dummyResults = new HashMap<EntityId, Object>();
+      int counter = 0;
+
+      for (EntityId 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, fetchSize);
+   }
+
+   @AfterMethod
+   public void tearDown()
+   {
+      ids = null;
+      dummyResults = null;
+      iterator = null;
+   }
+
+   public void testJumpToResult() throws IndexOutOfBoundsException
+   {
+      iterator.jumpToResult(0);
+      assert iterator.isFirst();
+
+      iterator.jumpToResult(1);
+      assert iterator.isAfterFirst();
+
+      iterator.jumpToResult((ids.size() - 1));
+      assert iterator.isLast();
+
+      iterator.jumpToResult(ids.size() - 2);
+      assert iterator.isBeforeLast();
+   }
+
+   public void testFirst()
+   {
+      assert iterator.isFirst() : "We should be pointing at the first element";
+      Object next = iterator.next();
+      assert next == dummyResults.get(ids.get(0));
+      assert !iterator.isFirst();
+
+      iterator.first();
+
+      assert iterator.isFirst() : "We should be pointing at the first element";
+      next = iterator.next();
+      assert next == dummyResults.get(ids.get(0));
+      assert !iterator.isFirst();
+
+   }
+
+   public void testLast()
+   {
+      //Jumps to the last element
+      iterator.last();
+
+      //Makes sure that the iterator is pointing at the last element.
+      assert iterator.isLast();
+
+      Object next = iterator.next();
+
+      //Returns the size of the list of ids.
+      int size = ids.size();
+
+      //Makes sure that previous is the last element.
+      assert next == dummyResults.get(ids.get(size - 1));
+
+      //Check that the iterator is NOT pointing at the last element.
+      assert !iterator.isLast();
+   }
+
+   public void testAfterFirst()
+   {
+      //Jump to the second element.
+      iterator.afterFirst();
+
+      //Check this
+      assert iterator.isAfterFirst();
+
+      //Previous element in the list
+      Object previous = iterator.previous();
+
+      //Check that previous is the first element.
+      assert previous == dummyResults.get(ids.get(1));
+
+      //Make sure that the iterator isn't pointing at the second element.
+      assert !iterator.isAfterFirst();
+
+   }
+
+   public void testBeforeLast()
+   {
+      //Jump to the penultimate element.
+      iterator.beforeLast();
+
+      //Check this
+      assert iterator.isBeforeLast();
+
+      //Next element - which should be the last.
+      Object next = iterator.next();
+
+      //Check that next is the penultimate element.
+      int size = ids.size();
+      assert next == dummyResults.get(ids.get(size - 2));
+
+      //Make sure that the iterator is not pointing at the penultimate element.
+      assert !iterator.isBeforeLast();
+   }
+
+   public void testIsFirst()
+   {
+      iterator.first();
+      assert iterator.isFirst();
+
+      iterator.next();
+      assert !iterator.isFirst();
+   }
+
+   public void testIsLast()
+   {
+      iterator.last();
+      assert iterator.isLast();
+
+      iterator.previous();
+      assert !iterator.isLast();
+   }
+
+   public void testIsAfterFirst()
+   {
+      iterator.afterFirst();
+      assert iterator.isAfterFirst();
+
+      iterator.previous();
+      assert !iterator.isAfterFirst();
+   }
+
+   public void testIsBeforeLast()
+   {
+      iterator.beforeLast();
+      assert iterator.isBeforeLast();
+   }
+
+   public void testNextAndHasNext()
+   {
+      iterator.first();
+      for (int i = 0; i < ids.size(); i++)
+      {
+         System.out.println("Loop number count: - " + (i + 1));
+         Object expectedValue = dummyResults.get(ids.get(i));
+         assert iterator.hasNext(); // should have next as long as we are less than the number of elements.
+         assert expectedValue == iterator.next(); // tests next()
+      }
+      assert !iterator.hasNext(); // this should now NOT be true.
+   }
+
+   public void testPreviousAndHasPrevious()
+   {
+      iterator.last();
+      for (int i = ids.size() - 1; i >= 0; i--)
+      {
+         Object expectedValue = dummyResults.get(ids.get(i));
+         assert iterator.hasPrevious(); // should have previous as long as we are more than the number of elements.
+         assert expectedValue == iterator.previous(); // tests previous()
+      }
+      assert !iterator.hasPrevious(); // this should now NOT be true.
+
+   }
+
+   public void testNextIndex()
+   {
+      iterator.first();
+      assert iterator.nextIndex() == 1;
+
+      iterator.last();
+      assert iterator.nextIndex() == ids.size();
+
+   }
+
+   public void testPreviousIndex()
+   {
+      iterator.first();
+      assert iterator.previousIndex() == -1;
+
+      iterator.last();
+      assert iterator.previousIndex() == (ids.size() - 2);
+   }
+
+   public static class DummyEntityLoader extends CacheEntityLoader
+   {
+      private List<EntityId> allKnownIds;
+      private Map<EntityId, Object> dummyValues;
+
+      public DummyEntityLoader(List<EntityId> allKnownIds, Map<EntityId, 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 <EntityId> ids)
+      {
+         List<Object> resultsToReturn = new ArrayList<Object>(ids.size());
+         // iterate through the list of ids we are looking for
+         for (EntityId id : ids)
+         {
+            resultsToReturn.add(dummyValues.get(id));
+         }
+
+         return resultsToReturn;
+      }
+
+      @Override
+      public Object load(EntityId id)
+      {
+         return dummyValues.get(id);
+      }
+   }
+}

Added: branches/ISPN-32/query/src/test/java/org/infinispan/query/SearchableCacheFactoryTest.java
===================================================================
--- branches/ISPN-32/query/src/test/java/org/infinispan/query/SearchableCacheFactoryTest.java	                        (rev 0)
+++ branches/ISPN-32/query/src/test/java/org/infinispan/query/SearchableCacheFactoryTest.java	2009-06-29 11:31:56 UTC (rev 503)
@@ -0,0 +1,44 @@
+package org.jboss.cache.search;
+
+import org.testng.annotations.Test;
+import org.jboss.cache.Cache;
+import org.jboss.cache.DefaultCacheFactory;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.pojo.PojoCacheFactory;
+import org.jboss.cache.pojo.PojoCache;
+
+/**
+ * @author Navin Surtani (<a href="mailto:nsurtani at redhat.com">nsurtani at redhat.com</a>)
+ *
+ * Test class for the SearchableCacheFactory.
+ */
+
+ at Test (groups = "functional")
+public class SearchableCacheFactoryTest
+{
+
+   @Test (expectedExceptions = IllegalArgumentException.class)
+   public void testCreateSearchableCacheWithZeroArray()
+   {
+      Class[] fakeClasses = new Class[0];
+      
+      Cache coreCache = new DefaultCacheFactory().createCache();
+      SearchableCache searchableCache = new SearchableCacheFactory().createSearchableCache(coreCache, null, fakeClasses);
+      
+   }
+
+   @Test (expectedExceptions = IllegalArgumentException.class)
+   public void testCreateSearchableCacheWithZeroArrayPojo()
+   {
+      Class[] fakeClasses = new Class[0];
+      boolean toStart = false;
+      PojoCache pojo = PojoCacheFactory.createCache(new Configuration(), toStart);
+      pojo.start(); // if toStart above is true, it will starts the cache automatically.
+
+      SearchableCache searchableCache = new SearchableCacheFactory().createSearchableCache(pojo, null, fakeClasses);
+
+   }
+
+
+
+}

Added: branches/ISPN-32/query/src/test/java/org/infinispan/query/SearchableCacheImplTest.java
===================================================================
--- branches/ISPN-32/query/src/test/java/org/infinispan/query/SearchableCacheImplTest.java	                        (rev 0)
+++ branches/ISPN-32/query/src/test/java/org/infinispan/query/SearchableCacheImplTest.java	2009-06-29 11:31:56 UTC (rev 503)
@@ -0,0 +1,28 @@
+package org.jboss.cache.search;
+
+import org.testng.annotations.Test;
+import org.jboss.cache.Cache;
+import org.jboss.cache.DefaultCacheFactory;
+
+/**
+ * @author Navin Surtani (<a href="mailto:nsurtani at redhat.com">nsurtani at redhat.com</a>)
+ */
+
+ at Test (groups = "functional")
+public class SearchableCacheImplTest
+{
+
+   @Test (expectedExceptions = NullPointerException.class)
+   public void testConstructorWithNullCache()
+   {
+      SearchableCacheImpl nullCache = new SearchableCacheImpl(null, null);
+      
+   }
+
+   @Test (expectedExceptions = NullPointerException.class)
+   public void testConstructorWithNullSearchFactory()
+   {
+      Cache cache = new DefaultCacheFactory().createCache();
+      SearchableCacheImpl nullSearchFactory = new SearchableCacheImpl(cache, null);
+   }
+}

Added: branches/ISPN-32/query/src/test/java/org/infinispan/query/TransformerTest.java
===================================================================
--- branches/ISPN-32/query/src/test/java/org/infinispan/query/TransformerTest.java	                        (rev 0)
+++ branches/ISPN-32/query/src/test/java/org/infinispan/query/TransformerTest.java	2009-06-29 11:31:56 UTC (rev 503)
@@ -0,0 +1,110 @@
+package org.jboss.cache.search;
+
+import org.jboss.cache.Fqn;
+import org.testng.annotations.Test;
+
+/**
+ * @author Navin Surtani (<a href="mailto:nsurtani at redhat.com">nsurtani at redhat.com</a>)
+ *         <p/>
+ *         Unit-test class for the Transformer class.
+ */
+
+ at Test(groups = "functional")
+public class TransformerTest
+
+{
+   /**
+    * Tests the generateId method.
+    */
+
+   public void testGenerateId() throws InvalidKeyException
+   {
+
+      Fqn fqn = Fqn.fromString("/a/b/c");
+      String key = "key";
+
+      String generatedId = Transformer.generateId(fqn, key);
+
+      assert generatedId.contentEquals("Fqn=[/a/b/c]Key=[key]");
+
+      assert !generatedId.contentEquals("/ab/c/d");
+   }
+
+   /**
+    * Tests the getFqn method.
+    */
+   public void testGetFqn()
+   {
+      Fqn fqn = Transformer.getFqn("Fqn=[/cat/dog/person]Key=[key]");
+
+      Fqn expectedFqn = Fqn.fromString("/cat/dog/person");
+
+      assert fqn.equals(expectedFqn);
+
+      expectedFqn = Fqn.fromString("/dog/cat/person");
+
+      assert !fqn.equals(expectedFqn);
+
+   }
+
+   /**
+    * Tests the getKey method.
+    */
+   public void testGetKey()
+   {
+      String key = Transformer.getKey("Fqn=[/a/b/c]Key=[thisIsMyKey]");
+
+      assert key.contentEquals("thisIsMyKey");
+
+      assert !key.contentEquals("thisIsNotMyKey");
+
+   }
+
+   @Test(expectedExceptions = NullPointerException.class)
+   public void testGetKeyWithNull()
+   {
+      Transformer.getKey(null);
+   }
+
+   @Test(expectedExceptions = InvalidFqnException.class)
+   public void testGenerateIdWithHackedString() throws InvalidKeyException
+   {
+      Transformer.generateId(Fqn.fromString("/Fqn=[/a/b/c"), "x");
+   }
+
+   @Test(expectedExceptions = InvalidFqnException.class)
+   public void testGenerateIdWithHackedFqn() throws InvalidKeyException
+   {
+      Transformer.generateId(Fqn.fromString("/Fqn=[/a/b/c"), "x");
+   }
+
+   @Test(expectedExceptions = InvalidFqnException.class)
+   public void testGenerateIdWithHackedFqn2() throws InvalidKeyException
+   {
+      Transformer.generateId(Fqn.fromString("/]Key=[/a/b/c"), "x");
+   }
+
+   @Test(expectedExceptions = InvalidKeyException.class)
+   public void testGenerateIdWithHackedKey() throws InvalidKeyException
+   {
+      Transformer.generateId(Fqn.fromString("/a/b/c"), "]Key=[");
+   }
+
+   @Test(expectedExceptions = InvalidKeyException.class)
+   public void testGenerateIdWithHackedKey2() throws InvalidKeyException
+   {
+      Transformer.generateId(Fqn.fromString("/a/b/c"), "Fqn=[");
+   }
+
+   @Test(expectedExceptions = NullPointerException.class)
+   public void testGenerateIdWithNullKey() throws InvalidKeyException
+   {
+      Transformer.generateId(Fqn.fromString("/a/b/c"), null);
+   }
+
+   @Test(expectedExceptions = NullPointerException.class)
+   public void testGenerateIdWithNullFqn() throws InvalidKeyException
+   {
+      Transformer.generateId(null, "x");
+   }
+}




More information about the infinispan-commits mailing list