EMBJOPR SVN: r164 - in trunk: jsfunit and 4 other directories.
by embjopr-commits@lists.jboss.org
Author: fjuma
Date: 2009-02-23 11:08:15 -0500 (Mon, 23 Feb 2009)
New Revision: 164
Added:
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/JMSTest.java
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/ResourceTestBase.java
trunk/jsfunit/testdata/destinations/
trunk/jsfunit/testdata/destinations/TestQueue-service.xml
trunk/jsfunit/testdata/destinations/TestTopic-service.xml
Modified:
trunk/core/src/main/webapp/include/resourceDataScroller.xhtml
trunk/jsfunit/pom.xml
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/DatasourceTestBase.java
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/EmbjoprTestCase.java
Log:
Added creation tests for topics and queues.
Added methods to EmbjoprTestCase.java to check the properties of managed components.
Modified: trunk/core/src/main/webapp/include/resourceDataScroller.xhtml
===================================================================
--- trunk/core/src/main/webapp/include/resourceDataScroller.xhtml 2009-02-23 16:00:38 UTC (rev 163)
+++ trunk/core/src/main/webapp/include/resourceDataScroller.xhtml 2009-02-23 16:08:15 UTC (rev 164)
@@ -67,7 +67,7 @@
<f:facet name="next">
<h:panelGroup>
<h:graphicImage value="images/ArrowNextNorm.gif" style="padding: 0px 5px 0px 7px;"/>
- <h:outputText value="#{messages['component.dataPaginator.nextpage']}"
+ <h:outputText id="nextPage" value="#{messages['component.dataPaginator.nextpage']}"
styleClass="rich-datascr-textlinks"/>
</h:panelGroup>
</f:facet>
Modified: trunk/jsfunit/pom.xml
===================================================================
--- trunk/jsfunit/pom.xml 2009-02-23 16:00:38 UTC (rev 163)
+++ trunk/jsfunit/pom.xml 2009-02-23 16:08:15 UTC (rev 164)
@@ -95,19 +95,28 @@
<scope>provided</scope>
<version>2.8.1</version>
</dependency>
-
<dependency>
<groupId>jdom</groupId>
<artifactId>jdom</artifactId>
<version>1.0</version>
</dependency>
-
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.4</version>
</dependency>
-
+ <dependency>
+ <groupId>org.jboss.integration</groupId>
+ <artifactId>jboss-profileservice-spi</artifactId>
+ <version>5.0.3.GA</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.man</groupId>
+ <artifactId>jboss-metatype</artifactId>
+ <version>2.0.0.GA</version>
+ <scope>provided</scope>
+ </dependency>
</dependencies>
@@ -291,6 +300,12 @@
<toFile>deploy/MultipleDatasources-ds.xml</toFile>
</configfile>
</configfiles>
+ <files>
+ <copy>
+ <file>${basedir}/testdata/destinations</file>
+ <toDir>deploy</toDir>
+ </copy>
+ </files>
</configuration>
<!-- /Container configuration -->
Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/DatasourceTestBase.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/DatasourceTestBase.java 2009-02-23 16:00:38 UTC (rev 163)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/DatasourceTestBase.java 2009-02-23 16:08:15 UTC (rev 164)
@@ -556,8 +556,7 @@
client.click("resourceConfigurationForm:saveButton");
// Check for the appropriate error messages
- String expectedMessage = "Failed to add Resource (see app server log for "
- + "additional details): A Local TX Datasource named "
+ String expectedMessage = "A Local TX Datasource named "
+ "'DefaultDS' already exists";
checkClientAndServerMessages(expectedMessage, expectedMessage, true);
}
Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/EmbjoprTestCase.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/EmbjoprTestCase.java 2009-02-23 16:00:38 UTC (rev 163)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/EmbjoprTestCase.java 2009-02-23 16:08:15 UTC (rev 164)
@@ -37,9 +37,20 @@
//import org.jboss.jmx.adaptor.rmi.RMIAdaptor; // Needs dependency: jmx-adaptor-plugin
import java.util.regex.Pattern;
import javax.xml.xpath.XPathException;
+import org.jboss.profileservice.spi.ProfileService;
+import org.jboss.profileservice.spi.ProfileKey;
+import javax.naming.InitialContext;
+import org.jboss.deployers.spi.management.ManagementView;
+import javax.naming.NamingException;
+import org.jboss.managed.api.ComponentType;
+import org.jboss.managed.api.ManagedProperty;
+import org.jboss.metatype.api.values.MetaValue;
+import org.jboss.managed.api.ManagedComponent;
+import org.jboss.managed.api.ManagedDeployment;
+import org.jboss.profileservice.spi.NoSuchDeploymentException;
+import org.jboss.metatype.api.values.SimpleValueSupport;
-
/**
* This is the base test class for Embedded Jopr test cases.
* It supplies access to a JSFClientSession object and a JSFServerSession
@@ -566,41 +577,160 @@
}
}
+
+ /**
+ * Checks whether given string looks like a double in terms of Java's Double,
+ * i.e. /<digit>+(\.<digit>+)?/
+ * @param value The string to check.
+ * @returns true if the
+ */
+ protected boolean looksLikeDouble(String value) {
+ try{
+ Double.parseDouble(value);
+ }catch(NumberFormatException ex){
+ return false;
+ }
+ return true;
+ }
+ /**
+ * If both expected and actual string look like a double,
+ * returns normalized double (with a decimal dot);
+ * Otherwise, returns original actual value.
+ * @param expected
+ * @param actual
+ */
+ protected String normalizeIfDoubleExpected(String expected, String actual) {
+ //return looksLikeDouble(expected) ? actual.replace(',', '.') : actual;
- /**
- * Checks whether given string looks like a double in terms of Java's Double,
- * i.e. /<digit>+(\.<digit>+)?/
- * @param value The string to check.
- * @returns true if the
- */
- protected boolean looksLikeDouble(String value) {
- try{
- Double.parseDouble(value);
- }catch(NumberFormatException ex){
- return false;
- }
- return true;
- }
+ if( !looksLikeDouble(expected) )
+ return actual;
- /**
- * If both expected and actual string look like a double,
- * returns normalized double (with a decimal dot);
- * Otherwise, returns original actual value.
- * @param expected
- * @param actual
- */
- protected String normalizeIfDoubleExpected(String expected, String actual) {
- //return looksLikeDouble(expected) ? actual.replace(',', '.') : actual;
+ String converted = actual.replace(',', '.');
+ return looksLikeDouble(converted) ? converted : actual;
+ }
+
+ /**
+ * Transform the given map of Strings to MetaValues into a
+ * map of Strings to Strings.
+ */
+ protected Map<String, String> formatPropertiesMap(Map<String, MetaValue> propertiesMap) {
+ Map<String, String> formattedPropertiesMap = new HashMap<String, String>();
+
+ for(String propertyName : propertiesMap.keySet()) {
+ SimpleValueSupport propertyMetaValue = (SimpleValueSupport)propertiesMap.get(propertyName);
+ String propertyStringValue = propertyMetaValue.getValue().toString();
+ formattedPropertiesMap.put(propertyName, propertyStringValue);
+ }
+
+ return formattedPropertiesMap;
+ }
+
+ /**
+ * Check the properties for a particular managed component.
+ *
+ * @param expectedProperties maps property names to expected values
+ * @param componentName - the name of the ManagedComponent
+ * @param type - the component type
+ */
+ protected void checkComponentProperties(Map<String, MetaValue> expectedProperties,
+ String componentName,
+ ComponentType type) throws Exception {
+
+ ManagedComponent component = getManagedComponent(componentName, type);
+ assertNotNull("The returned component was null", component);
+ assertEquals(componentName, component.getName());
+
+ Map<String, ManagedProperty> actualProperties = component.getProperties();
+ ManagedProperty prop;
+
+ // Verify that the property values are correct
+ for(String propertyName : expectedProperties.keySet()) {
+ prop = actualProperties.get(propertyName);
+
+ assertEquals("Incorrect value for '" + propertyName + "'",
+ expectedProperties.get(propertyName),
+ prop.getValue());
+ }
+ }
+
+ /**
+ * Return a ManagedComponent, given the component name and type.
+ */
+ protected ManagedComponent getManagedComponent(String componentName,
+ ComponentType type) throws Exception {
+
+ // Get the ManagedComponent
+ ManagementView mgtView = getCurrentProfileView();
+ ManagedComponent component = mgtView.getComponent(componentName, type);
+
+ return component;
+ }
+
+ /**
+ * Return whether or not the given deployment is deployed.
+ *
+ * @param deployment - the deployment we are interested in
+ */
+ protected boolean isDeployed(String deployment) throws Exception {
+ ManagementView currentProfileView = getCurrentProfileView();
+ ManagedDeployment managedDeployment = null;
+
+ try {
+ managedDeployment = currentProfileView.getDeployment(deployment,
+ ManagedDeployment.DeploymentPhase.APPLICATION);
+ } catch (NoSuchDeploymentException e) {
+ return false;
+ }
+
+ return managedDeployment != null;
+ }
+
+ /**
+ * Get the profile service.
+ */
+ protected ProfileService getProfileService()
+ {
+ ProfileService profileService = null;
+ InitialContext initialContext;
+
+ try {
+ initialContext = new InitialContext();
+ } catch (NamingException e) {
+ log.error("Unable to get an InitialContext to JBoss AS 5", e);
+ return null;
+ }
- if( !looksLikeDouble(expected) )
- return actual;
+ try {
+ profileService = (ProfileService) initialContext.lookup("ProfileService");
+ } catch (NamingException e) {
+ log.error("Could not find ProfileService Name on JBoss AS 5", e);
+ } catch (Exception e) {
+ log.error("Exception thrown when looking up ProfileService on JBoss AS 5", e);
+ }
+
+ return profileService;
+ }
- String converted = actual.replace(',', '.');
- return looksLikeDouble(converted) ? converted : actual;
- }
+ /**
+ * Get the current profile view.
+ */
+ protected ManagementView getCurrentProfileView()
+ {
+ ProfileService profileService = getProfileService();
+ ManagementView currentProfileView = profileService.getViewManager();
+ String[] domains = profileService.getDomains();
-
+ ProfileKey defaultKey = new ProfileKey(domains[0]);
+
+ try {
+ currentProfileView.loadProfile(defaultKey);
+ } catch (Exception e) {
+ log.error("Could not find default Profile in Current Profile View", e);
+ }
+
+ return currentProfileView;
+ }
}
Added: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/JMSTest.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/JMSTest.java (rev 0)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/JMSTest.java 2009-02-23 16:08:15 UTC (rev 164)
@@ -0,0 +1,377 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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 com.gargoylesoftware.htmlunit.html.*;
+import java.io.IOException;
+import junit.framework.Test;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Set;
+import org.jdom.Document;
+import org.jdom.Element;
+import org.jdom.input.SAXBuilder;
+import java.io.File;
+import org.jboss.jopr.jsfunit.*;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+import org.jboss.mx.util.MBeanServerLocator;
+import org.jboss.deployers.spi.management.KnownComponentTypes;
+import org.jboss.metatype.api.values.SimpleValueSupport;
+import org.jboss.metatype.api.values.MetaValue;
+import org.jboss.managed.api.ComponentType;
+
+/**
+ * This class contains tests for managing JMS topics and queues
+ * using Embedded Jopr. This test class should be run against
+ * JBAS 5.x.
+ *
+ * @author Farah Juma
+ *
+ */
+
+public class JMSTest extends ResourceTestBase {
+
+ public enum DestinationType {
+ QUEUE("Queues", "Queue"),
+ TOPIC("Topics", "Topic");
+
+ private final String navLabel;
+ private final String name;
+
+ DestinationType(String navLabel, String name) {
+ this.navLabel = navLabel;
+ this.name = name;
+ }
+
+ private String getNavLabel() {
+ return this.navLabel;
+ }
+
+ private String getName() {
+ return this.name;
+ }
+ }
+
+ private static final String QUEUE_DEFAULT_TEMPLATE="default__Queue";
+ private static final String TOPIC_DEFAULT_TEMPLATE="default__Topic";
+ private static final String JMS_NAV_LABEL="JMS Destinations";
+ private static final ComponentType QUEUE_COMPONENT_TYPE = KnownComponentTypes.JMSDestination.Queue.getType();
+ private static final ComponentType TOPIC_COMPONENT_TYPE = KnownComponentTypes.JMSDestination.Topic.getType();
+
+ /**
+ * Create a new topic or queue using the given destination type and properties.
+ */
+ protected void createDestination(DestinationType destinationType,
+ String templateName,
+ Map<String, MetaValue> propertiesMap) throws IOException {
+
+ // Expand the "JMS Destinations" tree node
+ ClickableElement datasourcesArrow = getNavTreeArrow(JMS_NAV_LABEL);
+ datasourcesArrow.click();
+
+ createResource(destinationType.getNavLabel(), templateName, propertiesMap);
+ }
+
+ /**
+ * Delete the given JMS destination.
+ *
+ * Assumes the JMS Destinations tree node is already expanded.
+ */
+ protected void deleteDestination(DestinationType destinationType,
+ String destinationName) throws IOException {
+ HtmlAnchor datasourceLink = getNavTreeLink(destinationType.getNavLabel());
+ datasourceLink.click();
+
+ deleteResource("resourceSummaryForm", destinationName);
+ }
+
+ /**
+ * Create a basic queue. Return the mapping of property names to property
+ * values.
+ */
+ protected Map<String, MetaValue> createQueue(String queueName) throws IOException {
+
+ Map<String, MetaValue> propertiesMap = new HashMap<String, MetaValue>();
+ propertiesMap.put("JNDIName", SimpleValueSupport.wrap(queueName));
+ propertiesMap.put("clustered", SimpleValueSupport.wrap(Boolean.FALSE));
+ propertiesMap.put("downCacheSize", SimpleValueSupport.wrap(new Integer(1500)));
+ propertiesMap.put("fullSize", SimpleValueSupport.wrap(new Integer(76000)));
+ propertiesMap.put("maxSize", SimpleValueSupport.wrap(new Integer(76000)));
+ propertiesMap.put("messageCounterHistoryDayLimit", SimpleValueSupport.wrap(new Integer(5)));
+ propertiesMap.put("pageSize", SimpleValueSupport.wrap(new Integer(1500)));
+
+ createDestination(DestinationType.QUEUE, QUEUE_DEFAULT_TEMPLATE, propertiesMap);
+ client.click("resourceConfigurationForm:saveButton");
+
+ return propertiesMap;
+ }
+
+ /**
+ * Create a basic topic. Return the mapping of property names to property
+ * values.
+ */
+ protected Map<String, MetaValue> createTopic(String topicName) throws IOException {
+ Map<String, MetaValue> propertiesMap = new HashMap<String, MetaValue>();
+ propertiesMap.put("JNDIName", SimpleValueSupport.wrap(topicName));
+ propertiesMap.put("clustered", SimpleValueSupport.wrap(Boolean.TRUE));
+ propertiesMap.put("fullSize", SimpleValueSupport.wrap(new Integer(70000)));
+ propertiesMap.put("maxSize", SimpleValueSupport.wrap(new Integer(70000)));
+ propertiesMap.put("redeliveryDelay", SimpleValueSupport.wrap(new Long(60000)));
+
+ createDestination(DestinationType.TOPIC, TOPIC_DEFAULT_TEMPLATE, propertiesMap);
+ client.click("resourceConfigurationForm:saveButton");
+
+ return propertiesMap;
+ }
+
+ /*
+ * CREATION TESTS
+ */
+
+ /**
+ * Create a new queue.
+ */
+ public void testCreateQueue() throws Exception {
+
+ String jndiName = "CreateQueue";
+ String expectedMessage = SUCCESS_MESSAGE + DestinationType.QUEUE.getName();
+
+ createDestinationCommon(DestinationType.QUEUE, QUEUE_DEFAULT_TEMPLATE,
+ jndiName, expectedMessage, QUEUE_COMPONENT_TYPE);
+ }
+
+ /**
+ * Create a new topic.
+ */
+ public void testCreateTopic() throws Exception {
+
+ String jndiName = "CreateTopic";
+ String expectedMessage = SUCCESS_MESSAGE + DestinationType.TOPIC.getName();
+
+ createDestinationCommon(DestinationType.TOPIC, TOPIC_DEFAULT_TEMPLATE,
+ jndiName, expectedMessage, TOPIC_COMPONENT_TYPE);
+ }
+
+ /**
+ * Common code for the testCreateQueue() and testCreateTopic() tests.
+ */
+ private void createDestinationCommon(DestinationType destinationType,
+ String destinationTemplate,
+ String jndiName,
+ String expectedMessage,
+ ComponentType componentType) throws Exception {
+
+ // The properties we want to configure
+ Map<String, MetaValue> propertiesMap = new HashMap<String, MetaValue>();
+ propertiesMap.put("JNDIName", SimpleValueSupport.wrap(jndiName));
+ propertiesMap.put("clustered", SimpleValueSupport.wrap(Boolean.TRUE));
+ propertiesMap.put("downCacheSize", SimpleValueSupport.wrap(new Integer(2500)));
+ propertiesMap.put("fullSize", SimpleValueSupport.wrap(new Integer(80000)));
+ propertiesMap.put("maxDeliveryAttempts", SimpleValueSupport.wrap(new Integer(15)));
+ propertiesMap.put("maxSize", SimpleValueSupport.wrap(new Integer(80000)));
+ propertiesMap.put("messageCounterHistoryDayLimit", SimpleValueSupport.wrap(new Integer(0)));
+ propertiesMap.put("pageSize", SimpleValueSupport.wrap(new Integer(2500)));
+ propertiesMap.put("redeliveryDelay", SimpleValueSupport.wrap(new Long(50000)));
+
+ createDestination(destinationType, destinationTemplate, propertiesMap);
+ client.click("resourceConfigurationForm:saveButton");
+
+ // Check for the appropriate success messages
+ checkClientAndServerMessages(expectedMessage, expectedMessage, false);
+
+ // Make sure the ManagedComponent was created
+ assertNotNull("The returned component was null",
+ getManagedComponent(jndiName, componentType));
+ assertTrue("The destination is not deployed ",
+ isDeployed(jndiName + "-service.xml"));
+
+ // Verify that the properties were set correctly
+ checkComponentProperties(propertiesMap, jndiName, componentType);
+
+ // Clean up
+ deleteDestination(destinationType, jndiName);
+ }
+
+ /**
+ * Attempt to create a new queue but leave a required value unset.
+ * Make sure the appropriate error message occurs.
+ */
+ public void testCreateQueueMissingRequiredValue() throws IOException {
+ createDestinationMissingRequiredValue(DestinationType.QUEUE, QUEUE_DEFAULT_TEMPLATE);
+ }
+
+ /**
+ * Attempt to create a new topic but leave a required value unset.
+ * Make sure the appropriate error message occurs.
+ */
+ public void testCreateTopicMissingRequiredValue() throws IOException {
+ createDestinationMissingRequiredValue(DestinationType.TOPIC, TOPIC_DEFAULT_TEMPLATE);
+ }
+
+ /**
+ * Common code for the testCreate*MissingRequiredValue() tests.
+ */
+ private void createDestinationMissingRequiredValue(DestinationType destinationType,
+ String destinationTemplate) throws IOException {
+ // Leave the JNDI name unset
+ Map<String, MetaValue> propertiesMap = new HashMap<String, MetaValue>();
+ propertiesMap.put("clustered", SimpleValueSupport.wrap(Boolean.TRUE));
+ propertiesMap.put("fullSize", SimpleValueSupport.wrap(new Integer(80000)));
+
+ createDestination(destinationType, destinationTemplate, propertiesMap);
+ client.click("resourceConfigurationForm:saveButton");
+
+ // Check for the appropriate error messages
+ checkClientAndServerMessages(INVALID_VALUE_MESSAGE,
+ MISSING_VALUE_MESSAGE, true);
+ }
+
+ /**
+ * Attempt to create a new queue but set a property value beyond
+ * its expected range of values. Make sure the appropriate error message
+ * occurs.
+ */
+ public void testCreateQueuePropertyOutOfRange() throws IOException {
+ createDestinationPropertyOutOfRange(DestinationType.QUEUE,
+ QUEUE_DEFAULT_TEMPLATE,
+ "PropertyOutOfRangeQueue");
+ }
+
+ /**
+ * Attempt to create a new topic but set a property value beyond
+ * its expected range of values. Make sure the appropriate error message
+ * occurs.
+ */
+ public void testCreateTopicPropertyOutOfRange() throws IOException {
+ createDestinationPropertyOutOfRange(DestinationType.TOPIC,
+ TOPIC_DEFAULT_TEMPLATE,
+ "PropertyOutOfRangeTopic");
+ }
+
+
+ /**
+ * Common code for the testCreate*PropertyOutOfRange() tests.
+ */
+ private void createDestinationPropertyOutOfRange(DestinationType destinationType,
+ String destinationTemplate,
+ String jndiName) throws IOException {
+ // The properties we want to configure
+ Map<String, MetaValue> propertiesMap = new HashMap<String, MetaValue>();
+ propertiesMap.put("JNDIName", SimpleValueSupport.wrap(jndiName));
+ propertiesMap.put("clustered", SimpleValueSupport.wrap(Boolean.TRUE));
+ propertiesMap.put("downCacheSize", SimpleValueSupport.wrap(new Integer(2500)));
+ propertiesMap.put("fullSize", SimpleValueSupport.wrap(new Integer(80000)));
+
+ // This number is too large
+ propertiesMap.put("maxDeliveryAttempts", SimpleValueSupport.wrap(new Long(Long.MAX_VALUE)));
+
+ createDestination(destinationType, destinationTemplate, propertiesMap);
+ client.click("resourceConfigurationForm:saveButton");
+
+ // Check for the appropriate error messages
+ checkClientAndServerMessages(INVALID_VALUE_MESSAGE,
+ OUT_OF_RANGE_MESSAGE, true);
+ }
+
+ /**
+ * Attempt to create a new queue but set a property value to an invalid
+ * type. Make sure the appropriate error message occurs.
+ */
+ public void testCreateQueueInvalidPropertyType() throws IOException {
+ createDestinationInvalidPropertyType(DestinationType.QUEUE,
+ QUEUE_DEFAULT_TEMPLATE,
+ "InvalidPropertyTypeQueue");
+ }
+
+ /**
+ * Attempt to create a new topic but set a property value to an invalid
+ * type. Make sure the appropriate error message occurs.
+ */
+ public void testCreateTopicInvalidPropertyType() throws IOException {
+ createDestinationInvalidPropertyType(DestinationType.TOPIC,
+ TOPIC_DEFAULT_TEMPLATE,
+ "InvalidPropertyTypeTopic");
+ }
+
+ /**
+ * Common code for the testCreate*InvalidPropertyType() tests.
+ */
+ private void createDestinationInvalidPropertyType(DestinationType destinationType,
+ String destinationTemplate,
+ String jndiName) throws IOException {
+ // The properties we want to configure
+ Map<String, MetaValue> propertiesMap = new HashMap<String, MetaValue>();
+ propertiesMap.put("JNDIName", SimpleValueSupport.wrap(jndiName));
+ propertiesMap.put("clustered", SimpleValueSupport.wrap(Boolean.TRUE));
+ propertiesMap.put("messageCounterHistoryDayLimit", SimpleValueSupport.wrap(new Integer(0)));
+ propertiesMap.put("redeliveryDelay", SimpleValueSupport.wrap(new Long(50000)));
+
+ // This property value is supposed to be an integer
+ propertiesMap.put("maxDeliveryAttempts", SimpleValueSupport.wrap("fifteen"));
+
+ createDestination(destinationType, destinationTemplate, propertiesMap);
+ client.click("resourceConfigurationForm:saveButton");
+
+ // Check for the appropriate error messages
+ checkClientAndServerMessages(INVALID_VALUE_MESSAGE,
+ INVALID_INTEGER_MESSAGE, true);
+ }
+
+ /**
+ * Attempt to create a new queue using a JNDI name that
+ * already exists. Make sure the appropriate error message occurs.
+ */
+ public void testCreateQueueDuplicateJNDIName() throws IOException {
+ createDestinationDuplicateJNDIName(DestinationType.QUEUE, QUEUE_DEFAULT_TEMPLATE,
+ "TestQueue");
+ }
+
+ /**
+ * Attempt to create a new topic using a JNDI name that
+ * already exists. Make sure the appropriate error message occurs.
+ */
+ public void testCreateTopicDuplicateJNDIName() throws IOException {
+ createDestinationDuplicateJNDIName(DestinationType.TOPIC, TOPIC_DEFAULT_TEMPLATE,
+ "TestTopic");
+ }
+
+ /**
+ * Common code for the testCreate*DuplicateJNDIName() tests.
+ */
+ public void createDestinationDuplicateJNDIName(DestinationType destinationType,
+ String destinationTemplate,
+ String jndiName) throws IOException {
+ // The properties we want to configure
+ Map<String, MetaValue> propertiesMap = new HashMap<String, MetaValue>();
+ propertiesMap.put("JNDIName", SimpleValueSupport.wrap(jndiName));
+
+ createDestination(destinationType, destinationTemplate, propertiesMap);
+ client.click("resourceConfigurationForm:saveButton");
+
+ // Check for the appropriate error messages
+ String expectedMessage = "A " + destinationType.getName() + " named '" + jndiName + "' already exists";
+ checkClientAndServerMessages(expectedMessage, expectedMessage, true);
+ }
+}
Added: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/ResourceTestBase.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/ResourceTestBase.java (rev 0)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/ResourceTestBase.java 2009-02-23 16:08:15 UTC (rev 164)
@@ -0,0 +1,104 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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 com.gargoylesoftware.htmlunit.html.*;
+import java.io.IOException;
+import junit.framework.Test;
+import org.jboss.jopr.jsfunit.*;
+import java.util.Map;
+import org.jboss.metatype.api.values.MetaValue;
+
+/**
+ * This class contains basic methods for creating and deleting
+ * resources (eg. Topics, Queues, etc.).
+ *
+ * @author Farah Juma
+ *
+ */
+
+public abstract class ResourceTestBase extends EmbjoprTestCase {
+
+ private final String MAX_ITEMS_PER_PAGE="20";
+
+ // Error messages
+ public static final String INVALID_VALUE_MESSAGE="An invalid value was specified for one or more properties";
+ public static final String MISSING_VALUE_MESSAGE="Value is required";
+ public static final String OUT_OF_RANGE_MESSAGE="Specified attribute is not between the expected values";
+ public static final String INVALID_INTEGER_MESSAGE="Value is not a valid integer";
+
+ // Success message
+ public static final String SUCCESS_MESSAGE = "Successfully added new ";
+ public static final String DELETE_MESSAGE = "Successfully deleted ";
+
+ /**
+ * Create a new resource using the given type, template, and properties.
+ *
+ * @param propertiesMap is a map of property names to property meta values
+ * @param resourceType must be the type of datasource, connection factory,
+ * or JMS destination, as it appears in the left nav (eg. "Local TX Datasources",
+ * "Queues", "Topics", etc").
+ *
+ */
+ public void createResource(String resourceType,
+ String resourceTemplate,
+ Map<String, MetaValue> propertiesMap) throws IOException {
+ HtmlAnchor resourceLink = getNavTreeLink(resourceType);
+ resourceLink.click();
+
+ // Add a new resource
+ client.click("actionHeaderForm:addNewNotContent");
+ HtmlSelect menu = (HtmlSelect)client.getElement("selectedTemplate");
+ menu.setSelectedAttribute(resourceTemplate, Boolean.TRUE);
+ client.click("resourceCreateForm:addButton");
+
+ // Configure the properties associated with this resource
+ Map<String, String> formattedPropertiesMap = formatPropertiesMap(propertiesMap);
+ fillOutForm(formattedPropertiesMap);
+ }
+
+ /**
+ * Delete the given resource.
+ *
+ * @param resourceFormName The name of the form that contains the delete button.
+ */
+ public void deleteResource(String resourceFormName, String resourceName) throws IOException {
+
+ HtmlSelect menu = (HtmlSelect)client.getElement("currentPageSize");
+ if(menu != null) {
+ menu.setSelectedAttribute(MAX_ITEMS_PER_PAGE, Boolean.TRUE);
+ }
+
+ HtmlButtonInput deleteButton;
+ try {
+ deleteButton = getDeleteButton(resourceFormName, resourceName);
+ deleteButton.click();
+ } catch (IllegalStateException e) {
+
+ // The delete button was not found on this page
+ client.click("nextPage");
+ deleteButton = getDeleteButton(resourceFormName, resourceName);
+ deleteButton.click();
+ }
+ }
+}
Added: trunk/jsfunit/testdata/destinations/TestQueue-service.xml
===================================================================
--- trunk/jsfunit/testdata/destinations/TestQueue-service.xml (rev 0)
+++ trunk/jsfunit/testdata/destinations/TestQueue-service.xml 2009-02-23 16:08:15 UTC (rev 164)
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<server>
+ <mbean xmbean-dd="xmdesc/Queue-xmbean.xml" name="jboss.messaging.destination:service=Queue,name=TestQueue" code="org.jboss.jms.server.destination.QueueService">
+ <annotation>@org.jboss.system.deployers.managed.ManagementObjectClass(code=org.jboss.jms.server.destination.QueueServiceMO)</annotation>
+ <attribute name="JNDIName">TestQueue</attribute>
+ <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
+ <depends>jboss.messaging:service=PostOffice</depends>
+ </mbean>
+</server>
Added: trunk/jsfunit/testdata/destinations/TestTopic-service.xml
===================================================================
--- trunk/jsfunit/testdata/destinations/TestTopic-service.xml (rev 0)
+++ trunk/jsfunit/testdata/destinations/TestTopic-service.xml 2009-02-23 16:08:15 UTC (rev 164)
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<server>
+ <mbean xmbean-dd="xmdesc/Topic-xmbean.xml" name="jboss.messaging.destination:service=Topic,name=TestTopic" code="org.jboss.jms.server.destination.TopicService">
+ <annotation>@org.jboss.system.deployers.managed.ManagementObjectClass(code=org.jboss.jms.server.destination.TopicServiceMO)</annotation>
+ <attribute name="JNDIName">TestTopic</attribute>
+ <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
+ <depends>jboss.messaging:service=PostOffice</depends>
+ </mbean>
+</server>
15 years, 10 months
EMBJOPR SVN: r163 - trunk/jsfunit.
by embjopr-commits@lists.jboss.org
Author: ozizka(a)redhat.com
Date: 2009-02-23 11:00:38 -0500 (Mon, 23 Feb 2009)
New Revision: 163
Modified:
trunk/jsfunit/pom.xml
Log:
Setting log level to ALL to see what's happening on Hudson
Modified: trunk/jsfunit/pom.xml
===================================================================
--- trunk/jsfunit/pom.xml 2009-02-20 03:23:06 UTC (rev 162)
+++ trunk/jsfunit/pom.xml 2009-02-23 16:00:38 UTC (rev 163)
@@ -253,7 +253,7 @@
<timeout>300000</timeout> <!-- 5 minutes -->
<systemProperties>
<!-- Used in jboss-log4j.xml. See /testdata/... -->
- <jboss.server.log.threshold>INFO</jboss.server.log.threshold>
+ <jboss.server.log.threshold>ALL</jboss.server.log.threshold>
<!-- Snoops request and response from client side. Result is in server.log
<jsfunit.htmlunitsnooper>enabled</jsfunit.htmlunitsnooper> -->
<jsfunit.testdata>${basedir}/testdata</jsfunit.testdata>
@@ -327,12 +327,16 @@
<configuration>
<skip>false</skip>
<includes>
- <include>**/as5/*Test.java</include>
- <include>**/jsfunit/*Test.java</include>
+ <include>**/as5/*Test.java</include>
+ <include>**/jsfunit/*Test.java</include>
+ <!--
+ -->
</includes>
<excludes>
<exclude>**/as4/**</exclude>
- <!-- <exclude>**/as5/*Datasource*</exclude> -->
+ <!--
+ <exclude>**/as5/*Datasource*</exclude>
+ -->
<!-- Temporarily disable as it fails now -->
<exclude>**/*ServerNodeSummaryTest*</exclude>
</excludes>
15 years, 10 months
EMBJOPR SVN: r162 - in trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit: exceptions and 1 other directory.
by embjopr-commits@lists.jboss.org
Author: ozizka(a)redhat.com
Date: 2009-02-19 22:23:06 -0500 (Thu, 19 Feb 2009)
New Revision: 162
Added:
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/exceptions/PageHasChangedException.java
Modified:
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/ApplicationTestBaseAS5.java
Log:
* PageAware
Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/ApplicationTestBaseAS5.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/ApplicationTestBaseAS5.java 2009-02-20 03:08:01 UTC (rev 161)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/ApplicationTestBaseAS5.java 2009-02-20 03:23:06 UTC (rev 162)
@@ -22,6 +22,7 @@
package org.jboss.jopr.jsfunit;
import com.gargoylesoftware.htmlunit.ElementNotFoundException;
+import com.gargoylesoftware.htmlunit.Page;
import java.util.List;
import java.util.Set;
import javax.management.*;
@@ -393,6 +394,8 @@
* Base class for parts that will check their validity before performing actions.
* Not necessary if we pay attention to validity, but why not check it -
* performance is not a question for us.
+ *
+ * TODO: Instead, use the Page returned from click() etc.
*/
protected class PageContextAwareElement {
private URL validForURL;
@@ -419,14 +422,27 @@
!validForURL_.equals(this.validForURL) )
{
throw new ActionOutOfSyncException(
- "This tab content box was created from another page and is not valid now.");
+ "This element wrapper was created from another page and is not valid now.");
}
}
}
-
+ /** Better try... */
+ protected class PageAware {
+ private Page validForPage;
+ public PageAware(){
+ this.validForPage = client.getContentPage();
+ }
+ public void checkIfStillValid() throws PageHasChangedException {
+ if( !client.getContentPage().equals( this.validForPage ) )
+ throw new PageHasChangedException(
+ "This element wrapper was created from another page and is not valid now.",
+ client.getContentPage(), this.validForPage );
+ }
+ }
+
/**
* Inner class for manipulation with tab content box.
*/
Added: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/exceptions/PageHasChangedException.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/exceptions/PageHasChangedException.java (rev 0)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/exceptions/PageHasChangedException.java 2009-02-20 03:23:06 UTC (rev 162)
@@ -0,0 +1,42 @@
+package org.jboss.jopr.jsfunit.exceptions;
+
+import com.gargoylesoftware.htmlunit.Page;
+
+/**
+ * Signalizes that there was an action performed
+ * that was out of context - e.g. clicking on a button
+ * that was a part of a HTML page that's already gone.
+ *
+ *
+ * @author ondra
+ */
+public class PageHasChangedException extends ActionOutOfSyncException {
+
+ private Page validForPage;
+ private Page actualPage;
+
+ public PageHasChangedException() {
+ }
+
+ public PageHasChangedException(String message) {
+ super(message);
+ }
+
+ public PageHasChangedException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public PageHasChangedException(Throwable cause) {
+ super(cause);
+ }
+
+ public PageHasChangedException( String message, Page validForPage, Page actualPage) {
+ super(message);
+ this.validForPage = validForPage;
+ this.actualPage = actualPage;
+ }
+
+
+
+
+}
15 years, 10 months
EMBJOPR SVN: r161 - trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit.
by embjopr-commits@lists.jboss.org
Author: ozizka(a)redhat.com
Date: 2009-02-19 22:08:01 -0500 (Thu, 19 Feb 2009)
New Revision: 161
Modified:
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/ApplicationTestBaseAS5.java
Log:
* Pagination controls
Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/ApplicationTestBaseAS5.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/ApplicationTestBaseAS5.java 2009-02-20 02:07:08 UTC (rev 160)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/ApplicationTestBaseAS5.java 2009-02-20 03:08:01 UTC (rev 161)
@@ -21,6 +21,7 @@
*/
package org.jboss.jopr.jsfunit;
+import com.gargoylesoftware.htmlunit.ElementNotFoundException;
import java.util.List;
import java.util.Set;
import javax.management.*;
@@ -701,9 +702,100 @@
}
- }// inner class ContentTableRow
+ }// inner class ContentTableRow
+
+ /**
+ * Pagination control
+ */
+ protected class ContentBoxPagination {
+
+ //private HtmlElement element;
+ //public HtmlElement getElement() { return element; }
+
+ private static final String ID_PAGE_CONTROLS = "categorySummaryForm:dataTableScroller";
+ private static final String ID_PAGE_SIZE_SELECT = "categorySummaryForm:currentPageSize";
+
+ protected HtmlDivision getPageContols(){
+ return (HtmlDivision) client.getElement(ID_PAGE_CONTROLS);
+ }
+
+ protected HtmlSelect getPageSizeSelect(){
+ return (HtmlSelect) client.getElement(ID_PAGE_SIZE_SELECT);
+ }
+
+
+ protected HtmlSpan getGoSpan( String spanLabel ){
+ String xPath = ".//span[normalize-string() = '"+spanLabel+"']";
+ return (HtmlSpan) getPageContols().getFirstByXPath(xPath);
+ }
+
+ protected HtmlTableCell getGoPage( int pageNumber ) throws HtmlElementNotFoundException{
+ String xPath = ".//td[normalize-string() = '"+pageNumber+"']";
+ HtmlElement td = getPageContols().getFirstByXPath(xPath);
+ if( null == td )
+ throw new HtmlElementNotFoundException(
+ "Page number "+pageNumber+" not found. Try 1 - "+this.getPageCount());
+ return (HtmlTableCell) td;
+ }
+
+
+ public void goFirst() throws IOException{
+ getGoSpan("First").click();
+ }
+
+ public void goPrev() throws IOException{
+ getGoSpan("Prev").click();
+ }
+
+ public void goNext() throws IOException{
+ getGoSpan("Next").click();
+ }
+
+ public void goLast() throws IOException{
+ getGoSpan("Last").click();
+ }
+
+ public void goPage( int pageNumber ) throws IOException, HtmlElementNotFoundException{
+ getGoPage(pageNumber).click();
+ }
+
+
+ public boolean isPageActive( int pageNumber ) throws IOException, HtmlElementNotFoundException{
+ return !getGoPage(pageNumber).getStyleAttribute().contains("-inact");
+ }
+
+ public int getPageCount(){
+ String xPath = ".//td[ count(./*) = 0 and normalize-string() > 0 ]";
+ List<?> elements = getPageContols().getByXPath(xPath);
+ return elements.size();
+ }
+
+ public void setItemsPerPage( int num ) throws HtmlElementNotFoundException{
+ String optionValue = ""+num;
+ HtmlSelect pageSizeSelect = getPageSizeSelect();
+
+ try{
+ pageSizeSelect.getOptionByValue(optionValue);
+ }
+ catch( ElementNotFoundException ex ){
+ StringBuilder sb = new StringBuilder(pageSizeSelect.getOptionSize());
+ for( HtmlOption opt : pageSizeSelect.getOptions() ){
+ sb.append(" ").append(opt.getValueAttribute());
+ }
+ String possibleOptions = sb.toString().trim().replace(" ", ", ");
+
+ throw new HtmlElementNotFoundException("Specified option is invalid. Try one of: "+possibleOptions, ex);
+ }
+
+ pageSizeSelect.setSelectedAttribute(optionValue, true);
+ }
+
+ }
+
+
+
}// ApplicationTestBaseAS5
15 years, 10 months
EMBJOPR SVN: r160 - in trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit: as5 and 1 other directories.
by embjopr-commits@lists.jboss.org
Author: ozizka(a)redhat.com
Date: 2009-02-19 21:07:08 -0500 (Thu, 19 Feb 2009)
New Revision: 160
Added:
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/exceptions/ActionNotAvailableException.java
Modified:
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/ApplicationTestBaseAS5.java
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/EmbjoprTestCase.java
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/HelloJoprTest.java
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/EarTest.java
Log:
* "EmbJopr TestKit" tested, fixed, some javadoc added.
* EarTest.java fixed, also demonstrates how to use test kit.
Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/ApplicationTestBaseAS5.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/ApplicationTestBaseAS5.java 2009-02-19 23:40:21 UTC (rev 159)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/ApplicationTestBaseAS5.java 2009-02-20 02:07:08 UTC (rev 160)
@@ -153,16 +153,25 @@
}
+ public void announceCurrentTest(){
+ log.info( " -------- Test: "+DebugUtils.getCurrentMethodFullName()+" -------- ");
+ }
+
+
/* ---- Copied from ServerNodeSummaryTest.java, before moving to EmbjoprTestCase.java --- */
+
+
+
+
/**
* Single nav tree instance.
*
@@ -181,20 +190,22 @@
*/
protected class NavTree {
+ public static final String ID_NAV_TREE_FORM = "navTreeForm";
+
private void clickRootNode() throws IOException, EmbJoprTestException {
- DomElement element = (DomElement)client.getElement("navTreeForm");
+ DomElement element = (DomElement)client.getElement(ID_NAV_TREE_FORM);
if( null == element )
- throw new HtmlElementNotFoundException("Can't find #navTreeForm.");
+ throw new HtmlElementNotFoundException("Can't find #"+ID_NAV_TREE_FORM+".");
// ID changes upon core build?
- //HtmlAnchor rootNodeLink = element.getFirstByXPath("//a[@id='navTreeForm:navTree:2::homeLink']");
+ //HtmlAnchor rootNodeLink = element.getFirstByXPath(".//a[@id='navTreeForm:navTree:2::homeLink']");
+ // No XSLT 2.0 support :(
// javax.xml.transform.TransformerException: Can't find function: matches
//HtmlAnchor rootNodeLink = element.getFirstByXPath(
- // "//a[matches(@id,'^navTreeForm:navTree:.+::homeLink$')]");
+ // ".//a[matches(@id,'^navTreeForm:navTree:.+::homeLink$')]");
-
- String xPath = "//a[ starts-with( @id, 'navTreeForm:navTree:' ) " +
+ String xPath = ".//a[ starts-with( @id, '"+ID_NAV_TREE_FORM+":navTree:' ) " +
" and contains( @id, '::homeLink' ) ]"; // XPath 2.0: ends-with( @id, '::homeLink' )
HtmlAnchor rootNodeLink = element.getFirstByXPath(xPath);
@@ -205,13 +216,27 @@
}
- public NavTreeNode getNodeByLabel( String label ){
+ /**
+ * Finds the nav tree node by it's link label.
+ *
+ * @param label
+ * @return
+ * @throws org.jboss.jopr.jsfunit.exceptions.HtmlElementNotFoundException
+ * when there's no node with given label.
+ */
+ public NavTreeNode getNodeByLabel( String label ) throws HtmlElementNotFoundException{
- DomElement element = (DomElement)client.getElement("navTreeForm");
+ DomElement navTreeForm = (DomElement)client.getElement(ID_NAV_TREE_FORM);
// A table which has an anchor containing given text.
- String xPath = "//table[//a[contains(@id,'typeSummaryLink') and string() = '"+label+"']]";
- HtmlTable nodeTable = element.getFirstByXPath( xPath );
+ // Note: Different node types have different id endings - typeSummaryLink, categorySummaryLink, ...
+ String xPath = ".//table[.//td[contains(@id,':text')]//a[contains(@id,'SummaryLink') and normalize-space() = '"+label+"']]";
+
+ HtmlTable nodeTable = navTreeForm.getFirstByXPath( xPath );
+
+ if( null == nodeTable )
+ throw new HtmlElementNotFoundException("Node '"+label+"' not found using XPath: "+xPath);
+
return new NavTreeNode(nodeTable);
}
@@ -219,10 +244,11 @@
/**
* Need a standard JSFUnit API to replace this code.
+ * @see getNodeByLabel().getLabelLink()
*/
public HtmlAnchor getNodeLink(String linkLabel)
{
- return getLinkInsideForm("navTreeForm", linkLabel);
+ return getLinkInsideForm(ID_NAV_TREE_FORM, linkLabel);
}
@@ -231,6 +257,7 @@
* given by resourceName. This method is used to expand tree nodes
* (eg. "Web Applications (WAR)", "Datasources", etc.) in the
* navigation tree.
+ * @see getNodeByLabel().getArrowLink()
*/
public ClickableElement getNodeArrow(String resourceName)
{
@@ -244,26 +271,10 @@
return (ClickableElement)client.getElement(id);
}
+ }// class NavTree
- // TODO: DRY - see NavTreeNode::isExpanded()
- public boolean isNodeExpanded( String linkLabel ) throws EmbJoprTestException
- {
- ClickableElement nodeArrow = getNodeArrow(linkLabel);
- HtmlElement img = (HtmlElement)nodeArrow.getFirstByXPath("img[@style='display: none;']");
- if( img.getId().endsWith("expanded") )
- return false;
- else if( img.getId().endsWith("collapsed") )
- return true;
- else
- throw new EmbJoprTestException("Can't determine whether nav tree node is expanded.");
-
- }
-
- }// class NavTree
-
-
/**
* Represents nav tree node.
* Contains convenience methods to work with the node.
@@ -278,7 +289,7 @@
this.elem = nodeTable;
}
-
+ /** Returns true if this node is expanded. */
public boolean isExpanded() throws EmbJoprTestException
{
HtmlAnchor arrowLink = this.getArrowLink();
@@ -293,17 +304,20 @@
}
+ /** Returns the text link of this node. */
public HtmlAnchor getLabelLink(){
// Until I come up with something smarter, let it be so:
- String xPath = "//td[contains(@id,':text')]/a";
+ String xPath = ".//td[contains(@id,':text')]/a";
return (HtmlAnchor) this.elem.getFirstByXPath( xPath );
}
+ /** Returns the arrow's link. */
public HtmlAnchor getArrowLink(){
- String xPath = "//td[contains(@id,':handles')]//a[contains(@id,':handle')]";
+ String xPath = ".//td[contains(@id,':handles')]//a[contains(@id,':handle')]";
return (HtmlAnchor) this.elem.getFirstByXPath( xPath );
}
+ /** Clicks the link of the this node. */
public void click() throws IOException {
this.getLabelLink().click();
}
@@ -331,7 +345,7 @@
return new TabContentBox(tabContentBox);
}
- public ClickableElement getTab( String label ) throws EmbJoprTestException {
+ public ClickableElement getTab( String label ) throws HtmlElementNotFoundException {
DomElement element = (DomElement)client.getElement("tabmenu");
String xPath = "ul/li/span[normalize-space(string())='"+label+"'] | ul/li/a[normalize-space(string())='"+label+"']";
@@ -339,36 +353,33 @@
if( null == tabContent )
- throw new EmbJoprTestException("Tab '"+label+" not found using XPath '"+xPath+"'");
+ throw new HtmlElementNotFoundException("Tab '"+label+" not found using XPath '"+xPath+"'");
return tabContent;
}
- public boolean isTabActive( String label ) throws IOException, EmbJoprTestException {
+ /** Returns true if the tab with given label is active (it's content is shown). */
+ public boolean isTabActive( String label ) throws IOException, HtmlElementNotFoundException {
StyledElement tabContent = getTab(label);
return "span".equals( tabContent.getTagName() )
&& tabContent.getClassAttribute().contains("active");
}
-
- public boolean isTabDisabled( String label ) throws EmbJoprTestException {
+ /** Returns true if the tab with given label is disabled (grayed and can't be activated). */
+ public boolean isTabDisabled( String label ) throws HtmlElementNotFoundException {
StyledElement tabContent = getTab(label);
return "span".equals( tabContent.getTagName() )
&& tabContent.getClassAttribute().contains("disabled");
}
- public void clickTab( String label ) throws IOException, EmbJoprTestException {
+ /** Shotcut - getTab(label).click(); Not necesarilly clicks an anchor. */
+ public void clickTab( String label ) throws IOException, ActionNotAvailableException, HtmlElementNotFoundException {
StyledElement tabContent = getTab(label);
-
- //if( !"a".equals( tabContent.getTagName() ) )
- //if( !( tabContent instanceof HtmlAnchor ) )
- // throw new AssertException("Tab is not an anchor: "+label);
-
if( !( tabContent instanceof ClickableElement ) )
- throw new EmbJoprTestException("Tab element <"+tabContent.getTagName()+"> is not clickable: "+label);
+ throw new ActionNotAvailableException("Tab element <"+tabContent.getTagName()+"> is not clickable: "+label);
((ClickableElement)tabContent).click();
@@ -440,7 +451,7 @@
{
checkIfStillValid();
- String xPath = "*[contains(string(), '"+headerText+"']/following::table";
+ String xPath = "*[contains(normalize-space(), '"+headerText+"')]/following::table";
// [@id='resourceSummaryForm:dataTable'] - is this reliable?
HtmlTable tableElement = (HtmlTable) element.getFirstByXPath(xPath);
return new ContentTable(tableElement);
@@ -459,7 +470,7 @@
checkIfStillValid();
- HtmlButtonInput button = this.element.getFirstByXPath("//input[@value = '"+label+"']");
+ HtmlButtonInput button = this.element.getFirstByXPath(".//input[normalize-space(@value)='"+label+"']");
if( null == button )
throw new HtmlElementNotFoundException("Button labelled '"+label+"' not found.");
@@ -506,7 +517,7 @@
// TODO: Escape the single quotes. By doubling?
// http://books.google.com/books?id=jzqFMlM0gb0C&pg=PA308&lpg=PA308&dq=xquer...
- String xPath = "//tr[contains(string(), '"+text+"')]";
+ String xPath = ".//tr[contains(string(), '"+text+"')]";
HtmlTableRow elm = (HtmlTableRow) element.getFirstByXPath(xPath);
if( null == elm )
throw new HtmlElementNotFoundException(xPath);
@@ -519,7 +530,7 @@
if( 0 == element.getRowCount() )
throw new HtmlElementNotFoundException("Table has no rows.");
- String xPath = "//tr[//a[string() = '"+linkLabel+"']]";
+ String xPath = ".//tr[//a[normalize-space()='"+linkLabel+"']]";
HtmlTableRow elm = (HtmlTableRow) element.getFirstByXPath(xPath);
if( null == elm )
throw new HtmlElementNotFoundException(xPath);
@@ -538,7 +549,7 @@
/**/ // Give it another chance, JavaScript could change it.
// Get all TH from the first THEAD row that contains TH.
- String xPath = "/thead/tr[th and pos()=0]/th";
+ String xPath = "./thead/tr[th and position()=1]/th";
List<HtmlTableHeaderCell> colHeaders = (List<HtmlTableHeaderCell>) this.element.getByXPath(xPath);
if( 0 == colHeaders.size() ){
@@ -605,14 +616,14 @@
/**
* Finds a <button> or <input type="button"> with the given label.
- * @param label The label of the button. Compared to a [trimmed] label text of the button.
+ * @param label The label of the button. Compared to a trimmed label text of the button.
* @returns the button element - either HtmlButtonInput or HtmlButton.
* @throws org.jboss.jopr.jsfunit.exceptions.HtmlElementNotFoundException
*/
public ClickableElement getButtonByLabel( String label ) throws HtmlElementNotFoundException
{
- String xPath = "//input[@type='button' and @value = '"+label+"']" +
- " || //button[ string() = '"+label+"']";
+ String xPath = ".//input[@type='button' and normalize-space(@value) = '"+label+"']" +
+ " || .//button[normalize-space() = '"+label+"']";
HtmlElement elm = this.element.getFirstByXPath(xPath);
if( null == elm )
throw new HtmlElementNotFoundException("Can't find the button using xPath: "+xPath);
@@ -636,7 +647,7 @@
{
HtmlTableCell cell = this.getCellByColumnName(colName);
- String xPath = "//a";
+ String xPath = ".//a";
HtmlAnchor link = (HtmlAnchor) this.element.getFirstByXPath(xPath);
if( null == link )
@@ -651,7 +662,7 @@
* @param string
*/
public HtmlAnchor getLinkByLabel(String linkLabel) throws HtmlElementNotFoundException {
- String xPath = "//a[string()='"+linkLabel+"']";
+ String xPath = ".//a[normalize-space()='"+linkLabel+"']";
HtmlAnchor link = (HtmlAnchor) this.element.getFirstByXPath(xPath);
if( null == link )
throw new HtmlElementNotFoundException(xPath);
@@ -672,17 +683,19 @@
return cell;
}
+ /**
+ * Returns this row's cell element from the column with specified name.
+ * @param colName Name of the column.
+ * @throws org.jboss.jopr.jsfunit.exceptions.HtmlElementNotFoundException
+ * if no such column exists in the table.
+ */
public HtmlTableCell getCellByColumnName( String colName ) throws HtmlElementNotFoundException
{
- if( null == this.containingTable.colIndexes ){
- //throw new HtmlElementNotFoundException("Table does not have columns analyzed yet.");
- this.containingTable.analyzeColumns();
- }
-
- int index = this.containingTable.colIndexes.get(colName);
+ int index = this.containingTable.getColumnIndexByName(colName);
return getCell(index);
}
+ /** Shortcut - returns text content of this row's cell from given column. */
public String getCellTextByColumnName( String colName ) throws HtmlElementNotFoundException {
return this.getCellByColumnName(colName).getTextContent();
}
Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/EmbjoprTestCase.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/EmbjoprTestCase.java 2009-02-19 23:40:21 UTC (rev 159)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/EmbjoprTestCase.java 2009-02-20 02:07:08 UTC (rev 160)
@@ -72,9 +72,9 @@
{
// Announce this test in the JBoss log.
- log.info("================================================");
+ log.info("==================================================================");
log.info(" Setting up test "+this.getClass().getName());
- log.info("================================================");
+ log.info("==================================================================");
// JVM version
@@ -104,6 +104,14 @@
this.server = jsfSession.getJSFServerSession();
}
+
+ @Override
+ protected void tearDown() throws Exception {
+ // Denounce this test in the JBoss log.
+ log.info("------ END OF TEST "+this.getClass().getName()+" -------");
+ }
+
+
/**
* Need a standard JSFUnit API to replace this code
Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/HelloJoprTest.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/HelloJoprTest.java 2009-02-19 23:40:21 UTC (rev 159)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/HelloJoprTest.java 2009-02-20 02:07:08 UTC (rev 160)
@@ -111,6 +111,7 @@
client.click("createContentForm:addButton");
// assert that the success message appeared on the client side
+ DebugUtils.writeFile("hello.html", client.getPageAsText());
assertTrue(client.getPageAsText().contains("hellothere.war created successfully"));
// assert text and sevrity level for FacesMessage on server side
Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/EarTest.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/EarTest.java 2009-02-19 23:40:21 UTC (rev 159)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/EarTest.java 2009-02-20 02:07:08 UTC (rev 160)
@@ -27,6 +27,7 @@
import java.io.IOException;
import junit.framework.Test;
import junit.framework.TestSuite;
+import org.jboss.jopr.jsfunit.exceptions.ActionNotAvailableException;
import org.jboss.jopr.jsfunit.exceptions.ActionOutOfSyncException;
import org.jboss.jopr.jsfunit.exceptions.EmbJoprTestException;
import org.jboss.jopr.jsfunit.exceptions.HtmlElementNotFoundException;
@@ -114,6 +115,7 @@
}
+
/**
* assertion:
@@ -128,8 +130,9 @@
* @param earFilePath
* @throws java.io.IOException
*/
- public void testNavigationToEar() throws IOException, HtmlElementNotFoundException, ActionOutOfSyncException
+ public void testNavigationToEar() throws IOException, HtmlElementNotFoundException, ActionOutOfSyncException, ActionNotAvailableException
{
+ announceCurrentTest();
NavTreeNode nodeServers = navTree.getNodeByLabel("JBossAS Servers");
nodeServers.click();
@@ -180,6 +183,8 @@
{
// Whooo-hooo! So much to click through!
+ tabMenu.clickTab("Summary");
+
// TODO: Pagination options: EMBJOPR-78
// resourceDataScroller.xhtml, TableManager.java, "pageSizes".
@@ -197,6 +202,7 @@
{
+ // Go back to applications Sumary screen.
navTree.getNodeByLabel("Applications").click();
}
// --- click ---
@@ -214,7 +220,6 @@
}// testNavigationToEar()
-
private void deployEar( String earFilePath ) throws IOException
{
Added: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/exceptions/ActionNotAvailableException.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/exceptions/ActionNotAvailableException.java (rev 0)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/exceptions/ActionNotAvailableException.java 2009-02-20 02:07:08 UTC (rev 160)
@@ -0,0 +1,30 @@
+package org.jboss.jopr.jsfunit.exceptions;
+
+/**
+ * Signalizes that there was an action performed
+ * that was out of context - e.g. clicking on a button
+ * that was a part of a HTML page that's already gone.
+ *
+ *
+ * @author ondra
+ */
+public class ActionNotAvailableException extends EmbJoprTestException {
+
+ public ActionNotAvailableException() {
+ }
+
+ public ActionNotAvailableException(String message) {
+ super(message);
+ }
+
+ public ActionNotAvailableException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public ActionNotAvailableException(Throwable cause) {
+ super(cause);
+ }
+
+
+
+}
15 years, 10 months
EMBJOPR SVN: r159 - trunk/jsfunit/testdata/ear.
by embjopr-commits@lists.jboss.org
Author: ozizka(a)redhat.com
Date: 2009-02-19 18:40:21 -0500 (Thu, 19 Feb 2009)
New Revision: 159
Added:
trunk/jsfunit/testdata/ear/malformed-application-xml.ear
Log:
Adding testdata: .ear with malformed application.xml descriptor.
Added: trunk/jsfunit/testdata/ear/malformed-application-xml.ear
===================================================================
(Binary files differ)
Property changes on: trunk/jsfunit/testdata/ear/malformed-application-xml.ear
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
15 years, 10 months
EMBJOPR SVN: r158 - in trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit: as5 and 1 other directory.
by embjopr-commits@lists.jboss.org
Author: ozizka(a)redhat.com
Date: 2009-02-18 22:37:07 -0500 (Wed, 18 Feb 2009)
New Revision: 158
Modified:
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/AppConstants.java
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/ApplicationTestBaseAS5.java
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/EarTest.java
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/EjbTest.java
Log:
Application tests updated
Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/AppConstants.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/AppConstants.java 2009-02-19 02:57:30 UTC (rev 157)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/AppConstants.java 2009-02-19 03:37:07 UTC (rev 158)
@@ -33,6 +33,8 @@
public static final String NAV_RAR = "Resource Adaptor (RAR)s";
public static final String NAV_WAR = "Web Application (WAR)s";
+ public static final String EAR_MALFORMED_APP_FILENAME = "malformed-application-xml.ear";
+
// Test Archives
public static final String BASIC_JAR = "deployment-ejb.jar";
public static final String BASIC_EAR = "eardeployment.ear";
Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/ApplicationTestBaseAS5.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/ApplicationTestBaseAS5.java 2009-02-19 02:57:30 UTC (rev 157)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/ApplicationTestBaseAS5.java 2009-02-19 03:37:07 UTC (rev 158)
@@ -21,14 +21,21 @@
*/
package org.jboss.jopr.jsfunit;
-import com.gargoylesoftware.htmlunit.html.*;
-import java.io.IOException;
+import java.util.List;
import java.util.Set;
-import javax.management.JMException;
-import javax.management.MBeanServer;
-import javax.management.ObjectName;
+import javax.management.*;
import org.jboss.mx.util.MBeanServerLocator;
+import org.jboss.jopr.jsfunit.exceptions.*;
+import com.gargoylesoftware.htmlunit.html.*;
+import java.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+
+
+
/**
* This is the base test class for Embedded Jopr Application tests.
*
@@ -38,10 +45,10 @@
public abstract class ApplicationTestBaseAS5 extends EmbjoprTestCase
implements AppConstants {
- protected String label = null;
- protected final String serviceName = null;
- protected final String xmlElementName = null;
- protected final String templateHtmlSelectValue = null;
+ //protected String label = null;
+ //protected final String serviceName = null;
+ //protected final String xmlElementName = null;
+ //protected final String templateHtmlSelectValue = null;
@@ -55,8 +62,9 @@
* This method should query the JMX server and decide whether the given
* MBean displays deployed resource.
*
- *
* TODO: Move to EmbJoprTestCase?
+ * TODO: Consider using MBean jboss.management.local:j2eeType=J2EEServer,name=Local,
+ * which has attribute String[] deployedObjects
*
* @param deploymentMBean Name of the MBean to examine. Differs between AS4 and 5.
* @return true if the MBean indicates that the resource is deployed, false otherwise.
@@ -143,5 +151,548 @@
throw new RuntimeException(e);
}
}
+
+
+
+
+
+
-}
+
+
+ /* ---- Copied from ServerNodeSummaryTest.java, before moving to EmbjoprTestCase.java --- */
+
+
+ /**
+ * Single nav tree instance.
+ *
+ * Using instance instead of static methods is necessary
+ * if we want to subclass this tools for AS 4 tests in the future.
+ */
+ protected NavTree navTree = new NavTree();
+
+ /**
+ * Inner class to encapsulate navigation tree operations.
+ *
+ * Note that this class does not hold any element reference,
+ * because the reference becomes invalid with every navigation action.
+ *
+ * Instead, all these methods call client methods.
+ */
+ protected class NavTree {
+
+ private void clickRootNode() throws IOException, EmbJoprTestException {
+ DomElement element = (DomElement)client.getElement("navTreeForm");
+ if( null == element )
+ throw new HtmlElementNotFoundException("Can't find #navTreeForm.");
+
+ // ID changes upon core build?
+ //HtmlAnchor rootNodeLink = element.getFirstByXPath("//a[@id='navTreeForm:navTree:2::homeLink']");
+
+ // javax.xml.transform.TransformerException: Can't find function: matches
+ //HtmlAnchor rootNodeLink = element.getFirstByXPath(
+ // "//a[matches(@id,'^navTreeForm:navTree:.+::homeLink$')]");
+
+
+ String xPath = "//a[ starts-with( @id, 'navTreeForm:navTree:' ) " +
+ " and contains( @id, '::homeLink' ) ]"; // XPath 2.0: ends-with( @id, '::homeLink' )
+ HtmlAnchor rootNodeLink = element.getFirstByXPath(xPath);
+
+ if( null == rootNodeLink )
+ throw new HtmlElementNotFoundException("Root node not found using XPath: "+xPath);
+
+ rootNodeLink.click();
+ }
+
+
+ public NavTreeNode getNodeByLabel( String label ){
+
+ DomElement element = (DomElement)client.getElement("navTreeForm");
+
+ // A table which has an anchor containing given text.
+ String xPath = "//table[//a[contains(@id,'typeSummaryLink') and string() = '"+label+"']]";
+ HtmlTable nodeTable = element.getFirstByXPath( xPath );
+ return new NavTreeNode(nodeTable);
+
+ }
+
+
+ /**
+ * Need a standard JSFUnit API to replace this code.
+ */
+ public HtmlAnchor getNodeLink(String linkLabel)
+ {
+ return getLinkInsideForm("navTreeForm", linkLabel);
+ }
+
+
+ /**
+ * Finds the arrow icon in the nav tree that corresponds to the resource
+ * given by resourceName. This method is used to expand tree nodes
+ * (eg. "Web Applications (WAR)", "Datasources", etc.) in the
+ * navigation tree.
+ */
+ public ClickableElement getNodeArrow(String resourceName)
+ {
+ HtmlAnchor link = getNodeLink(resourceName);
+ String id = link.getIdAttribute();
+
+ // An example id is: "navTreeForm:navTree:81:82:83:84::typeSummaryLink"
+ // The icon's id would be: "81:82:83:84::typeSummary:handle:img:collapsed"
+ int index = id.lastIndexOf("Link");
+ id = id.substring(0, index) + ":handle";
+ return (ClickableElement)client.getElement(id);
+ }
+
+
+ // TODO: DRY - see NavTreeNode::isExpanded()
+ public boolean isNodeExpanded( String linkLabel ) throws EmbJoprTestException
+ {
+ ClickableElement nodeArrow = getNodeArrow(linkLabel);
+
+ HtmlElement img = (HtmlElement)nodeArrow.getFirstByXPath("img[@style='display: none;']");
+
+ if( img.getId().endsWith("expanded") )
+ return false;
+ else if( img.getId().endsWith("collapsed") )
+ return true;
+ else
+ throw new EmbJoprTestException("Can't determine whether nav tree node is expanded.");
+
+ }
+
+ }// class NavTree
+
+
+ /**
+ * Represents nav tree node.
+ * Contains convenience methods to work with the node.
+ */
+ protected class NavTreeNode {
+
+ /** Keeps the table element of this node. */
+ private HtmlElement elem;
+ public HtmlElement getElement() { return this.elem; }
+
+ private NavTreeNode( HtmlTable nodeTable ){
+ this.elem = nodeTable;
+ }
+
+
+ public boolean isExpanded() throws EmbJoprTestException
+ {
+ HtmlAnchor arrowLink = this.getArrowLink();
+ HtmlElement img = (HtmlElement)arrowLink.getFirstByXPath("img[@style='display: none;']");
+
+ if( img.getId().endsWith("expanded") )
+ return false;
+ else if( img.getId().endsWith("collapsed") )
+ return true;
+ else
+ throw new EmbJoprTestException("Can't determine whether nav tree node is expanded.");
+
+ }
+
+ public HtmlAnchor getLabelLink(){
+ // Until I come up with something smarter, let it be so:
+ String xPath = "//td[contains(@id,':text')]/a";
+ return (HtmlAnchor) this.elem.getFirstByXPath( xPath );
+ }
+
+ public HtmlAnchor getArrowLink(){
+ String xPath = "//td[contains(@id,':handles')]//a[contains(@id,':handle')]";
+ return (HtmlAnchor) this.elem.getFirstByXPath( xPath );
+ }
+
+ public void click() throws IOException {
+ this.getLabelLink().click();
+ }
+
+
+ }// class NavTreeNode()
+
+
+
+
+ protected final TabMenu tabMenu = new TabMenu();
+
+ /**
+ * Inner class to encapsulate tab menu operations.
+ */
+ protected class TabMenu {
+
+ public TabContentBox getTabContentBox() throws HtmlElementNotFoundException {
+
+ HtmlElement contentElement = (HtmlElement) client.getElement("content");
+ HtmlElement tabContentBox = (HtmlElement) contentElement.getFirstByXPath("div[@class='tabmenubox']");
+ if( null == tabContentBox )
+ throw new HtmlElementNotFoundException("Tab content box not found using div[@class='tabmenubox'] XPath");
+
+ return new TabContentBox(tabContentBox);
+ }
+
+ public ClickableElement getTab( String label ) throws EmbJoprTestException {
+
+ DomElement element = (DomElement)client.getElement("tabmenu");
+ String xPath = "ul/li/span[normalize-space(string())='"+label+"'] | ul/li/a[normalize-space(string())='"+label+"']";
+ ClickableElement tabContent = element.getFirstByXPath(xPath);
+
+
+ if( null == tabContent )
+ throw new EmbJoprTestException("Tab '"+label+" not found using XPath '"+xPath+"'");
+
+ return tabContent;
+
+ }
+
+ public boolean isTabActive( String label ) throws IOException, EmbJoprTestException {
+
+ StyledElement tabContent = getTab(label);
+ return "span".equals( tabContent.getTagName() )
+ && tabContent.getClassAttribute().contains("active");
+ }
+
+
+ public boolean isTabDisabled( String label ) throws EmbJoprTestException {
+ StyledElement tabContent = getTab(label);
+ return "span".equals( tabContent.getTagName() )
+ && tabContent.getClassAttribute().contains("disabled");
+ }
+
+ public void clickTab( String label ) throws IOException, EmbJoprTestException {
+
+ StyledElement tabContent = getTab(label);
+
+ //if( !"a".equals( tabContent.getTagName() ) )
+ //if( !( tabContent instanceof HtmlAnchor ) )
+ // throw new AssertException("Tab is not an anchor: "+label);
+
+ if( !( tabContent instanceof ClickableElement ) )
+ throw new EmbJoprTestException("Tab element <"+tabContent.getTagName()+"> is not clickable: "+label);
+
+ ((ClickableElement)tabContent).click();
+
+ }
+
+ }
+
+
+ /**
+ * Base class for parts that will check their validity before performing actions.
+ * Not necessary if we pay attention to validity, but why not check it -
+ * performance is not a question for us.
+ */
+ protected class PageContextAwareElement {
+ private URL validForURL;
+ private String validForDate;
+
+ /** Store the context identifiing attributes upon creation. */
+ public PageContextAwareElement() {
+ // TODO: Shouldn't we store the elements's page instead of current?
+ this.validForDate = client.getContentPage().getWebResponse().getResponseHeaderValue("Date");
+ this.validForURL = client.getContentPage().getWebResponse().getUrl();
+ }
+
+ /**
+ * Checks whether this element is still valid in the current web page context,
+ * i.e. whether we are still on the page in which this element existed.
+ * @throws org.jboss.jopr.jsfunit.exceptions.ActionOutOfSyncException
+ */
+ public void checkIfStillValid() throws ActionOutOfSyncException {
+
+ String validForDate_ = client.getContentPage().getWebResponse().getResponseHeaderValue("Date");
+ URL validForURL_ = client.getContentPage().getWebResponse().getUrl();
+
+ if( !validForDate_.equals(this.validForDate) ||
+ !validForURL_.equals(this.validForURL) )
+ {
+ throw new ActionOutOfSyncException(
+ "This tab content box was created from another page and is not valid now.");
+ }
+ }
+
+ }
+
+
+
+ /**
+ * Inner class for manipulation with tab content box.
+ */
+ protected class TabContentBox extends PageContextAwareElement {
+
+ private HtmlElement element;
+ public HtmlElement getElement() { return element; }
+
+ public TabContentBox(HtmlElement element) {
+ super();
+ this.element = element;
+ }
+
+ /**
+ * Returns first table under given header.
+ *
+ * Unfortunately, headers are not H2 or similar, but DIV class="instructionalText".
+ * To be revised later.
+ *
+ * @return
+ */
+ public ContentTable getTableUnderHeader( String headerText ) throws ActionOutOfSyncException
+ {
+ checkIfStillValid();
+
+ String xPath = "*[contains(string(), '"+headerText+"']/following::table";
+ // [@id='resourceSummaryForm:dataTable'] - is this reliable?
+ HtmlTable tableElement = (HtmlTable) element.getFirstByXPath(xPath);
+ return new ContentTable(tableElement);
+ }
+
+
+ /**
+ * Finds first button with given label inside this box.
+ * @param label
+ * @return
+ * @throws org.jboss.jopr.jsfunit.exceptions.HtmlElementNotFoundException
+ * @throws org.jboss.jopr.jsfunit.exceptions.ActionOutOfSyncException
+ */
+ public HtmlButtonInput getButtonByLabel( String label )
+ throws HtmlElementNotFoundException, ActionOutOfSyncException {
+
+ checkIfStillValid();
+
+ HtmlButtonInput button = this.element.getFirstByXPath("//input[@value = '"+label+"']");
+ if( null == button )
+ throw new HtmlElementNotFoundException("Button labelled '"+label+"' not found.");
+
+ return button;
+
+ }
+
+ }// inner class TabContentBox
+
+
+
+ /**
+ * Row of a content table.
+ * Contains convenience methods for accessing content tables in EmbJopr.
+ */
+ protected class ContentTable {
+
+ private HtmlTable element;
+ public HtmlTable getElement() { return element; }
+
+ public ContentTable( HtmlTable element) {
+ this.element = element;
+ }
+
+ // Columns maps
+ private List<String> colLabels = null;
+ private Map<String, Integer> colIndexes = null;
+ //private boolean analyzedButNotFound = false;
+
+
+
+ /**
+ * Returns the first row that contains given text, or throws HtmlElementNotFoundException.
+ * @param text
+ * @return
+ * @throws org.jboss.jopr.jsfunit.exceptions.HtmlElementNotFoundException
+ * when no row contains specified text.
+ */
+ public ContentTableRow getFirstRowContainingText( String text )
+ throws HtmlElementNotFoundException
+ {
+ if( 0 == element.getRowCount() )
+ throw new HtmlElementNotFoundException("Table has no rows.");
+
+ // TODO: Escape the single quotes. By doubling?
+ // http://books.google.com/books?id=jzqFMlM0gb0C&pg=PA308&lpg=PA308&dq=xquer...
+ String xPath = "//tr[contains(string(), '"+text+"')]";
+ HtmlTableRow elm = (HtmlTableRow) element.getFirstByXPath(xPath);
+ if( null == elm )
+ throw new HtmlElementNotFoundException(xPath);
+ return new ContentTableRow(elm, this);
+ }
+
+ public ContentTableRow getFirstRowContainingLink( String linkLabel )
+ throws HtmlElementNotFoundException
+ {
+ if( 0 == element.getRowCount() )
+ throw new HtmlElementNotFoundException("Table has no rows.");
+
+ String xPath = "//tr[//a[string() = '"+linkLabel+"']]";
+ HtmlTableRow elm = (HtmlTableRow) element.getFirstByXPath(xPath);
+ if( null == elm )
+ throw new HtmlElementNotFoundException(xPath);
+ return new ContentTableRow(elm, this);
+ }
+
+ /**
+ * Creates a list of columns headers
+ * and a label => col index map.
+ */
+ public void analyzeColumns() throws HtmlElementNotFoundException
+ {
+
+ /*if( this.analyzedButNotFound )
+ throw new HtmlElementNotFoundException("Table has no column headers.");
+ /**/ // Give it another chance, JavaScript could change it.
+
+ // Get all TH from the first THEAD row that contains TH.
+ String xPath = "/thead/tr[th and pos()=0]/th";
+ List<HtmlTableHeaderCell> colHeaders = (List<HtmlTableHeaderCell>) this.element.getByXPath(xPath);
+
+ if( 0 == colHeaders.size() ){
+ //this.analyzedButNotFound = true;
+ throw new HtmlElementNotFoundException("Table has no column headers.");
+ }
+
+ List<String> colLabels_ = new ArrayList(colHeaders.size());
+ Map<String, Integer> colIndexes_ = new HashMap(colHeaders.size());
+
+ //for( HtmlTableHeaderCell th : colHeaders ){
+ for( int i = 0; i < colHeaders.size(); i++ ) {
+ HtmlTableHeaderCell th = colHeaders.get(i);
+ String sHeader = th.getTextContent();
+ colLabels_.add( sHeader );
+ colIndexes_.put( sHeader, i );
+ }
+
+ this.colLabels = colLabels_;
+ this.colIndexes = colIndexes_;
+
+ }
+
+ /**
+ * Returns an index of the column with given name in the TH header,
+ * or throws HtmlElementNotFound in two cases:
+ * 1) Table does not have column headers
+ * 2) No header with such name was found.
+ *
+ * @param colName
+ * @return
+ * @throws org.jboss.jopr.jsfunit.exceptions.HtmlElementNotFoundException
+ */
+ public int getColumnIndexByName( String colName ) throws HtmlElementNotFoundException {
+ if( null == this.colIndexes )
+ this.analyzeColumns();
+
+ Integer index = this.colIndexes.get(colName);
+ if( null == index )
+ throw new HtmlElementNotFoundException("No column named '"+colName+"'.");
+
+ return index;
+ }
+
+ }// inner class ContentTable
+
+
+
+ /**
+ * Row of a content table.
+ * Contains convenience methods for accessing content table rows in EmbJopr.
+ */
+ protected class ContentTableRow {
+
+ private HtmlTableRow element;
+ public HtmlTableRow getElement() { return element; }
+
+ private ContentTable containingTable;
+
+ private ContentTableRow(HtmlTableRow elm, ContentTable containingTable) {
+ this.element = elm;
+ this.containingTable = containingTable;
+ }
+
+ /**
+ * Finds a <button> or <input type="button"> with the given label.
+ * @param label The label of the button. Compared to a [trimmed] label text of the button.
+ * @returns the button element - either HtmlButtonInput or HtmlButton.
+ * @throws org.jboss.jopr.jsfunit.exceptions.HtmlElementNotFoundException
+ */
+ public ClickableElement getButtonByLabel( String label ) throws HtmlElementNotFoundException
+ {
+ String xPath = "//input[@type='button' and @value = '"+label+"']" +
+ " || //button[ string() = '"+label+"']";
+ HtmlElement elm = this.element.getFirstByXPath(xPath);
+ if( null == elm )
+ throw new HtmlElementNotFoundException("Can't find the button using xPath: "+xPath);
+ if( !(elm instanceof HtmlButton ) && !(elm instanceof HtmlButtonInput) )
+ throw new HtmlElementNotFoundException("Element is not a button, but: "+elm.getClass().getName());
+
+ return (ClickableElement)elm;
+ }
+
+
+ /**
+ * Gives the (first) link from the cell of this row, from the column with given header.
+ * @param colName
+ * @return
+ * @throws org.jboss.jopr.jsfunit.exceptions.HtmlElementNotFoundException
+ * in two cases:
+ * 1) Table has no column of given name
+ * 2) There's no link in that cell.
+ */
+ public HtmlAnchor getFirstLinkFromColumn(String colName) throws HtmlElementNotFoundException
+ {
+ HtmlTableCell cell = this.getCellByColumnName(colName);
+
+ String xPath = "//a";
+ HtmlAnchor link = (HtmlAnchor) this.element.getFirstByXPath(xPath);
+
+ if( null == link )
+ throw new HtmlElementNotFoundException("No link found in column '"+colName+"'");
+
+ return link;
+ }
+
+
+ /**
+ * Returns the link with given label.
+ * @param string
+ */
+ public HtmlAnchor getLinkByLabel(String linkLabel) throws HtmlElementNotFoundException {
+ String xPath = "//a[string()='"+linkLabel+"']";
+ HtmlAnchor link = (HtmlAnchor) this.element.getFirstByXPath(xPath);
+ if( null == link )
+ throw new HtmlElementNotFoundException(xPath);
+ return link;
+ }
+
+ /**
+ * Returns the cell of this table from given index,
+ * or throws IndexOutOfBoundsException.
+ *
+ * TODO: May throw IndexOutOfBoundsException - leave unchecked?
+ *
+ * @param index
+ * @return
+ */
+ public HtmlTableCell getCell( int index ){
+ HtmlTableCell cell = this.element.getCell(index);
+ return cell;
+ }
+
+ public HtmlTableCell getCellByColumnName( String colName ) throws HtmlElementNotFoundException
+ {
+ if( null == this.containingTable.colIndexes ){
+ //throw new HtmlElementNotFoundException("Table does not have columns analyzed yet.");
+ this.containingTable.analyzeColumns();
+ }
+
+ int index = this.containingTable.colIndexes.get(colName);
+ return getCell(index);
+ }
+
+ public String getCellTextByColumnName( String colName ) throws HtmlElementNotFoundException {
+ return this.getCellByColumnName(colName).getTextContent();
+ }
+
+
+ }// inner class ContentTableRow
+
+
+}// ApplicationTestBaseAS5
+
+
+
+
Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/EarTest.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/EarTest.java 2009-02-19 02:57:30 UTC (rev 157)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/EarTest.java 2009-02-19 03:37:07 UTC (rev 158)
@@ -27,7 +27,10 @@
import java.io.IOException;
import junit.framework.Test;
import junit.framework.TestSuite;
-import javax.faces.application.FacesMessage;
+import org.jboss.jopr.jsfunit.exceptions.ActionOutOfSyncException;
+import org.jboss.jopr.jsfunit.exceptions.EmbJoprTestException;
+import org.jboss.jopr.jsfunit.exceptions.HtmlElementNotFoundException;
+import org.w3c.dom.Node;
@@ -52,53 +55,196 @@
/*
* testName: testBasicEarDeployment
- * assertion: verify basic deployment of Enterprise Archive
+ * assertion: verify basic deployment of Enterprise Archive
* test Strategy: Navigate to Enterprise Applications.
* Add a new resource. Verify the resource was successfully
* deployed. Undeploy the archive for test clean up purposes.
*
*/
- public void testBasicEarDeployment() throws IOException
+ public void testBasicEarDeployment() throws IOException, EmbJoprTestException
{
- // Navigate to Enterprise Archives
- HtmlAnchor earLink = getNavTreeLink(NAV_EAR);
- earLink.click();
- // click on the "Add new resource" button
- client.click("actionHeaderForm:addNewContent"); // 404 if setThrowExceptionOnFailingStatusCode(true) above
+ String earFilePath = System.getProperty("jsfunit.testdata") + "/ear/"+BASIC_EAR;
+ deployEar( earFilePath );
- // upload hellothere.war
- HtmlFileInput fileInput = (HtmlFileInput)client.getElement("createContentForm:file");
- fileInput.setContentType("application/ear");
- fileInput.setValueAttribute(System.getProperty("jsfunit.testdata") + "/ear/eardeployment.ear");
- client.click("createContentForm:addButton");
+ String expectedMessage = BASIC_EAR + " created successfully";
- // assert that the success message appeared on the client side
- assertTrue(client.getPageAsText().contains("eardeployment.ear created successfully"));
+ checkClientAndServerMessages(expectedMessage, expectedMessage, false);
- // assert text and sevrity level for FacesMessage on server side
- assertTrue(server.getFacesMessages().hasNext());
- FacesMessage successMessage = server.getFacesMessages().next();
- assertTrue(FacesMessage.SEVERITY_INFO.equals(successMessage.getSeverity()));
- assertTrue(successMessage.getDetail().contains("eardeployment.ear created successfully"));
-
// Use JMX to assert that the EAR components really did deploy successfully
- assertTrue("JMX doesn't report EAR as exposed: eardeployment.ear", isEarDeployed("eardeployment.ear"));
+ assertTrue("JMX doesn't report EAR as exposed: eardeployment.ear", isEarDeployed(BASIC_EAR));
assertTrue("JMX doesn't report EJB sessiona.jar as exposed.", isEJBDeployed("sessiona.jar"));
assertTrue("JMX doesn't report EJB sessionb.jar as exposed.", isEJBDeployed("sessionb.jar"));
// Undeploy the EAR
- HtmlButtonInput deleteButton = getAppDeleteButton("eardeployment.ear");
- deleteButton.click();
+ undeployEar( BASIC_EAR );
- assertTrue(client.getPageAsText().contains("Successfully deleted Enterprise Application (EAR) 'eardeployment.ear'."));
+ expectedMessage = "Successfully deleted Enterprise Application (EAR) '"+BASIC_EAR+"'.";
+ assertTrue(client.getPageAsText().contains( expectedMessage ));
// This assert doesn't work. The JXM view is not consistent with the mananaged view.
// JBAS-XXXX
//assertFalse(isEarDeployed("eardeployment.ear"));
//assertFalse(isEJBDeployed("sessiona.jar"));
//assertFalse(isEJBDeployed("sessionb.jar"));
+
}
+ /**
+ * assertion:
+
+ Verify an .ear that contained a bad deployment descriptor
+ fails deployment, fixed using console, and can then be
+ successfully deployed.
+ test Strategy:
+
+ Deploy an .ear that is known to have a bad deployment
+ descriptor. Verify the console shows deployment failed.
+ Edit the .ear resource to fix the achive. Redeploy and
+ verify the archive has been deployed successfully.
+
+ */
+ public void testBadEarRedeploy() throws IOException {
+
+ String earFilePath = System.getProperty("jsfunit.testdata") + "/ear/"+EAR_MALFORMED_APP_FILENAME;
+ deployEar(earFilePath);
+
+ checkClientAndServerMessages("Failed to create Resource", "Failed to create Resource", true);
+
+ }
+
+ /**
+ * assertion:
+
+ Verify the navigation sequence to Enterprise Applications.
+
+ test Strategy:
+
+ From the root of the navigation tree:
+ Click JBossAS Servers ==> JBoss App Server:${config}
+ ==> Applications ==> Enterprise Application
+
+ * @param earFilePath
+ * @throws java.io.IOException
+ */
+ public void testNavigationToEar() throws IOException, HtmlElementNotFoundException, ActionOutOfSyncException
+ {
+
+ NavTreeNode nodeServers = navTree.getNodeByLabel("JBossAS Servers");
+ nodeServers.click();
+ // --- click ---
+
+ {
+ String headerText = "JBossAS Server";
+
+ 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 =
+ tabMenu.getTabContentBox().getTableUnderHeader("JBoss Application Server")
+ .getFirstRowContainingLink("JBoss App Server:default");
+ // Click the server link
+ //HtmlAnchor link row.getLinkByLabel("JBoss App Server: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();
+ }
+ // --- click ---
+
+ {
+ String pageText = client.getPageAsText();
+
+ String headerText = "JBoss App Server:default";
+ 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));
+
+ // TODO: This page reports "Version:5.0 CR1" - EMBJOPR-77
+
+ navTree.getNodeByLabel("Applications").click();
+
+ }
+ // --- click ---
+
+
+ {
+ // Whooo-hooo! So much to click through!
+
+ // TODO: Pagination options: EMBJOPR-78
+ // resourceDataScroller.xhtml, TableManager.java, "pageSizes".
+
+
+ // There's at least one Application with State == UP.
+ //ContentTable table = tabMenu.getTabContentBox().getTableUnderHeader("Different types of Applications");
+ ContentTable table = new ContentTable((HtmlTable)client.getElement("categorySummaryForm:dataTable"));
+ ContentTableRow row = table.getFirstRowContainingText("UP");
+
+ // Go further - try to click on any Application that is up.
+ HtmlAnchor link = row.getFirstLinkFromColumn("Name");
+ link.click();
+ }
+ // --- click ---
+
+
+ {
+ navTree.getNodeByLabel("Applications").click();
+ }
+ // --- click ---
+
+
+ {
+ navTree.getNodeByLabel(NAV_EAR).click();
+ }
+ // --- click ---
+
+
+
+
+
+ }// testNavigationToEar()
+
+
+
+ private void deployEar( String earFilePath ) throws IOException
+ {
+
+ // Navigate to Enterprise Archives
+ navTree.getNodeLink(NAV_EAR).click();
+
+ // click on the "Add new resource" button
+ client.click("actionHeaderForm:addNewContent"); // 404 if setThrowExceptionOnFailingStatusCode(true) above
+
+ // upload hellothere.war
+ HtmlFileInput fileInput = (HtmlFileInput)client.getElement("createContentForm:file");
+ fileInput.setContentType("application/ear");
+ fileInput.setValueAttribute(earFilePath);
+ client.click("createContentForm:addButton");
+ }
+
+ private void undeployEar( String earFileName ) throws IOException, EmbJoprTestException
+ {
+
+ // Navigate to Enterprise Archives
+ navTree.getNodeLink(NAV_EAR).click();
+
+ tabMenu.clickTab("Summary");
+
+ HtmlButtonInput deleteButton = getAppDeleteButton( earFileName );
+ deleteButton.click();
+
+
+ }
+
+
+
}
Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/EjbTest.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/EjbTest.java 2009-02-19 02:57:30 UTC (rev 157)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/EjbTest.java 2009-02-19 03:37:07 UTC (rev 158)
@@ -73,6 +73,9 @@
// click on the "Add new resource" button
client.click("actionHeaderForm:addNewContent"); // 404 if setThrowExceptionOnFailingStatusCode(true) above
+ // TODO: "/ejb/BASIC_JAR" causes exceptions in seam:
+ // http://wwwapps.rdu.redhat.com/w3xpastebin/pastebin.php?show=9842
+
String filePath = System.getProperty("jsfunit.testdata") + "/ejb/"+BASIC_JAR;
log.info("Uploading EJB archive: "+filePath);
File uploadFile = new File(filePath);
15 years, 10 months
EMBJOPR SVN: r157 - trunk/jsfunit.
by embjopr-commits@lists.jboss.org
Author: ozizka(a)redhat.com
Date: 2009-02-18 21:57:30 -0500 (Wed, 18 Feb 2009)
New Revision: 157
Modified:
trunk/jsfunit/pom.xml
Log:
Added commons-lang dependency (string utils library)
Modified: trunk/jsfunit/pom.xml
===================================================================
--- trunk/jsfunit/pom.xml 2009-02-17 21:32:24 UTC (rev 156)
+++ trunk/jsfunit/pom.xml 2009-02-19 02:57:30 UTC (rev 157)
@@ -95,11 +95,19 @@
<scope>provided</scope>
<version>2.8.1</version>
</dependency>
+
<dependency>
<groupId>jdom</groupId>
<artifactId>jdom</artifactId>
<version>1.0</version>
</dependency>
+
+ <dependency>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ <version>2.4</version>
+ </dependency>
+
</dependencies>
@@ -244,6 +252,7 @@
<log>${basedir}/target/jboss5.x.logs/cargo.log</log>
<timeout>300000</timeout> <!-- 5 minutes -->
<systemProperties>
+ <!-- Used in jboss-log4j.xml. See /testdata/... -->
<jboss.server.log.threshold>INFO</jboss.server.log.threshold>
<!-- Snoops request and response from client side. Result is in server.log
<jsfunit.htmlunitsnooper>enabled</jsfunit.htmlunitsnooper> -->
@@ -323,6 +332,7 @@
</includes>
<excludes>
<exclude>**/as4/**</exclude>
+ <!-- <exclude>**/as5/*Datasource*</exclude> -->
<!-- Temporarily disable as it fails now -->
<exclude>**/*ServerNodeSummaryTest*</exclude>
</excludes>
15 years, 10 months
EMBJOPR SVN: r156 - in trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit: as5 and 1 other directories.
by embjopr-commits@lists.jboss.org
Author: ozizka(a)redhat.com
Date: 2009-02-17 16:32:24 -0500 (Tue, 17 Feb 2009)
New Revision: 156
Added:
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/exceptions/DeploymentException.java
Modified:
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/ApplicationTestBaseAS5.java
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/DebugUtils.java
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/EmbjoprTestCase.java
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/JMXUtils.java
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/EarTest.java
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/EjbTest.java
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/WarTest.java
Log:
Added logging to setUp() to let us find start of the test more easily
Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/ApplicationTestBaseAS5.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/ApplicationTestBaseAS5.java 2009-02-17 17:14:00 UTC (rev 155)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/ApplicationTestBaseAS5.java 2009-02-17 21:32:24 UTC (rev 156)
@@ -22,7 +22,9 @@
package org.jboss.jopr.jsfunit;
import com.gargoylesoftware.htmlunit.html.*;
+import java.io.IOException;
import java.util.Set;
+import javax.management.JMException;
import javax.management.MBeanServer;
import javax.management.ObjectName;
import org.jboss.mx.util.MBeanServerLocator;
@@ -49,36 +51,72 @@
}
+ /**
+ * This method should query the JMX server and decide whether the given
+ * MBean displays deployed resource.
+ *
+ *
+ * TODO: Move to EmbJoprTestCase?
+ *
+ * @param deploymentMBean Name of the MBean to examine. Differs between AS4 and 5.
+ * @return true if the MBean indicates that the resource is deployed, false otherwise.
+ * @throws javax.management.JMException upon JMX related error, including invalid
+ * or non-existent MBean / attribute name.
+ * @throws java.io.IOException upon I/O error.
+ */
+ protected boolean isMBeanStateDeployedImpl(ObjectName mBeanName) throws JMException, IOException
+ {
+ JMXUtils jmxUtils = JMXUtils.getInstanceForLocalJBoss();
+ Object state = jmxUtils.getMBeanAttribute(mBeanName, "State");
+ return ("DEPLOYED".equals( state.toString() ));
+ }
- public boolean isEJBDeployed(String ejbJarName) throws RuntimeException
+ protected boolean isMBeanStateDeployedImpl(String mBeanName) throws JMException, IOException {
+ return isMBeanStateDeployedImpl( new ObjectName(mBeanName) );
+ }
+
+
+ /**
+ * Queries JBoss via JMX for given query and checks whether the
+ * StateString property of the first result is "Started".
+ *
+ * @param mBeanName
+ * @return true if the StateString property of the first MBean found is "Started".
+ * @throws javax.management.JMException
+ * @throws java.io.IOException
+ */
+ protected boolean isMBeanStateDeployedByQuery(String mBeanName) throws JMException, IOException
{
+ log.info("Querying JMX: "+mBeanName);
- try {
- MBeanServer jmxServer = MBeanServerLocator.locateJBoss();
- ObjectName objName =
- new ObjectName("jboss.j2ee:module=\"" +
- ejbJarName + "\",service=EjbModule");
- Set mBeans = jmxServer.queryNames(objName, null);
+ ObjectName objName = new ObjectName(mBeanName);
- if (mBeans.size() != 1) {
- return false;
- }
+ MBeanServer jmxServer = MBeanServerLocator.locateJBoss();
+ Set mBeans = jmxServer.queryNames(objName, null);
+ if (mBeans.size() != 1) {
+ return false;
+ }
+ ObjectName deploymentMBean = (ObjectName) mBeans.iterator().next();
+ // Returns org.jboss.deployers.spi.DeploymentState.
+ Object state = jmxServer.getAttribute(deploymentMBean, "State");
+ return "DEPLOYED".equals(state.toString()) || "3".equals(state.toString());
+ }
- ObjectName deploymentMBean = (ObjectName) mBeans.iterator().next();
- // returns org.jboss.deployers.spi.DeploymentState
- Object state = jmxServer.getAttribute(deploymentMBean, "StateString");
- return "Started".equals(state.toString());
-
- } catch (Exception e) {
+ public boolean isEJBDeployed(String ejbJarName) throws RuntimeException
+ {
+ try {
+ String mBeanName = "jboss.j2ee:module=\""+ejbJarName+"\",service=EjbModule";
+ return isMBeanStateDeployedByQuery(mBeanName);
+ }
+ catch (Exception e) {
throw new RuntimeException(e);
}
}
public boolean isWarDeployed(String warName) throws RuntimeException
{
-
if (warName.endsWith(".war")) {
warName = warName.substring(0, warName.lastIndexOf(".war"));
} else {
@@ -86,52 +124,22 @@
}
try {
- MBeanServer jmxServer = MBeanServerLocator.locateJBoss();
- ObjectName objName =
- new ObjectName("jboss.deployment:id=\"jboss.web.deployment:war=/" +
- warName + "\",*");
- Set mBeans = jmxServer.queryNames(objName, null);
-
- if (mBeans.size() != 1) {
- return false;
- }
-
- ObjectName deploymentMBean = (ObjectName) mBeans.iterator().next();
-
- // returns org.jboss.deployers.spi.DeploymentState
- Object state = jmxServer.getAttribute(deploymentMBean, "State");
-
- return "DEPLOYED".equals(state.toString());
-
- } catch (Exception e) {
+ String query = "jboss.deployment:id=\"jboss.web.deployment:war=/"+warName+"\",*";
+ return isMBeanStateDeployedByQuery(query);
+ }
+ catch (Exception e) {
throw new RuntimeException(e);
}
}
public boolean isEarDeployed(String earName) throws RuntimeException
{
-
try {
-
- MBeanServer jmxServer = MBeanServerLocator.locateJBoss();
- ObjectName objName =
- new ObjectName("jboss.deployment:id=\"vfszip:" +
- System.getProperty("jsfunit.deploy.dir") + "/" + earName + "\",*");
-
- Set mBeans = jmxServer.queryNames(objName, null);
-
- if (mBeans.size() != 1) {
- return false;
- }
-
- ObjectName deploymentMBean = (ObjectName) mBeans.iterator().next();
-
- // returns org.jboss.deployers.spi.DeploymentState
- Object state = jmxServer.getAttribute(deploymentMBean, "State");
-
- return "DEPLOYED".equals(state.toString());
-
- } catch (Exception e) {
+ String query = "jboss.deployment:id=\"vfszip:" +
+ System.getProperty("jsfunit.deploy.dir") + "/" + earName + "\",*";
+ return isMBeanStateDeployedByQuery(query);
+ }
+ catch (Exception e) {
throw new RuntimeException(e);
}
}
Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/DebugUtils.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/DebugUtils.java 2009-02-17 17:14:00 UTC (rev 155)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/DebugUtils.java 2009-02-17 21:32:24 UTC (rev 156)
@@ -59,6 +59,26 @@
}
+ /**
+ *
+ * @return
+ */
+ public static String getCurrentMethodFullName() {
+ StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
+ StackTraceElement ste = stackTrace[3];
+ return ste.getClassName() +"#"+ ste.getMethodName();
+ /*
+ StringBuilder sb = new StringBuilder();
+ for( StackTraceElement ste : stackTrace ){
+ sb.append(" -- ").append( ste.getClassName() ).append("#").append( ste.getMethodName() ).append("\n");
+ }
+ return sb.toString();
+ */
+
+ }
+
+
+
}
Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/EmbjoprTestCase.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/EmbjoprTestCase.java 2009-02-17 17:14:00 UTC (rev 155)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/EmbjoprTestCase.java 2009-02-17 21:32:24 UTC (rev 156)
@@ -103,8 +103,8 @@
this.client = jsfSession.getJSFClientSession();
this.server = jsfSession.getJSFServerSession();
- }
-
+ }
+
/**
* Need a standard JSFUnit API to replace this code
*/
Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/JMXUtils.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/JMXUtils.java 2009-02-17 17:14:00 UTC (rev 155)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/JMXUtils.java 2009-02-17 21:32:24 UTC (rev 156)
@@ -1,18 +1,17 @@
package org.jboss.jopr.jsfunit;
import java.io.IOException;
-import java.util.Comparator;
-import java.util.Hashtable;
-import java.util.Set;
-import java.util.SortedSet;
-import java.util.TreeSet;
+import java.util.*;
import javax.management.*;
import javax.naming.*;
import org.jboss.mx.util.MBeanServerLocator;
/**
* JMX utilities.
- * TODO: Write set, invoke if needed. Possibly also remote JMX support (will we ever need it?).
+ *
+ * TODO: Write set(), invoke() if needed.
+ * Possibly also remote JMX support (will we ever need it?).
+ *
* @author ondra
*/
public final class JMXUtils{
Property changes on: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5
___________________________________________________________________
Name: svn:ignore
+ JMXUtilsAS5.java
Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/EarTest.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/EarTest.java 2009-02-17 17:14:00 UTC (rev 155)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/EarTest.java 2009-02-17 21:32:24 UTC (rev 156)
@@ -25,17 +25,9 @@
import org.jboss.jopr.jsfunit.*;
import com.gargoylesoftware.htmlunit.html.*;
import java.io.IOException;
-import java.util.*;
import junit.framework.Test;
import junit.framework.TestSuite;
-import java.util.Map;
import javax.faces.application.FacesMessage;
-import javax.faces.context.FacesContext;
-import javax.servlet.http.HttpServletRequest;
-import com.gargoylesoftware.htmlunit.WebClient;
-import javax.management.MBeanServer;
-import javax.management.ObjectName;
-import org.jboss.mx.util.MBeanServerLocator;
@@ -91,9 +83,9 @@
assertTrue(successMessage.getDetail().contains("eardeployment.ear created successfully"));
// Use JMX to assert that the EAR components really did deploy successfully
- assertTrue(isEarDeployed("eardeployment.ear"));
- assertTrue(isEJBDeployed("sessiona.jar"));
- assertTrue(isEJBDeployed("sessionb.jar"));
+ assertTrue("JMX doesn't report EAR as exposed: eardeployment.ear", isEarDeployed("eardeployment.ear"));
+ assertTrue("JMX doesn't report EJB sessiona.jar as exposed.", isEJBDeployed("sessiona.jar"));
+ assertTrue("JMX doesn't report EJB sessionb.jar as exposed.", isEJBDeployed("sessionb.jar"));
// Undeploy the EAR
HtmlButtonInput deleteButton = getAppDeleteButton("eardeployment.ear");
Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/EjbTest.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/EjbTest.java 2009-02-17 17:14:00 UTC (rev 155)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/EjbTest.java 2009-02-17 21:32:24 UTC (rev 156)
@@ -22,14 +22,15 @@
package org.jboss.jopr.jsfunit.as5;
-import java.util.logging.Level;
-import java.util.logging.Logger;
import org.jboss.jopr.jsfunit.*;
import com.gargoylesoftware.htmlunit.html.*;
+import java.io.File;
+import java.io.FileNotFoundException;
import java.io.IOException;
import junit.framework.Test;
import junit.framework.TestSuite;
import javax.faces.application.FacesMessage;
+import org.jboss.jopr.jsfunit.exceptions.EmbJoprTestException;
@@ -61,8 +62,10 @@
*
*/
- public void testBasicEjbDeployment() throws IOException
+ public void testBasicEjbDeployment() throws IOException, EmbJoprTestException
{
+ log.info(DebugUtils.getCurrentMethodFullName());
+
// Navigate to EJB Applications
HtmlAnchor ejbLink = getNavTreeLink(NAV_EJB);
ejbLink.click();
@@ -70,10 +73,16 @@
// click on the "Add new resource" button
client.click("actionHeaderForm:addNewContent"); // 404 if setThrowExceptionOnFailingStatusCode(true) above
- // upload ejb
+ String filePath = System.getProperty("jsfunit.testdata") + "/ejb/"+BASIC_JAR;
+ log.info("Uploading EJB archive: "+filePath);
+ File uploadFile = new File(filePath);
+ if( !uploadFile.exists() )
+ throw new EmbJoprTestException("Can't find EJB file to upload: '"+filePath+"'");
+
+ // upload ejb
HtmlFileInput fileInput = (HtmlFileInput)client.getElement("createContentForm:file");
fileInput.setContentType("application/ejb");
- fileInput.setValueAttribute(System.getProperty("jsfunit.testdata") + "/ejb/BASIC_JAR");
+ fileInput.setValueAttribute(filePath);
client.click("createContentForm:addButton");
log.info("HTTP status after EJB upload: "+client.getContentPage().getWebResponse().getStatusCode());
Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/WarTest.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/WarTest.java 2009-02-17 17:14:00 UTC (rev 155)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/WarTest.java 2009-02-17 21:32:24 UTC (rev 156)
@@ -25,17 +25,13 @@
import org.jboss.jopr.jsfunit.*;
import com.gargoylesoftware.htmlunit.html.*;
import java.io.IOException;
-import java.util.*;
import junit.framework.Test;
import junit.framework.TestSuite;
-import java.util.Map;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;
import com.gargoylesoftware.htmlunit.WebClient;
-import javax.management.MBeanServer;
-import javax.management.ObjectName;
-import org.jboss.mx.util.MBeanServerLocator;
+import org.jboss.jopr.jsfunit.exceptions.DeploymentException;
@@ -58,45 +54,29 @@
}
- /*
- * testName: testBasicWarDeployment
- * assertion: verify basic deployment of an EJB JAR.
- * test Strategy: Navigate to WAR Applications.
- * Add a new resource. Verify the resource was successfully
- * deployed. Undeploy the archive.
- *
- */
-
-
+ /*
+ * testName: testBasicWarDeployment
+ * assertion: verify basic deployment of an EJB JAR.
+ * test Strategy: Navigate to WAR Applications.
+ * Add a new resource. Verify the resource was successfully
+ * deployed. Undeploy the archive.
+ *
+ */
public void testBasicWarDeployment() throws IOException
{
- // click the nave tree
- HtmlAnchor warLink = getNavTreeLink(NAV_WAR);
- warLink.click();
- // click on the "Add new resource" button
- client.click("actionHeaderForm:addNewContent"); // 404 if setThrowExceptionOnFailingStatusCode(true) above
+ deployWAR();
- // upload hellothere.war
- HtmlFileInput fileInput = (HtmlFileInput)client.getElement("createContentForm:file");
- fileInput.setContentType("application/war");
- fileInput.setValueAttribute(System.getProperty("jsfunit.testdata") + "/war/hellothere.war");
- client.click("createContentForm:addButton");
+ // Check the success message.
+ String expectedMessage = "Resource hellothere.war created successfully!";
+ checkClientAndServerMessages(expectedMessage, expectedMessage, false);
- // assert that the success message appeared on the client side
- assertTrue(client.getPageAsText().contains("Resource hellothere.war created successfully!"));
-
- // assert text and sevrity level for FacesMessage on server side
- assertTrue(server.getFacesMessages().hasNext());
- FacesMessage successMessage = server.getFacesMessages().next();
- assertTrue(FacesMessage.SEVERITY_INFO.equals(successMessage.getSeverity()));
- assertTrue(successMessage.getDetail().contains("Resource hellothere.war created successfully!"));
-
// Use JMX to assert that the WAR really did deploy successfully
- assertTrue(isWarDeployed("hellothere.war"));
+ assertTrue("WAR was not deployed according to JMX", isWarDeployed("hellothere.war"));
// use HtmlUnit to test the newly deployed war in a new WebClient session
// note that I have full access to the FacesContext and the previous request
+ //Thread.sleep(3000); // Give JBoss some time to launch the webapp.
HttpServletRequest request =
(HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
int port = request.getLocalPort();
@@ -114,5 +94,25 @@
//assertFalse(isWarDeployed("hellothere.war"));
}
+
+ /**
+ * Deploys WAR.
+ */
+ private void deployWAR() throws IOException {
+ // click the nave tree
+ HtmlAnchor warLink = getNavTreeLink(NAV_WAR);
+ warLink.click();
+
+ // click on the "Add new resource" button
+ client.click("actionHeaderForm:addNewContent"); // 404 if setThrowExceptionOnFailingStatusCode(true) above
+
+ // upload hellothere.war
+ HtmlFileInput fileInput = (HtmlFileInput)client.getElement("createContentForm:file");
+ fileInput.setContentType("application/war");
+ fileInput.setValueAttribute(System.getProperty("jsfunit.testdata") + "/war/hellothere.war");
+ client.click("createContentForm:addButton");
+
+ }
+
}
Added: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/exceptions/DeploymentException.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/exceptions/DeploymentException.java (rev 0)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/exceptions/DeploymentException.java 2009-02-17 21:32:24 UTC (rev 156)
@@ -0,0 +1,30 @@
+package org.jboss.jopr.jsfunit.exceptions;
+
+/**
+ * Signalizes that there was an action performed
+ * that was out of context - e.g. clicking on a button
+ * that was a part of a HTML page that's already gone.
+ *
+ *
+ * @author ondra
+ */
+public class DeploymentException extends EmbJoprTestException {
+
+ public DeploymentException() {
+ }
+
+ public DeploymentException(String message) {
+ super(message);
+ }
+
+ public DeploymentException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public DeploymentException(Throwable cause) {
+ super(cause);
+ }
+
+
+
+}
15 years, 10 months
EMBJOPR SVN: r155 - trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit.
by embjopr-commits@lists.jboss.org
Author: ozizka(a)redhat.com
Date: 2009-02-17 12:14:00 -0500 (Tue, 17 Feb 2009)
New Revision: 155
Modified:
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/EmbjoprTestCase.java
Log:
Added logging to setUp() to let us find start of the test more easily
Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/EmbjoprTestCase.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/EmbjoprTestCase.java 2009-02-17 15:46:54 UTC (rev 154)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/EmbjoprTestCase.java 2009-02-17 17:14:00 UTC (rev 155)
@@ -71,6 +71,12 @@
public void setUp() throws IOException
{
+ // Announce this test in the JBoss log.
+ log.info("================================================");
+ log.info(" Setting up test "+this.getClass().getName());
+ log.info("================================================");
+
+
// JVM version
log.info("Java version: "+System.getProperty("java.version") + "," +
" vendor: " +System.getProperty("java.vendor"));
15 years, 10 months