[embjopr-commits] EMBJOPR SVN: r204 - in trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit: as5 and 1 other directory.
embjopr-commits at lists.jboss.org
embjopr-commits at lists.jboss.org
Tue Mar 10 19:45:55 EDT 2009
Author: ozizka at redhat.com
Date: 2009-03-10 19:45:55 -0400 (Tue, 10 Mar 2009)
New Revision: 204
Added:
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/ApplicationsPageTest.java
Modified:
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/ApplicationTestBaseAS5.java
Log:
Added Application browsing and pagination tests.
Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/ApplicationTestBaseAS5.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/ApplicationTestBaseAS5.java 2009-03-10 23:22:42 UTC (rev 203)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/ApplicationTestBaseAS5.java 2009-03-10 23:45:55 UTC (rev 204)
@@ -370,7 +370,7 @@
if( null == tabContent )
- throw new HtmlElementNotFoundException("Tab '"+label+" not found using XPath '"+xPath+"'");
+ throw new HtmlElementNotFoundException("Tab '"+label+"' not found using XPath '"+xPath+"'");
return tabContent;
@@ -499,7 +499,7 @@
{
checkIfStillValid();
- String xPath = ".//form//table[contains( normalize-space(@id), ':dataTable'))]";
+ String xPath = ".//form//table[contains( normalize-space(@id), ':dataTable')]";
// [@id='resourceSummaryForm:dataTable'] - is this reliable?
HtmlTable tableElement = (HtmlTable) element.getFirstByXPath(xPath);
return new ContentTable(tableElement);
@@ -901,9 +901,13 @@
}
}
- protected HtmlSpan getGoSpan( String spanLabel ){
+ protected HtmlSpan getGoSpan( String spanLabel ) throws HtmlElementNotFoundException {
String xPath = ".//span[normalize-space() = '"+spanLabel+"']";
- return (HtmlSpan) getPageContols().getFirstByXPath(xPath);
+ HtmlSpan span = getPageContols().getFirstByXPath(xPath);
+ if( null == span )
+ throw new HtmlElementNotFoundException(
+ "Span with '"+spanLabel+"' not found using XPath '"+xPath+"'");
+ return span;
}
protected HtmlTableCell getGoPage( int pageNumber ) throws HtmlElementNotFoundException{
@@ -916,25 +920,26 @@
}
- public boolean goFirst() throws IOException{
+ public boolean goFirst() throws IOException, HtmlElementNotFoundException{
+ // TODO: Compare old and new page object reference?
HtmlSpan goSpan = getGoSpan("First");
goSpan.click();
return !"".equals( ((HtmlTableCell)goSpan.getParentNode()).getOnClickAttribute() );
}
- public boolean goPrev() throws IOException{
+ public boolean goPrev() throws IOException, HtmlElementNotFoundException{
HtmlSpan goSpan = getGoSpan("Prev");
goSpan.click();
return !"".equals( ((HtmlTableCell)goSpan.getParentNode()).getOnClickAttribute() );
}
- public boolean goNext() throws IOException{
+ public boolean goNext() throws IOException, HtmlElementNotFoundException{
HtmlSpan goSpan = getGoSpan("Next");
goSpan.click();
return !"".equals( ((HtmlTableCell)goSpan.getParentNode()).getOnClickAttribute() );
}
- public boolean goLast() throws IOException{
+ public boolean goLast() throws IOException, HtmlElementNotFoundException{
HtmlSpan goSpan = getGoSpan("Last");
goSpan.click();
return !"".equals( ((HtmlTableCell)goSpan.getParentNode()).getOnClickAttribute() );
Added: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/ApplicationsPageTest.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/ApplicationsPageTest.java (rev 0)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/ApplicationsPageTest.java 2009-03-10 23:45:55 UTC (rev 204)
@@ -0,0 +1,293 @@
+/*
+ * 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;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.commons.lang.StringUtils;
+import org.jboss.jopr.jsfunit.AppConstants.DeployableTypes;
+import org.jboss.jopr.jsfunit.ApplicationTestBaseAS5;
+import org.jboss.jopr.jsfunit.DebugUtils;
+import org.jboss.jopr.jsfunit.exceptions.EmbJoprTestException;
+
+
+
+
+
+
+/**
+ * This class contains tests for testing the EmbJopr Application
+ * Management Functions for Enterprise Application archives with JBoss AS 5.
+ *
+ * @author Shelly McGowan
+ *
+ */
+public class ApplicationsPageTest extends ApplicationTestBaseAS5 {
+
+ public ApplicationsPageTest() {
+ }
+ private ApplicationsPageTest(String testToRun) {
+ super(testToRun);
+ }
+
+
+ public void testNavigationToApplications() throws EmbJoprTestException, IOException {
+
+ //DebugUtils.writeFile("target/appNav.html", client.getPageAsText());
+
+ sleep(2000);
+
+ // Navigate to apps summary tab
+ NavTreeNode appsNode = navTree.getNodeByLabel(NAV_APPLICATIONS);
+ assertNotNull(appsNode);
+ appsNode.click();
+ tabMenu.clickTab("Summary");
+
+ // Check text bits appearance.
+ String text = client.getElement("content").getTextContent();
+ assertTrue("Content part should contain 'Applications' header.", text.contains("Applications") );
+ assertTrue("Content part should contain 'View by Type' label.", text.contains("View by Type") );
+
+ }
+
+
+
+ /**
+ * Test pagination in Applications page.
+ *
+ * FAILS HERE because of EMBJOPR-61.
+ * Bad number of listed rows at page 2. expected:<5> but was:<0>
+ */
+ public void testAppsPagination() throws EmbJoprTestException, IOException {
+
+ // Navigate to apps summary tab
+ NavTreeNode appsNode = navTree.getNodeByLabel(NAV_APPLICATIONS);
+ assertNotNull(appsNode);
+ appsNode.click();
+ tabMenu.clickTab("Summary");
+
+ sleep(1000);
+
+ // Get and check total items count.
+ int itemsCount = new ContentBoxPagination().getTotalItemsCount();
+
+ // Returns null, skipping.
+ //Number serverCount = (Number) server.getManagedBeanValue("#{paginationDataModel.size}");
+ //assertEquals("Items count reported in page differs from server's.", serverCount, itemsCount);
+
+ // Check whether trinomial equation fits
+ int itemsPerPage = new ContentBoxPagination().getItemsPerPage();
+ int expectedPages = itemsCount / itemsPerPage;
+ if( itemsCount % itemsPerPage > 0 )
+ expectedPages++;
+ int pageCount = new ContentBoxPagination().getPageCount();
+ assertEquals("Expected number of pages: "+itemsCount+" / "+itemsPerPage, expectedPages, pageCount);
+
+ // ------- FAILS HERE because of EMBJOPR-61. --------- //
+ int page = 0;
+ while( new ContentBoxPagination().goNext() ){
+
+ page++;
+ if( page > expectedPages )
+ throw new EmbJoprTestException("Got too far when clicking Next" +
+ " - to "+page+"th page, expected only "+expectedPages+".");
+
+ // Get rows.
+ ContentTable table = tabMenu.getTabContentBox().getFirstTable();
+ List<ContentTableRow> rows = table.getRows();
+
+ // Check the number of rows listed against what set in combo.
+ if( page < expectedPages )
+ assertEquals("Bad number of listed rows at page "+page+".", itemsPerPage, rows.size() );
+ else
+ assertEquals("Bad number of listed rows at last page.", itemsCount % itemsPerPage, rows.size() );
+
+ }// while (next page)
+
+
+ // TODO: And back
+
+ // TODO: Go to specified page
+
+ // TODO: Check that more pages do not list same app.
+
+ }// testAppsPagination()
+
+
+
+
+ /**
+ * Tests Applications listing.
+ * Creates a list of all apps listed,
+ * then checks whether they are listed when using different type filters.
+ *
+ * FAILS HERE because of EMBJOPR-61:
+ * Span with 'Next not found using XPath './/span[normalize-space() = 'Next']'
+ */
+ public void testAppsListing() throws EmbJoprTestException, IOException {
+
+ // Navigate to apps summary tab
+ NavTreeNode appsNode = navTree.getNodeByLabel(NAV_APPLICATIONS);
+ assertNotNull(appsNode);
+ appsNode.click();
+ tabMenu.clickTab("Summary");
+
+
+
+ // Iterate through all the applications,
+ // check whether the type is determined well,
+ // and store the info in a pool to be used later.
+
+ ApplicationsPool appsPool = new ApplicationsPool();
+
+ // For all pages...
+
+ // ------- FAILS HERE because of EMBJOPR-61. --------- //
+ int max = 100;
+ while( max-- > 0 && new ContentBoxPagination().goNext() ){
+
+ // Get rows.
+ ContentTable table = tabMenu.getTabContentBox().getFirstTable();
+ List<ContentTableRow> rows = table.getRows();
+
+ // For all rows...
+ for( ContentTableRow row : rows ) {
+ appsPool.add( new ApplicationInfo(
+ row.getCellTextByColumnName("Name"),
+ parseDeployableType( row.getCellTextByColumnName("Type") )
+ ) );
+ }// for
+
+ }// while (next page)
+
+
+
+ // TODO: Now change the View by Type select and see whether all apps of that type are displayed.
+
+ // TODO: Get to the filter via nav tree.
+
+
+ }// testNavigationToApplications()
+
+
+
+ /**
+ * Determines the type of the deployable based on the value
+ * in the Type column in EmbJopr.
+ */
+ public DeployableTypes parseDeployableType( String desc ) throws EmbJoprTestException
+ {
+ for( DeployableTypes type : DeployableTypes.values() ){
+ if( desc.toUpperCase().contains( type.name() )){
+ return type;
+ }
+ }
+ throw new EmbJoprTestException("Unrecognized deployable type: "+desc);
+ }
+
+ /**
+ * Determines the type of the deployable using the value
+ * in the Name column in EmbJopr's Summary tab.
+ */
+ public DeployableTypes determineDeployableTypeFromName( String name ) throws EmbJoprTestException
+ {
+ for( DeployableTypes type : DeployableTypes.values() ){
+ if( StringUtils.endsWith(name, type.getSuffix() ) ) return type;
+ if( StringUtils.endsWith(name, type.getExtension() ) ) return type;
+ }
+ throw new EmbJoprTestException("Unrecognized deployable type: "+name);
+ }
+
+
+}// class ApplicationsTest
+/**
+ * Application info - it's type (EAR, WAR, ...) and name.
+ * @author ondra
+ */
+class ApplicationInfo {
+
+ private String name;
+ private DeployableTypes type;
+
+ public String getName() { return name; }
+ public DeployableTypes getType() { return type; }
+
+ public ApplicationInfo(String name, DeployableTypes type) {
+ this.name = name;
+ this.type = type;
+ }
+
+
+ @Override
+ public String toString() {
+ return getType().name()+" "+getName();
+ }
+
+ /**
+ * Overriden to work correctly in ApplicationPool.
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if( null == obj ) return false;
+ if( this == obj ) return true;
+ if( ! (obj instanceof ApplicationInfo) ) return false;
+ return this.name.equals( ((ApplicationInfo)obj).name )
+ && this.type.equals( ((ApplicationInfo)obj).type );
+ }
+
+ @Override
+ public int hashCode() { return this.name.hashCode() + this.type.hashCode(); }
+
+}
+
+
+
+/**
+ * Pool of applications; to handle apps listed in EmbJopr.
+ */
+class ApplicationsPool {
+
+ private List<ApplicationInfo> apps = new ArrayList();
+ private Map<DeployableTypes, List<ApplicationInfo>> mapAppsByType = new HashMap();
+
+ public void add( ApplicationInfo app ){
+ // Add to the list of all apps.
+ this.apps.add(app);
+ // Add to the groups separated by type.
+ List<ApplicationInfo> typeGroup = this.mapAppsByType.get(app.getType());
+ if(null == typeGroup){
+ typeGroup = new ArrayList<ApplicationInfo>();
+ this.mapAppsByType.put(app.getType(), typeGroup );
+ }
+ typeGroup.add(app);
+ }
+}
+
+
+
+
+
+
More information about the embjopr-commits
mailing list