Clover Coverage Report - itracker
Coverage timestamp: Tue May 1 2012 16:42:12 CEST
53   140   15   8.83
6   92   0.28   6
6     2.5  
1    
 
 
  AbstractSeleniumTestCase       Line # 21 53 15 0% 0.0
 
No Tests
 
1    package org.itracker.selenium;
2   
3    import com.dumbster.smtp.SimpleSmtpServer;
4    import com.thoughtworks.selenium.Selenium;
5    import org.apache.commons.logging.Log;
6    import org.apache.log4j.Logger;
7    import org.itracker.AbstractDependencyInjectionTest;
8    import sun.java2d.pipe.SpanShapeRenderer;
9   
10    import java.io.IOException;
11    import java.net.ServerSocket;
12   
13    /**
14    * It is a base class for all Selenium-based test ca se.
15    * It performa initialization of Selenium client part and
16    * retrieves some generally-used parameters like hose application
17    * is running at, port, context.
18    *
19    * @author Andrey Sergievskiy <seas@andreysergievskiy.com>
20    */
 
21    public abstract class AbstractSeleniumTestCase extends AbstractDependencyInjectionTest {
22    public final static String SE_TIMEOUT = "20000";
23    public final static int SMTP_PORT = 2525;
24    protected SimpleSmtpServer smtpServer;
25    protected Selenium selenium;
26    protected String applicationHost;
27    protected int applicationPort;
28    protected String applicationPath;
29    Logger log = Logger.getLogger(getClass());
30   
 
31  0 toggle public AbstractSeleniumTestCase() {
32  0 try {
33  0 selenium = SeleniumManager.getSelenium();
34  0 assertNotNull(selenium);
35  0 applicationHost = SeleniumManager.getApplicationHost();
36  0 applicationPort = SeleniumManager.getApplicationPort();
37  0 applicationPath = SeleniumManager.getApplicationPath();
38    } catch (final IOException e) {
39  0 log.error(e);
40  0 fail(e.getMessage());
41    }
42    }
43   
44    // @Override
45    // public void onTearDown() throws Exception {
46    //
47    // log.info("onTearDown: stopping smtp");
48    // stopSMTP();
49    // log.info("onTearDown: stopped smtp");
50    //
51    // super.onTearDown();
52    //
53    // }
54    //
55    // @Override
56    // public void onSetUp() throws Exception {
57    // super.onSetUp();
58    // log.info("onSetUp: starting smtp");
59    // startSMTP();
60    // log.info("onSetUp: started smtp");
61    // }
62   
 
63  0 toggle SimpleSmtpServer startSMTP() throws InterruptedException {
64  0 log.info("startSMTP: skip smtp until working");
65  0 if (true) return null;
66   
67   
68  0 log.info("Starting smtp");
69  0 if (null != smtpServer && !smtpServer.isStopped()) {
70  0 log.warn("Already running smtp");
71  0 stopSMTP();
72  0 log.info("Already running smtp stopped");
73    }
74  0 smtpServer = null;
75  0 try {
76  0 ServerSocket s = new ServerSocket(SMTP_PORT);
77  0 log.info("sleep 100");
78  0 Thread.currentThread().sleep(100);
79  0 log.info("close socket");
80  0 s.close();
81  0 log.info("sleep 100");
82  0 Thread.currentThread().sleep(100);
83    } catch (IOException ioe) {
84  0 fail("Socket " + SMTP_PORT + " is open: " + ioe.getMessage());
85    }
86  0 log.info("SimpleSmtpServer.start("+SMTP_PORT+")");
87  0 SimpleSmtpServer smtp = SimpleSmtpServer.start(SMTP_PORT);
88  0 log.info("sleep 300");
89  0 Thread.currentThread().sleep(300);
90   
91  0 log.info("checking running smtp");
92    // assertNotNull("smtp is null", smtp);
93  0 if (smtp.isStopped()) {
94  0 throw new RuntimeException("Could not Start smtpServer");
95    }
96   
97  0 log.info("got running smtp " + smtp);
98  0 smtpServer = smtp;
99  0 log.info("Started smtp");
100  0 return smtp;
101    }
102   
 
103  0 toggle void stopSMTP() {
104  0 log.info("stopSMTP: skip smtp until working");
105  0 if (true) return;
106   
107  0 log.info("Stopping smtp");
108    // assertNotNull("null smtp", smtpServer);
109  0 try {
110  0 smtpServer.stop();
111  0 Thread.currentThread().sleep(300);
112  0 if (!smtpServer.isStopped()) {
113  0 throw new RuntimeException("Could not Stop smtpServer");
114    }
115    } catch (Exception e) {
116  0 log.warn("failed to close smtp", e);
117    // fail("could not stop smtp: " + smtpServer + ": " + e.getMessage());
118    } finally {
119  0 smtpServer = null;
120    }
121   
122  0 log.info("Stopped smtp");
123    }
124   
 
125  0 toggle final void assertElementPresent(String q) {
126  0 assertTrue(selenium.getLocation() + "#" + q + " expected present", selenium.isElementPresent(q));
127    }
128   
 
129  0 toggle final void assertTextEquals(String expected, String q) {
130  0 assertEquals(selenium.getLocation() + "#" + q, expected, selenium.getText(q));
131    }
132   
133    /**
134    * This will initialize a new selenium session for this test scope.
135    */
 
136  0 toggle protected void closeSession() {
137  0 SeleniumManager.closeSession(selenium);
138  0 assertElementPresent("login");
139    }
140    }