[jboss-cvs] JBossCache/tests/functional/org/jboss/cache ...
Manik Surtani
manik at jboss.org
Mon Mar 12 14:13:47 EDT 2007
User: msurtani
Date: 07/03/12 14:13:47
Modified: tests/functional/org/jboss/cache FqnTest.java
Log:
JBCACHE-1005
Revision Changes Path
1.23 +121 -76 JBossCache/tests/functional/org/jboss/cache/FqnTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: FqnTest.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/FqnTest.java,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -b -r1.22 -r1.23
--- FqnTest.java 11 Jan 2007 13:49:06 -0000 1.22
+++ FqnTest.java 12 Mar 2007 18:13:47 -0000 1.23
@@ -19,10 +19,25 @@
* Tests {@link Fqn}.
*
* @author <a href="mailto:bela at jboss.org">Bela Ban</a> May 9, 2003
- * @version $Revision: 1.22 $
+ * @version $Revision: 1.23 $
*/
public class FqnTest extends TestCase
{
+ private Cache cache;
+
+ protected void setUp()
+ {
+ cache = null;
+ }
+
+ protected void tearDown()
+ {
+ if (cache != null)
+ {
+ cache.stop();
+ cache = null;
+ }
+ }
public FqnTest(String s)
{
@@ -40,7 +55,7 @@
public void testOne()
{
- Fqn fqn = new Fqn(22);
+ Fqn<Integer> fqn = new Fqn<Integer>(22);
log("one fqn is " + fqn);
assertEquals(1, fqn.size());
int hcode = fqn.hashCode();
@@ -56,11 +71,11 @@
public void testFqn()
{
- Fqn fqn = Fqn.fromString("/a/b/c");
+ Fqn<String> fqn = Fqn.fromString("/a/b/c");
log("fqn is " + fqn);
assertEquals(3, fqn.size());
- Fqn fqn2 = new Fqn(new Object[]{"a", "b", "c"});
+ Fqn<String> fqn2 = new Fqn<String>("a", "b", "c");
log("fqn2 is " + fqn2);
assertEquals(3, fqn2.size());
assertEquals("fqn should equal fqn2", fqn, fqn2);
@@ -69,11 +84,11 @@
public void testHereogeneousNames()
{
- Fqn fqn = new Fqn(new Object[]{"string", 38, true});
+ Fqn<Object> fqn = new Fqn<Object>("string", 38, true);
log("fqn is " + fqn);
assertEquals(3, fqn.size());
- Fqn fqn2 = new Fqn(new Object[]{"string", 38, true});
+ Fqn<Object> fqn2 = new Fqn<Object>("string", 38, true);
assertEquals(fqn, fqn2);
assertEquals(fqn.hashCode(), fqn2.hashCode());
}
@@ -81,21 +96,21 @@
public void testHashcode()
{
Fqn fqn1, fqn2;
- fqn1 = new Fqn(new Object[]{"a", "b", "c"});
+ fqn1 = new Fqn<Object>("a", "b", "c");
fqn2 = Fqn.fromString("/a/b/c");
log("fqn is " + fqn1);
assertEquals(fqn1, fqn2);
- HashMap map = new HashMap();
+ HashMap<Fqn, Integer> map = new HashMap<Fqn, Integer>();
map.put(fqn1, 33);
map.put(fqn2, 34);
assertEquals(1, map.size());
- assertEquals(34, map.get(fqn1));
+ assertEquals(new Integer(34), map.get(fqn1));
}
public void testHashcode2()
{
- Fqn fqn = new Fqn(-1);
+ Fqn<Integer> fqn = new Fqn<Integer>(-1);
log("one fqn is " + fqn);
assertEquals(1, fqn.size());
int hcode = fqn.hashCode();
@@ -104,29 +119,32 @@
public void testEquals()
{
- Fqn fqn1 = new Fqn("person/test");
+ Fqn<String> fqn1 = new Fqn<String>("person/test");
- Fqn f1, f2, f3;
+ Fqn<String> f1;
+ Fqn<String> f2;
+ Fqn<String> f3;
- f1 = new Fqn(fqn1, "0");
- f2 = new Fqn(fqn1, "1");
- f3 = new Fqn(fqn1, "2");
+ f1 = new Fqn<String>(fqn1, "0");
+ f2 = new Fqn<String>(fqn1, "1");
+ f3 = new Fqn<String>(fqn1, "2");
- HashMap map = new HashMap();
+ HashMap<Fqn<String>, String> map = new HashMap<Fqn<String>, String>();
map.put(f1, "0");
map.put(f2, "1");
map.put(f3, "2");
- assertNotNull("f1 ", map.get(new Fqn(fqn1, "0")));
- assertNotNull("f2 ", map.get(new Fqn(fqn1, "1")));
- assertNotNull("f3 ", map.get(new Fqn(fqn1, "2")));
+ assertNotNull("f1 ", map.get(new Fqn<String>(fqn1, "0")));
+ assertNotNull("f2 ", map.get(new Fqn<String>(fqn1, "1")));
+ assertNotNull("f3 ", map.get(new Fqn<String>(fqn1, "2")));
}
public void testEquals2()
{
- Fqn f1, f2;
+ Fqn<String> f1;
+ Fqn<String> f2;
f1 = Fqn.fromString("/a/b/c");
f2 = Fqn.fromString("/a/b/c");
assertEquals(f1, f2);
@@ -140,7 +158,7 @@
public void testEquals2WithMarshalling() throws Exception
{
- Fqn f1, f2;
+ Fqn<String> f1, f2;
f1 = Fqn.fromString("/a/b/c");
f2 = marshalAndUnmarshal(f1);
assertEquals(f1, f2);
@@ -149,26 +167,27 @@
public void testEquals3()
{
- Fqn f1, f2;
- f1 = new Fqn(new Object[]{"a", 322649, Boolean.TRUE});
- f2 = new Fqn();
+ Fqn<Object> f1;
+ Fqn<? extends Object> f2;
+ f1 = new Fqn<Object>("a", 322649, Boolean.TRUE);
+ f2 = new Fqn<String>();
assertFalse(f1.equals(f2));
assertFalse(f2.equals(f1));
f2 = Fqn.fromString("a/322649/TRUE");
assertFalse(f1.equals(f2));
- f2 = new Fqn(new Object[]{"a", 322649, Boolean.FALSE});
+ f2 = new Fqn<Object>("a", 322649, Boolean.FALSE);
assertFalse(f1.equals(f2));
- f2 = new Fqn(new Object[]{"a", 322649, Boolean.TRUE});
+ f2 = new Fqn<Object>("a", 322649, Boolean.TRUE);
assertEquals(f1, f2);
}
public void testEquals3WithMarshalling() throws Exception
{
Fqn f1, f2;
- f1 = new Fqn(new Object[]{"a", 322649, Boolean.TRUE});
+ f1 = new Fqn<Object>("a", 322649, Boolean.TRUE);
f2 = marshalAndUnmarshal(f1);
assertEquals(f1, f2);
assertEquals(f2, f1);
@@ -177,18 +196,18 @@
f2 = marshalAndUnmarshal(f2);
assertFalse(f1.equals(f2));
- f2 = new Fqn(new Object[]{"a", 322649, Boolean.FALSE});
+ f2 = new Fqn<Object>("a", 322649, Boolean.FALSE);
f2 = marshalAndUnmarshal(f2);
assertFalse(f1.equals(f2));
- f2 = new Fqn(new Object[]{"a", 322649, Boolean.TRUE});
+ f2 = new Fqn<Object>("a", 322649, Boolean.TRUE);
f2 = marshalAndUnmarshal(f2);
assertEquals(f1, f2);
}
public void testEquals4()
{
- Fqn fqn = Fqn.fromString("X");
+ Fqn<String> fqn = Fqn.fromString("X");
// Check casting
assertFalse("Casting ok", fqn.equals("X"));
// Check null
@@ -197,21 +216,21 @@
public void testClone() throws CloneNotSupportedException
{
- Fqn fqn1 = Fqn.fromString("/a/b/c");
- Fqn fqn2 = fqn1.clone();
+ Fqn<String> fqn1 = Fqn.fromString("/a/b/c");
+ Fqn<String> fqn2 = fqn1.clone();
assertEquals(fqn1, fqn2);
assertEquals(fqn1.hashCode(), fqn2.hashCode());
}
public void testNullElements() throws CloneNotSupportedException
{
- Fqn fqn0 = new Fqn((Object) null);
+ Fqn<Object> fqn0 = new Fqn<Object>((Object) null);
assertEquals(1, fqn0.size());
- Fqn fqn1 = new Fqn(new Object[]{"NULL", null, 0});
+ Fqn<Object> fqn1 = new Fqn<Object>("NULL", null, 0);
assertEquals(3, fqn1.size());
- Fqn fqn2 = new Fqn(new Object[]{"NULL", null, 0,});
+ Fqn<Object> fqn2 = new Fqn<Object>("NULL", null, 0);
assertEquals(fqn1.hashCode(), fqn2.hashCode());
assertEquals(fqn1, fqn2);
assertEquals(fqn1, fqn1.clone());
@@ -219,14 +238,14 @@
public void testIteration()
{
- Fqn fqn = Fqn.fromString("/a/b/c");
+ Fqn<String> fqn = Fqn.fromString("/a/b/c");
assertEquals(3, fqn.size());
- Fqn tmp_fqn = new Fqn();
+ Fqn<Object> tmp_fqn = new Fqn<Object>();
assertEquals(0, tmp_fqn.size());
for (int i = 0; i < fqn.size(); i++)
{
- Object obj = fqn.get(i);
- tmp_fqn = new Fqn(tmp_fqn, obj);
+ String s = fqn.get(i);
+ tmp_fqn = new Fqn<Object>(tmp_fqn, s);
assertEquals(tmp_fqn.size(), i + 1);
}
assertEquals(3, tmp_fqn.size());
@@ -235,8 +254,8 @@
public void testIsChildOf()
{
- Fqn child = Fqn.fromString("/a/b");
- Fqn parent = Fqn.fromString("/a");
+ Fqn<String> child = Fqn.fromString("/a/b");
+ Fqn<String> parent = Fqn.fromString("/a");
assertTrue("Is child of ", child.isChildOf(parent));
assertFalse("Is child of ", parent.isChildOf(child));
assertTrue("Is same ", child.isChildOrEquals(child));
@@ -248,27 +267,27 @@
public void testIsChildOf2()
{
- Fqn child = Fqn.fromString("/a/b/c/d");
- assertEquals("Fqn ", "/b/c/d", child.getFqnChild(1, child.size()).toString());
+ Fqn<String> child = Fqn.fromString("/a/b/c/d");
+ assertEquals("Fqn ", "/b/c/d", child.getSubFqn(1, child.size()).toString());
}
public void testParentage()
{
- Fqn fqnRoot = new Fqn();
- Fqn parent = fqnRoot.getParent();
+ Fqn<String> fqnRoot = new Fqn<String>();
+ Fqn<String> parent = fqnRoot.getParent();
assertEquals(parent, fqnRoot);
- Fqn fqnOne = Fqn.fromString("/one");
+ Fqn<String> fqnOne = Fqn.fromString("/one");
parent = fqnOne.getParent();
assertEquals(parent, fqnRoot);
assertTrue(fqnOne.isChildOf(parent));
- Fqn fqnTwo = Fqn.fromString("/one/two");
+ Fqn<String> fqnTwo = Fqn.fromString("/one/two");
parent = fqnTwo.getParent();
assertEquals(parent, fqnOne);
assertTrue(fqnTwo.isChildOf(parent));
- Fqn fqnThree = Fqn.fromString("/one/two/three");
+ Fqn<String> fqnThree = Fqn.fromString("/one/two/three");
parent = fqnThree.getParent();
assertEquals(parent, fqnTwo);
assertTrue(fqnThree.isChildOf(parent));
@@ -277,7 +296,7 @@
public void testRoot()
{
- Fqn fqn = new Fqn();
+ Fqn<String> fqn = new Fqn<String>();
assertTrue(fqn.isRoot());
fqn = Fqn.fromString("/one/two");
@@ -286,35 +305,33 @@
public void testGetName()
{
- Fqn integerFqn = new Fqn(1);
+ Fqn<Integer> integerFqn = new Fqn<Integer>(1);
assertEquals("1", integerFqn.getLastElementAsString());
Object object = new Object();
- Fqn objectFqn = new Fqn(object);
+ Fqn<Object> objectFqn = new Fqn<Object>(object);
assertEquals(object.toString(), objectFqn.getLastElementAsString());
}
public void testCloningString() throws CloneNotSupportedException
{
- Fqn f = Fqn.fromString("/a/b/c");
+ Fqn<String> f = Fqn.fromString("/a/b/c");
assertEquals(f, f.clone());
}
public void testCloningOtherTypes() throws CloneNotSupportedException
{
- Fqn f = new Fqn(new Object[]{"blah", 10, Boolean.TRUE});
+ Fqn<Object> f = new Fqn<Object>("blah", 10, Boolean.TRUE);
assertEquals(f, f.clone());
}
public void testRemovalNonString() throws Exception
{
- Fqn f = new Fqn(new Object[]{"test", 1});
- // CacheImpl tc = (CacheImpl) DefaultCacheFactory.getInstance().createCache(false);
- // tc.getConfiguration().setCacheMode("LOCAL");
- // tc.start();
+ Fqn<Object> f = new Fqn<Object>("test", 1);
+
Configuration c = new Configuration();
c.setCacheMode("LOCAL");
- Cache cache = DefaultCacheFactory.getInstance().createCache(c);
+ cache = DefaultCacheFactory.getInstance().createCache(c);
cache.put(f, "key", "value");
@@ -327,34 +344,62 @@
assertFalse(cache.getRoot().hasChild(f));
}
- public void testGetChildFqn()
+ Fqn marshalAndUnmarshal(Fqn fqn) throws Exception
{
- Fqn f = Fqn.fromString("/one/two/three");
+ byte[] buf = Util.objectToByteBuffer(fqn);
+ return (Fqn) Util.objectFromByteBuffer(buf);
+ }
- // calling getChild with index of '2' should result in "/one/two"
- assertEquals(Fqn.fromString("/one/two"), f.getFqnChild(2));
- assertEquals(Fqn.fromString("/one"), f.getFqnChild(1));
- assertEquals(Fqn.fromString("/one/two/three"), f.getFqnChild(3));
- try
+ // testing generics
+
+ public void testGenerics()
{
- f.getFqnChild(4);
- fail("Should have barfed");
+ Fqn<String> f = Fqn.fromString("/blah/blah");
+ Fqn<String> f2 = Fqn.fromString("/blah/blah");
+ assertEquals(f, f2);
+
+ Fqn<Integer> f3 = new Fqn<Integer>(1, 2, 3, 5);
+
+ Fqn<Integer> f4 = new Fqn<Integer>(1, 2, 3);
+
+ assertEquals(f3.getParent(), f4);
}
- catch (IndexOutOfBoundsException e)
+
+ public void testGenerations()
{
- // this is expected
- }
+ Fqn<Integer> f = new Fqn<Integer>(1, 2, 3, 4, 5, 6, 7);
- }
+ assertEquals(f, f.getAncestor(f.size()));
+ assertEquals(f.getParent(), f.getAncestor(f.size() - 1));
+ assertEquals(Fqn.ROOT, f.getAncestor(0));
+ assertEquals(new Fqn<Integer>(1), f.getAncestor(1));
+ assertEquals(new Fqn<Integer>(1, 2), f.getAncestor(2));
+ assertEquals(new Fqn<Integer>(1, 2, 3), f.getAncestor(3));
+ assertEquals(new Fqn<Integer>(1, 2, 3, 4), f.getAncestor(4));
+ assertEquals(new Fqn<Integer>(1, 2, 3, 4, 5), f.getAncestor(5));
+ try
+ {
+ f.getAncestor(-1);
+ fail("Should fail");
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
- Fqn marshalAndUnmarshal(Fqn fqn) throws Exception
+ try
{
- byte[] buf = Util.objectToByteBuffer(fqn);
- Fqn newFqn = (Fqn) Util.objectFromByteBuffer(buf);
- return newFqn;
+ f.getAncestor(f.size() + 1);
+ fail("Should fail");
}
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
void log(String msg)
{
More information about the jboss-cvs-commits
mailing list