/*
 * Copyright 2016 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package de.vorb.platon.config;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

import java.net.URL;

@Configuration
@PropertySource(value = "classpath:config/application.properties")
public class SpringITConfig {

    @Value("${TRAVIS_JOB_NUMBER}")
    private String jobNumber;

    @Value("${selenium.version}")
    private String seleniumVersion;

    @Value("http://${SAUCE_USERNAME}:${SAUCE_ACCESS_KEY}@localhost:4445/wd/hub")
    private URL remoteUrl;

    @Bean
    public WebDriver webDriver() {

        final DesiredCapabilities capabilities = DesiredCapabilities.firefox();
        capabilities.setCapability("tunnel-identifier", jobNumber);
        capabilities.setCapability("seleniumVersion", seleniumVersion);

        return new RemoteWebDriver(remoteUrl, capabilities);
    }

}

@@ -837,21 +837,25 @@
 otation.
-Value
+Autowired
 ;%0Aimport
@@ -1023,16 +1023,104 @@
 Source;%0A
+import org.springframework.core.env.Environment;%0A%0Aimport java.net.MalformedURLException;
 %0Aimport 
@@ -1256,289 +1256,261 @@
    @
-Value(%22$%7BTRAVIS_JOB_NUMBER%7D%22)%0A    private String jobNumber;%0A%0A    @Value(%22$%7Bselenium.version%7D%22)%0A    private String seleniumVersion;%0A%0A    @Value(%22http://$%7BSAUCE_USERNAME%7D:$%7BSAUCE_ACCESS_KEY%7D@localhost:4445/wd/hub%22)%0A    private URL remoteUrl;%0A%0A    @Bean%0A    public WebDriver webDriver
+Autowired%0A    private Environment env;%0A%0A    @Bean%0A    public WebDriver webDriver() throws MalformedURLException %7B%0A        return new RemoteWebDriver(getRemoteUrl(), getDesiredCapabilities());%0A    %7D%0A%0A    private DesiredCapabilities getDesiredCapabilities
 () %7B
@@ -1591,16 +1591,50 @@
 efox();%0A
+        if (useSauceLabs()) %7B%0A    
         
@@ -1685,20 +1685,51 @@
 r%22, 
-jobNumber);%0A
+env.getProperty(%22TRAVIS_JOB_NUMBER%22));%0A    
     
@@ -1778,24 +1778,41 @@
 rsion%22, 
+env.getProperty(%22
 selenium
 Version)
@@ -1807,17 +1807,30 @@
 nium
-V
+.v
 ersion
-);
+%22));%0A        %7D
 %0A%0A  
@@ -1846,53 +1846,482 @@
 urn 
-new RemoteWebDriver(remoteUrl, capabilities);
+capabilities;%0A    %7D%0A%0A    private boolean useSauceLabs() %7B%0A        return env.getProperty(%22SAUCE_USERNAME%22) != null;%0A    %7D%0A%0A    private URL getRemoteUrl() throws MalformedURLException %7B%0A        if (useSauceLabs()) %7B%0A            return new URL(String.format(%22http://%25s:%25s@localhost:4445/wd/hub%22,%0A                    env.getProperty(%22SAUCE_USERNAME%22), env.getProperty(%22SAUCE_ACCESS_KEY%22)));%0A        %7D else %7B%0A            return new URL(%22http://localhost:4445/wd/hub%22);%0A        %7D
 %0A   

Make integration tests run on developer machines