package org.jboss.cache.aop.collection;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.aop.PojoCache;
import org.jboss.cache.PropertyConfigurator;
import org.jboss.cache.Fqn;

import java.util.List;
import java.util.ArrayList;

//import org.jboss.test.JBossTestCase;


/**
 * List implementation testing.
 */

public class CachedListImplAopTest extends TestCase
{
   Log log=LogFactory.getLog(CachedListImplAopTest.class);
   PojoCache cache_, cache1_;

   public CachedListImplAopTest(String name)
   {
      super(name);
   }

   protected void setUp() throws Exception
   {
      super.setUp();
      log.info("setUp() ....");
      String configFile = "META-INF/replSync-service.xml";
      cache_ = new PojoCache();
      PropertyConfigurator config = new PropertyConfigurator();
      config.configure(cache_, configFile); // read in generic replSync xml
      cache_.start();

      cache1_ = new PojoCache();
      config = new PropertyConfigurator();
      config.configure(cache1_, configFile); // read in generic replSync xml
      cache1_.start();
   }

   protected void tearDown() throws Exception
   {
      super.tearDown();
      cache_.stop();
   }

   public void testDummy()
   {

   }

   public void testSimpleRepl() throws Exception
   {
      List list = new ArrayList();
      list.add("1");
      list.add("2");

      cache_.putObject("/list", list);

      // proxy now
      list = (List)cache_.getObject("/list");

      // test repl
//      cache_.put(Fqn.fromString("/test"), "1", list);

      ArrayList l1 = (ArrayList)cache1_.get(Fqn.fromString("test"), "1");
      System.out.println(" list : " +l1);
   }

   public static Test suite() throws Exception
   {
      return new TestSuite(CachedListImplAopTest.class);
   }

   public static void main(String[] args) throws Exception
   {
      junit.textui.TestRunner.run(suite());
   }

}

