| 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 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
@author |
| 20 |
|
|
|
|
|
| 0% |
Uncovered Elements: 65 (65) |
Complexity: 15 |
Complexity Density: 0.28 |
|
| 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 |
|
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 2 |
Complexity Density: 0.25 |
|
| 31 |
0
|
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 |
|
|
| 45 |
|
|
| 46 |
|
|
| 47 |
|
|
| 48 |
|
|
| 49 |
|
|
| 50 |
|
|
| 51 |
|
|
| 52 |
|
|
| 53 |
|
|
| 54 |
|
|
| 55 |
|
|
| 56 |
|
|
| 57 |
|
|
| 58 |
|
|
| 59 |
|
|
| 60 |
|
|
| 61 |
|
|
| 62 |
|
|
|
|
|
| 0% |
Uncovered Elements: 33 (33) |
Complexity: 6 |
Complexity Density: 0.21 |
|
| 63 |
0
|
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 |
|
|
| 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 |
|
|
|
|
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 4 |
Complexity Density: 0.33 |
|
| 103 |
0
|
void stopSMTP() {... |
| 104 |
0
|
log.info("stopSMTP: skip smtp until working"); |
| 105 |
0
|
if (true) return; |
| 106 |
|
|
| 107 |
0
|
log.info("Stopping smtp"); |
| 108 |
|
|
| 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 |
|
|
| 118 |
|
} finally { |
| 119 |
0
|
smtpServer = null; |
| 120 |
|
} |
| 121 |
|
|
| 122 |
0
|
log.info("Stopped smtp"); |
| 123 |
|
} |
| 124 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 125 |
0
|
final void assertElementPresent(String q) {... |
| 126 |
0
|
assertTrue(selenium.getLocation() + "#" + q + " expected present", selenium.isElementPresent(q)); |
| 127 |
|
} |
| 128 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 129 |
0
|
final void assertTextEquals(String expected, String q) {... |
| 130 |
0
|
assertEquals(selenium.getLocation() + "#" + q, expected, selenium.getText(q)); |
| 131 |
|
} |
| 132 |
|
|
| 133 |
|
|
| 134 |
|
|
| 135 |
|
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 136 |
0
|
protected void closeSession() {... |
| 137 |
0
|
SeleniumManager.closeSession(selenium); |
| 138 |
0
|
assertElementPresent("login"); |
| 139 |
|
} |
| 140 |
|
} |