Revision 9f5b6bce
Added by Andreas Kohlbecker about 12 years ago
modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/main/java/eu/etaxonomy/dataportal/junit/DataPortalContextSuite.java | ||
---|---|---|
1 | 1 |
/** |
2 |
*
|
|
2 |
* |
|
3 | 3 |
*/ |
4 | 4 |
package eu.etaxonomy.dataportal.junit; |
5 | 5 |
|
... | ... | |
14 | 14 |
import org.junit.runners.model.FrameworkMethod; |
15 | 15 |
import org.junit.runners.model.InitializationError; |
16 | 16 |
import org.junit.runners.model.Statement; |
17 |
import org.junit.runners.model.TestClass; |
|
17 | 18 |
|
18 | 19 |
import eu.etaxonomy.dataportal.DataPortalContext; |
19 | 20 |
import eu.etaxonomy.dataportal.DataPortalContexts; |
21 |
import eu.etaxonomy.dataportal.selenium.CdmDataPortalTestBase; |
|
20 | 22 |
|
21 | 23 |
|
22 | 24 |
/** |
... | ... | |
26 | 28 |
public class DataPortalContextSuite extends Suite{ |
27 | 29 |
|
28 | 30 |
private final List<Runner> runners = new ArrayList<Runner>(); |
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
31 | 33 |
private class TestClassRunnerWithDataPortalContext extends |
32 | 34 |
BlockJUnit4ClassRunner { |
33 |
|
|
34 |
private DataPortalContext context; |
|
35 |
|
|
36 |
private final DataPortalContext context;
|
|
35 | 37 |
|
36 | 38 |
/** |
37 | 39 |
* @param klass |
... | ... | |
41 | 43 |
super(klass); |
42 | 44 |
this.context = context; |
43 | 45 |
} |
44 |
|
|
46 |
|
|
45 | 47 |
@Override |
46 | 48 |
public Object createTest() throws Exception { |
47 |
return getTestClass().getOnlyConstructor().newInstance(context); |
|
49 |
Object testClass = getTestClass().getOnlyConstructor().newInstance(); |
|
50 |
((CdmDataPortalTestBase)testClass).setContext(context); |
|
51 |
return testClass; |
|
48 | 52 |
} |
49 |
|
|
53 |
|
|
50 | 54 |
@Override |
51 | 55 |
protected String getName() { |
52 | 56 |
return String.format("%s@%s", getTestClass().getName(), context.name()); |
... | ... | |
55 | 59 |
@Override |
56 | 60 |
protected String testName(final FrameworkMethod method) { |
57 | 61 |
return String.format("%s@%s", method.getName(), context.name()); |
58 |
|
|
62 |
|
|
59 | 63 |
} |
60 |
|
|
64 |
|
|
61 | 65 |
@Override |
62 | 66 |
protected Statement classBlock(RunNotifier notifier) { |
63 | 67 |
return childrenInvoker(notifier); |
64 | 68 |
} |
65 |
|
|
69 |
|
|
66 | 70 |
@Override |
67 | 71 |
protected void validateZeroArgConstructor(List<Throwable> errors) { |
72 |
super.validateZeroArgConstructor(errors); |
|
73 |
validateCdmDataPortalTestBase(errors); |
|
74 |
} |
|
75 |
|
|
76 |
protected void validateCdmDataPortalTestBase(List<Throwable> errors) { |
|
68 | 77 |
// constructor should have exactly one arg |
69 |
if (hasOneConstructor() |
|
70 |
&& !(getTestClass().getOnlyConstructor().getParameterTypes().length == 1)) { |
|
71 |
String gripe= "Test class should have exactly one public constructor with DataPortalContext as argument"; |
|
78 |
if ( ! CdmDataPortalTestBase.class.isAssignableFrom(getTestClass().getJavaClass()) ){ |
|
79 |
String gripe= "Test class must be a subclass of " + CdmDataPortalTestBase.class.getName(); |
|
72 | 80 |
errors.add(new Exception(gripe)); |
73 | 81 |
} |
74 | 82 |
} |
75 |
|
|
76 |
private boolean hasOneConstructor() { |
|
77 |
return getTestClass().getJavaClass().getConstructors().length == 1; |
|
78 |
} |
|
79 | 83 |
} |
80 | 84 |
|
81 | 85 |
/** |
... | ... | |
88 | 92 |
runners.add(new TestClassRunnerWithDataPortalContext(klass, cntxt)); |
89 | 93 |
} |
90 | 94 |
} |
91 |
|
|
95 |
|
|
92 | 96 |
@Override |
93 | 97 |
protected List<Runner> getChildren() { |
94 | 98 |
return runners; |
modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/test/java/eu/etaxonomy/dataportal/selenium/CdmDataPortalSeleniumRCTestBase.java | ||
---|---|---|
1 | 1 |
// $Id$ |
2 | 2 |
/** |
3 | 3 |
* Copyright (C) 2009 EDIT |
4 |
* European Distributed Institute of Taxonomy
|
|
4 |
* European Distributed Institute of Taxonomy |
|
5 | 5 |
* http://www.e-taxonomy.eu |
6 |
*
|
|
6 |
* |
|
7 | 7 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
8 | 8 |
* See LICENSE.TXT at the top of this package for the full license terms. |
9 | 9 |
*/ |
... | ... | |
22 | 22 |
|
23 | 23 |
/** |
24 | 24 |
* http://seleniumhq.org/docs/03_webdriver.html#emulating-selenium-rc |
25 |
*
|
|
25 |
* |
|
26 | 26 |
* @author a.kohlbecker |
27 | 27 |
* @deprecated SeleniumRCTests should only be used if you are really desperatly |
28 | 28 |
* shor in time and you need to use the Selenium 1 IDE in order to |
... | ... | |
31 | 31 |
@Deprecated |
32 | 32 |
public abstract class CdmDataPortalSeleniumRCTestBase extends CdmDataPortalTestBase { |
33 | 33 |
|
34 |
/** |
|
35 |
* @param context |
|
36 |
*/ |
|
37 |
public CdmDataPortalSeleniumRCTestBase(DataPortalContext context) { |
|
38 |
super(context); |
|
39 |
} |
|
40 |
|
|
41 | 34 |
protected static Selenium selenium; |
42 | 35 |
|
43 | 36 |
@Before |
modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/test/java/eu/etaxonomy/dataportal/selenium/CdmDataPortalTestBase.java | ||
---|---|---|
1 | 1 |
/** |
2 |
*
|
|
2 |
* |
|
3 | 3 |
*/ |
4 | 4 |
package eu.etaxonomy.dataportal.selenium; |
5 | 5 |
|
... | ... | |
22 | 22 |
|
23 | 23 |
/** |
24 | 24 |
* @author a.kohlbecker |
25 |
*
|
|
25 |
* |
|
26 | 26 |
*/ |
27 | 27 |
@RunWith(DataPortalContextSuite.class) |
28 | 28 |
public abstract class CdmDataPortalTestBase { |
... | ... | |
35 | 35 |
|
36 | 36 |
protected static WebDriver driver; |
37 | 37 |
|
38 |
private final DataPortalContext context;
|
|
38 |
private DataPortalContext context; |
|
39 | 39 |
|
40 | 40 |
public DataPortalContext getContext() { |
41 | 41 |
return context; |
42 | 42 |
} |
43 | 43 |
|
44 |
public CdmDataPortalTestBase(DataPortalContext context){
|
|
44 |
public void setContext(DataPortalContext context) {
|
|
45 | 45 |
this.context = context; |
46 |
|
|
46 | 47 |
} |
47 | 48 |
|
48 | 49 |
@BeforeClass |
... | ... | |
88 | 89 |
|
89 | 90 |
/** |
90 | 91 |
* -Dwebdriver.firefox.bin=/usr/lib/iceweasel/firefox-bin |
91 |
*
|
|
92 |
* |
|
92 | 93 |
* See http://code.google.com/p/selenium/wiki/FirefoxDriverInternals |
93 |
*
|
|
94 |
* |
|
94 | 95 |
* @return |
95 | 96 |
*/ |
96 | 97 |
public static WebDriver initFirefoxDriver() { |
... | ... | |
122 | 123 |
/** |
123 | 124 |
* Return the {@link DataPortalContext#getBaseUri()} of the currently active |
124 | 125 |
* context as String |
125 |
*
|
|
126 |
* |
|
126 | 127 |
* @return string representatoin of the DataPortal base URI |
127 | 128 |
*/ |
128 | 129 |
public String getBaseUrl() { |
modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/test/java/eu/etaxonomy/dataportal/selenium/ExampleTest.java | ||
---|---|---|
1 | 1 |
// $Id$ |
2 | 2 |
/** |
3 | 3 |
* Copyright (C) 2009 EDIT |
4 |
* European Distributed Institute of Taxonomy
|
|
4 |
* European Distributed Institute of Taxonomy |
|
5 | 5 |
* http://www.e-taxonomy.eu |
6 |
*
|
|
6 |
* |
|
7 | 7 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
8 | 8 |
* See LICENSE.TXT at the top of this package for the full license terms. |
9 | 9 |
*/ |
... | ... | |
11 | 11 |
|
12 | 12 |
import junit.framework.Assert; |
13 | 13 |
|
14 |
import org.junit.Ignore; |
|
15 | 14 |
import org.junit.Test; |
16 | 15 |
import org.openqa.selenium.By; |
17 | 16 |
import org.openqa.selenium.RenderedWebElement; |
... | ... | |
24 | 23 |
@DataPortalContexts( { DataPortalContext.cichorieae }) |
25 | 24 |
public class ExampleTest extends CdmDataPortalSeleniumRCTestBase { |
26 | 25 |
|
27 |
/** |
|
28 |
* @param context |
|
29 |
*/ |
|
30 |
public ExampleTest(DataPortalContext context) { |
|
31 |
super(context); |
|
32 |
} |
|
33 |
|
|
34 | 26 |
@Test |
35 | 27 |
public void testSearchLCommunis() throws Exception { |
36 | 28 |
driver.get(getBaseUrl() |
... | ... | |
58 | 50 |
|
59 | 51 |
/** |
60 | 52 |
* This test emulates the Selenium RC API |
61 |
*
|
|
53 |
* |
|
62 | 54 |
* @throws Exception |
63 | 55 |
*/ |
64 | 56 |
@Test |
modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/test/java/eu/etaxonomy/dataportal/selenium/tests/CichorieaeSearchTest.java | ||
---|---|---|
1 | 1 |
// $Id$ |
2 | 2 |
/** |
3 | 3 |
* Copyright (C) 2009 EDIT |
4 |
* European Distributed Institute of Taxonomy
|
|
4 |
* European Distributed Institute of Taxonomy |
|
5 | 5 |
* http://www.e-taxonomy.eu |
6 |
*
|
|
6 |
* |
|
7 | 7 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
8 | 8 |
* See LICENSE.TXT at the top of this package for the full license terms. |
9 | 9 |
*/ |
... | ... | |
23 | 23 |
@DataPortalContexts( { DataPortalContext.cichorieae }) |
24 | 24 |
public class CichorieaeSearchTest extends CdmDataPortalTestBase { |
25 | 25 |
|
26 |
|
|
27 |
public CichorieaeSearchTest(DataPortalContext context) { |
|
28 |
super(context); |
|
29 |
} |
|
30 |
|
|
31 | 26 |
@Test |
32 | 27 |
public void testSearchLCommunis() throws Exception { |
33 | 28 |
driver.get(getBaseUrl() |
modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/test/java/eu/etaxonomy/dataportal/selenium/tests/CyprusSearchTest.java | ||
---|---|---|
1 | 1 |
// $Id$ |
2 | 2 |
/** |
3 | 3 |
* Copyright (C) 2009 EDIT |
4 |
* European Distributed Institute of Taxonomy
|
|
4 |
* European Distributed Institute of Taxonomy |
|
5 | 5 |
* http://www.e-taxonomy.eu |
6 |
*
|
|
6 |
* |
|
7 | 7 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
8 | 8 |
* See LICENSE.TXT at the top of this package for the full license terms. |
9 | 9 |
*/ |
... | ... | |
26 | 26 |
|
27 | 27 |
@DataPortalContexts( { DataPortalContext.cyprus }) |
28 | 28 |
public class CyprusSearchTest extends CdmDataPortalTestBase{ |
29 |
|
|
30 |
/** |
|
31 |
* @param context |
|
32 |
*/ |
|
33 |
public CyprusSearchTest(DataPortalContext context) { |
|
34 |
super(context); |
|
35 |
} |
|
36 | 29 |
|
37 | 30 |
/** |
38 | 31 |
* see http://dev.e-taxonomy.eu/trac/ticket/2350 |
Also available in: Unified diff
writing test classes simplified