testmarshalpsml.java
来自「jetspeed源代码」· Java 代码 · 共 631 行 · 第 1/2 页
JAVA
631 行
assertNotNull(ref);
assertTrue(ref.getName().equals("ReferenceTest"));
assertTrue(ref.getId().equals("300"));
Portlets epr = ref.getPortletsReference();
assertNotNull(epr);
assertEquals("group/apache/page/news/media-type/html", ref.getPath());
/* SHIT
assertNotNull(epr.getMetaInfo());
assertNotNull(epr.getMetaInfo().getTitle());
assertTrue(epr.getMetaInfo().getTitle().equals("Default Apache News page"));
// DST: - TODO: only use 'test' psml for unit tests -
// otherwise the tests are against moving targets;
// DST: assertTrue(epr.getController().getParameter("mode").getValue().equals("row"));
// DST: assertTrue(epr.getSkin().getParameter("selected-color").getValue().equals("#990000"));
Entry ent = epr.getEntry(0);
assertTrue(ent.getParent().equals("Apacheweek"));
Iterator itt = p.getPortletsIterator();
while (itt.hasNext())
{
Portlets pp = (Portlets)itt.next();
System.out.println(" PORTLETS %%% " + pp.getId());
if (pp instanceof Reference)
{
System.out.println(" PORTLETS %%% REF: " + pp.getId());
}
}
*/
}
catch (Exception e)
{
String errmsg = "Error in psml mapping creation: " + e.toString();
e.printStackTrace();
System.err.println(errmsg);
assertNotNull(errmsg, null);
}
}
else
{
String errmsg = "PSML Mapping not found or not a file or unreadable: ";
System.err.println(errmsg);
assertNotNull(errmsg, null);
}
}
/**
* Tests unmarshaling security
* @throws Exception
*/
public void testUnmarshalSecurity() throws Exception
{
System.out.println("Testing marshalling of PSML on base *** Security ***");
String psmlFile = "webapp/WEB-INF/psml/test/testsecurity.psml";
Mapping mapping = null;
String mapFile = getMappingFileName();
File map = new File(mapFile);
if (map.exists() && map.isFile() && map.canRead())
{
try
{
FileReader reader = new FileReader(psmlFile);
mapping = new Mapping();
InputSource is = new InputSource( new FileReader(map) );
is.setSystemId( mapFile );
mapping.loadMapping( is );
Unmarshaller unmarshaller = new Unmarshaller(mapping);
Security security = (Security)unmarshaller.unmarshal(reader);
assertNotNull(security);
assertTrue(security.getId().equals("1000"));
}
catch (Exception e)
{
String errmsg = "Error in psml mapping creation: " + e.toString();
System.err.println(errmsg);
assertNotNull(errmsg, null);
}
}
else
{
String errmsg = "PSML Mapping not found or not a file or unreadable.";
System.err.println(errmsg);
assertNotNull(errmsg, null);
}
}
/**
* Tests unmarshaling security
* @throws Exception
*/
public void testUnmarshalSecurityRef() throws Exception
{
System.out.println("Testing marshalling of PSML on base *** Security-ref ***");
String psmlFile = "webapp/WEB-INF/psml/test/testcase_securityref.psml";
Mapping mapping = null;
String mapFile = getMappingFileName();
File map = new File(mapFile);
if (map.exists() && map.isFile() && map.canRead())
{
FileReader reader = new FileReader(psmlFile);
mapping = new Mapping();
InputSource is = new InputSource( new FileReader(map) );
is.setSystemId( mapFile );
mapping.loadMapping( is );
System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++");
Unmarshaller unmarshaller = new Unmarshaller(mapping);
Portlets rootset = (Portlets)unmarshaller.unmarshal(reader);
System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++");
assertTrue(rootset.getName().equals("theRootSet"));
assertTrue(rootset.getId().equals("01"));
SecurityReference securityRef = rootset.getSecurityRef();
assertNotNull("got SecurityRef", securityRef);
assertEquals( "Name of parent", "all_users", securityRef.getParent());
}
else
{
String errmsg = "PSML Mapping not found or not a file or unreadable.";
System.err.println(errmsg);
assertNotNull(errmsg, null);
}
}
/*
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 testMarshalPsml() throws Exception
{
System.out.println("Testing marshalling of PSML on base *** IdentityElement ***");
String psmlFile = "webapp/WEB-INF/psml/test/testcaseMarshall.psml";
Mapping mapping = null;
String mapFile = getMappingFileName();
File map = new File(mapFile);
if (map.exists() && map.isFile() && map.canRead())
{
try
{
FileReader reader = new FileReader(psmlFile);
mapping = new Mapping();
InputSource is = new InputSource( new FileReader(map) );
is.setSystemId( mapFile );
mapping.loadMapping( is );
System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++");
Unmarshaller unmarshaller = new Unmarshaller(mapping);
Portlets rootset = (Portlets)unmarshaller.unmarshal(reader);
System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++");
assertTrue(rootset.getName().equals("theRootSet"));
assertTrue(rootset.getId().equals("01"));
Iterator itt = rootset.getPortletsIterator();
while (itt.hasNext())
{
Portlets pp = (Portlets)itt.next();
System.out.println(" PORTLETS %%% " + pp.getId());
if (pp instanceof Reference)
{
System.out.println(" PORTLETS %%% REF: " + pp.getId());
}
}
Iterator itr = rootset.getReferenceIterator();
while (itr.hasNext())
{
Reference r = (Reference)itr.next();
System.out.println(" REFERENCE %%% " + r.getId());
}
OutputFormat format = new OutputFormat();
format.setIndenting(true);
format.setIndent(4);
File f = new File("marshalled.psml");
FileWriter writer = null;
writer = new FileWriter(f);
System.out.println("-----------------------------------------------------------------");
Serializer serializer = new XMLSerializer(writer, format);
Marshaller marshaller = new Marshaller(serializer.asDocumentHandler());
marshaller.setMapping(mapping);
marshaller.marshal(rootset);
System.out.println("-----------------------------------------------------------------");
System.out.println("done");
}
catch (Exception e)
{
String errmsg = "Error in psml mapping creation: " + e.toString();
e.printStackTrace();
System.err.println(errmsg);
assertNotNull(errmsg, null);
}
}
else
{
String errmsg = "PSML Mapping not found or not a file or unreadable: ";
System.err.println(errmsg);
assertNotNull(errmsg, null);
}
}
public void testMetaInfo() throws Exception
{
boolean foundEntry07 = false;
boolean foundPortlet02 = false;
System.out.println("Testing marshalling of PSML on base *** IdentityElement ***");
String psmlFile = "webapp/WEB-INF/psml/test/testcaseMarshall.psml";
Mapping mapping = null;
String mapFile = getMappingFileName();
File map = new File(mapFile);
if (map.exists() && map.isFile() && map.canRead())
{
try
{
FileReader reader = new FileReader(psmlFile);
mapping = new Mapping();
InputSource is = new InputSource( new FileReader(map) );
is.setSystemId( mapFile );
mapping.loadMapping( is );
System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++");
Unmarshaller unmarshaller = new Unmarshaller(mapping);
Portlets rootset = (Portlets)unmarshaller.unmarshal(reader);
System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++");
assertTrue(rootset.getName().equals("theRootSet"));
assertTrue(rootset.getId().equals("01"));
Iterator itt = rootset.getPortletsIterator();
while (itt.hasNext())
{
Portlets pp = (Portlets)itt.next();
System.out.println(" PORTLETS %%% " + pp.getId());
if ( pp.getId().equals("02"))
{
foundPortlet02 = true;
MetaInfo pp02MetaInfo = pp.getMetaInfo();
assertNotNull( "Portlet ID 02 has metaInfo", pp02MetaInfo);
assertEquals( "Portlet ID 02 Title", "Portlet Title", pp02MetaInfo.getTitle());
assertEquals( "Portlet ID 02 Title", "Portlet Description", pp02MetaInfo.getDescription());
assertEquals( "Portlet ID 02 Title", "Portlet Image", pp02MetaInfo.getImage());
Iterator pp02itt = pp.getEntriesIterator();
while (pp02itt.hasNext())
{
Entry pp02Entry = (Entry) pp02itt.next();
assertNotNull( "Portlet Id 02 has entry", pp02Entry);
if (pp02Entry.getId().equals("07"))
{
foundEntry07 = true;
MetaInfo entry07MetaInfo = pp02Entry.getMetaInfo();
assertNotNull( "Entry ID 07 has metaInfo", entry07MetaInfo);
assertEquals( "Entry ID 07 Title", "Entry Title", entry07MetaInfo.getTitle());
assertEquals( "Entry ID 07 Title", "Entry Description", entry07MetaInfo.getDescription());
assertEquals( "Entry ID 07 Title", "Entry Image", entry07MetaInfo.getImage());
}
}
}
}
assertTrue( "Tested Portlet 02", foundPortlet02);
assertTrue( "Tested Entry 07", foundEntry07);
}
catch (Exception e)
{
String errmsg = "Error in psml mapping creation: " + e.toString();
e.printStackTrace();
System.err.println(errmsg);
assertNotNull(errmsg, null);
}
}
else
{
String errmsg = "PSML Mapping not found or not a file or unreadable: ";
System.err.println(errmsg);
assertNotNull(errmsg, null);
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?