KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > services > portal > test > TestConverter


1 /***************************************************************************
2  * Copyright 2001-2003 The eXo Platform SARL All rights reserved. *
3  * Please look at license.txt in info directory for more license detail. *
4  **************************************************************************/

5 package org.exoplatform.services.portal.test;
6
7 import java.io.InputStream JavaDoc;
8 import java.net.URL JavaDoc;
9 import org.exoplatform.services.portal.impl.*;
10 import org.exoplatform.services.portal.impl.converter.*;
11 import org.exoplatform.services.portal.model.*;
12 import org.exoplatform.services.portletcontainer.pci.model.ExoPortletPreferences;
13 import org.exoplatform.services.portletcontainer.pci.model.Preference;
14 import org.exoplatform.test.BasicTestCase;
15
16 import com.thoughtworks.xstream.XStream;
17 import com.thoughtworks.xstream.io.xml.XppDriver;
18
19 /**
20  * Thu, May 15, 2003 @
21  * @author: Tuan Nguyen
22  * @version: $Id: TestConverter.java,v 1.6 2004/07/20 12:41:09 tuan08 Exp $
23  * @since: 0.0
24  * @email: tuan08@yahoo.com
25  */

26 public class TestConverter extends BasicTestCase {
27   private XStream xstream_ ;
28   
29   public TestConverter(String JavaDoc name) {
30     super(name);
31   }
32
33   public void setUp() throws Exception JavaDoc {
34     xstream_ = new XStream(new XppDriver());
35     xstream_.alias("user-portal-config", Backup.class);
36     xstream_.alias("portal-config", PortalConfig.class);
37     xstream_.alias("page-set", PageSet.class);
38     xstream_.alias("page", Page.class);
39     xstream_.alias("container", Container.class);
40     xstream_.alias("portlet", Portlet.class);
41     xstream_.alias("body", Body.class);
42     xstream_.alias("node", NodeImpl.class);
43     xstream_.registerConverter(new PortletConverter());
44     xstream_.registerConverter(new ExoPortletPreferencesConverter());
45     xstream_.registerConverter(new PreferenceConverter());
46   }
47   
48   public void testConverter() throws Exception JavaDoc {
49     Portlet portlet = new Portlet() ;
50     portlet.setRenderer("renderer") ;
51     portlet.setDecorator("decorator") ;
52     Preference pref = new Preference() ;
53     pref.setName("test") ;
54     pref.addValue("test") ;
55     ExoPortletPreferences prefs = new ExoPortletPreferences() ;
56     prefs.put(pref.getName(), pref) ;
57     portlet.setPortletPreferences(prefs) ;
58     String JavaDoc xml = xstream_.toXML(portlet);
59     System.out.println(xml) ;
60     portlet = (Portlet) xstream_.fromXML(xml) ;
61     assertEquals("Expect renderer value", "renderer", portlet.getRenderer()) ;
62     assertEquals("Expect decorator value", "decorator", portlet.getDecorator()) ;
63   }
64   
65   public void testParser() throws Exception JavaDoc {
66     /*
67      URL url = new URL("file:./src/java/exo/services/portal/conf/exo-config.xml");
68      InputStream is = url.openStream() ;
69      PortalConfig pc = XMLParser.parsePortal(is) ;
70      */

71   }
72   protected String JavaDoc getDescription() {
73     return "Test Converter" ;
74   }
75 }
Popular Tags