Project

General

Profile

« Previous | Next » 

Revision 1e1c8a26

Added by Andreas Kohlbecker almost 13 years ago

unit tests are dataportal configuration aware

View differences:

.gitattributes
250 250
modules/cdm_dataportal/site/site.xml -text
251 251
modules/cdm_dataportal/test/TestSuite-search.html -text
252 252
modules/cdm_dataportal/test/java/dataportal-selenium-tests/pom.xml -text
253
modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/main/java/eu/etaxonomy/dataportal/DataPortalContext.java -text
254
modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/main/java/eu/etaxonomy/dataportal/DataPortalContextAwareRunner.java -text
255
modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/main/java/eu/etaxonomy/dataportal/DataPortalManager.java -text
256
modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/test/java/eu/etaxonomy/dataportal/selenium/CdmDataPortalSeleniumRCTestBase.java -text
253 257
modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/test/java/eu/etaxonomy/dataportal/selenium/CdmDataPortalTestBase.java -text
254
modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/test/java/eu/etaxonomy/dataportal/selenium/SearchLCommunisTest.java -text
258
modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/test/java/eu/etaxonomy/dataportal/selenium/ExampleTest.java -text
255 259
modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/test/resources/org/mozilla/addons/add_on_compatibility_reporter-0.8.3-fx+tb+sm.xpi -text
256 260
modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/test/resources/org/mozilla/addons/firebug-1.6.2.xpi -text
257 261
modules/cdm_dataportal/test/phpUnit/TestUtils.php -text
modules/cdm_dataportal/test/java/dataportal-selenium-tests/pom.xml
69 69
			<version>4.6</version>
70 70
			<scope>test</scope>
71 71
		</dependency>
72
		<dependency>
73
			<!-- used for executing drush commnads -->
74
			<groupId>org.apache.commons</groupId>
75
			<artifactId>commons-exec</artifactId>
76
			<version>1.1</version>
77
		</dependency>
72 78
		<!--
73 79
			selenium 2 webdriver, see
74 80
			http://seleniumhq.org/docs/03_webdriver.html#with-maven
......
93 99
			<artifactId>webdriver-htmlunit</artifactId>
94 100
			<version>0.9.7376</version>
95 101
		</dependency>
102
		<dependency>
103
			<groupId>org.seleniumhq.selenium</groupId>
104
			<artifactId>selenium</artifactId>
105
			<version>2.0a7</version>
106
		</dependency>
96 107
	</dependencies>
