/*
* JBoss, Home of Professional Open Source.
* Copyright 2009, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.jopr.jsfunit.as5.app.rar;
import com.gargoylesoftware.htmlunit.Page;
import org.jboss.jopr.jsfunit.util.DescribedCondition;
import org.jboss.jopr.jsfunit.util.ActiveConditionChecker;
import org.jboss.jopr.jsfunit.*;
import com.gargoylesoftware.htmlunit.html.*;
import java.io.*;
import java.util.*;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.math.RandomUtils;
import org.jboss.jopr.jsfunit.AppConstants.DeployableTypes;
import org.jboss.jopr.jsfunit.exceptions.*;
import org.jboss.jopr.jsfunit.util.EmbJoprTestToolkit.*;
import org.w3c.dom.Node;
/**
* This class contains tests for testing the EmbJopr Application
* Management Functions for Resource Adapters with JBoss AS 5.
*
* @author Shelly McGowan
*
*/
public class RarTest extends ApplicationTestBaseAS5 {
public static final DeployableTypes APP_TYPE = DeployableTypes.RAR;
/**
* @return the suite of tests being tested
*/
public static Test suite()
{
String testToRun = System.getProperty("jsfunit.test.single");
if( null == testToRun ){
return new TestSuite(RarTest.class);
}
else{
// TODO: Try running single test set in system property.
// http://members.pingnet.ch/gamma/junit.htm
TestSuite suite = new TestSuite();
//suite.addTest(this.getClass().getConstructor(String.class).newInstance(testToRun));
suite.addTest( new RarTest(testToRun) );
return suite;
}
}
public RarTest() {
}
private RarTest(String testToRun) {
super(testToRun);
}
/*
* testName: testBasicRarDeployment
* assertion: verify basic deployment of a standalone resource adapter
* test Strategy: Navigate to Resource Adapter.
* Add a new resource. Verify the resource was successfully
* deployed. Undeploy the archive for test clean up purposes.
*
*/
public void testBasicRarDeployment() throws IOException, EmbJoprTestException
{
final String DEPLOYABLE_NAME = BASIC_RAR;
try {
// Deploy the RAR.
String rarFilePath = ejtt.getTestDataDir() + "/rar/"+DEPLOYABLE_NAME;
deployRar( rarFilePath );
String expectedMessage = DEPLOYABLE_NAME + " created successfully";
checkClientAndServerMessages(expectedMessage, expectedMessage, false);
assertTrue("JMX doesn't report RAR, jbosstestadapter.rar as deployed.", isRarDeployed(BASIC_RAR));
}
finally {
ejtt.deployment.undeployViaEmbJopr(APP_TYPE, DEPLOYABLE_NAME);
}
assertFalse(isRarDeployed(BASIC_RAR));
}
/**
* assertion: Verify the navigation sequence to Resource Adapters.
*
* test Strategy:
*
* From the root of the navigation tree:i
* Click JBossAS Servers ==> JBoss App Server:${config}
* ==> Applications ==> Resource Adapters
*
*/
public void testNavigationToRar() throws IOException, HtmlElementNotFoundException,
ActionOutOfSyncException, ActionNotAvailableException, EmbJoprTestException, InterruptedException
{
// JBossAS Servers node
NavTreeNode nodeServers = ejtt.getNavTree().getNodeByLabel("JBossAS Servers");
nodeServers.click();
{
String headerText = "JBossAS Server";
String jbossConfig = ejtt.getJBossConfig();
assertTrue("Page doesn't contain the header: "+headerText,
client.getPageAsText().contains(headerText));
assertTrue("EmbJopr should list at least one server (the one it is running on)" +
" and that should be in the UP sate.",
client.getPageAsText().contains("UP"));
// Check whether the server is listed. If not, Exception is thrown.
ContentTableRow row =
ejtt.getTabMenu().getTabContentBox().getTableUnderHeader("JBoss Application Server")
.getFirstRowContainingLink( String.format(AS_NODE_NAME_FORMAT, jbossConfig) );
// Click the server link
//HtmlAnchor link row.getLinkByLabel("JBAS (default)");
Node firstLink = row.getCellByColumnName("Name").getElementsByTagName("a").item(0);
if( null == firstLink || !(firstLink instanceof HtmlAnchor) )
throw new HtmlElementNotFoundException("Can't find the server link.");
((HtmlAnchor)firstLink).click();
}
// JBoss App Server:${config} node
{
String pageText = client.getPageAsText();
String jbossConfig = ejtt.getJBossConfig();
String headerText = String.format(AS_NODE_NAME_FORMAT, jbossConfig);
assertTrue("Page doesn't contain the header: "+headerText,
pageText.contains(headerText));
headerText = "General Properties";
assertTrue("Page doesn't contain the header: "+headerText,
pageText.contains(headerText));
ejtt.getNavTree().getNodeByLabel("Applications").click();
}
// Applications node
{
ejtt.getTabMenu().clickTab("Summary");
HtmlTable tableElement = (HtmlTable)client.getElement("categorySummaryForm:dataTable");
ContentTable table = ejtt.getTabMenu().getTabContentBox().getTable(tableElement);
ContentTableRow row = table.getFirstRowContainingText("UP");
// Go further - try to click on any Application that is up.
HtmlAnchor link = row.getFirstLinkFromColumn("Name");
link.click();
}
{
// Go back to applications Sumary screen.
ejtt.getNavTree().getNodeByLabel("Applications").click();
}
// Concrete appliction node.
{
// Deploy the RAR.
String rarFilePath = System.getProperty(SYSPROP_TESTDATA_DIR) + "/rar/"+BASIC_RAR;
deployRar( rarFilePath );
ejtt.getNavTree().getNodeByLabel(NAV_RAR).click();
ContentTableRow rarRow = ejtt.getDefaultContentTable().getFirstRowContainingLink(BASIC_RAR);
assertTrue("Page doesn't list "+BASIC_RAR+" in Summary tab.", rarRow != null );
// Go to the summary through listed item.
rarRow.getLinkByLabel(BASIC_RAR).click();
// Check that we have the summary tab for the selected RAR.
assertTrue( "RAR name ("+BASIC_RAR+") not found in the content box.",
ejtt.getTabMenu().getTabContentBox().getElement().getTextContent().contains(BASIC_RAR) );
// Go to the summary through nav tree node.
NavTreeNode rarNode = ejtt.getNavTree().getNodeByLabel(NAV_RAR);
if( !rarNode.isExpanded() ){
log.info("Expanding.");
rarNode.getArrowLink().click();
Thread.sleep(2000);
}
ejtt.getNavTree().getNodeByLabel(BASIC_RAR).click();
// Check that we have the summary tab for the selected RAR.
ejtt.getTabMenu().getTabContentBox().getElement().getTextContent().contains(BASIC_RAR);
undeployRar(BASIC_RAR);
}
}// testNavigationToRar()
/**
* Assertion: Verify the content of the Resource Adapter Summary tab
*
*
*/
public void testRarSummaryTab() throws EmbJoprTestException, IOException, Exception {
final int DEPLOY_TIMEOUT_SEC = 20;
// Deploy the RAR
String rarFilePath = System.getProperty(SYSPROP_TESTDATA_DIR) + "/rar/"+BASIC_RAR;
deployRar( rarFilePath );
try {
// Wait until the RAR appears...
new ActiveConditionChecker(new DescribedCondition("RAR appears in Summary tab list") {
public boolean isTrue() throws Exception {
// Refresh, then check.
ejtt.getNavTree().getNodeByLabel(NAV_RAR).click();
ContentTableRow rarRow = ejtt.getDefaultContentTable().findFirstRowContainingLink(BASIC_RAR);
return null != rarRow;
}
}).dumpPageOnTimeout(this).throwOnTimeout().waitWithTimeout(2000, 5);
ContentTableRow rarRow = ejtt.getDefaultContentTable().getFirstRowContainingLink(BASIC_RAR);
// Wait until the Status is "UP".
// TODO: Replace with ActiveConditionChecker.
int maxLoops = DEPLOY_TIMEOUT_SEC;
do {
String statusText = rarRow.getCellTextByColumnName("Status");
log.debug("RAR Status: "+statusText);
if( "UP".equals(statusText) )
break;
// Refresh page after 1 second.
ejtt.getNavTree().getNodeByLabel(NAV_RAR).click();
rarRow = ejtt.getDefaultContentTable().getFirstRowContainingLink(BASIC_RAR);
// We don't want an infinite loop by mistake.
if( maxLoops-- <= 0 ){
throw new EmbJoprTestException("RAR "+BASIC_RAR+" not UP after "+DEPLOY_TIMEOUT_SEC+" seconds.");
}
} while( true );
// FAILS because of EMBJOPR-80.
rarRow.getLinkByLabel(BASIC_RAR).click();
// Check the values in info table(s)
// General Properties
HtmlTable genpropTable = ejtt.getTabMenu().getTabContentBox().getTableUnderHeader(LABEL_GENERAL_PROPERTIES).getElement();
ContentInfoTable infoTable = ejtt.getContentInfoTable( genpropTable );
Properties props = infoTable.getProperties();
assertEquals(BASIC_RAR, props.getProperty("Name").trim());
// Resource Traits
infoTable = ejtt.getContentInfoTable(
ejtt.getTabMenu().getTabContentBox().getTableUnderHeader(LABEL_TRAITS).getElement() );
props = infoTable.getProperties();
String path = ejtt.getDeployDir()+"/"+BASIC_RAR;
assertEquals(path, props.getProperty("Path").trim());
assertEquals("no", props.getProperty("Exploded?").trim());
}
finally {
try {
undeployRar(BASIC_RAR);
}catch( Exception ex ){
log.error("Caught exception when undeploying: "+ex, ex);
}
}
}// testRarSummary()
/**
* Changes RAR configuration, and checks whether the changes were saved.
*
* JOPR-147
*/
public void DISABLEDtestRarConfigurationTab() throws IOException, EmbJoprTestException {
final String DEPLOYABLE_NAME = BASIC_RAR;
// Deploy the RAR.
String rarFilePath = ejtt.getTestDataDir() +"/rar/"+ DEPLOYABLE_NAME;
deployRar( rarFilePath );
try {
ejtt.getNavTree().getNodeByLabel(APP_TYPE.getNavTreeLabel()).click();
ejtt.deployment.waitActivelyForDeployment(APP_TYPE, DEPLOYABLE_NAME, 3000, 15);
// Navigate to the Configuration tab
ContentTableRow rarRow = ejtt.getDefaultContentTable().getFirstRowContainingLink(DEPLOYABLE_NAME);
rarRow.getLinkByLabel(DEPLOYABLE_NAME).click();
Page prevPage = client.getContentPage();
ejtt.tabMenu.clickConfigurationTab();
assertNotSame("We should move to other page after clicking the Config tab.",
prevPage, client.getContentPage());
// Read properties.
Properties props = new Properties();
String filePath = ejtt.getTestDataDir()+"/rar/"+"rar-conf-basic.properties";
props.load(new FileInputStream( filePath ));
// Set the configuration options and Save
fillOutForm(props);
//ejtt.getTabMenu().getTabContentBox().getButtonByLabel("Save");
ejtt.getClickableByID("resourceConfigurationForm:saveButton").click();
// Check whether the properties were saved.
ejtt.tabMenu.clickConfigurationTab();
// TODO: We don't see the success message! EMBJOPR-89
checkClientAndServerMessages("successfully", "successfully", false);
// FAILS because some of the values are read-only. EMBJOPR-96
checkForm(props);
// TODO: Finish when the properties are marked read-only.
}
finally {
try {
undeployRar(DEPLOYABLE_NAME);
}catch( Exception ex ){
log.error("Caught exception when undeploying: "+ex, ex);
}
}
}
// Utils
private void deployRar( String rarFilePath ) throws IOException, HtmlElementNotFoundException
{
if( !(new File(rarFilePath)).exists())
throw new FileNotFoundException(rarFilePath);
log.info("Deploying: "+rarFilePath);
// Navigate to Enterprise Archives
ejtt.getNavTree().getNodeLink(NAV_RAR).click();
// click on the "Add new resource" button
client.click("actionHeaderForm:addNewContent"); // 404 if setThrowExceptionOnFailingStatusCode(true) above
// Upload the file
HtmlFileInput fileInput = (HtmlFileInput)client.getElement("createContentForm:file");
fileInput.setContentType("application/rar");
fileInput.setValueAttribute(rarFilePath);
client.click("createContentForm:addButton");
ejtt.sleep( 2000 );
// Log the message
ejtt.logServerMessage("Something went wrong with deploy: ");
}
private void undeployRar( String rarFileName ) throws IOException,
HtmlElementNotFoundException, ActionNotAvailableException
{
// Navigate to Enterprise Archives
ejtt.getNavTree().getNodeLink(NAV_RAR).click();
ejtt.getTabMenu().clickSummaryTab();
/// Debug log - we're getting HTTP 500 here :/
String dumpFile = "target/"+this.getName()+"-undeployRar-"+(1000+RandomUtils.nextInt(1000))+".html";
log.debug("Dumping page to "+dumpFile);
DebugUtils.writeFile( dumpFile, client.getPageAsText());
int httpStatusCode = client.getContentPage().getWebResponse().getStatusCode();
if( 200 != httpStatusCode )
log.warn("Status code before undeployment is: "+httpStatusCode);
HtmlButtonInput deleteButton = getAppDeleteButton( rarFileName );
deleteButton.click();
// Log the message (with prefix of potential warning)
ejtt.logServerMessage("Something went wrong with undeploy: ");
// Sleep for 3 sec. TODO: write some waitForUndeployed()
ejtt.sleep( 3000 );
}
}// class RarTest