Clover coverage report -
Coverage timestamp: Thu Jul 5 2007 20:02:32 EDT
file stats: LOC: 219   Methods: 10
NCLOC: 134   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
SetTest.java - 98.8% 90% 97.9%
coverage coverage
 1    /*
 2    * JBoss, Home of Professional Open Source
 3    * Copyright 2005, JBoss Inc., and individual contributors as indicated
 4    * by the @authors tag. See the copyright.txt in the distribution for a
 5    * full listing of individual contributors.
 6    *
 7    * This is free software; you can redistribute it and/or modify it
 8    * under the terms of the GNU Lesser General Public License as
 9    * published by the Free Software Foundation; either version 2.1 of
 10    * the License, or (at your option) any later version.
 11    *
 12    * This software is distributed in the hope that it will be useful,
 13    * but WITHOUT ANY WARRANTY; without even the implied warranty of
 14    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 15    * Lesser General Public License for more details.
 16    *
 17    * You should have received a copy of the GNU Lesser General Public
 18    * License along with this software; if not, write to the Free
 19    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 20    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 21    */
 22    package org.jboss.cache.pojo.notification;
 23   
 24    import java.util.LinkedHashSet;
 25    import java.util.Set;
 26   
 27    import junit.framework.Test;
 28    import junit.framework.TestCase;
 29    import junit.framework.TestSuite;
 30   
 31    import org.jboss.cache.pojo.PojoCache;
 32    import org.jboss.cache.pojo.PojoCacheFactory;
 33    import org.jboss.cache.pojo.notification.event.AttachedEvent;
 34    import org.jboss.cache.pojo.notification.event.DetachedEvent;
 35    import org.jboss.cache.pojo.notification.event.Event;
 36    import org.jboss.cache.pojo.notification.event.SetModifiedEvent;
 37    import org.jboss.cache.pojo.test.Person;
 38   
 39    //$Id: SetTest.java,v 1.2 2007/06/29 04:34:01 jgreene Exp $
 40   
 41    /**
 42    * Tests set notifications
 43    *
 44    * @author Jason T. Greene
 45    */
 46    public class SetTest extends TestCase
 47    {
 48    private PojoCache cache;
 49    private Listener listener = new Listener();
 50   
 51  3 public SetTest(String name)
 52    {
 53  3 super(name);
 54    }
 55   
 56  3 protected void setUp() throws Exception
 57    {
 58  3 super.setUp();
 59  3 String configFile = "META-INF/local-service.xml";
 60  3 boolean toStart = false;
 61  3 cache = PojoCacheFactory.createCache(configFile, toStart);
 62  3 cache.start();
 63  3 cache.addListener(listener);
 64    }
 65   
 66  3 protected void tearDown() throws Exception
 67    {
 68  3 super.tearDown();
 69  3 cache.stop();
 70    }
 71   
 72  18 private <T extends Event> T takeNotification(Class<T> clazz)
 73    {
 74  18 T notification = listener.take(clazz);
 75  18 verifyNotification(notification);
 76   
 77  18 return notification;
 78    }
 79   
 80  18 protected void verifyNotification(Event notification)
 81    {
 82  18 assertSame(cache, notification.getContext().getPojoCache());
 83  18 assertEquals(true, notification.isLocal());
 84    }
 85   
 86  1 @SuppressWarnings("unchecked")
 87    public void testSetAddNotification() throws Exception
 88    {
 89  1 final String test1 = "test1";
 90  1 final String test2 = "test2";
 91   
 92  1 Set<String> set = new LinkedHashSet<String>();
 93  1 set.add(test1);
 94  1 set.add(test2);
 95  1 cache.attach("a", set);
 96  1 set = (Set) cache.find("a");
 97   
 98    // String attach
 99  1 AttachedEvent attach = takeNotification(AttachedEvent.class);
 100  1 assertEquals(test1, attach.getSource());
 101   
 102    // Set add
 103  1 SetModifiedEvent modify = takeNotification(SetModifiedEvent.class);
 104  1 assertEquals(SetModifiedEvent.Operation.ADD, modify.getOperation());
 105  1 assertEquals(test1, modify.getValue());
 106   
 107    // String attach
 108  1 attach = takeNotification(AttachedEvent.class);
 109  1 assertEquals(test2, attach.getSource());
 110   
 111    // Set add
 112  1 modify = takeNotification(SetModifiedEvent.class);
 113  1 assertEquals(SetModifiedEvent.Operation.ADD, modify.getOperation());
 114  1 assertEquals(test2, modify.getValue());
 115   
 116    // Set Attach
 117  1 attach = takeNotification(AttachedEvent.class);
 118  1 assertSame(set, attach.getSource());
 119   
 120    }
 121   
 122  1 @SuppressWarnings("unchecked")
 123    public void testSetRemoveNotification() throws Exception
 124    {
 125  1 final String test1 = "test1";
 126  1 final String test2 = "test2";
 127   
 128  1 Set<String> set = new LinkedHashSet<String>();
 129  1 set.add(test1);
 130  1 set.add(test2);
 131  1 cache.attach("a", set);
 132   
 133  1 set = (Set<String>) cache.find("a");
 134  1 set.remove(test2);
 135   
 136    // String attach
 137  1 AttachedEvent attach = takeNotification(AttachedEvent.class);
 138  1 assertEquals(test1, attach.getSource());
 139   
 140    // Set add
 141  1 SetModifiedEvent modify = takeNotification(SetModifiedEvent.class);
 142  1 assertEquals(SetModifiedEvent.Operation.ADD, modify.getOperation());
 143  1 assertEquals(test1, modify.getValue());
 144   
 145    // String attach
 146  1 attach = takeNotification(AttachedEvent.class);
 147  1 assertEquals(test2, attach.getSource());
 148   
 149    // Set add
 150  1 modify = takeNotification(SetModifiedEvent.class);
 151  1 assertEquals(SetModifiedEvent.Operation.ADD, modify.getOperation());
 152  1 assertEquals(test2, modify.getValue());
 153   
 154    // Set Attach
 155  1 attach = takeNotification(AttachedEvent.class);
 156  1 assertSame(set, attach.getSource());
 157   
 158    // Set remove
 159  1 modify = takeNotification(SetModifiedEvent.class);
 160  1 assertEquals(SetModifiedEvent.Operation.REMOVE, modify.getOperation());
 161  1 assertEquals(test2, modify.getValue());
 162   
 163    // String detach
 164  1 DetachedEvent detach = takeNotification(DetachedEvent.class);
 165  1 assertEquals(test2, detach.getSource());
 166    }
 167   
 168  1 public void testObjectSetAdd() throws Exception
 169    {
 170  1 final String drumming = "druming";
 171  1 final String engineering = "engineering";
 172   
 173  1 Person test = new Person();
 174  1 test.setName("Joe");
 175  1 test.setAge(30);
 176   
 177  1 Set<String> set = new LinkedHashSet<String>();
 178  1 set.add(drumming);
 179  1 set.add(engineering);
 180  1 test.setSkills(set);
 181  1 cache.attach("a", test);
 182   
 183    // String attach
 184  1 AttachedEvent attach = takeNotification(AttachedEvent.class);
 185  1 assertEquals(drumming, attach.getSource());
 186   
 187    // List add
 188  1 SetModifiedEvent modify = takeNotification(SetModifiedEvent.class);
 189  1 assertEquals(SetModifiedEvent.Operation.ADD, modify.getOperation());
 190  1 assertEquals(drumming, modify.getValue());
 191   
 192    // String attach
 193  1 attach = takeNotification(AttachedEvent.class);
 194  1 assertEquals(engineering, attach.getSource());
 195   
 196    // List add
 197  1 modify = takeNotification(SetModifiedEvent.class);
 198  1 assertEquals(SetModifiedEvent.Operation.ADD, modify.getOperation());
 199  1 assertEquals(engineering, modify.getValue());
 200   
 201    // List Attach
 202  1 attach = takeNotification(AttachedEvent.class);
 203  1 assertEquals(test.getSkills(), attach.getSource());
 204   
 205    // Person Attach
 206  1 attach = takeNotification(AttachedEvent.class);
 207  1 assertEquals(test, attach.getSource());
 208    }
 209   
 210  1 public static Test suite() throws Exception
 211    {
 212  1 return new TestSuite(SetTest.class);
 213    }
 214   
 215  0 public static void main(String[] args) throws Exception
 216    {
 217  0 junit.textui.TestRunner.run(SetTest.suite());
 218    }
 219    }