97 108

  
98 109

  
modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/main/java/eu/etaxonomy/dataportal/DataPortalContext.java
1
package eu.etaxonomy.dataportal;
2

  
3
import java.net.URI;
4
import java.net.URISyntaxException;
5
import java.util.UUID;
6

  
7
public enum DataPortalContext {
8
	
9
	cichorieae(
10
			"http://160.45.63.201/dataportal/preview/cichorieae/",
11
			"http://127.0.0.1:8080",
12
			"534e190f-3339-49ba-95d9-fa27d5493e3e"),
13
	palmae(
14
			"http://160.45.63.201/dataportal/preview/palmae/",
15
			"http://127.0.0.1:8080",
16
			"534e190f-3339-49ba-95d9-fa27d5493e3e");
17
	//floraMalesiana;
18
	
19
	URI baseUri;
20
	URI cdmServerUri;
21
	UUID classificationUUID;
22
	String themeName;
23

  
24
	
25
	private DataPortalContext(String baseUri, String cdmServerUri,
26
			String classificationUUID) {
27
		try {
28
			this.baseUri = new URI(baseUri);
29
		} catch (URISyntaxException e) {
30
			e.printStackTrace();
31
		}
32
		try {
33
			this.cdmServerUri = new URI(cdmServerUri);
34
		} catch (URISyntaxException e) {
35
			e.printStackTrace();
36
		}
37
		this.classificationUUID = UUID.fromString(classificationUUID);
38
	}
39

  
40

  
41
	public URI getBaseUri() {
42
		return baseUri;
43
	}
44

  
45

  
46
	public URI getCdmServerUri() {
47
		return cdmServerUri;
48
	}
49

  
50

  
51
	public UUID getClassificationUUID() {
52
		return classificationUUID;
53
	}
54
	
55
	
56
	
57
	
58
}
modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/main/java/eu/etaxonomy/dataportal/DataPortalContextAwareRunner.java
1
package eu.etaxonomy.dataportal;
2

  
3
import java.lang.annotation.ElementType;
4
import java.lang.annotation.Inherited;
5
import java.lang.annotation.Retention;
6
import java.lang.annotation.RetentionPolicy;
7
import java.lang.annotation.Target;
8

  
9
import org.junit.internal.AssumptionViolatedException;
10
import org.junit.internal.runners.model.EachTestNotifier;
11
import org.junit.runner.notification.RunNotifier;
12
import org.junit.runner.notification.StoppedByUserException;
13
import org.junit.runners.BlockJUnit4ClassRunner;
14
import org.junit.runners.model.InitializationError;
15
import org.junit.runners.model.Statement;
16

  
17
public class DataPortalContextAwareRunner extends BlockJUnit4ClassRunner {
18
	
19

  
20
	@Retention(RetentionPolicy.RUNTIME)
21
	@Target(ElementType.TYPE)
22
	@Inherited
23
	public @interface DataPortalContexts {
24
		/**
25
		 * @return an array of DataPortalContext to which the annotated test class is applicable
26
		 */
27
		DataPortalContext[] value();
28
	}
29
	
30
	private DataPortalContext dataPortalContext; 
31
	
32
	public DataPortalContextAwareRunner(Class<?> klass)
33
			throws InitializationError {
34
		super(klass);
35
		dataPortalContext = DataPortalManager.currentDataPortalContext();
36
	}
37
	
38
	@Override
39
	public void run(final RunNotifier notifier) {
40
		EachTestNotifier testNotifier= new EachTestNotifier(notifier,
41
				getDescription());
42
		
43
		boolean isApplicableToContext = false;
44
		DataPortalContexts dataPortalContextsAnotation = getTestClass().getJavaClass().getAnnotation(DataPortalContexts.class);
45
		for(DataPortalContext cntxt : dataPortalContextsAnotation.value()){
46
			if(dataPortalContext.equals(cntxt)){
47
				isApplicableToContext = true;
48
			}
49
		}
50
		
51
		if(!isApplicableToContext){
52
			testNotifier.fireTestIgnored();
53
			return;
54
		}
55
			
56
		try {
57
			Statement statement= classBlock(notifier);
58
			statement.evaluate();
59
		} catch (AssumptionViolatedException e) {
60
			testNotifier.fireTestIgnored();
61
		} catch (StoppedByUserException e) {
62
			throw e;
63
		} catch (Throwable e) {
64
			testNotifier.addFailure(e);
65
		}
66
	}
67

  
68
}
modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/main/java/eu/etaxonomy/dataportal/DataPortalManager.java
1
/**
2
 * 
3
 */
4
package eu.etaxonomy.dataportal;
5

  
6
import static eu.etaxonomy.dataportal.DataPortalContext.*;
7

  
8
/**
9
 * @author a.kohlbecker
10
 *
11
 */
12
public class DataPortalManager {
13
	
14
	static DataPortalManager managerInstance = null;
15
	
16
	private DataPortalContext currentDataPortalContext = cichorieae;
17
	
18
	public static void prepare() {
19
		if(managerInstance == null){
20
			managerInstance = new DataPortalManager();
21
			managerInstance.setupDataPortal();
22
		}
23
	}
24
	
25
	public static DataPortalContext currentDataPortalContext(){
26
		prepare();
27
		return managerInstance.currentDataPortalContext;
28
	}
29

  
30
	private void setupDataPortal() {
31
		//TODO 
32
	}
33

  
34
}
modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/test/java/eu/etaxonomy/dataportal/selenium/CdmDataPortalSeleniumRCTestBase.java
1
package eu.etaxonomy.dataportal.selenium;
2

  
3
import org.junit.BeforeClass;
4
import org.openqa.selenium.WebDriverBackedSelenium;
5

  
6
import com.thoughtworks.selenium.Selenium;
7

  
8
import eu.etaxonomy.dataportal.DataPortalManager;
9

  
10
public abstract class CdmDataPortalSeleniumRCTestBase extends
11
		CdmDataPortalTestBase {
12

  
13
	protected static Selenium selenium;
14

  
15
	@BeforeClass
16
	public static void setUpDriver() {
17
		CdmDataPortalTestBase.setUpDriver();
18
		selenium = new WebDriverBackedSelenium(driver, DataPortalManager
19
				.currentDataPortalContext().getBaseUri().toString());
20
	}
21

  
22
	@BeforeClass
23
	public static void closeDriver() {
24
		if (selenium != null) {
25
			selenium.stop();
26
		}
27
		CdmDataPortalTestBase.closeDriver();
28
	}
29

  
30
}
modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/test/java/eu/etaxonomy/dataportal/selenium/CdmDataPortalTestBase.java
5 5

  
6 6
import java.io.IOException;
7 7

  
8
import org.junit.AfterClass;
9
import org.junit.BeforeClass;
10
import org.junit.runner.RunWith;
8 11
import org.openqa.selenium.WebDriver;
9 12
import org.openqa.selenium.chrome.ChromeDriver;
10 13
import org.openqa.selenium.firefox.FirefoxDriver;
11 14
import org.openqa.selenium.firefox.FirefoxProfile;
12 15
import org.openqa.selenium.ie.InternetExplorerDriver;
13 16

  
17
import eu.etaxonomy.dataportal.DataPortalContextAwareRunner;
18

  
14 19
/**
15 20
 * @author a.kohlbecker
16 21
 *
17 22
 */
