You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by ta...@apache.org on 2003/12/27 18:02:36 UTC
cvs commit: jakarta-jetspeed-2/portal/src/test/org/apache/jetspeed/spi/services/prefs TestPreferences.java TestPropertyManagerService.java
taylor 2003/12/27 09:02:36
Modified: portal/src/java/org/apache/jetspeed/services/factory
FactoryManagerServiceImpl.java
portal/src/java/org/apache/jetspeed/spi/services/prefs/impl
PropertyManagerServiceImpl.java
portal/src/test/org/apache/jetspeed/spi/services/prefs
TestPreferences.java
TestPropertyManagerService.java
Log:
Preferences patch from David Le Strat
- adds unit tests to Prefs
Revision Changes Path
1.4 +8 -6 jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/services/factory/FactoryManagerServiceImpl.java
Index: FactoryManagerServiceImpl.java
===================================================================
RCS file: /home/cvs/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/services/factory/FactoryManagerServiceImpl.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- FactoryManagerServiceImpl.java 27 Dec 2003 05:35:51 -0000 1.3
+++ FactoryManagerServiceImpl.java 27 Dec 2003 17:02:36 -0000 1.4
@@ -93,6 +93,13 @@
private final static String CONFIG_FACTORY_PRE = "plutofactory.";
+ /** Map of factories, keyed off Pluto interface name to portal factory class */
+ private Map factoryMap = new HashMap();
+
+ /** List of portal factory classes */
+ private List factoryList = new LinkedList();
+
+
public FactoryManagerServiceImpl()
{
}
@@ -285,10 +292,5 @@
return ((Factory) factoryMap.get (managedInterface));
}
-
- // --- PRIVATE MEMBERS --- //
-
- private Map factoryMap = new HashMap ();
- private List factoryList = new LinkedList ();
}
1.2 +0 -2 jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/spi/services/prefs/impl/PropertyManagerServiceImpl.java
Index: PropertyManagerServiceImpl.java
===================================================================
RCS file: /home/cvs/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/spi/services/prefs/impl/PropertyManagerServiceImpl.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- PropertyManagerServiceImpl.java 8 Dec 2003 18:28:06 -0000 1.1
+++ PropertyManagerServiceImpl.java 27 Dec 2003 17:02:36 -0000 1.2
@@ -316,10 +316,8 @@
propertySetDefId,
(String) currentPropertyKey.get(PROPERTYKEY_NAME),
((Short) currentPropertyKey.get(PROPERTYKEY_TYPE)).shortValue());
- System.out.println("Adding property key: " + (String) currentPropertyKey.get(PROPERTYKEY_NAME));
propertyKeysObj.add(ppk);
}
- System.out.println(propertyKeysObj.size());
try
{
1.3 +58 -87 jakarta-jetspeed-2/portal/src/test/org/apache/jetspeed/spi/services/prefs/TestPreferences.java
Index: TestPreferences.java
===================================================================
RCS file: /home/cvs/jakarta-jetspeed-2/portal/src/test/org/apache/jetspeed/spi/services/prefs/TestPreferences.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- TestPreferences.java 8 Dec 2003 19:13:36 -0000 1.2
+++ TestPreferences.java 27 Dec 2003 17:02:36 -0000 1.3
@@ -105,9 +105,22 @@
junit.awtui.TestRunner.main(new String[] { TestPreferences.class.getName()});
}
- public void setup()
+ /**
+ * @see junit.framework.TestCase#setUp()
+ */
+ public void setUp()
+ {
+ super.setUp();
+ destroyPropertySetDefTestObject();
+ }
+
+ /**
+ * @see junit.framework.TestCase#tearDown()
+ */
+ public void tearDown()
{
- System.out.println("Setup: Testing the java.util.prefs.Preferences implementation");
+ super.tearDown();
+ destroyPropertySetDefTestObject();
}
/**
@@ -140,9 +153,13 @@
public void testUserRoot()
{
Preferences prefs = Preferences.userRoot();
- if ((null == prefs) || (!(prefs.absolutePath().equals("/"))))
+ if (null != prefs)
{
- assertTrue(false);
+ assertTrue("expected user root == '/', " + prefs.absolutePath(), prefs.absolutePath().equals("/"));
+ }
+ else
+ {
+ assertTrue("expected user root == '/', " + prefs, false);
}
}
@@ -152,9 +169,13 @@
public void testSystemRoot()
{
Preferences prefs = Preferences.systemRoot();
- if ((null == prefs) || (!(prefs.absolutePath().equals("/"))))
+ if (null != prefs)
{
- assertTrue(false);
+ assertTrue("expected system root == '/', " + prefs.absolutePath(), prefs.absolutePath().equals("/"));
+ }
+ else
+ {
+ assertTrue("expected system root == '/', " + prefs, false);
}
}
@@ -170,12 +191,12 @@
String[] childrenNames = prefs.childrenNames();
if (childrenNames.length > 0)
{
- assertTrue(false);
+ assertTrue("expected no children, " + childrenNames.length + ", " + childrenNames[0], childrenNames.length == 0);
}
}
catch (BackingStoreException bse)
{
- assertTrue(false);
+ assertTrue("backing store exception: " + bse, false);
}
// TODO Test with children.
@@ -194,24 +215,42 @@
// Absolute path.
// 1. The node does not exist. Create it.
Preferences prefs0 = Preferences.userRoot().node(testAbsNodeName);
- if ((null == prefs0) || (!(prefs0.absolutePath().equals(testAbsNodeName))))
+ if (null != prefs0)
{
- assertTrue(false);
+ assertTrue(
+ "expected node == '" + testAbsNodeName + "', " + prefs0.absolutePath(),
+ prefs0.absolutePath().equals(testAbsNodeName));
+ }
+ else
+ {
+ assertTrue("expected node == '" + testAbsNodeName + "', " + prefs0, false);
}
// 2. If node exists. Get it.
Preferences prefs1 = Preferences.userRoot().node(testAbsNodeName);
- if ((null == prefs1) || (!(prefs1.absolutePath().equals(testAbsNodeName))))
+ if (null != prefs1)
{
- assertTrue(false);
+ assertTrue(
+ "expected node == '" + testAbsNodeName + "', " + prefs1.absolutePath(),
+ prefs1.absolutePath().equals(testAbsNodeName));
+ }
+ else
+ {
+ assertTrue("expected node == '" + testAbsNodeName + "', " + prefs1, false);
}
//Relative path.
Preferences prefs3 = Preferences.userRoot().node(testAbsNodeName0);
Preferences prefs4 = prefs3.node(testRelNodeName);
- if ((null == prefs4) || (!(prefs4.absolutePath().equals(testAbsNodeName0 + "/" + testRelNodeName))))
+ if (null != prefs4)
{
- assertTrue(false);
+ assertTrue(
+ "expected node == '" + testAbsNodeName0 + "/" + testRelNodeName + "', " + prefs4.absolutePath(),
+ prefs4.absolutePath().equals(testAbsNodeName0 + "/" + testRelNodeName));
+ }
+ else
+ {
+ assertTrue("expected node == '" + testAbsNodeName0 + "/" + testRelNodeName + "', " + prefs4, false);
}
// Remove all nodes.
@@ -221,7 +260,7 @@
}
catch (BackingStoreException bse)
{
- assertTrue(false);
+ assertTrue("backing store exception: " + bse, false);
}
}
@@ -235,7 +274,7 @@
String propertySetNodeName = "propertyset1";
String fullPropertySetPath = "/" + userNodeName + "/" + principalNodeName + "/" + propertySetNodeName;
int[] propertySetDefIds = new int[2];
-
+
try
{
initPropertySetDefTestObject();
@@ -253,13 +292,13 @@
{
assertTrue(false);
}
-
+
// 2. Current node is defined as property set.
Preferences prefs1 = Preferences.userRoot().node(fullPropertySetPath);
prefs1.put("propertyName00", "true");
String prop1 = prefs1.get("propertyName00", null);
assertTrue("expected prop1 == true, " + prop1, prop1.equals("true"));
-
+
// Test remove property.
prefs1.remove("propertyName00");
prop1 = prefs1.get("propertyName00", null);
@@ -283,13 +322,10 @@
}
catch (BackingStoreException bse)
{
- assertTrue(false);
+ assertTrue("backing store exception: " + bse, false);
}
- destroyPropertySetDefTestObject();
}
-
-
/**
* <p>Init property set definition object.</p>
*/
@@ -353,70 +389,5 @@
{
}
}
-
- /**
- * <p>Init property values collection object.</p>
- * @param propertySetDefId The property set definition id.
- * @param propertyKeyIds The property key ids.
- * @return A collection of property values.
- */
- /*
- protected Collection initPropertyValuesCollectionTestObject(Map propertyKeys)
- {
- PropertyManagerService propms = getPropertyManagerService();
- Collection propertyValues = new ArrayList(4);
- // This is a boolean property.
- Integer ppkId00 = (Integer) TestUtils.getMapKeyByValue(propertyKeys, "propertyName00");
- if (null != ppkId00)
- {
- Map propertyValue00 = new HashMap();
- propertyValue00.put(ProfileManagerService.PROPERTY_KEY_ID, ppkId00);
- propertyValue00.put(ProfileManagerService.PROPERTY_VALUE, new Boolean("true"));
- propertyValues.add(propertyValue00);
- } // This is a long property
- Integer ppkId01 = (Integer) TestUtils.getMapKeyByValue(propertyKeys, "propertyName01");
- if (null != ppkId01)
- {
- Map propertyValue01 = new HashMap();
- propertyValue01.put(ProfileManagerService.PROPERTY_KEY_ID, ppkId01);
- propertyValue01.put(ProfileManagerService.PROPERTY_VALUE, new Long("123"));
- propertyValues.add(propertyValue01);
- } // This is a double property.
- Integer ppkId02 = (Integer) TestUtils.getMapKeyByValue(propertyKeys, "propertyName02");
- if (null != ppkId02)
- {
- Map propertyValue02 = new HashMap();
- propertyValue02.put(ProfileManagerService.PROPERTY_KEY_ID, ppkId02);
- propertyValue02.put(ProfileManagerService.PROPERTY_VALUE, new Double("123.23"));
- propertyValues.add(propertyValue02);
- } // This is a text property.
- Integer ppkId03 = (Integer) TestUtils.getMapKeyByValue(propertyKeys, "propertyName03");
- if (null != ppkId03)
- {
- Map propertyValue03 = new HashMap();
- propertyValue03.put(ProfileManagerService.PROPERTY_KEY_ID, ppkId03);
- propertyValue03.put(ProfileManagerService.PROPERTY_VALUE, "value3");
- propertyValues.add(propertyValue03);
- } // This is a boolean property.
- Integer ppkId10 = (Integer) TestUtils.getMapKeyByValue(propertyKeys, "propertyName10");
- if (null != ppkId10)
- {
- Map propertyValue10 = new HashMap();
- propertyValue10.put(ProfileManagerService.PROPERTY_KEY_ID, ppkId10);
- propertyValue10.put(ProfileManagerService.PROPERTY_VALUE, new Boolean("true"));
- propertyValues.add(propertyValue10);
- } // This is a long property
- Integer ppkId11 = (Integer) TestUtils.getMapKeyByValue(propertyKeys, "propertyName11");
- if (null != ppkId11)
- {
- Map propertyValue11 = new HashMap();
- propertyValue11.put(ProfileManagerService.PROPERTY_KEY_ID, ppkId11);
- propertyValue11.put(ProfileManagerService.PROPERTY_VALUE, new Long("123"));
- propertyValues.add(propertyValue11);
- }
-
- return propertyValues;
- }
- */
}
1.2 +49 -29 jakarta-jetspeed-2/portal/src/test/org/apache/jetspeed/spi/services/prefs/TestPropertyManagerService.java
Index: TestPropertyManagerService.java
===================================================================
RCS file: /home/cvs/jakarta-jetspeed-2/portal/src/test/org/apache/jetspeed/spi/services/prefs/TestPropertyManagerService.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TestPropertyManagerService.java 8 Dec 2003 18:28:07 -0000 1.1
+++ TestPropertyManagerService.java 27 Dec 2003 17:02:36 -0000 1.2
@@ -102,9 +102,22 @@
junit.awtui.TestRunner.main(new String[] { TestPropertyManagerService.class.getName()});
}
- public void setup()
+ /**
+ * @see junit.framework.TestCase#setUp()
+ */
+ public void setUp()
{
- System.out.println("Setup: Testing the property manager service implementation");
+ super.setUp();
+ destroyPropertySetDefTestObject(true);
+ }
+
+ /**
+ * @see junit.framework.TestCase#tearDown()
+ */
+ public void tearDown()
+ {
+ super.tearDown();
+ destroyPropertySetDefTestObject(true);
}
/**
@@ -151,7 +164,7 @@
catch (PropertyException pex)
{
// Property set defintion already exists.
- assertTrue(false);
+ assertTrue("property set definition already exists. exception caught: " + pex, false);
}
destroyPropertySetDefTestObject(false);
@@ -171,7 +184,7 @@
}
catch (PropertyException pex)
{
- assertTrue(false);
+ assertTrue("could not initialize property set definition. exception caught: " + pex, false);
}
pms.updatePropertySetDef(propertySetDefs[0], "propertysetupdate0", USER_PROPERTY_SET_TYPE);
@@ -180,11 +193,14 @@
try
{
updatedPropertySetDefId = pms.getPropertySetDefIdByType("propertysetupdate0", USER_PROPERTY_SET_TYPE);
- assertEquals(propertySetDefs[0], updatedPropertySetDefId);
+ assertEquals(
+ "expected property set def id == " + propertySetDefs[0] + ", ",
+ propertySetDefs[0],
+ updatedPropertySetDefId);
}
catch (PropertyException pex)
{
- assertTrue(false);
+ assertTrue("could not get property set definition id. exception caught: " + pex, false);
}
pms.updatePropertySetDef(updatedPropertySetDefId, "propertyset0", USER_PROPERTY_SET_TYPE);
@@ -205,19 +221,19 @@
}
catch (PropertyException pex)
{
- assertTrue(false);
+ assertTrue("could not initialize property set definition. exception caught: " + pex, false);
}
try
{
Map propSetsMap = pms.getAllPropertySetsByType(USER_PROPERTY_SET_TYPE);
- assertTrue(propSetsMap.containsValue("propertyset0"));
- assertTrue(propSetsMap.containsValue("propertyset1"));
- assertTrue(propSetsMap.containsValue("propertyset2"));
+ assertTrue("property set map should contain: propertyset0, ", propSetsMap.containsValue("propertyset0"));
+ assertTrue("property set map should contain: propertyset1, ", propSetsMap.containsValue("propertyset1"));
+ assertTrue("property set map should contain: propertyset2, ", propSetsMap.containsValue("propertyset2"));
}
- catch (PropertyException propexc)
+ catch (PropertyException pex)
{
- assertTrue(false);
+ assertTrue("could not get property set map: " + pex, false);
}
destroyPropertySetDefTestObject(true);
@@ -237,7 +253,7 @@
}
catch (PropertyException pex)
{
- assertTrue(false);
+ assertTrue("could not initialize property set definition. exception caught: " + pex, false);
}
try
@@ -246,7 +262,7 @@
}
catch (PropertyException pex)
{
- assertTrue(false);
+ assertTrue("could not remove property set definition. exception caught: " + pex, false);
}
int propertySetDefId = -1;
@@ -256,7 +272,9 @@
}
catch (PropertyException pex)
{
- assertTrue(true);
+ assertTrue(
+ "caught expected exception while getting property set definition id for propertyset0. exception caught: " + pex,
+ true);
}
}
@@ -274,7 +292,7 @@
}
catch (PropertyException pex)
{
- assertTrue(false);
+ assertTrue("could not initialize property set definition. exception caught: " + pex, false);
}
try
@@ -285,11 +303,13 @@
"propertyName0".toLowerCase());
pms.updatePropertyKey(ppkId.intValue(), "PropertyNameUpdate0");
Map updatedPropertyMap = pms.getPropertyKeysBySetDef(propertySetDefs[0]);
- assertTrue(updatedPropertyMap.containsValue("PropertyNameUpdate0"));
+ assertTrue(
+ "updated property set map should contain: PropertyNameUpdate0 in lower case, ",
+ updatedPropertyMap.containsValue("PropertyNameUpdate0"));
}
- catch (PropertyException propexc)
+ catch (PropertyException pex)
{
- assertTrue(false);
+ assertTrue("could not get updated property set map: " + pex, false);
}
destroyPropertySetDefTestObject(true);
@@ -326,9 +346,9 @@
prefs1.put("propertyName0", "true");
}
- catch (PropertyException propexc)
+ catch (PropertyException pex)
{
- assertTrue(false);
+ assertTrue("could not add property keys: " + pex, false);
}
// Now let's remove the keys.
@@ -339,20 +359,20 @@
propms.removePropertyKey(((Integer) i.next()).intValue());
}
}
- catch (PropertyException propexc)
+ catch (PropertyException pex)
{
- assertTrue(false);
+ assertTrue("could not remove property keys: " + pex, false);
}
// Let's verify it was removed.
try
{
Map propKeysCol = propms.getPropertyKeysBySetDef(propertySetDefs[0]);
- assertEquals(0, propKeysCol.size());
+ assertEquals("expected property key map size == 0, ", 0, propKeysCol.size());
}
- catch (PropertyException propexc)
+ catch (PropertyException pex)
{
- assertTrue(false);
+ assertTrue("could not get property keys: " + pex, false);
}
// Clean up everything else.
@@ -363,15 +383,15 @@
}
catch (BackingStoreException bse)
{
- assertTrue(false);
+ assertTrue("backing store exception: " + bse, false);
}
try
{
propms.removePropertySetDef(propertySetDefs[0]);
}
- catch (PropertyException propex)
+ catch (PropertyException pex)
{
- assertTrue(false);
+ assertTrue("could not remove property set definition: " + pex, false);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jetspeed-dev-help@jakarta.apache.org