KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.List JavaDoc;
8 import org.exoplatform.container.PortalContainer;
9 import org.exoplatform.services.database.HibernateService;
10 import org.exoplatform.services.organization.OrganizationService;
11 import org.exoplatform.services.organization.User;
12 import org.exoplatform.services.portal.PortalConfigDescription;
13 import org.exoplatform.services.portal.PortalConfigService;
14 import org.exoplatform.services.portal.Query;
15 import org.exoplatform.services.portal.impl.NodeImpl;
16 import org.exoplatform.services.portal.model.Node;
17 import org.exoplatform.services.portal.model.Page;
18 import org.exoplatform.services.portal.model.PageReference;
19 import org.exoplatform.services.portal.model.PortalConfig;
20 import org.exoplatform.test.BasicTestCase;
21
22 /**
23  * Thu, May 15, 2003 @
24  * @author: Tuan Nguyen
25  * @version: $Id: TestPortalConfigService.java,v 1.19 2004/10/20 20:56:28 tuan08 Exp $
26  * @since: 0.0
27  * @email: tuan08@yahoo.com
28  */

29 public class TestPortalConfigService extends BasicTestCase {
30   static protected PortalConfigService service_ ;
31   static protected OrganizationService orgService_ ;
32
33   public TestPortalConfigService(String JavaDoc name) {
34     super(name);
35   }
36
37   public void setUp() throws Exception JavaDoc {
38     if (service_ == null) {
39       PortalContainer manager = PortalContainer.getInstance();
40       service_ =
41         (PortalConfigService) manager.getComponentInstanceOfType(PortalConfigService.class) ;
42       orgService_ = (OrganizationService) manager.getComponentInstanceOfType(OrganizationService.class);
43     }
44   }
45   
46   public void tearDown() throws Exception JavaDoc {
47     PortalContainer manager = PortalContainer.getInstance();
48     HibernateService hservice =
49         (HibernateService) manager.getComponentInstanceOfType(HibernateService.class) ;
50     hservice.closeSession();
51   }
52   
53   public void testService() throws Exception JavaDoc {
54     String JavaDoc[] users = {"exo", "admin", "demo", "exotest"} ;
55     createUser("exotest") ;
56     for(int i = 0 ; i < users.length; i++) {
57         String JavaDoc owner = users[i] ;
58         PortalConfig config = service_.getPortalConfig(owner) ;
59         Node root = service_.getNodeNavigation(owner) ;
60         assertNodeData(root) ;
61         Query q = new Query(owner , null , null ) ;
62         List JavaDoc list = service_.findAllPageDescriptions(q).getAll() ;
63         assertTrue("Expect at least one page ", list.size() > 0) ;
64         
65         list = service_.findAllPortalConfigDescriptions(q).getAll() ;
66         assertTrue("Expect at least one portal config ", list.size() == 1) ;
67         PortalConfigDescription desc = (PortalConfigDescription) list.get(0);
68         assertTrue("View Permission is not null ", desc.getViewPermission() != null ) ;
69         assertTrue("View Permission is not null ", desc.getEditPermission() != null ) ;
70         
71         String JavaDoc xml = service_.getPortalConfigAsXmlString(owner);
72         assertTrue("portal congig in xml ", xml != null ) ;
73       
74         orgService_.removeUser(owner) ;
75         list = service_.findAllPageDescriptions(q).getAll() ;
76         assertTrue("Expect no page ", list.size() == 0) ;
77       config = service_.getPortalConfig(owner) ;
78         assertTrue("should not find the PortalConfig object", config == null) ;
79     }
80   }
81  
82   public void testSharePortal() throws Exception JavaDoc {
83     String JavaDoc sharePortalUser = "shareportal" ;
84     User user = createUser(sharePortalUser) ;
85     PortalConfig config = service_.getPortalConfig(sharePortalUser) ;
86     Node root = service_.getNodeNavigation(sharePortalUser) ;
87     assertNodeData(root) ;
88     assertEquals("No user can edit the portal layout", "noone", config.getEditPermission()) ;
89   }
90   
91   private User createUser(String JavaDoc userName) throws Exception JavaDoc {
92     User user = orgService_.createUserInstance() ;
93     user.setUserName(userName) ;
94     user.setPassword("exo") ;
95     user.setFirstName("Exo") ;
96     user.setLastName("Platform") ;
97     user.setEmail("exo@exoportal.org") ;
98     orgService_.createUser(user);
99     return user ;
100   }
101   
102   private void assertNodeData(Node node) throws Exception JavaDoc {
103     PageReference pageReference = node.getPageReference("text/xhtml") ;
104     String JavaDoc pageReferenceId = pageReference.getPageReference() ;
105     if(pageReferenceId != null && pageReferenceId.length() > 0) {
106       System.out.println("page reference = " + pageReferenceId);
107       Page page = service_.getPage(pageReferenceId) ;
108       assertTrue("Page reference should exsit " , page != null) ;
109     }
110     for (int i = 0; i < node.getChildrenSize(); i++) {
111       NodeImpl child = (NodeImpl) node.getChild(i) ;
112       assertNodeData(child) ;
113     }
114   }
115   
116   protected String JavaDoc getDescription() {
117     return "Test User Portal Configuration service" ;
118   }
119 }
Popular Tags