23
@RunWith(DataPortalContextAwareRunner.class)
18 24
public abstract class CdmDataPortalTestBase {
19 25
	
20 26
	private static final String FIREBUG_VERSION = "1.6.2";
21 27

  
22
	protected WebDriver driver;
28
	protected static WebDriver driver;
29

  
30
    @BeforeClass
31
    public static void setUpDriver() {
32
    	driver = initFirefoxDriver();
33
    }
34
    
35
    
36
    @AfterClass
37
    public static void closeDriver() {
38
    	if(driver != null){
39
    		driver.quit();
40
    	}
41
    }
23 42
	
24 43
	public WebDriver initChromeDriver() {
25 44
		//System.setProperty("webdriver.chrome.bin", "C:\\Dokumente und Einstellungen\\a.kohlbecker.BGBM\\Lokale Einstellungen\\Anwendungsdaten\\Google\\Chrome\\Application\\chrome.exe");
......
36 55
	 * See http://code.google.com/p/selenium/wiki/FirefoxDriverInternals
37 56
	 * @return
38 57
	 */
39
	public WebDriver initFirefoxDriver() {
58
	public static WebDriver initFirefoxDriver() {
40 59
		//System.setProperty("webdriver.firefox.bin", "C:\\Programme\\Mozilla Firefox 3\\firefox.exe");
41 60
		//System.out.println("##:" + System.getProperty("webdriver.firefox.bin"));
42 61
		FirefoxProfile firefoxProfile = new FirefoxProfile();
43 62
    	try {
44 63
    		
45
    		firefoxProfile.addExtension(this.getClass(), "/org/mozilla/addons/firebug-" + FIREBUG_VERSION + ".xpi");
64
    		firefoxProfile.addExtension(CdmDataPortalTestBase.class, "/org/mozilla/addons/firebug-" + FIREBUG_VERSION + ".xpi");
46 65
    		firefoxProfile.setPreference("extensions.firebug.currentVersion", FIREBUG_VERSION); // avoid displaying firt run page
47 66
    		
48 67
    		// --- allow enabling incompatible addons
......
62 81
		
63 82
        return driver;
64 83
	}
84
	
65 85

  
66 86
}
modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/test/java/eu/etaxonomy/dataportal/selenium/ExampleTest.java
1
package eu.etaxonomy.dataportal.selenium;
2

  
3
import junit.framework.Assert;
4

  
5
import org.junit.Test;
6
import org.openqa.selenium.By;
7
import org.openqa.selenium.RenderedWebElement;
8
import org.openqa.selenium.WebElement;
9

  
10
import eu.etaxonomy.dataportal.DataPortalContext;
11
import eu.etaxonomy.dataportal.DataPortalContextAwareRunner.DataPortalContexts;
12

  
13
@DataPortalContexts({
14
	DataPortalContext.palmae
15
	})
16
public class ExampleTest extends CdmDataPortalSeleniumRCTestBase {
17
	
18
	static String baseUrl = "http://wp6-cichorieae.e-taxonomy.eu/portal/";
19

  
20
	public static String getBaseUrl() {
21
		return baseUrl;
22
	}
23

  
24
    @Test
25
	public void testSearchLCommunis() throws Exception {
26
    	driver.get(baseUrl + "?query=Lapsana+com*&search[tree]=534e190f-3339-49ba-95d9-fa27d5493e3e&q=cdm_dataportal%2Fsearch%2Ftaxon&search[pageSize]=25&search[pageNumber]=0&search[doTaxa]=1&search[doSynonyms]=1&search[doTaxaByCommonNames]=0");
27
    	WebElement taxonElement = driver.findElement(By.xpath("/html/body/div/div/div[2]/div[2]/div/div/div/ul/li/span[@ref='/name/f280f79f-5903-47b0-8352-53e4204c6cf1']"));
28
    	
29
    	WebElement nameElement = taxonElement.findElement(By.className("BotanicalName"));
30
    	
31
    	RenderedWebElement namePart1 = (RenderedWebElement)nameElement.findElement(By.xpath("span[1]"));
32
    	Assert.assertEquals("Lapsana", namePart1.getText());
33
    	Assert.assertEquals("italic", namePart1.getValueOfCssProperty("font-style"));
34
    	
35
    	RenderedWebElement namePart2 = (RenderedWebElement)nameElement.findElement(By.xpath("span[2]"));
36
    	Assert.assertEquals("communis", namePart2.getText());
37
    	Assert.assertEquals("italic", namePart2.getValueOfCssProperty("font-style"));
38
    	
39
    	RenderedWebElement authorPart = (RenderedWebElement)nameElement.findElement(By.xpath("span[3]"));
40
    	Assert.assertEquals("L.", authorPart.getText());
41
    	Assert.assertEquals("normal", authorPart.getValueOfCssProperty("font-style"));
42
    	
43
    	RenderedWebElement referenceElement = (RenderedWebElement)taxonElement.findElement(By.className("reference"));
44
    	Assert.assertEquals("Sp. Pl.: 811. 1753", referenceElement.findElement((By.className("reference"))).getText());
45
	}
46
    
47
    /**
48
     * This test emulates the Selenium RC API
49
     * 
50
     * @throws Exception
51
     */
52
    @Test
53
	public void testSearchLCommunisUsingSeleniumRC() throws Exception {
54
    	selenium.open("?query=Lapsana+com*&search[tree]=534e190f-3339-49ba-95d9-fa27d5493e3e&q=cdm_dataportal%2Fsearch%2Ftaxon&search[pageSize]=25&search[pageNumber]=0&search[doTaxa]=1&search[doSynonyms]=1&search[doTaxaByCommonNames]=0");
55
    	selenium.isTextPresent("Lapsana");
56
    	selenium.isTextPresent("communis");
57
    	selenium.isTextPresent("L.");
58
    	selenium.isTextPresent("Sp. Pl.: 811. 1753");
59
	}
60

  
61
}
modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/test/java/eu/etaxonomy/dataportal/selenium/SearchLCommunisTest.java
1
package eu.etaxonomy.dataportal.selenium;
2

  
3
import java.io.IOException;
4

  
5
import junit.framework.Assert;
6

  
7
import org.junit.After;
8
import org.junit.Before;
9
import org.junit.Test;
10
import org.openqa.selenium.By;
11
import org.openqa.selenium.WebDriver;
12
import org.openqa.selenium.WebElement;
13
import org.openqa.selenium.chrome.ChromeDriver;
14
import org.openqa.selenium.firefox.FirefoxDriver;
15
import org.openqa.selenium.firefox.FirefoxProfile;
16
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
17
import org.openqa.selenium.ie.InternetExplorerDriver;
18

  
19
public class SearchLCommunisTest extends CdmDataPortalTestBase {
20
	
21
	static String baseUrl = "http://wp6-cichorieae.e-taxonomy.eu/portal/";
22

  
23
    @Before
24
    public void setUpDriver() {
25
    	driver = initFirefoxDriver();
26
    }
27

  
28

  
29
    @After
30
    public void closeDriver() {
31
        driver.quit();
32
    }
33

  
34
    @Test
35
	public void testSearchLCommunis() throws Exception {
36
    	driver.get(baseUrl + "?query=Lapsana+com*&search[tree]=534e190f-3339-49ba-95d9-fa27d5493e3e&q=cdm_dataportal%2Fsearch%2Ftaxon&search[pageSize]=25&search[pageNumber]=0&search[doTaxa]=1&search[doSynonyms]=1&search[doTaxaByCommonNames]=0");
37
    	WebElement taxonElement = driver.findElement(By.xpath("/html/body/div/div/div[2]/div[2]/div/div/div/ul/li/span[@ref='/name/f280f79f-5903-47b0-8352-53e4204c6cf1']"));
38
    	
39
    	WebElement nameElement = taxonElement.findElement(By.className("BotanicalName"));
40
    	Assert.assertEquals("Lapsana", nameElement.findElement(By.xpath("span[1]")).getText());
41
    	Assert.assertEquals("communis", nameElement.findElement(By.xpath("span[2]")).getText());
42
    	Assert.assertEquals("L.", nameElement.findElement(By.xpath("span[3]")).getText());
43
    	
44
    	WebElement referenceElement = taxonElement.findElement(By.className("reference"));
45
    	Assert.assertEquals("Sp. Pl.: 811. 1753", referenceElement.findElement((By.className("reference"))).getText());
46
	}
47

  
48

  
49
}

Also available in: Unified diff