Project

General

Profile

Download (3.43 KB) Statistics
| Branch: | Tag: | Revision:
1
package eu.etaxonomy.cdm;
2

    
3

    
4
import org.junit.AfterClass;
5
import org.junit.BeforeClass;
6
import org.junit.runner.RunWith;
7
import org.openqa.selenium.WebDriver;
8
import org.openqa.selenium.chrome.ChromeDriver;
9
import org.springframework.beans.factory.annotation.Autowired;
10
import org.springframework.boot.test.SpringApplicationConfiguration;
11
import org.springframework.boot.test.WebIntegrationTest;
12
import org.springframework.core.env.Environment;
13
import org.springframework.test.context.TestPropertySource;
14
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
15

    
16
import com.codeborne.selenide.WebDriverRunner;
17

    
18
@RunWith(SpringJUnit4ClassRunner.class)
19
// @SpringBootTest only since spring 4.0
20
@SpringApplicationConfiguration(
21
        classes = {WebAppIntegrationTestConfig.class},
22
        locations=
23
        // "file:./src/main/webapp/WEB-INF/applicationContext-dbunit.xml"
24
        // loads the root context which also will provide the CdmVaadinConfiguration.CdmVaadinServlet
25
        "file:./src/main/webapp/WEB-INF/applicationContext.xml"
26
)
27
// the datasource to be used in the tests is defined in:
28
@TestPropertySource("classpath:selenide-integration-test.properties")
29
@WebIntegrationTest(randomPort=true, value={
30
    // "server.port=8087", // does not work this way , so it is hard coded in WebAppIntegrationTestConfig
31
    // #################################
32
    // The below way to set the properties for the test does not work with spring boot 1.3.1 spring 4.2.4
33
    // he only way to set the properties is to use the @TestPropertySource to load the properties from a location
34
    // "user.home=./target/",
35
    //"cdm.beanDefinitionFile=./src/test/resources/datasources.xml",
36
    //"cdm.datasource=h2_cdmTest"
37
    }
38
)
39
//@DirtiesContext // this is a reminder that this annotation can be used.
40
public class SelenideTestBase {
41

    
42
    // @Value("${local.server.port}")
43
    // this will not work since the AutowiredAnnotationBeanPostProcessor will
44
    // try resolve this value before ServerPortInfoApplicationContextInitializer has set it.
45
    private int localServerPort = -1 ;
46
    private int managementPort = -1;
47
    private String managementContextPath = null;
48

    
49
    // ------------------------------------------------------------------------
50
    // replacement for failing @Value("${local.server.port}", etc
51
    @Autowired
52
    Environment environment;
53
    protected int localServerPort() {
54
        if(localServerPort < 0){
55
            localServerPort = environment.getProperty("local.server.port", Integer.class);
56
        }
57
        return localServerPort;
58
    }
59
    protected int managementPort() {
60
        if(localServerPort < 0){
61
            managementPort = environment.getProperty("management.port", Integer.class);
62
        }
63
        return managementPort;
64
    }
65
    protected String managementContextPath() {
66
        if(managementContextPath == null) {
67
            managementContextPath = environment.getProperty("management.context-path");
68
        }
69
        return managementContextPath;
70
    }
71
    // ------------------------------------------------------------------------
72

    
73
    protected static WebDriver driver;
74

    
75
    @BeforeClass
76
    public static void init() {
77
        System.setProperty("webdriver.chrome.driver", "selenium/bin/linux/googlechrome/64bit/chromedriver");
78
        driver = new ChromeDriver();
79
        WebDriverRunner.setWebDriver(driver);
80
    }
81

    
82
    @AfterClass
83
    public static void teardown() {
84
        if (driver != null) {
85
            driver.quit();
86
        }
87
    }
88
}
(2-2/4)