Skip to content

Commit

Permalink
Add mechanism to recognize Application Server #605
Browse files Browse the repository at this point in the history
(cherry picked from commit c184140)

Conflicts:
	terasoluna-gfw-functionaltest-env/configs/jboss7-postgresql/resources/META-INF/spring/application-env.properties
	terasoluna-gfw-functionaltest-env/configs/resin-oracle/resources/META-INF/spring/application-env.properties
	terasoluna-gfw-functionaltest-env/configs/resin-postgresql/resources/META-INF/spring/application-env.properties
	terasoluna-gfw-functionaltest-env/configs/tomcat-oracle/resources/META-INF/spring/application-env.properties
	terasoluna-gfw-functionaltest-env/configs/tomcat-postgresql/resources/META-INF/spring/application-env.properties
	terasoluna-gfw-functionaltest-env/configs/tomcat8-oracle/resources/META-INF/spring/application-env.properties
	terasoluna-gfw-functionaltest-env/configs/tomcat8-postgresql/resources/META-INF/spring/application-env.properties
	terasoluna-gfw-functionaltest-env/configs/tomcat85-oracle/resources/META-INF/spring/application-env.properties
	terasoluna-gfw-functionaltest-env/configs/tomcat85-postgresql/resources/META-INF/spring/application-env.properties
	terasoluna-gfw-functionaltest-env/configs/weblogic-oracle/resources/META-INF/spring/application-env.properties
	terasoluna-gfw-functionaltest-env/configs/webotx-oracle/resources/META-INF/spring/application-env.properties
	terasoluna-gfw-functionaltest-env/configs/webspherelp-db2/resources/META-INF/spring/application-env.properties
	terasoluna-gfw-functionaltest-env/configs/webspheretr-db2/resources/META-INF/spring/application-env.properties
	terasoluna-gfw-functionaltest-env/src/main/resources/META-INF/spring/application-env.properties
  • Loading branch information
btyanagawamg committed Jun 12, 2017
1 parent e61715a commit 2635cef
Show file tree
Hide file tree
Showing 12 changed files with 87 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
app.redirect.allowed.externalUrl=http://terasolunaorg.github.io

application.server.name=resin
application.server.version=4
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
app.redirect.allowed.externalUrl=http://terasolunaorg.github.io

application.server.name=resin
application.server.version=4
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
app.redirect.allowed.externalUrl=http://terasolunaorg.github.io

application.server.name=tomcat
application.server.version=7
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
app.redirect.allowed.externalUrl=http://terasolunaorg.github.io

application.server.name=tomcat
application.server.version=7
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
app.redirect.allowed.externalUrl=http://terasolunaorg.github.io

application.server.name=tomcat
application.server.version=8.0
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
app.redirect.allowed.externalUrl=http://terasolunaorg.github.io

application.server.name=weblogic
application.server.version=12
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
app.redirect.allowed.externalUrl=http://terasolunaorg.github.io

## application server name and version properties are used in order to
## change the assertions in test which depends on application server.
## when the new profile is added, set appropriate values.
application.server.name=tomcat
application.server.version=8.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.terasoluna.gfw.functionaltest.app;

/**
* Enumeration class for identifying application server.
* <p>
* If application server name is not set in application.env.properties, <br/>
* UNKNOWN is set.
* </p>
*/
public enum ApServerName {
UNKNOWN, RESIN, TOMCAT, WEBLOGIC
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Class that provides a (logic for WebDriver) browser operation.
Expand All @@ -30,6 +32,8 @@ public class WebDriverOperations {

protected long defaultTimeoutSecForImplicitlyWait = 5;

private static final Logger logger = LoggerFactory.getLogger(WebDriverOperations.class);

public WebDriverOperations(WebDriver webDriver) {
this.webDriver = webDriver;
}
Expand All @@ -43,6 +47,15 @@ public void setDefaultTimeoutForImplicitlyWait(
this.defaultTimeoutSecForImplicitlyWait = defaultTimeoutSecForImplicitlyWait;
}

/**
* Get the text (display value) set for the specified element.
* @param by Identifier to look for elements
* @return And returns the text (display value)
*/
public String getText(By by) {
return webDriver.findElement(by).getText();
}

/**
* Check the specified element exists.
* @param by Identifier to look for elements
Expand Down Expand Up @@ -76,4 +89,27 @@ public void setDefaultTimeoutForImplicitlyWait() {
public void setTimeoutForImplicitlyWait(long timeout, TimeUnit timeUnit) {
webDriver.manage().timeouts().implicitlyWait(timeout, timeUnit);
}

/**
* Get application server name.
* @return application server name
*/
public ApServerName getApServerName() {
String serverName = getText(By.id("apServerName")).toUpperCase();
try {
return ApServerName.valueOf(serverName);
} catch (IllegalArgumentException e) {
logger.warn("Unkown application server name:{} is detected.", serverName);
// If server name not defined in the ApServerName class, set it to UNKNOWN.
return ApServerName.UNKNOWN;
}
}

/**
* Get application server version.
* @return application server version
*/
public String getApServerVersion() {
return getText(By.id("apServerVersion"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.terasoluna.gfw.functionaltest.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

/**
* Class that registers the value defined in application-env.properties of each profile in environment.
* <p>
* Passes application server information to WebDriver through JSP so that asserts can be changed for each application server.
* </p>
*/
@Configuration
@PropertySource("classpath:/META-INF/spring/application-env.properties")
public class PropertySourceConfig {
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,6 @@
<property name="exceptionLogger" ref="variationExceptionLogger" />
</bean>

<context:component-scan base-package="org.terasoluna.gfw.functionaltest.config" />

</beans>
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
<tiles:insertAttribute name="header" />
<tiles:insertAttribute name="body" />
<hr>
<p align="right">
Application Server :
<span id="apServerName"><spring:eval expression="@environment.getProperty('application.server.name')"/></span>
<span id="apServerVersion"><spring:eval expression="@environment.getProperty('application.server.version')"/></span>
</p>
<p style="text-align: center; background: #e5eCf9;">
<spring:message code="copyright" htmlEscape="false" />
(X-Track:${f:h(requestScope["X-Track"])})</p>
Expand Down

0 comments on commit 2635cef

Please sign in to comment.