?? testmarshallregistry.java
字號:
assertTrue(feeder.getName().equals("Feeder"));
assertTrue(feeder.getType().equals("ref"));
Iterator fi = feeder.listCategories();
Category cat = (Category) fi.next();
assertTrue(cat.getName().equals("news.world.politics"));
assertTrue(cat.getGroup().equals("news"));
assertTrue(feeder.hasCategory("news.world.politics", "news"));
feeder.addCategory("news.us.economy");
assertTrue(feeder.hasCategory("news.us.economy"));
feeder.removeCategory("news.us.economy");
assertTrue(!feeder.hasCategory("news.us.economy"));
/*
Iterator fi = feeder.listCategories();
Category cat = (Category)fi.next();
System.out.println("cat = " + cat.getName());
System.out.println("cat.group = " + cat.getGroup());
}
*/
}
catch (Exception e)
{
String errmsg = "Error in xreg mapping creation: " + e.toString();
// e.printStackTrace();
assertNotNull(errmsg, null);
}
}
else
{
String errmsg = "Registy Mapping not found or not a file or unreadable: ";
System.err.println(errmsg);
assertNotNull(errmsg, null);
}
}
/**
* Tests unmarshaling registry fragment
* @throws Exception
*/
public void testUnmarshallSecurityRegistry() throws Exception
{
boolean entryFound = false;
System.out.println("Testing marshalling of Registry security-entry");
String xregFile = "webapp/WEB-INF/psml/test/testcase-security.xreg";
Mapping mapping = null;
String mapFile = getMappingFileName();
File map = new File(mapFile);
if (map.exists() && map.isFile() && map.canRead())
{
FileReader reader = new FileReader(xregFile);
mapping = new Mapping();
InputSource is = new InputSource(new FileReader(map));
is.setSystemId(mapFile);
mapping.loadMapping(is);
Unmarshaller unmarshaller = new Unmarshaller(mapping);
RegistryFragment fragment = (RegistryFragment) unmarshaller.unmarshal(reader);
assertNotNull(fragment);
Vector securityEntries = fragment.getSecurityEntries();
assertTrue("Security Entries exist", !securityEntries.isEmpty());
// test abstract
SecurityEntry securityEntry = (SecurityEntry) securityEntries.firstElement();
assertNotNull("Got first Security Entry", securityEntry);
assertTrue("Getting expect security entry", securityEntry.getName().equals("basic_testcase"));
// Get the action
Vector securityAccesses = securityEntry.getAccesses();
assertNotNull("Got SecurityAccesses", securityAccesses);
SecurityAccess securityAccess = (SecurityAccess) securityAccesses.firstElement();
assertNotNull("Got SecurityAccess", securityAccess);
assertEquals("Verify action", "view", securityAccess.getAction());
// Get allows
Vector securityAllows = securityAccess.getAllows();
assertNotNull("Got SecurityAllows", securityAllows);
SecurityAllow securityAllow = (SecurityAllow) securityAllows.firstElement();
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());
securityAllow = (SecurityAllow) securityAllows.elementAt(2);
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"));
// 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"));
// 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"));
// 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"));
// Test the wide-open entry
entryFound = false;
for (Iterator securityIterator = securityEntries.iterator(); securityIterator.hasNext();)
{
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"));
}
}
assertTrue("Found wide_open security entry", entryFound);
// Test the owner-only entry
entryFound = false;
for (Iterator securityIterator = securityEntries.iterator(); securityIterator.hasNext();)
{
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"));
}
}
assertTrue("Found owner_only security entry", entryFound);
}
}
public void testUnmarshallSecurityReference() throws Exception
{
System.out.println("Testing marshalling of Registry security-ref");
String xregFile = "webapp/WEB-INF/psml/test/testcase-security.xreg";
Mapping mapping = null;
String mapFile = getMappingFileName();
File map = new File(mapFile);
if (map.exists() && map.isFile() && map.canRead())
{
FileReader reader = new FileReader(xregFile);
mapping = new Mapping();
InputSource is = new InputSource(new FileReader(map));
is.setSystemId(mapFile);
mapping.loadMapping(is);
Unmarshaller unmarshaller = new Unmarshaller(mapping);
RegistryFragment fragment = (RegistryFragment) unmarshaller.unmarshal(reader);
assertNotNull(fragment);
Vector securityEntries = fragment.getSecurityEntries();
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();
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());
}
}
assertTrue("Found wide_open security entry", entryFound);
// Test the use_only entry
entryFound = false;
for (securityIterator = securityEntries.iterator(); securityIterator.hasNext();)
{
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);
}
}
assertEquals("Found user_only security entry", true, entryFound);
}
}
/**
* Tests IdentityElement unmarshaling entryset base stuff
* @throws Exception
*/
/*
Configuration object to run Turbine outside a servlet container
( uses turbine.properties )
*/
private static TurbineConfig config = null;
/*
Sets up TurbineConfig using the system property:
<pre>turbine.properties</pre>
*/
static
{
try
{
config = new TurbineConfig("webapp", "/WEB-INF/conf/TurbineResources.properties");
config.init();
}
catch (Exception e)
{
fail(StringUtils.stackTrace(e));
}
}
public void testUnmarshallURL() throws Exception
{
System.out.println("Testing marshalling of Registry, URL");
String xregFile = "webapp/WEB-INF/psml/test/url-testcase.xreg";
Mapping mapping = null;
String mapFile = getMappingFileName();
File map = new File(mapFile);
if (map.exists() && map.isFile() && map.canRead())
{
try
{
FileReader reader = new FileReader(xregFile);
mapping = new Mapping();
InputSource is = new InputSource(new FileReader(map));
is.setSystemId(mapFile);
mapping.loadMapping(is);
Unmarshaller unmarshaller = new Unmarshaller(mapping);
ContentURL url = (ContentURL) unmarshaller.unmarshal(reader);
assertNotNull(url);
System.out.println(url.getURL());
assertTrue(url.getURL().equals("http://www.xmlhack.com/rss.php"));
assertTrue(url.isCacheKey());
}
catch (Exception e)
{
String errmsg = "Error in xreg mapping creation: " + e.toString();
System.err.println(errmsg);
assertNotNull(errmsg, null);
}
}
else
{
String errmsg = "Registy Mapping not found or not a file or unreadable: ";
System.err.println(errmsg);
assertNotNull(errmsg, null);
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -