KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > services > portal > log > TestPortalLogService


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.log;
6
7 import java.util.HashMap JavaDoc;
8 import java.util.Date JavaDoc ;
9 import org.exoplatform.container.PortalContainer;
10 import org.exoplatform.container.SessionContainer;
11 import org.exoplatform.container.monitor.SessionMonitor ;
12 import org.exoplatform.container.monitor.ActionData;
13 import org.exoplatform.services.portal.log.impl.PortalLogServiceImpl ;
14 import org.exoplatform.services.portal.log.impl.SessionLogDataImpl ;
15 import org.exoplatform.test.BasicTestCase;
16 /**
17  * Thu, May 15, 2003 @
18  * @author: Tuan Nguyen
19  * @version: $Id: TestPortalMonitorService.java,v 1.5 2004/07/24 16:34:05 tuan08 Exp $
20  * @since: 0.0
21  * @email: tuan08@yahoo.com
22  */

23 public class TestPortalLogService extends BasicTestCase {
24
25   PortalContainer pcontainer_ ;
26   SessionContainer scontainer_ ;
27   PortalLogServiceImpl service_ ;
28
29   public TestPortalLogService(String JavaDoc name) {
30     super(name);
31   }
32
33   public void setUp() throws Exception JavaDoc {
34     setTestNumber(1) ;
35     pcontainer_ = PortalContainer.getInstance();
36     scontainer_ = pcontainer_.createSessionContainer("session.container", "anon") ;
37     service_ =
38       (PortalLogServiceImpl) pcontainer_.getComponentInstanceOfType(PortalLogServiceImpl.class);
39   }
40
41   public void tearDown() throws Exception JavaDoc {
42   }
43   
44   public void testPortalMonitorService() throws Exception JavaDoc {
45     SessionMonitor monitor = scontainer_.getMonitor() ;
46     HashMap JavaDoc map = new HashMap JavaDoc() ;
47     map.put("param1", "value 1") ;
48     map.put("param2", "value 2") ;
49     scontainer_.startActionLifcycle() ;
50     for(int i =0 ; i < 10; i++ ) {
51       scontainer_.startActionLifcycle() ;
52       ActionData data = new ActionData("user", "/page/name", "post", 500, map) ;
53       scontainer_.getMonitor().log(data) ;
54       scontainer_.endActionLifcycle() ;
55     }
56     scontainer_.startActionLifcycle() ;
57     ActionData data = new ActionData("user", "/page/name", "post", 500, map) ;
58     scontainer_.getMonitor().error("a errror", new Exception JavaDoc());
59     scontainer_.getMonitor().log(data) ;
60     scontainer_.endActionLifcycle() ;
61     
62     SessionLogData logData = new SessionLogDataImpl() ;
63     logData.setAccessTime(new Date JavaDoc(monitor.getAccessTime())) ;
64     logData.setRemoteUser(monitor.getRemoteUser()) ;
65     logData.setRemoteUser(monitor.getIPAddress()) ;
66     logData.setActionHistory(monitor.getHistory()) ;
67     service_.saveSessionLogData(logData) ;
68     
69     SessionLogDataImpl ld = (SessionLogDataImpl)service_.getSessionLogData(logData.getId()) ;
70     System.out.println(ld.getData()) ;
71     Thread.sleep(2000) ;
72   }
73   
74   protected String JavaDoc getDescription() {
75     return "Test portal monitor service " ;
76   }
77 }
78
Popular Tags