paulsp 2002/08/25 14:12:44
Modified: src/java/org/apache/jetspeed/services/registry
TestMarshallRegistry.java
Log:
o Housekeeping directed by checkStyle.
No functional changes
Revision Changes Path
1.6 +107 -95
jakarta-jetspeed/src/java/org/apache/jetspeed/services/registry/TestMarshallRegistry.java
Index: TestMarshallRegistry.java
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/services/registry/TestMarshallRegistry.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- TestMarshallRegistry.java 25 Aug 2002 19:09:42 -0000 1.5
+++ TestMarshallRegistry.java 25 Aug 2002 21:12:44 -0000 1.6
@@ -68,20 +68,23 @@
import junit.framework.TestCase;
//castor support
-import org.exolab.castor.xml.MarshalException;
import org.exolab.castor.xml.Unmarshaller;
-import org.exolab.castor.xml.ValidationException;
import org.exolab.castor.mapping.Mapping;
-import org.exolab.castor.mapping.MappingException;
import org.xml.sax.InputSource;
-import org.apache.jetspeed.om.registry.*;
+// Jetspeed imports
+import org.apache.jetspeed.om.registry.CachedParameter;
+import org.apache.jetspeed.om.registry.Category;
+import org.apache.jetspeed.om.registry.ContentURL;
+import org.apache.jetspeed.om.registry.MetaInfo;
+import org.apache.jetspeed.om.registry.Parameter;
+import org.apache.jetspeed.om.registry.PortletEntry;
+import org.apache.jetspeed.om.registry.SecurityAccess;
+import org.apache.jetspeed.om.registry.SecurityAllow;
+import org.apache.jetspeed.om.registry.SecurityEntry;
import org.apache.jetspeed.om.SecurityReference;
-import org.apache.turbine.services.TurbineServices;
-import org.apache.jetspeed.services.idgenerator.*;
-import org.apache.stratum.configuration.Configuration;
-import org.apache.stratum.configuration.PropertiesConfiguration;
+// Turbine imports
import org.apache.turbine.util.TurbineConfig;
import org.apache.turbine.util.StringUtils;
@@ -92,15 +95,17 @@
* @version $Id$
*/
-public class TestMarshallRegistry extends TestCase {
+public class TestMarshallRegistry extends TestCase
+{
/**
* Defines the testcase name for JUnit.
*
* @param name the testcase's name.
*/
- public TestMarshallRegistry( String name ) {
- super( name );
+ public TestMarshallRegistry(String name)
+ {
+ super(name);
}
/**
@@ -108,22 +113,26 @@
*
* @param args the arguments. Not used
*/
- public static void main(String args[]) {
- junit.awtui.TestRunner.main( new String[] {
TestMarshallRegistry.class.getName() } );
+ public static void main(String args[])
+ {
+ junit.awtui.TestRunner.main(new String[] {
TestMarshallRegistry.class.getName() });
}
- public void setup() {
+ public void setup()
+ {
System.out.println("Setup: Testing marshalling of Registry");
}
+
/**
* Creates the test suite.
*
* @return a test suite (<code>TestSuite</code>) that includes all methods
* starting with "test"
*/
- public static Test suite() {
+ public static Test suite()
+ {
// All methods starting with "test" will be executed in the test suite.
- return new TestSuite( TestMarshallRegistry.class );
+ return new TestSuite(TestMarshallRegistry.class);
}
private String getMappingFileName()
@@ -150,17 +159,17 @@
{
FileReader reader = new FileReader(xregFile);
mapping = new Mapping();
- InputSource is = new InputSource( new FileReader(map) );
- is.setSystemId( mapFile );
- mapping.loadMapping( is );
+ InputSource is = new InputSource(new FileReader(map));
+ is.setSystemId(mapFile);
+ mapping.loadMapping(is);
Unmarshaller unmarshaller = new Unmarshaller(mapping);
- RegistryFragment fragment =
(RegistryFragment)unmarshaller.unmarshal(reader);
+ RegistryFragment fragment = (RegistryFragment)
unmarshaller.unmarshal(reader);
assertNotNull(fragment);
Vector portlets = fragment.getPortlets();
// test abstract
- PortletEntry rss = (PortletEntry)portlets.elementAt(1);
+ PortletEntry rss = (PortletEntry) portlets.elementAt(1);
assertNotNull(rss);
assertTrue(rss.getName().equals("RSS"));
assertTrue(!rss.isHidden());
@@ -173,7 +182,7 @@
HashMap mapParams = new HashMap();
while (it.hasNext())
{
- String name = (String)it.next();
+ String name = (String) it.next();
Parameter p = rss.getParameter(name);
assertNotNull(p);
//System.out.println("PARAM:" + p.getName() + " = " +
p.getValue());
@@ -184,7 +193,7 @@
assertTrue(mapParams.containsKey("itemdisplayed"));
// test ref
- PortletEntry hack = (PortletEntry)portlets.elementAt(2);
+ PortletEntry hack = (PortletEntry) portlets.elementAt(2);
assertNotNull(hack);
assertTrue(hack.getName().equals("XMLHack"));
assertTrue(hack.isHidden());
@@ -201,7 +210,7 @@
it = hack.getParameterNames();
while (it.hasNext())
{
- String name = (String)it.next();
+ String name = (String) it.next();
Parameter p = hack.getParameter(name);
assertNotNull(p);
//System.out.println("HACK PARAM:" + p.getName() + " = " +
p.getValue());
@@ -211,19 +220,19 @@
assertTrue(mapParams.containsKey("stylesheet"));
assertTrue(mapParams.containsKey("itemdisplayed"));
assertTrue(mapParams.containsKey("HACK"));
- Parameter p = (Parameter)mapParams.get("HACK");
+ Parameter p = (Parameter) mapParams.get("HACK");
assertTrue(p.getValue().equals("hacker"));
- Parameter p2 = (Parameter)mapParams.get("showtitle");
+ Parameter p2 = (Parameter) mapParams.get("showtitle");
MetaInfo p2m = p2.getMetaInfo();
assertTrue(p2m.getTitle().equals("Show title description ?"));
assertTrue(p2.getTitle().equals("Show title description ?"));
Map pMap = hack.getParameterMap();
- String v15 = (String)pMap.get("itemdisplayed");
+ String v15 = (String) pMap.get("itemdisplayed");
assertTrue(v15.equals("15"));
// test falling back on meta info
- PortletEntry mp = (PortletEntry)portlets.elementAt(5);
+ PortletEntry mp = (PortletEntry) portlets.elementAt(5);
assertNotNull(mp);
assertTrue(mp.getName().equals("MetaTest"));
assertTrue(mp.getType().equals("ref"));
@@ -242,9 +251,9 @@
Iterator mpi = mp.listMediaTypes();
assertNotNull(mpi);
HashMap mpMap = new HashMap();
- while(mpi.hasNext())
+ while (mpi.hasNext())
{
- String s = (String)mpi.next();
+ String s = (String) mpi.next();
mpMap.put(s, s);
}
assertTrue(mpMap.containsKey("html"));
@@ -252,20 +261,20 @@
assertTrue(mpMap.containsKey("xml"));
assertTrue(mp.hasMediaType("wml"));
- PortletEntry mt = (PortletEntry)portlets.elementAt(6);
+ PortletEntry mt = (PortletEntry) portlets.elementAt(6);
assertNotNull(mt);
assertTrue(mt.getName().equals("NoMediaType"));
assertTrue(mt.getType().equals("ref"));
Iterator mti = mt.listMediaTypes();
assertNotNull(mti);
assertTrue(mti.hasNext());
- String s = (String)mti.next();
+ String s = (String) mti.next();
assertTrue(s.equals("html"));
assertTrue(hack.getURL().equals("http://www.xmlhack.com/rss.php"));
assertTrue(hack.isCachedOnURL());
- PortletEntry keytest = (PortletEntry)portlets.elementAt(7);
+ PortletEntry keytest = (PortletEntry) portlets.elementAt(7);
assertNotNull(keytest);
assertTrue(keytest.getName().equals("KeyTest"));
assertTrue(keytest.getType().equals("ref"));
@@ -273,7 +282,7 @@
mpMap.clear();
while (it.hasNext())
{
- String name = (String)it.next();
+ String name = (String) it.next();
CachedParameter cp = keytest.getCachedParameter(name);
mpMap.put(cp.getName(), cp);
//System.out.println("param = " + cp.getName() + "," +
cp.getValue());
@@ -281,30 +290,30 @@
}
assertTrue(keytest.isCachedOnURL() == false);
- CachedParameter cp = (CachedParameter)mpMap.get("newsid");
+ CachedParameter cp = (CachedParameter) mpMap.get("newsid");
assertNotNull(cp);
assertTrue(cp.isCachedOnName() == false);
assertTrue(cp.isCachedOnValue() == true);
- cp = (CachedParameter)mpMap.get("sportsid");
+ cp = (CachedParameter) mpMap.get("sportsid");
assertNotNull(cp);
assertTrue(cp.isCachedOnName() == true);
assertTrue(cp.isCachedOnValue() == false);
- cp = (CachedParameter)mpMap.get("contact2");
+ cp = (CachedParameter) mpMap.get("contact2");
assertNotNull(cp);
assertTrue(cp.isCachedOnName() == true);
assertTrue(cp.isCachedOnValue() == true);
- cp = (CachedParameter)mpMap.get("showtitle");
+ cp = (CachedParameter) mpMap.get("showtitle");
assertNotNull(cp);
assertTrue(cp.isCachedOnName() == true);
assertTrue(cp.isCachedOnValue() == true);
// categories
- PortletEntry feeder = (PortletEntry)portlets.elementAt(3);
+ PortletEntry feeder = (PortletEntry) portlets.elementAt(3);
assertNotNull(feeder);
assertTrue(feeder.getName().equals("Feeder"));
assertTrue(feeder.getType().equals("ref"));
Iterator fi = feeder.listCategories();
- Category cat = (Category)fi.next();
+ Category cat = (Category) fi.next();
assertTrue(cat.getName().equals("news.world.politics"));
assertTrue(cat.getGroup().equals("news"));
assertTrue(feeder.hasCategory("news.world.politics", "news"));
@@ -354,75 +363,75 @@
{
FileReader reader = new FileReader(xregFile);
mapping = new Mapping();
- InputSource is = new InputSource( new FileReader(map) );
- is.setSystemId( mapFile );
- mapping.loadMapping( is );
+ InputSource is = new InputSource(new FileReader(map));
+ is.setSystemId(mapFile);
+ mapping.loadMapping(is);
Unmarshaller unmarshaller = new Unmarshaller(mapping);
- RegistryFragment fragment =
(RegistryFragment)unmarshaller.unmarshal(reader);
+ RegistryFragment fragment = (RegistryFragment)
unmarshaller.unmarshal(reader);
assertNotNull(fragment);
Vector securityEntries = fragment.getSecurityEntries();
- assertTrue( "Security Entries exist", !securityEntries.isEmpty());
+ assertTrue("Security Entries exist", !securityEntries.isEmpty());
// test abstract
- SecurityEntry securityEntry =
(SecurityEntry)securityEntries.firstElement();
+ SecurityEntry securityEntry = (SecurityEntry)
securityEntries.firstElement();
assertNotNull("Got first Security Entry", securityEntry);
- assertTrue("Getting expect security
entry",securityEntry.getName().equals("basic_testcase"));
+ assertTrue("Getting expect security entry",
securityEntry.getName().equals("basic_testcase"));
// Get the action
Vector securityAccesses = securityEntry.getAccesses();
- assertNotNull( "Got SecurityAccesses", securityAccesses);
+ assertNotNull("Got SecurityAccesses", securityAccesses);
SecurityAccess securityAccess = (SecurityAccess)
securityAccesses.firstElement();
- assertNotNull( "Got SecurityAccess", securityAccess);
- assertEquals( "Verify action", "view", securityAccess.getAction());
+ assertNotNull("Got SecurityAccess", securityAccess);
+ assertEquals("Verify action", "view", securityAccess.getAction());
// Get allows
Vector securityAllows = securityAccess.getAllows();
- assertNotNull( "Got SecurityAllows", securityAllows);
+ assertNotNull("Got SecurityAllows", securityAllows);
SecurityAllow securityAllow = (SecurityAllow)
securityAllows.firstElement();
- assertNotNull( "Got SecurityAllow", securityAllow);
- assertEquals( "Verify role", "clerk", securityAllow.getRole());
- assertNull( "Verify user" , securityAllow.getUser());
+ assertNotNull("Got SecurityAllow", securityAllow);
+ assertEquals("Verify role", "clerk", securityAllow.getRole());
+ assertNull("Verify user" , securityAllow.getUser());
securityAllow = (SecurityAllow) securityAllows.elementAt(1);
- assertNotNull( "Got SecurityAllow", securityAllow);
- assertNull( "Verify role", securityAllow.getRole());
- assertEquals( "Verify user", "joe" , securityAllow.getUser());
+ assertNotNull("Got SecurityAllow", securityAllow);
+ assertNull("Verify role", securityAllow.getRole());
+ assertEquals("Verify user", "joe", securityAllow.getUser());
securityAllow = (SecurityAllow) securityAllows.elementAt(2);
- assertNotNull( "Got SecurityAllow", securityAllow);
- assertEquals( "Verify role", "manager", securityAllow.getRole());
- assertEquals( "Verify user", "fred" , securityAllow.getUser());
+ assertNotNull("Got SecurityAllow", securityAllow);
+ assertEquals("Verify role", "manager", securityAllow.getRole());
+ assertEquals("Verify user", "fred", securityAllow.getUser());
// test allows
- assertEquals( "clerk role can view", true,
securityEntry.allowsRole("clerk","view"));
- assertEquals( "manager role can view", true,
securityEntry.allowsRole("manager","view"));
- assertEquals( "anonymous role can NOT view", false,
securityEntry.allowsRole("anonymous","view"));
- assertEquals( "fred user can view", true,
securityEntry.allowsUser("fred","view"));
- assertEquals( "joe user can view", true,
securityEntry.allowsUser("joe","view"));
- assertEquals( "anonymous user can NOT view", false,
securityEntry.allowsUser("anonymous","view"));
+ assertEquals("clerk role can view", true,
securityEntry.allowsRole("clerk", "view"));
+ assertEquals("manager role can view", true,
securityEntry.allowsRole("manager", "view"));
+ assertEquals("anonymous role can NOT view", false,
securityEntry.allowsRole("anonymous", "view"));
+ assertEquals("fred user can view", true,
securityEntry.allowsUser("fred", "view"));
+ assertEquals("joe user can view", true, securityEntry.allowsUser("joe",
"view"));
+ assertEquals("anonymous user can NOT view", false,
securityEntry.allowsUser("anonymous", "view"));
// Customize has <allow-id user="*"/>
- assertEquals( "clerk role can NOT customize", false,
securityEntry.allowsRole("clerk","customize"));
- assertEquals( "joe user can customize", true,
securityEntry.allowsUser("joe","customize"));
+ assertEquals("clerk role can NOT customize", false,
securityEntry.allowsRole("clerk", "customize"));
+ assertEquals("joe user can customize", true,
securityEntry.allowsUser("joe", "customize"));
// Minimize has no <allows-if .../>
- assertEquals( "clerk role can NOT minimize", true,
securityEntry.allowsRole("clerk","minimize"));
- assertEquals( "joe user can NOT minimize", true,
securityEntry.allowsUser("joe","minimize"));
+ assertEquals("clerk role can NOT minimize", true,
securityEntry.allowsRole("clerk", "minimize"));
+ assertEquals("joe user can NOT minimize", true,
securityEntry.allowsUser("joe", "minimize"));
// Maximixe is not defined
- assertEquals( "clerk role can NOT maximize", false,
securityEntry.allowsRole("clerk","maximize"));
- assertEquals( "joe user can NOT maximize", false,
securityEntry.allowsUser("joe","maximize"));
+ assertEquals("clerk role can NOT maximize", false,
securityEntry.allowsRole("clerk", "maximize"));
+ assertEquals("joe user can NOT maximize", false,
securityEntry.allowsUser("joe", "maximize"));
// Test the wide-open entry
entryFound = false;
for (Iterator securityIterator = securityEntries.iterator();
securityIterator.hasNext();)
{
- securityEntry = (SecurityEntry)securityIterator.next();
+ securityEntry = (SecurityEntry) securityIterator.next();
if (securityEntry.getName().equals("wide_open") == true)
{
entryFound = true;
- assertEquals( "any role is NOT allowed", false,
securityEntry.allowsRole("customer", "do_any_thing"));
- assertEquals( "any user is allowed", true,
securityEntry.allowsUser("joe_customer", "do_any_thing"));
+ assertEquals("any role is NOT allowed", false,
securityEntry.allowsRole("customer", "do_any_thing"));
+ assertEquals("any user is allowed", true,
securityEntry.allowsUser("joe_customer", "do_any_thing"));
}
}
assertTrue("Found wide_open security entry", entryFound);
@@ -431,13 +440,16 @@
entryFound = false;
for (Iterator securityIterator = securityEntries.iterator();
securityIterator.hasNext();)
{
- securityEntry = (SecurityEntry)securityIterator.next();
+ securityEntry = (SecurityEntry) securityIterator.next();
if (securityEntry.getName().equals("owner_only") == true)
{
entryFound = true;
- assertEquals( "User joe_customer is not allowed", false,
securityEntry.allowsUser("joe_customer","do_any_thing"));
- assertEquals( "User joe_customer is not allowed", false,
securityEntry.allowsUser("joe_customer","do_any_thing", "joe_owner"));
- assertEquals( "User joe_owner is allowed", true,
securityEntry.allowsUser("joe_owner","do_any_thing", "joe_owner"));
+ assertEquals("User joe_customer is not allowed", false,
+ securityEntry.allowsUser("joe_customer",
"do_any_thing"));
+ assertEquals("User joe_customer is not allowed", false,
+ securityEntry.allowsUser("joe_customer",
"do_any_thing", "joe_owner"));
+ assertEquals("User joe_owner is allowed", true,
+ securityEntry.allowsUser("joe_owner",
"do_any_thing", "joe_owner"));
}
}
assertTrue("Found owner_only security entry", entryFound);
@@ -457,27 +469,27 @@
{
FileReader reader = new FileReader(xregFile);
mapping = new Mapping();
- InputSource is = new InputSource( new FileReader(map) );
- is.setSystemId( mapFile );
- mapping.loadMapping( is );
+ InputSource is = new InputSource(new FileReader(map));
+ is.setSystemId(mapFile);
+ mapping.loadMapping(is);
Unmarshaller unmarshaller = new Unmarshaller(mapping);
- RegistryFragment fragment =
(RegistryFragment)unmarshaller.unmarshal(reader);
+ RegistryFragment fragment = (RegistryFragment)
unmarshaller.unmarshal(reader);
assertNotNull(fragment);
Vector securityEntries = fragment.getSecurityEntries();
- assertTrue( "Security Entries exist", !securityEntries.isEmpty());
+ assertTrue("Security Entries exist", !securityEntries.isEmpty());
// Test the wide-open entry
boolean entryFound = false;
Iterator securityIterator = null;
for (securityIterator = securityEntries.iterator();
securityIterator.hasNext();)
{
- SecurityEntry securityEntry =
(SecurityEntry)securityIterator.next();
+ SecurityEntry securityEntry = (SecurityEntry)
securityIterator.next();
if (securityEntry.getName().equals("wide_open") == true)
{
entryFound = true;
SecurityReference securityReference =
securityEntry.getSecurityRef();
- assertNotNull( "Security entry 'wide_open' has a
SecurityReference", securityReference);
- assertEquals( "Got parent", "admin_only",
securityReference.getParent());
+ assertNotNull("Security entry 'wide_open' has a
SecurityReference", securityReference);
+ assertEquals("Got parent", "admin_only",
securityReference.getParent());
}
}
assertTrue("Found wide_open security entry", entryFound);
@@ -486,12 +498,12 @@
entryFound = false;
for (securityIterator = securityEntries.iterator();
securityIterator.hasNext();)
{
- SecurityEntry securityEntry =
(SecurityEntry)securityIterator.next();
+ SecurityEntry securityEntry = (SecurityEntry)
securityIterator.next();
if (securityEntry.getName().equals("user_only") == true)
{
entryFound = true;
SecurityReference securityReference =
securityEntry.getSecurityRef();
- assertNull( "Security entry 'user_open' has no
SecurityReference", securityReference);
+ assertNull("Security entry 'user_open' has no
SecurityReference", securityReference);
}
}
assertEquals("Found user_only security entry", true, entryFound);
@@ -518,7 +530,7 @@
{
try
{
- config = new TurbineConfig( "../webapp",
"/WEB-INF/conf/TurbineResources.properties");
+ config = new TurbineConfig("../webapp",
"/WEB-INF/conf/TurbineResources.properties");
config.init();
}
catch (Exception e)
@@ -543,11 +555,11 @@
{
FileReader reader = new FileReader(xregFile);
mapping = new Mapping();
- InputSource is = new InputSource( new FileReader(map) );
- is.setSystemId( mapFile );
- mapping.loadMapping( is );
+ InputSource is = new InputSource(new FileReader(map));
+ is.setSystemId(mapFile);
+ mapping.loadMapping(is);
Unmarshaller unmarshaller = new Unmarshaller(mapping);
- ContentURL url = (ContentURL)unmarshaller.unmarshal(reader);
+ ContentURL url = (ContentURL) unmarshaller.unmarshal(reader);
assertNotNull(url);
System.out.println(url.getURL());
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>