1 5 package org.exoplatform.services.portal.log; 6 7 import java.util.HashMap ; 8 import java.util.Date ; 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 23 public class TestPortalLogService extends BasicTestCase { 24 25 PortalContainer pcontainer_ ; 26 SessionContainer scontainer_ ; 27 PortalLogServiceImpl service_ ; 28 29 public TestPortalLogService(String name) { 30 super(name); 31 } 32 33 public void setUp() throws Exception { 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 { 42 } 43 44 public void testPortalMonitorService() throws Exception { 45 SessionMonitor monitor = scontainer_.getMonitor() ; 46 HashMap map = new HashMap () ; 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 ()); 59 scontainer_.getMonitor().log(data) ; 60 scontainer_.endActionLifcycle() ; 61 62 SessionLogData logData = new SessionLogDataImpl() ; 63 logData.setAccessTime(new Date (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 getDescription() { 75 return "Test portal monitor service " ; 76 } 77 } 78 | Popular Tags |