[jboss-cvs] JBossCache/tests/functional/org/jboss/cache/pojo/notification ...

Jason Thomas Greene jgreene at jboss.com
Thu Jun 7 01:50:21 EDT 2007


  User: jgreene 
  Date: 07/06/07 01:50:20

  Added:       tests/functional/org/jboss/cache/pojo/notification         
                        ListTest.java Listener.java MapTest.java
                        ObjectTest.java ReplicatedListTest.java
                        ReplicatedMapTest.java ReplicatedObjectTest.java
                        ReplicatedSetTest.java SetTest.java
  Log:
  Add more thorough test coverage of notifications
  
  Revision  Changes    Path
  1.1      date: 2007/06/07 05:50:20;  author: jgreene;  state: Exp;JBossCache/tests/functional/org/jboss/cache/pojo/notification/ListTest.java
  
  Index: ListTest.java
  ===================================================================
  /*
  * JBoss, Home of Professional Open Source
  * Copyright 2005, JBoss Inc., and individual contributors as indicated
  * by the @authors tag. See the copyright.txt in the distribution for a
  * full listing of individual contributors.
  *
  * This 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 software 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 software; if not, write to the Free
  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
  package org.jboss.cache.pojo.notification;
  
  import java.util.ArrayList;
  import java.util.List;
  
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  
  import org.jboss.cache.pojo.PojoCache;
  import org.jboss.cache.pojo.PojoCacheFactory;
  import org.jboss.cache.pojo.notification.AttachNotification;
  import org.jboss.cache.pojo.notification.DetachNotification;
  import org.jboss.cache.pojo.notification.ListModifyNotification;
  import org.jboss.cache.pojo.notification.Notification;
  import org.jboss.cache.pojo.test.Person;
  
  //$Id: ListTest.java,v 1.1 2007/06/07 05:50:20 jgreene Exp $
  
  /**
   * Tests list notifications
   *
   * @author Jason T. Greene
   */
  public class ListTest extends TestCase
  {
     protected PojoCache cache;
     protected Listener listener = new Listener();
  
     public ListTest(String name)
     {
        super(name);
     }
  
     protected void setUp() throws Exception
     {
        super.setUp();
        String configFile = "META-INF/local-service.xml";
        boolean toStart = false;
        cache = PojoCacheFactory.createCache(configFile, toStart);
        cache.start();
        cache.addListener(listener);
     }
  
     protected void tearDown() throws Exception
     {
        super.tearDown();
        cache.stop();
     }
  
     private <T extends Notification> T takeNotification(Class<T> clazz)
     {
        T notification = listener.take(clazz);
        verifyNotification(notification);
  
        return notification;
     }
  
     protected void verifyNotification(Notification notification)
     {
        assertSame(cache, notification.getContext().getPojoCache());
        assertEquals(true, notification.isLocal());
     }
  
     public void testListAddNotification() throws Exception
     {
        final String test1 = "test1";
        final String test2 = "test2";
  
        List<String> list = new ArrayList<String>();
        list.add(test1);
        list.add(test2);
        cache.attach("a", list);
        list = (List) cache.find("a");
  
        // String attach
        AttachNotification attach = (AttachNotification) takeNotification(AttachNotification.class);
        assertEquals(test1, attach.getSource());
  
        // List add
        ListModifyNotification modify = takeNotification(ListModifyNotification.class);
        assertEquals(ListModifyNotification.Operation.ADD, modify.getOperation());
        assertEquals(test1, modify.getValue());
        assertEquals(0, modify.getIndex());
  
        // String attach
        attach = takeNotification(AttachNotification.class);
        assertEquals(test2, attach.getSource());
  
        // List add
        modify = takeNotification(ListModifyNotification.class);
        assertEquals(ListModifyNotification.Operation.ADD, modify.getOperation());
        assertEquals(test2, modify.getValue());
        assertEquals(1, modify.getIndex());
  
        // List Attach
        attach = takeNotification(AttachNotification.class);
        assertEquals(list, attach.getSource());
  
     }
  
     public void testListSetNotification() throws Exception
     {
        final String test1 = "test1";
        final String test2 = "test2";
  
        List<String> list = new ArrayList<String>();
        list.add(test1);
        cache.attach("a", list);
        list = (List) cache.find("a");
        list.set(0, test2);
  
        // String attach
        AttachNotification attach = takeNotification(AttachNotification.class);
        assertEquals(test1, attach.getSource());
  
        // List add
        ListModifyNotification modify = takeNotification(ListModifyNotification.class);
        assertEquals(ListModifyNotification.Operation.ADD, modify.getOperation());
        assertEquals(test1, modify.getValue());
        assertEquals(0, modify.getIndex());
  
        // List Attach
        attach = takeNotification(AttachNotification.class);
        assertEquals(list, attach.getSource());
  
        // String detach
        DetachNotification detach = takeNotification(DetachNotification.class);
        assertEquals(test1, detach.getSource());
  
        // String attach
        attach = takeNotification(AttachNotification.class);
        assertEquals(test2, attach.getSource());
  
        // List set
        modify = takeNotification(ListModifyNotification.class);
        assertEquals(ListModifyNotification.Operation.SET, modify.getOperation());
        assertEquals(test2, modify.getValue());
        assertEquals(0, modify.getIndex());
     }
  
     public void testListRemoveNotification() throws Exception
     {
        final String test1 = "test1";
        final String test2 = "test2";
  
        List<String> list = new ArrayList<String>();
        list.add(test1);
        list.add(test2);
        cache.attach("a", list);
        list = (List) cache.find("a");
        list.remove(1);
  
        // String attach
        AttachNotification attach = takeNotification(AttachNotification.class);
        assertEquals(test1, attach.getSource());
  
        // List add
        ListModifyNotification modify = takeNotification(ListModifyNotification.class);
        assertEquals(ListModifyNotification.Operation.ADD, modify.getOperation());
        assertEquals(test1, modify.getValue());
        assertEquals(0, modify.getIndex());
  
        // String attach
        attach = takeNotification(AttachNotification.class);
        assertEquals(test2, attach.getSource());
  
        // List add
        modify = takeNotification(ListModifyNotification.class);
        assertEquals(ListModifyNotification.Operation.ADD, modify.getOperation());
        assertEquals(test2, modify.getValue());
        assertEquals(1, modify.getIndex());
  
        // List Attach
        attach = takeNotification(AttachNotification.class);
        assertEquals(list, attach.getSource());
  
        // List remove
        modify = takeNotification(ListModifyNotification.class);
        assertEquals(ListModifyNotification.Operation.REMOVE, modify.getOperation());
        assertEquals(test2, modify.getValue());
        assertEquals(1, modify.getIndex());
  
        // String detach
        DetachNotification detach = takeNotification(DetachNotification.class);
        assertEquals(test2, detach.getSource());
     }
  
     public void testObjectListAdd() throws Exception
     {
        final String english = "English";
        final String taiwanese = "Taiwanese";
  
        Person test = new Person();
        test.setName("Ben");
        test.setAge(10);
  
        ArrayList<String> list = new ArrayList<String>();
  
        list.add(english);
        list.add(taiwanese);
        test.setLanguages(list);
  
        cache.attach("a", test);
  
        // String attach
        AttachNotification attach = takeNotification(AttachNotification.class);
        assertEquals(english, attach.getSource());
  
        // List add
        ListModifyNotification modify = takeNotification(ListModifyNotification.class);
        assertEquals(ListModifyNotification.Operation.ADD, modify.getOperation());
        assertEquals(english, modify.getValue());
        assertEquals(0, modify.getIndex());
  
        // String attach
        attach = takeNotification(AttachNotification.class);
        assertEquals(taiwanese, attach.getSource());
  
        // List add
        modify = takeNotification(ListModifyNotification.class);
        assertEquals(ListModifyNotification.Operation.ADD, modify.getOperation());
        assertEquals(taiwanese, modify.getValue());
        assertEquals(1, modify.getIndex());
  
        // List Attach
        attach = takeNotification(AttachNotification.class);
        assertEquals(test.getLanguages(), attach.getSource());
  
        // Person Attach
        attach = takeNotification(AttachNotification.class);
        assertEquals(test, attach.getSource());
     }
  
     public static Test suite() throws Exception
     {
        return new TestSuite(ListTest.class);
     }
  
     public static void main(String[] args) throws Exception
     {
        junit.textui.TestRunner.run(ListTest.suite());
     }
  }
  
  
  
  1.1      date: 2007/06/07 05:50:20;  author: jgreene;  state: Exp;JBossCache/tests/functional/org/jboss/cache/pojo/notification/Listener.java
  
  Index: Listener.java
  ===================================================================
  /*
  * JBoss, Home of Professional Open Source
  * Copyright 2005, JBoss Inc., and individual contributors as indicated
  * by the @authors tag. See the copyright.txt in the distribution for a
  * full listing of individual contributors.
  *
  * This 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 software 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 software; if not, write to the Free
  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
  
  package org.jboss.cache.pojo.notification;
  
  import java.util.LinkedList;
  import java.util.Queue;
  
  import junit.framework.AssertionFailedError;
  
  import org.jboss.cache.pojo.PojoCacheListener;
  import org.jboss.cache.pojo.notification.ArrayModifyNotification;
  import org.jboss.cache.pojo.notification.AttachNotification;
  import org.jboss.cache.pojo.notification.DetachNotification;
  import org.jboss.cache.pojo.notification.FieldModifyNotification;
  import org.jboss.cache.pojo.notification.ListModifyNotification;
  import org.jboss.cache.pojo.notification.MapModifyNotification;
  import org.jboss.cache.pojo.notification.Notification;
  import org.jboss.cache.pojo.notification.SetModifyNotification;
  
  // $Id: Listener.java,v 1.1 2007/06/07 05:50:20 jgreene Exp $
  
  /**
   * A recoding Listener for notification test package.
   *
   * @author Jason T. Greene
   */
  class Listener implements PojoCacheListener
  {
     private Queue<Notification> events = new LinkedList<Notification>();
  
     @SuppressWarnings("unchecked")
     public <T extends Notification> T take(Class<T> t)
     {
        Notification notification = events.remove();
        if (!t.isInstance(notification))
           throw new IllegalStateException("Expected notification type: " + t.getSimpleName() + " but was: " + notification.getClass().getSimpleName());
  
        return (T) notification;
     }
  
     public void clear()
     {
        events.clear();
     }
  
     public void attach(AttachNotification attach)
     {
        events.offer(attach);
     }
  
     public void detach(DetachNotification detach)
     {
        events.offer(detach);
     }
  
     public void modify(FieldModifyNotification field)
     {
        events.offer(field);
     }
  
     public void modify(SetModifyNotification set)
     {
        events.offer(set);
     }
  
     public void modify(ListModifyNotification list)
     {
        events.offer(list);
     }
  
     public void modify(MapModifyNotification map)
     {
        events.offer(map);
     }
  
     public void modify(ArrayModifyNotification notification)
     {
        events.offer(notification);
     }
  }
  
  
  1.1      date: 2007/06/07 05:50:20;  author: jgreene;  state: Exp;JBossCache/tests/functional/org/jboss/cache/pojo/notification/MapTest.java
  
  Index: MapTest.java
  ===================================================================
  /*
  * JBoss, Home of Professional Open Source
  * Copyright 2005, JBoss Inc., and individual contributors as indicated
  * by the @authors tag. See the copyright.txt in the distribution for a
  * full listing of individual contributors.
  *
  * This 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 software 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 software; if not, write to the Free
  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
  package org.jboss.cache.pojo.notification;
  
  import java.util.LinkedHashMap;
  import java.util.Map;
  
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  
  import org.jboss.cache.pojo.PojoCache;
  import org.jboss.cache.pojo.PojoCacheFactory;
  import org.jboss.cache.pojo.notification.AttachNotification;
  import org.jboss.cache.pojo.notification.DetachNotification;
  import org.jboss.cache.pojo.notification.MapModifyNotification;
  import org.jboss.cache.pojo.notification.Notification;
  import org.jboss.cache.pojo.test.Person;
  
  //$Id: MapTest.java,v 1.1 2007/06/07 05:50:20 jgreene Exp $
  
  /**
   * Tests map notifications
   *
   * @author Jason T. Greene
   */
  public class MapTest extends TestCase
  {
     private PojoCache cache;
     private Listener listener = new Listener();
  
     public MapTest(String name)
     {
        super(name);
     }
  
     protected void setUp() throws Exception
     {
        super.setUp();
        String configFile = "META-INF/local-service.xml";
        boolean toStart = false;
        cache = PojoCacheFactory.createCache(configFile, toStart);
        cache.start();
        cache.addListener(listener);
     }
  
  
     protected void tearDown() throws Exception
     {
        super.tearDown();
        cache.stop();
     }
  
     private <T extends Notification> T takeNotification(Class<T> clazz)
     {
        T notification = listener.take(clazz);
        verifyNotification(notification);
  
        return notification;
     }
  
     protected void verifyNotification(Notification notification)
     {
        assertSame(cache, notification.getContext().getPojoCache());
        assertEquals(true, notification.isLocal());
     }
  
     public void testMapAddNotification() throws Exception
     {
        final String key1 = "key1";
        final String key2 = "key2";
        final String test1 = "test1";
        final String test2 = "test2";
  
        Map<String, String> map = new LinkedHashMap<String, String>();
        map.put(key1, test1);
        map.put(key2, test2);
        cache.attach("a", map);
        map = (Map) cache.find("a");
  
        // String attach
        AttachNotification attach = takeNotification(AttachNotification.class);
        assertEquals(test1, attach.getSource());
  
        // Map put
        MapModifyNotification modify = takeNotification(MapModifyNotification.class);
        assertEquals(MapModifyNotification.Operation.PUT, modify.getOperation());
        assertEquals(key1, modify.getKey());
        assertEquals(test1, modify.getValue());
  
        // String attach
        attach = takeNotification(AttachNotification.class);
        assertEquals(test2, attach.getSource());
  
        // Map put
        modify = takeNotification(MapModifyNotification.class);
        assertEquals(MapModifyNotification.Operation.PUT, modify.getOperation());
        assertEquals(key2, modify.getKey());
        assertEquals(test2, modify.getValue());
  
        // Map Attach
        attach = takeNotification(AttachNotification.class);
        assertSame(map, attach.getSource());
  
     }
  
     public void testMapRemoveNotification() throws Exception
     {
        final String key1 = "key1";
        final String key2 = "key2";
        final String test1 = "test1";
        final String test2 = "test2";
  
        Map<String, String> map = new LinkedHashMap<String, String>();
        map.put(key1, test1);
        map.put(key2, test2);
        cache.attach("a", map);
        map = (Map) cache.find("a");
        map.remove(key2);
  
        // String attach
        AttachNotification attach = takeNotification(AttachNotification.class);
        assertEquals(test1, attach.getSource());
  
        // Map put
        MapModifyNotification modify = takeNotification(MapModifyNotification.class);
        assertEquals(MapModifyNotification.Operation.PUT, modify.getOperation());
        assertEquals(key1, modify.getKey());
        assertEquals(test1, modify.getValue());
  
        // String attach
        attach = takeNotification(AttachNotification.class);
        assertEquals(test2, attach.getSource());
  
        // Map put
        modify = takeNotification(MapModifyNotification.class);
        assertEquals(MapModifyNotification.Operation.PUT, modify.getOperation());
        assertEquals(key2, modify.getKey());
        assertEquals(test2, modify.getValue());
  
        // Map Attach
        attach = takeNotification(AttachNotification.class);
        assertSame(map, attach.getSource());
  
        // Map remove
        modify = takeNotification(MapModifyNotification.class);
        assertEquals(MapModifyNotification.Operation.REMOVE, modify.getOperation());
        assertEquals(key2, modify.getKey());
        assertEquals(test2, modify.getValue());
  
        // String detach
        DetachNotification detach = takeNotification(DetachNotification.class);
        assertEquals(test2, detach.getSource());
     }
  
     public void testObjectMapAdd() throws Exception
     {
        final String key1 = "key1";
        final String key2 = "key2";
        final String drumming = "druming";
        final String engineering = "engineering";
  
        Person test = new Person();
        test.setName("Joe");
        test.setAge(30);
  
        Map<String, String> map = new LinkedHashMap<String, String>();
        map.put(key1, drumming);
        map.put(key2, engineering);
        test.setHobbies(map);
        cache.attach("a", test);
  
        // String attach
        AttachNotification attach = takeNotification(AttachNotification.class);
        assertEquals(drumming, attach.getSource());
  
        // Map put
        MapModifyNotification modify = takeNotification(MapModifyNotification.class);
        assertEquals(MapModifyNotification.Operation.PUT, modify.getOperation());
        assertEquals(key1, modify.getKey());
        assertEquals(drumming, modify.getValue());
  
        // String attach
        attach = takeNotification(AttachNotification.class);
        assertEquals(engineering, attach.getSource());
  
        // Map put
        modify = takeNotification(MapModifyNotification.class);
        assertEquals(key2, modify.getKey());
        assertEquals(MapModifyNotification.Operation.PUT, modify.getOperation());
        assertEquals(engineering, modify.getValue());
  
        // Map Attach
        attach = takeNotification(AttachNotification.class);
        assertEquals(test.getHobbies(), attach.getSource());
  
        // Person Attach
        attach = takeNotification(AttachNotification.class);
        assertEquals(test, attach.getSource());
     }
  
     public static Test suite() throws Exception
     {
        return new TestSuite(MapTest.class);
     }
  
     public static void main(String[] args) throws Exception
     {
        junit.textui.TestRunner.run(MapTest.suite());
     }
  }
  
  
  
  1.1      date: 2007/06/07 05:50:20;  author: jgreene;  state: Exp;JBossCache/tests/functional/org/jboss/cache/pojo/notification/ObjectTest.java
  
  Index: ObjectTest.java
  ===================================================================
  /*
   * JBoss, Home of Professional Open Source
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  
  package org.jboss.cache.pojo.notification;
  
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  
  import org.jboss.cache.pojo.PojoCache;
  import org.jboss.cache.pojo.PojoCacheFactory;
  import org.jboss.cache.pojo.notification.AttachNotification;
  import org.jboss.cache.pojo.notification.DetachNotification;
  import org.jboss.cache.pojo.notification.FieldModifyNotification;
  import org.jboss.cache.pojo.notification.Notification;
  import org.jboss.cache.pojo.test.Address;
  import org.jboss.cache.pojo.test.Person;
  
  // $Id: ObjectTest.java,v 1.1 2007/06/07 05:50:20 jgreene Exp $
  
  /**
   * Tests attach, detach, and field modify notifications
   *
   * @author Jason T. Greene
   */
  public class ObjectTest extends TestCase
  {
     private PojoCache cache;
     private Listener listener;
  
     public ObjectTest(String name)
     {
        super(name);
     }
  
     protected void setUp() throws Exception
     {
        super.setUp();
        String configFile = "META-INF/local-service.xml";
        boolean toStart = false;
        cache = PojoCacheFactory.createCache(configFile, toStart);
        cache.start();
  
        listener = new Listener();
        cache.addListener(listener);
     }
  
     private <T extends Notification> T takeNotification(Class<T> clazz)
     {
        T notification = listener.take(clazz);
        verifyNotification(notification);
  
        return notification;
     }
  
     protected void verifyNotification(Notification notification)
     {
        assertSame(cache, notification.getContext().getPojoCache());
        assertEquals(true, notification.isLocal());
     }
  
     public static Test suite() throws Exception
     {
        return new TestSuite(ObjectTest.class);
     }
  
     public static void main(String[] args) throws Exception
     {
        junit.textui.TestRunner.run(ObjectTest.suite());
     }
  
     protected void tearDown() throws Exception
     {
        super.tearDown();
        cache.stop();
     }
  
     public void testAttachNotification() throws Exception
     {
        Person test = new Person();
        test.setName("Ben");
        test.setAge(10);
        cache.attach("/a", test);
        AttachNotification attach = takeNotification(AttachNotification.class);
        assertEquals(test, attach.getSource());
     }
  
     public void testAttachNotification2() throws Exception
     {
        Person test = new Person();
        test.setName("Ben");
        test.setAge(10);
        Address addr = new Address();
        test.setAddress(addr);
        cache.attach("/a", test);
  
        // Address Attach
        AttachNotification attach = takeNotification(AttachNotification.class);
        assertEquals(addr, attach.getSource());
  
        // Person Attach
        attach = takeNotification(AttachNotification.class);
        assertEquals(test, attach.getSource());
     }
  
     public void testDetachNotification() throws Exception
     {
        Person test = new Person();
        test.setName("Ben");
        test.setAge(10);
        cache.attach("/a", test);
  
        // Person Attach
        AttachNotification attach = takeNotification(AttachNotification.class);
        assertEquals(test, attach.getSource());
  
        cache.detach("/a");
  
        // Person Detach
        DetachNotification detach = takeNotification(DetachNotification.class);
        assertEquals(test, detach.getSource());
     }
  
     public void testFieldNotification() throws Exception
     {
        Person test = new Person();
        test.setName("Ben");
        test.setAge(10);
        cache.attach("/a", test);
  
        // Person Attach
        AttachNotification attach = takeNotification(AttachNotification.class);
        assertEquals(test, attach.getSource());
  
        // Field modification
        test.setAge(20);
        FieldModifyNotification modify = takeNotification(FieldModifyNotification.class);
        assertEquals(test, modify.getSource());
        assertEquals(test.getClass().getDeclaredField("age"), modify.getField());
        assertEquals(20, modify.getValue());
  
        // Object Field Modification
        Address addr = new Address();
        addr.setCity("Madison");
        addr.setStreet("State St.");
        addr.setZip(53703);
        test.setAddress(addr);
  
        // First Attach
        attach = takeNotification(AttachNotification.class);
        assertEquals(addr, attach.getSource());
  
        // Then Modify
        modify = takeNotification(FieldModifyNotification.class);
        assertEquals(test, modify.getSource());
        assertEquals(test.getClass().getDeclaredField("address"), modify.getField());
        assertEquals(addr, modify.getValue());
     }
  }
  
  
  1.1      date: 2007/06/07 05:50:20;  author: jgreene;  state: Exp;JBossCache/tests/functional/org/jboss/cache/pojo/notification/ReplicatedListTest.java
  
  Index: ReplicatedListTest.java
  ===================================================================
  /*
  * JBoss, Home of Professional Open Source
  * Copyright 2005, JBoss Inc., and individual contributors as indicated
  * by the @authors tag. See the copyright.txt in the distribution for a
  * full listing of individual contributors.
  *
  * This 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 software 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 software; if not, write to the Free
  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
  package org.jboss.cache.pojo.notification;
  
  import junit.framework.Test;
  import junit.framework.TestSuite;
  
  import org.jboss.cache.config.Configuration.CacheMode;
  import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
  import org.jboss.cache.pojo.PojoCache;
  import org.jboss.cache.pojo.PojoCacheFactory;
  import org.jboss.cache.pojo.notification.Notification;
  
  //$Id: ReplicatedListTest.java,v 1.1 2007/06/07 05:50:20 jgreene Exp $
  
  /**
   * Tests replicated list notifications
   *
   * @author Jason T. Greene
   */
  public class ReplicatedListTest extends ListTest
  {
     private PojoCache listenerCache;
  
     public ReplicatedListTest(String name)
     {
        super(name);
     }
  
     protected void setUp() throws Exception
     {
        super.setUp();
  
        cache = PojoCacheFactory.createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC), false);
        cache.start();
        listenerCache = PojoCacheFactory.createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC), false);
        listenerCache.start();
        listenerCache.addListener(listener);
     }
  
     protected void tearDown() throws Exception
     {
        super.tearDown();
        cache.stop();
        listenerCache.stop();
     }
  
     protected void verifyNotification(Notification notification)
     {
        assertSame(listenerCache, notification.getContext().getPojoCache());
        assertEquals(false, notification.isLocal());
     }
  
     public static Test suite() throws Exception
     {
        return new TestSuite(ReplicatedListTest.class);
     }
  
     public static void main(String[] args) throws Exception
     {
        junit.textui.TestRunner.run(ReplicatedListTest.suite());
     }
  }
  
  
  
  1.1      date: 2007/06/07 05:50:20;  author: jgreene;  state: Exp;JBossCache/tests/functional/org/jboss/cache/pojo/notification/ReplicatedMapTest.java
  
  Index: ReplicatedMapTest.java
  ===================================================================
  /*
  * JBoss, Home of Professional Open Source
  * Copyright 2005, JBoss Inc., and individual contributors as indicated
  * by the @authors tag. See the copyright.txt in the distribution for a
  * full listing of individual contributors.
  *
  * This 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 software 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 software; if not, write to the Free
  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
  package org.jboss.cache.pojo.notification;
  
  import junit.framework.Test;
  import junit.framework.TestSuite;
  
  import org.jboss.cache.config.Configuration.CacheMode;
  import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
  import org.jboss.cache.pojo.PojoCache;
  import org.jboss.cache.pojo.PojoCacheFactory;
  import org.jboss.cache.pojo.notification.Notification;
  
  //$Id: ReplicatedMapTest.java,v 1.1 2007/06/07 05:50:20 jgreene Exp $
  
  /**
   * Tests replicated map notifications
   *
   * @author Jason T. Greene
   */
  public class ReplicatedMapTest extends ListTest
  {
     private PojoCache listenerCache;
  
     public ReplicatedMapTest(String name)
     {
        super(name);
     }
  
     protected void setUp() throws Exception
     {
        super.setUp();
  
        cache = PojoCacheFactory.createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC), false);
        cache.start();
        listenerCache = PojoCacheFactory.createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC), false);
        listenerCache.start();
        listenerCache.addListener(listener);
     }
  
     protected void tearDown() throws Exception
     {
        super.tearDown();
        cache.stop();
        listenerCache.stop();
     }
  
     protected void verifyNotification(Notification notification)
     {
        assertSame(listenerCache, notification.getContext().getPojoCache());
        assertEquals(false, notification.isLocal());
     }
  
     public static Test suite() throws Exception
     {
        return new TestSuite(ReplicatedMapTest.class);
     }
  
     public static void main(String[] args) throws Exception
     {
        junit.textui.TestRunner.run(ReplicatedMapTest.suite());
     }
  }
  
  
  
  1.1      date: 2007/06/07 05:50:20;  author: jgreene;  state: Exp;JBossCache/tests/functional/org/jboss/cache/pojo/notification/ReplicatedObjectTest.java
  
  Index: ReplicatedObjectTest.java
  ===================================================================
  /*
  * JBoss, Home of Professional Open Source
  * Copyright 2005, JBoss Inc., and individual contributors as indicated
  * by the @authors tag. See the copyright.txt in the distribution for a
  * full listing of individual contributors.
  *
  * This 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 software 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 software; if not, write to the Free
  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
  package org.jboss.cache.pojo.notification;
  
  import junit.framework.Test;
  import junit.framework.TestSuite;
  
  import org.jboss.cache.config.Configuration.CacheMode;
  import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
  import org.jboss.cache.pojo.PojoCache;
  import org.jboss.cache.pojo.PojoCacheFactory;
  import org.jboss.cache.pojo.notification.Notification;
  
  //$Id: ReplicatedObjectTest.java,v 1.1 2007/06/07 05:50:20 jgreene Exp $
  
  /**
   * Tests replicated set notifications
   *
   * @author Jason T. Greene
   */
  public class ReplicatedObjectTest extends ListTest
  {
     private PojoCache listenerCache;
  
     public ReplicatedObjectTest(String name)
     {
        super(name);
     }
  
     protected void setUp() throws Exception
     {
        super.setUp();
  
        cache = PojoCacheFactory.createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC), false);
        cache.start();
        listenerCache = PojoCacheFactory.createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC), false);
        listenerCache.start();
        listenerCache.addListener(listener);
     }
  
     protected void tearDown() throws Exception
     {
        super.tearDown();
        cache.stop();
        listenerCache.stop();
     }
  
     protected void verifyNotification(Notification notification)
     {
        assertSame(listenerCache, notification.getContext().getPojoCache());
        assertEquals(false, notification.isLocal());
     }
  
     public static Test suite() throws Exception
     {
        return new TestSuite(ReplicatedObjectTest.class);
     }
  
     public static void main(String[] args) throws Exception
     {
        junit.textui.TestRunner.run(ReplicatedObjectTest.suite());
     }
  }
  
  
  
  1.1      date: 2007/06/07 05:50:20;  author: jgreene;  state: Exp;JBossCache/tests/functional/org/jboss/cache/pojo/notification/ReplicatedSetTest.java
  
  Index: ReplicatedSetTest.java
  ===================================================================
  /*
  * JBoss, Home of Professional Open Source
  * Copyright 2005, JBoss Inc., and individual contributors as indicated
  * by the @authors tag. See the copyright.txt in the distribution for a
  * full listing of individual contributors.
  *
  * This 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 software 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 software; if not, write to the Free
  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
  package org.jboss.cache.pojo.notification;
  
  import junit.framework.Test;
  import junit.framework.TestSuite;
  
  import org.jboss.cache.config.Configuration.CacheMode;
  import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
  import org.jboss.cache.pojo.PojoCache;
  import org.jboss.cache.pojo.PojoCacheFactory;
  import org.jboss.cache.pojo.notification.Notification;
  
  //$Id: ReplicatedSetTest.java,v 1.1 2007/06/07 05:50:20 jgreene Exp $
  
  /**
   * Tests replicated set notifications
   *
   * @author Jason T. Greene
   */
  public class ReplicatedSetTest extends ListTest
  {
     private PojoCache listenerCache;
  
     public ReplicatedSetTest(String name)
     {
        super(name);
     }
  
     protected void setUp() throws Exception
     {
        super.setUp();
  
        cache = PojoCacheFactory.createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC), false);
        cache.start();
        listenerCache = PojoCacheFactory.createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC), false);
        listenerCache.start();
        listenerCache.addListener(listener);
     }
  
     protected void tearDown() throws Exception
     {
        super.tearDown();
        cache.stop();
        listenerCache.stop();
     }
  
     protected void verifyNotification(Notification notification)
     {
        assertSame(listenerCache, notification.getContext().getPojoCache());
        assertEquals(false, notification.isLocal());
     }
  
     public static Test suite() throws Exception
     {
        return new TestSuite(ReplicatedSetTest.class);
     }
  
     public static void main(String[] args) throws Exception
     {
        junit.textui.TestRunner.run(ReplicatedSetTest.suite());
     }
  }
  
  
  
  1.1      date: 2007/06/07 05:50:20;  author: jgreene;  state: Exp;JBossCache/tests/functional/org/jboss/cache/pojo/notification/SetTest.java
  
  Index: SetTest.java
  ===================================================================
  /*
  * JBoss, Home of Professional Open Source
  * Copyright 2005, JBoss Inc., and individual contributors as indicated
  * by the @authors tag. See the copyright.txt in the distribution for a
  * full listing of individual contributors.
  *
  * This 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 software 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 software; if not, write to the Free
  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
  package org.jboss.cache.pojo.notification;
  
  import java.util.LinkedHashSet;
  import java.util.Set;
  
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  
  import org.jboss.cache.pojo.PojoCache;
  import org.jboss.cache.pojo.PojoCacheFactory;
  import org.jboss.cache.pojo.test.Person;
  
  //$Id: SetTest.java,v 1.1 2007/06/07 05:50:20 jgreene Exp $
  
  /**
   * Tests set notifications
   *
   * @author Jason T. Greene
   */
  public class SetTest extends TestCase
  {
     private PojoCache cache;
     private Listener listener = new Listener();
  
     public SetTest(String name)
     {
        super(name);
     }
  
     protected void setUp() throws Exception
     {
        super.setUp();
        String configFile = "META-INF/local-service.xml";
        boolean toStart = false;
        cache = PojoCacheFactory.createCache(configFile, toStart);
        cache.start();
        cache.addListener(listener);
     }
  
     protected void tearDown() throws Exception
     {
        super.tearDown();
        cache.stop();
     }
  
     private <T extends Notification> T takeNotification(Class<T> clazz)
     {
        T notification = listener.take(clazz);
        verifyNotification(notification);
  
        return notification;
     }
  
     protected void verifyNotification(Notification notification)
     {
        assertSame(cache, notification.getContext().getPojoCache());
        assertEquals(true, notification.isLocal());
     }
  
     @SuppressWarnings("unchecked")
     public void testSetAddNotification() throws Exception
     {
        final String test1 = "test1";
        final String test2 = "test2";
  
        Set<String> set = new LinkedHashSet<String>();
        set.add(test1);
        set.add(test2);
        cache.attach("a", set);
        set = (Set) cache.find("a");
  
        // String attach
        AttachNotification attach = takeNotification(AttachNotification.class);
        assertEquals(test1, attach.getSource());
  
        // Set add
        SetModifyNotification modify = takeNotification(SetModifyNotification.class);
        assertEquals(SetModifyNotification.Operation.ADD, modify.getOperation());
        assertEquals(test1, modify.getValue());
  
        // String attach
        attach = takeNotification(AttachNotification.class);
        assertEquals(test2, attach.getSource());
  
        // Set add
        modify = takeNotification(SetModifyNotification.class);
        assertEquals(SetModifyNotification.Operation.ADD, modify.getOperation());
        assertEquals(test2, modify.getValue());
  
        // Set Attach
        attach = takeNotification(AttachNotification.class);
        assertSame(set, attach.getSource());
  
     }
  
     @SuppressWarnings("unchecked")
     public void testSetRemoveNotification() throws Exception
     {
        final String test1 = "test1";
        final String test2 = "test2";
  
        Set<String> set = new LinkedHashSet<String>();
        set.add(test1);
        set.add(test2);
        cache.attach("a", set);
  
        set = (Set<String>) cache.find("a");
        set.remove(test2);
  
        // String attach
        AttachNotification attach = takeNotification(AttachNotification.class);
        assertEquals(test1, attach.getSource());
  
        // Set add
        SetModifyNotification modify = takeNotification(SetModifyNotification.class);
        assertEquals(SetModifyNotification.Operation.ADD, modify.getOperation());
        assertEquals(test1, modify.getValue());
  
        // String attach
        attach = takeNotification(AttachNotification.class);
        assertEquals(test2, attach.getSource());
  
        // Set add
        modify = takeNotification(SetModifyNotification.class);
        assertEquals(SetModifyNotification.Operation.ADD, modify.getOperation());
        assertEquals(test2, modify.getValue());
  
        // Set Attach
        attach = takeNotification(AttachNotification.class);
        assertSame(set, attach.getSource());
  
        // Set remove
        modify = takeNotification(SetModifyNotification.class);
        assertEquals(SetModifyNotification.Operation.REMOVE, modify.getOperation());
        assertEquals(test2, modify.getValue());
  
        // String detach
        DetachNotification detach = takeNotification(DetachNotification.class);
        assertEquals(test2, detach.getSource());
     }
  
     public void testObjectSetAdd() throws Exception
     {
        final String drumming = "druming";
        final String engineering = "engineering";
  
        Person test = new Person();
        test.setName("Joe");
        test.setAge(30);
  
        Set<String> set = new LinkedHashSet<String>();
        set.add(drumming);
        set.add(engineering);
        test.setSkills(set);
        cache.attach("a", test);
  
        // String attach
        AttachNotification attach = takeNotification(AttachNotification.class);
        assertEquals(drumming, attach.getSource());
  
        // List add
        SetModifyNotification modify = takeNotification(SetModifyNotification.class);
        assertEquals(SetModifyNotification.Operation.ADD, modify.getOperation());
        assertEquals(drumming, modify.getValue());
  
        // String attach
        attach = takeNotification(AttachNotification.class);
        assertEquals(engineering, attach.getSource());
  
        // List add
        modify = takeNotification(SetModifyNotification.class);
        assertEquals(SetModifyNotification.Operation.ADD, modify.getOperation());
        assertEquals(engineering, modify.getValue());
  
        // List Attach
        attach = takeNotification(AttachNotification.class);
        assertEquals(test.getSkills(), attach.getSource());
  
        // Person Attach
        attach = takeNotification(AttachNotification.class);
        assertEquals(test, attach.getSource());
     }
  
     public static Test suite() throws Exception
     {
        return new TestSuite(SetTest.class);
     }
  
     public static void main(String[] args) throws Exception
     {
        junit.textui.TestRunner.run(SetTest.suite());
     }
  }
  
  
  



More information about the jboss-cvs-commits mailing list