You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ja...@apache.org on 2010/09/07 11:02:55 UTC
svn commit: r993292 [1/2] - in /myfaces/gsoc/webapptest: ./ api/ api/src/
api/src/main/ api/src/main/java/ api/src/main/java/org/
api/src/main/java/org/apache/ api/src/main/java/org/apache/myfaces/
api/src/main/java/org/apache/myfaces/test/ api/src/mai...
Author: jakobk
Date: Tue Sep 7 09:02:52 2010
New Revision: 993292
URL: http://svn.apache.org/viewvc?rev=993292&view=rev
Log:
MYFACESTEST-6 Module for automated webapp tests for MyFaces core + extensions (integrate GSoC project - big thanks to Cosmin Martinconi for his work
Added:
myfaces/gsoc/webapptest/
myfaces/gsoc/webapptest/api/
myfaces/gsoc/webapptest/api/pom.xml
myfaces/gsoc/webapptest/api/src/
myfaces/gsoc/webapptest/api/src/main/
myfaces/gsoc/webapptest/api/src/main/java/
myfaces/gsoc/webapptest/api/src/main/java/org/
myfaces/gsoc/webapptest/api/src/main/java/org/apache/
myfaces/gsoc/webapptest/api/src/main/java/org/apache/myfaces/
myfaces/gsoc/webapptest/api/src/main/java/org/apache/myfaces/test/
myfaces/gsoc/webapptest/api/src/main/java/org/apache/myfaces/test/webapp/
myfaces/gsoc/webapptest/api/src/main/java/org/apache/myfaces/test/webapp/api/
myfaces/gsoc/webapptest/api/src/main/java/org/apache/myfaces/test/webapp/api/ResourceFinder.java
myfaces/gsoc/webapptest/api/src/main/java/org/apache/myfaces/test/webapp/api/WebappTestConfigurator.java
myfaces/gsoc/webapptest/api/src/main/java/org/apache/myfaces/test/webapp/api/annotation/
myfaces/gsoc/webapptest/api/src/main/java/org/apache/myfaces/test/webapp/api/annotation/Assertable.java
myfaces/gsoc/webapptest/api/src/main/java/org/apache/myfaces/test/webapp/api/annotation/Configuration.java
myfaces/gsoc/webapptest/api/src/main/java/org/apache/myfaces/test/webapp/api/annotation/ConfigurationTestSuite.java
myfaces/gsoc/webapptest/api/src/main/java/org/apache/myfaces/test/webapp/api/annotation/PageBean.java
myfaces/gsoc/webapptest/api/src/main/java/org/apache/myfaces/test/webapp/api/annotation/Tester.java
myfaces/gsoc/webapptest/api/src/main/java/org/apache/myfaces/test/webapp/api/annotation/View.java
myfaces/gsoc/webapptest/api/src/main/java/org/apache/myfaces/test/webapp/api/dependencies/
myfaces/gsoc/webapptest/api/src/main/java/org/apache/myfaces/test/webapp/api/dependencies/WebappConfiguration.java
myfaces/gsoc/webapptest/api/src/main/java/org/apache/myfaces/test/webapp/api/runner/
myfaces/gsoc/webapptest/api/src/main/java/org/apache/myfaces/test/webapp/api/runner/WebappServletTestRunner.java
myfaces/gsoc/webapptest/api/src/main/java/org/apache/myfaces/test/webapp/api/runner/WebappTestRunner.java
myfaces/gsoc/webapptest/api/src/main/java/org/apache/myfaces/test/webapp/api/tester/
myfaces/gsoc/webapptest/api/src/main/java/org/apache/myfaces/test/webapp/api/tester/WebappTester.java
myfaces/gsoc/webapptest/api/src/main/resources/
myfaces/gsoc/webapptest/api/src/site/
myfaces/gsoc/webapptest/api/src/test/
myfaces/gsoc/webapptest/examples/
myfaces/gsoc/webapptest/examples/pom.xml
myfaces/gsoc/webapptest/examples/src/
myfaces/gsoc/webapptest/examples/src/main/
myfaces/gsoc/webapptest/examples/src/main/java/
myfaces/gsoc/webapptest/examples/src/main/java/org/
myfaces/gsoc/webapptest/examples/src/main/java/org/apache/
myfaces/gsoc/webapptest/examples/src/main/java/org/apache/myfaces/
myfaces/gsoc/webapptest/examples/src/main/java/org/apache/myfaces/test/
myfaces/gsoc/webapptest/examples/src/main/java/org/apache/myfaces/test/webapp/
myfaces/gsoc/webapptest/examples/src/main/java/org/apache/myfaces/test/webapp/examples/
myfaces/gsoc/webapptest/examples/src/main/java/org/apache/myfaces/test/webapp/examples/ExampleBean.java
myfaces/gsoc/webapptest/examples/src/main/resources/
myfaces/gsoc/webapptest/examples/src/main/webapp/
myfaces/gsoc/webapptest/examples/src/main/webapp/META-INF/
myfaces/gsoc/webapptest/examples/src/main/webapp/META-INF/MANIFEST.MF
myfaces/gsoc/webapptest/examples/src/main/webapp/WEB-INF/
myfaces/gsoc/webapptest/examples/src/main/webapp/WEB-INF/faces-config.xml
myfaces/gsoc/webapptest/examples/src/main/webapp/WEB-INF/web.xml
myfaces/gsoc/webapptest/examples/src/main/webapp/test.xhtml
myfaces/gsoc/webapptest/examples/src/site/
myfaces/gsoc/webapptest/examples/src/test/
myfaces/gsoc/webapptest/examples/src/test/java/
myfaces/gsoc/webapptest/examples/src/test/java/org/
myfaces/gsoc/webapptest/examples/src/test/java/org/apache/
myfaces/gsoc/webapptest/examples/src/test/java/org/apache/myfaces/
myfaces/gsoc/webapptest/examples/src/test/java/org/apache/myfaces/test/
myfaces/gsoc/webapptest/examples/src/test/java/org/apache/myfaces/test/webapp/
myfaces/gsoc/webapptest/examples/src/test/java/org/apache/myfaces/test/webapp/examples/
myfaces/gsoc/webapptest/examples/src/test/java/org/apache/myfaces/test/webapp/examples/ExampleTestCase.java
myfaces/gsoc/webapptest/examples/src/test/java/org/apache/myfaces/test/webapp/examples/MyWebappTestCase.java
myfaces/gsoc/webapptest/examples/src/test/resources/
myfaces/gsoc/webapptest/examples/src/test/resources/arquillian.xml
myfaces/gsoc/webapptest/examples/src/test/resources/jndi.properties
myfaces/gsoc/webapptest/examples/src/test/resources/log4j.xml
myfaces/gsoc/webapptest/impl/
myfaces/gsoc/webapptest/impl/pom.xml
myfaces/gsoc/webapptest/impl/src/
myfaces/gsoc/webapptest/impl/src/main/
myfaces/gsoc/webapptest/impl/src/main/java/
myfaces/gsoc/webapptest/impl/src/main/java/org/
myfaces/gsoc/webapptest/impl/src/main/java/org/apache/
myfaces/gsoc/webapptest/impl/src/main/java/org/apache/myfaces/
myfaces/gsoc/webapptest/impl/src/main/java/org/apache/myfaces/test/
myfaces/gsoc/webapptest/impl/src/main/java/org/apache/myfaces/test/webapp/
myfaces/gsoc/webapptest/impl/src/main/java/org/apache/myfaces/test/webapp/impl/
myfaces/gsoc/webapptest/impl/src/main/java/org/apache/myfaces/test/webapp/impl/ActionListenerWrapper.java
myfaces/gsoc/webapptest/impl/src/main/java/org/apache/myfaces/test/webapp/impl/AnnotationManager.java
myfaces/gsoc/webapptest/impl/src/main/java/org/apache/myfaces/test/webapp/impl/ArchiveManager.java
myfaces/gsoc/webapptest/impl/src/main/java/org/apache/myfaces/test/webapp/impl/ELResolverWrapper.java
myfaces/gsoc/webapptest/impl/src/main/java/org/apache/myfaces/test/webapp/impl/ProxyInterceptor.java
myfaces/gsoc/webapptest/impl/src/main/java/org/apache/myfaces/test/webapp/impl/TesttErrorManager.java
myfaces/gsoc/webapptest/impl/src/main/java/org/apache/myfaces/test/webapp/impl/WebappTestConfiguratorImpl.java
myfaces/gsoc/webapptest/impl/src/main/java/org/apache/myfaces/test/webapp/impl/WebappTestPhaseListener.java
myfaces/gsoc/webapptest/impl/src/main/java/org/apache/myfaces/test/webapp/impl/WebappTesterImpl.java
myfaces/gsoc/webapptest/impl/src/main/java/org/apache/myfaces/test/webapp/impl/dependencies/
myfaces/gsoc/webapptest/impl/src/main/java/org/apache/myfaces/test/webapp/impl/dependencies/HtmlUnitDependency.java
myfaces/gsoc/webapptest/impl/src/main/java/org/apache/myfaces/test/webapp/impl/dependencies/StandardDependency.java
myfaces/gsoc/webapptest/impl/src/main/java/org/apache/myfaces/test/webapp/impl/metadata/
myfaces/gsoc/webapptest/impl/src/main/java/org/apache/myfaces/test/webapp/impl/metadata/TestCaseMetadata.java
myfaces/gsoc/webapptest/impl/src/main/java/org/apache/myfaces/test/webapp/impl/metadata/action/
myfaces/gsoc/webapptest/impl/src/main/java/org/apache/myfaces/test/webapp/impl/metadata/action/TestActionClick.java
myfaces/gsoc/webapptest/impl/src/main/java/org/apache/myfaces/test/webapp/impl/metadata/action/TestActionEvent.java
myfaces/gsoc/webapptest/impl/src/main/java/org/apache/myfaces/test/webapp/impl/metadata/action/TestActionGetPage.java
myfaces/gsoc/webapptest/impl/src/main/java/org/apache/myfaces/test/webapp/impl/metadata/action/TestActionInput.java
myfaces/gsoc/webapptest/impl/src/main/java/org/apache/myfaces/test/webapp/impl/metadata/assertion/
myfaces/gsoc/webapptest/impl/src/main/java/org/apache/myfaces/test/webapp/impl/metadata/assertion/AssertableELExpression.java
myfaces/gsoc/webapptest/impl/src/main/java/org/apache/myfaces/test/webapp/impl/metadata/assertion/AssertableProxyMethod.java
myfaces/gsoc/webapptest/impl/src/main/java/org/apache/myfaces/test/webapp/impl/metadata/assertion/AssertableValue.java
myfaces/gsoc/webapptest/impl/src/main/java/org/apache/myfaces/test/webapp/impl/metadata/assertion/TestAssertCondition.java
myfaces/gsoc/webapptest/impl/src/main/java/org/apache/myfaces/test/webapp/impl/metadata/assertion/TestAssertExpectCall.java
myfaces/gsoc/webapptest/impl/src/main/java/org/apache/myfaces/test/webapp/impl/metadata/assertion/TestAssertion.java
myfaces/gsoc/webapptest/impl/src/main/resources/
myfaces/gsoc/webapptest/impl/src/main/resources/META-INF/
myfaces/gsoc/webapptest/impl/src/main/resources/META-INF/services/
myfaces/gsoc/webapptest/impl/src/main/resources/META-INF/services/org.apache.myfaces.test.webapp.api.WebappTestConfigurator
myfaces/gsoc/webapptest/impl/src/site/
myfaces/gsoc/webapptest/impl/src/test/
myfaces/gsoc/webapptest/pom.xml
Added: myfaces/gsoc/webapptest/api/pom.xml
URL: http://svn.apache.org/viewvc/myfaces/gsoc/webapptest/api/pom.xml?rev=993292&view=auto
==============================================================================
--- myfaces/gsoc/webapptest/api/pom.xml (added)
+++ myfaces/gsoc/webapptest/api/pom.xml Tue Sep 7 09:02:52 2010
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.myfaces.test</groupId>
+ <artifactId>webapp-tests-project</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ </parent>
+ <artifactId>webapp-tests-api</artifactId>
+ <packaging>jar</packaging>
+ <name>MyFaces Automated Webapp Tests API</name>
+
+</project>
\ No newline at end of file
Added: myfaces/gsoc/webapptest/api/src/main/java/org/apache/myfaces/test/webapp/api/ResourceFinder.java
URL: http://svn.apache.org/viewvc/myfaces/gsoc/webapptest/api/src/main/java/org/apache/myfaces/test/webapp/api/ResourceFinder.java?rev=993292&view=auto
==============================================================================
--- myfaces/gsoc/webapptest/api/src/main/java/org/apache/myfaces/test/webapp/api/ResourceFinder.java (added)
+++ myfaces/gsoc/webapptest/api/src/main/java/org/apache/myfaces/test/webapp/api/ResourceFinder.java Tue Sep 7 09:02:52 2010
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.test.webapp.api;
+
+import org.apache.myfaces.test.webapp.api.tester.WebappTester;
+
+import java.util.*;
+
+/**
+ * @author Cosmin Martinconi, 06.08.2010
+ */
+public class ResourceFinder {
+
+ public static final String WEBAPP_TESTER = WebappTester.class.getName();
+ public static final String WEBAPP_TEST_CONFIGURATOR = WebappTestConfigurator.class.getName();
+
+ private static Map<String, Object> registeredResources = new HashMap<String, Object>();
+
+ public static Object getResource(String resourceName) {
+ if (resourceName == null) {
+ throw new NullPointerException("resourceClass may not be null");
+ }
+
+ if ((!registeredResources.containsKey(resourceName)) && WEBAPP_TEST_CONFIGURATOR.equals(resourceName)) {
+ WebappTestConfigurator config = ServiceLoader.load(WebappTestConfigurator.class).iterator().next();
+
+ setResource(WEBAPP_TEST_CONFIGURATOR, config);
+ }
+
+ if (!registeredResources.containsKey(resourceName)) {
+ throw new IllegalArgumentException("no resource " + resourceName + " configured for this application.");
+ } else {
+ return registeredResources.get(resourceName);
+ }
+ }
+
+ public static void setResource(String resourceName, Object implObj) {
+
+ registeredResources.put(resourceName, implObj);
+ }
+}
Added: myfaces/gsoc/webapptest/api/src/main/java/org/apache/myfaces/test/webapp/api/WebappTestConfigurator.java
URL: http://svn.apache.org/viewvc/myfaces/gsoc/webapptest/api/src/main/java/org/apache/myfaces/test/webapp/api/WebappTestConfigurator.java?rev=993292&view=auto
==============================================================================
--- myfaces/gsoc/webapptest/api/src/main/java/org/apache/myfaces/test/webapp/api/WebappTestConfigurator.java (added)
+++ myfaces/gsoc/webapptest/api/src/main/java/org/apache/myfaces/test/webapp/api/WebappTestConfigurator.java Tue Sep 7 09:02:52 2010
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.test.webapp.api;
+
+/**
+ * @author Cosmin Martinconi, 06.08.2010
+ */
+public abstract class WebappTestConfigurator {
+
+ private boolean inContainer;
+
+ public abstract void configure(Class testClass);
+
+ public abstract void injectAssertableProxies(Object testObj);
+
+ public abstract void atServletConfiguration();
+
+ public abstract boolean isTestSuiteConfig();
+
+ public static WebappTestConfigurator getCurrentInstance() {
+ return (WebappTestConfigurator)ResourceFinder.getResource(ResourceFinder.WEBAPP_TEST_CONFIGURATOR);
+ }
+
+ public boolean isInContainer() {
+ return inContainer;
+ }
+
+ public void setInContainer(boolean inContainer) {
+ this.inContainer = inContainer;
+ }
+}
Added: myfaces/gsoc/webapptest/api/src/main/java/org/apache/myfaces/test/webapp/api/annotation/Assertable.java
URL: http://svn.apache.org/viewvc/myfaces/gsoc/webapptest/api/src/main/java/org/apache/myfaces/test/webapp/api/annotation/Assertable.java?rev=993292&view=auto
==============================================================================
--- myfaces/gsoc/webapptest/api/src/main/java/org/apache/myfaces/test/webapp/api/annotation/Assertable.java (added)
+++ myfaces/gsoc/webapptest/api/src/main/java/org/apache/myfaces/test/webapp/api/annotation/Assertable.java Tue Sep 7 09:02:52 2010
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.test.webapp.api.annotation;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+/**
+ * @author Cosmin Martinconi, 27.07.2010
+ */
+
+@Documented
+@Retention(RUNTIME)
+@Target(ElementType.FIELD)
+public @interface Assertable {
+}
Added: myfaces/gsoc/webapptest/api/src/main/java/org/apache/myfaces/test/webapp/api/annotation/Configuration.java
URL: http://svn.apache.org/viewvc/myfaces/gsoc/webapptest/api/src/main/java/org/apache/myfaces/test/webapp/api/annotation/Configuration.java?rev=993292&view=auto
==============================================================================
--- myfaces/gsoc/webapptest/api/src/main/java/org/apache/myfaces/test/webapp/api/annotation/Configuration.java (added)
+++ myfaces/gsoc/webapptest/api/src/main/java/org/apache/myfaces/test/webapp/api/annotation/Configuration.java Tue Sep 7 09:02:52 2010
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.test.webapp.api.annotation;
+
+import org.apache.myfaces.test.webapp.api.dependencies.WebappConfiguration;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * When a class is annotated with <code>@Configuration</code> or extends a class annotated
+ * with <code>@Configuration</code>, the WebappTestRunner will configure the deployed archive
+ * to include the dependencies from the provided Configuration value class.
+ *
+ * @author Cosmin Martinconi, 02.07.2010
+ */
+
+@Target(ElementType.TYPE)
+@Retention(RetentionPolicy.RUNTIME)
+public @interface Configuration {
+
+ Class<? extends WebappConfiguration> value();
+}
Added: myfaces/gsoc/webapptest/api/src/main/java/org/apache/myfaces/test/webapp/api/annotation/ConfigurationTestSuite.java
URL: http://svn.apache.org/viewvc/myfaces/gsoc/webapptest/api/src/main/java/org/apache/myfaces/test/webapp/api/annotation/ConfigurationTestSuite.java?rev=993292&view=auto
==============================================================================
--- myfaces/gsoc/webapptest/api/src/main/java/org/apache/myfaces/test/webapp/api/annotation/ConfigurationTestSuite.java (added)
+++ myfaces/gsoc/webapptest/api/src/main/java/org/apache/myfaces/test/webapp/api/annotation/ConfigurationTestSuite.java Tue Sep 7 09:02:52 2010
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.test.webapp.api.annotation;
+
+import org.apache.myfaces.test.webapp.api.dependencies.WebappConfiguration;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * By adding the <code>@ConfigurationTestSuite</code> annotation to a class, you tell the WebappTestRunner
+ * to run the classes TestCase for all the configurations provided. For each of the configured classes, a new
+ * test will be created with it's specific dependencies.
+ *
+ * @author Cosmin Martinconi, 02.07.2010
+ */
+@Target(ElementType.TYPE)
+@Retention(RetentionPolicy.RUNTIME)
+public @interface ConfigurationTestSuite {
+
+ Class<? extends WebappConfiguration>[] value();
+
+ String configName() default "all";
+
+ /**
+ * For multiple Configurations
+ */
+ @Target(ElementType.TYPE)
+ @Retention(RetentionPolicy.RUNTIME)
+ public @interface List
+ {
+
+ ConfigurationTestSuite[] value();
+
+ }
+
+}
Added: myfaces/gsoc/webapptest/api/src/main/java/org/apache/myfaces/test/webapp/api/annotation/PageBean.java
URL: http://svn.apache.org/viewvc/myfaces/gsoc/webapptest/api/src/main/java/org/apache/myfaces/test/webapp/api/annotation/PageBean.java?rev=993292&view=auto
==============================================================================
--- myfaces/gsoc/webapptest/api/src/main/java/org/apache/myfaces/test/webapp/api/annotation/PageBean.java (added)
+++ myfaces/gsoc/webapptest/api/src/main/java/org/apache/myfaces/test/webapp/api/annotation/PageBean.java Tue Sep 7 09:02:52 2010
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.test.webapp.api.annotation;
+
+import java.lang.annotation.Target;
+
+/**
+ * The page bean of the TestCase view.
+ *
+ * @author Cosmin Martinconi, 16.06.2010
+ */
+@Target({}) // disallow anywhere outside of @View
+public @interface PageBean{
+
+ String scope() default "session";
+
+ String name() default ""; // empty String specifies: name = clazz.getName()
+
+ Class<?> clazz();
+
+}
Added: myfaces/gsoc/webapptest/api/src/main/java/org/apache/myfaces/test/webapp/api/annotation/Tester.java
URL: http://svn.apache.org/viewvc/myfaces/gsoc/webapptest/api/src/main/java/org/apache/myfaces/test/webapp/api/annotation/Tester.java?rev=993292&view=auto
==============================================================================
--- myfaces/gsoc/webapptest/api/src/main/java/org/apache/myfaces/test/webapp/api/annotation/Tester.java (added)
+++ myfaces/gsoc/webapptest/api/src/main/java/org/apache/myfaces/test/webapp/api/annotation/Tester.java Tue Sep 7 09:02:52 2010
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.test.webapp.api.annotation;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+/**
+ * Any TestCase must provide a field annotated with <code>@Tester</code>, which will
+ * tell the WebappTestRunner to inject a Tester instance containing the control methods.
+ *
+ * @author Cosmin Martinconi, 02.07.2010
+ */
+@Documented
+@Retention(RUNTIME)
+@Target(ElementType.FIELD)
+public @interface Tester {
+
+}
Added: myfaces/gsoc/webapptest/api/src/main/java/org/apache/myfaces/test/webapp/api/annotation/View.java
URL: http://svn.apache.org/viewvc/myfaces/gsoc/webapptest/api/src/main/java/org/apache/myfaces/test/webapp/api/annotation/View.java?rev=993292&view=auto
==============================================================================
--- myfaces/gsoc/webapptest/api/src/main/java/org/apache/myfaces/test/webapp/api/annotation/View.java (added)
+++ myfaces/gsoc/webapptest/api/src/main/java/org/apache/myfaces/test/webapp/api/annotation/View.java Tue Sep 7 09:02:52 2010
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.test.webapp.api.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * This annotation will tell the WebappTestRunner which view will be tested, specifying the
+ * viewId and it's Page Beans.
+ *
+ * @author Cosmin Martinconi, 16.06.2010
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.TYPE)
+public @interface View
+{
+
+ String id();
+
+ PageBean[] pageBeans() default {};
+
+}
Added: myfaces/gsoc/webapptest/api/src/main/java/org/apache/myfaces/test/webapp/api/dependencies/WebappConfiguration.java
URL: http://svn.apache.org/viewvc/myfaces/gsoc/webapptest/api/src/main/java/org/apache/myfaces/test/webapp/api/dependencies/WebappConfiguration.java?rev=993292&view=auto
==============================================================================
--- myfaces/gsoc/webapptest/api/src/main/java/org/apache/myfaces/test/webapp/api/dependencies/WebappConfiguration.java (added)
+++ myfaces/gsoc/webapptest/api/src/main/java/org/apache/myfaces/test/webapp/api/dependencies/WebappConfiguration.java Tue Sep 7 09:02:52 2010
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.test.webapp.api.dependencies;
+
+/**
+ * This interface defines a configuration for the {@link org.apache.myfaces.test.webapp.api.annotation.Configuration}
+ *
+ * @author Cosmin Martinconi, 06.07.2010
+ */
+public interface WebappConfiguration {
+
+ public String getGroupId();
+
+ public String getArtifactId();
+
+ public String getVersion();
+
+}
Added: myfaces/gsoc/webapptest/api/src/main/java/org/apache/myfaces/test/webapp/api/runner/WebappServletTestRunner.java
URL: http://svn.apache.org/viewvc/myfaces/gsoc/webapptest/api/src/main/java/org/apache/myfaces/test/webapp/api/runner/WebappServletTestRunner.java?rev=993292&view=auto
==============================================================================
--- myfaces/gsoc/webapptest/api/src/main/java/org/apache/myfaces/test/webapp/api/runner/WebappServletTestRunner.java (added)
+++ myfaces/gsoc/webapptest/api/src/main/java/org/apache/myfaces/test/webapp/api/runner/WebappServletTestRunner.java Tue Sep 7 09:02:52 2010
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.test.webapp.api.runner;
+
+import org.apache.myfaces.test.webapp.api.WebappTestConfigurator;
+import org.jboss.arquillian.protocol.servlet_3.ServletTestRunner;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+
+/**
+ * @author Cosmin Martinconi, 07.08.2010
+ */
+public class WebappServletTestRunner extends ServletTestRunner {
+
+ @Override
+ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ WebappTestConfigurator wtConfig = WebappTestConfigurator.getCurrentInstance();
+ wtConfig.atServletConfiguration();
+
+ wtConfig.setInContainer(true);
+ super.doGet(request, response);
+ wtConfig.setInContainer(false);
+ }
+
+}
Added: myfaces/gsoc/webapptest/api/src/main/java/org/apache/myfaces/test/webapp/api/runner/WebappTestRunner.java
URL: http://svn.apache.org/viewvc/myfaces/gsoc/webapptest/api/src/main/java/org/apache/myfaces/test/webapp/api/runner/WebappTestRunner.java?rev=993292&view=auto
==============================================================================
--- myfaces/gsoc/webapptest/api/src/main/java/org/apache/myfaces/test/webapp/api/runner/WebappTestRunner.java (added)
+++ myfaces/gsoc/webapptest/api/src/main/java/org/apache/myfaces/test/webapp/api/runner/WebappTestRunner.java Tue Sep 7 09:02:52 2010
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.test.webapp.api.runner;
+
+import org.apache.myfaces.test.webapp.api.ResourceFinder;
+import org.apache.myfaces.test.webapp.api.WebappTestConfigurator;
+import org.apache.myfaces.test.webapp.api.tester.WebappTester;
+import org.jboss.arquillian.junit.Arquillian;
+import org.junit.runner.notification.RunNotifier;
+import org.junit.runners.model.FrameworkMethod;
+import org.junit.runners.model.InitializationError;
+import org.junit.runners.model.Statement;
+
+/**
+ * @author Cosmin Martinconi, 05.08.2010
+ */
+public class WebappTestRunner extends Arquillian {
+
+ private WebappTester webappTester;
+ private WebappTestConfigurator wtConfig;
+
+ public WebappTestRunner(Class<?> klass) throws InitializationError {
+ super(klass);
+
+ wtConfig = WebappTestConfigurator.getCurrentInstance();
+ wtConfig.configure(klass);
+
+ webappTester = (WebappTester)ResourceFinder.getResource(ResourceFinder.WEBAPP_TESTER);
+ }
+
+ @Override
+ public void run(final RunNotifier notifier) {
+
+ super.run(notifier);
+
+ if (wtConfig.isTestSuiteConfig() && !wtConfig.isInContainer()) {
+ this.run(notifier);
+ }
+ }
+
+ @Override
+ protected Statement withBefores(final FrameworkMethod method, final Object target, final Statement originalStatement) {
+
+ if (wtConfig.isInContainer()) {
+ webappTester.setUpTestMethod();
+ }
+
+ return super.withBefores(method, target, originalStatement);
+ }
+
+ @Override
+ protected Statement withAfters(final FrameworkMethod method, final Object target, final Statement originalStatement) {
+ final Statement statementWithAfters = super.withAfters(method, target, originalStatement);
+ return new Statement() {
+ @Override
+ public void evaluate() throws Throwable {
+ statementWithAfters.evaluate();
+
+ if (wtConfig.isInContainer()) {
+ webappTester.executeTestMethod();
+ webappTester.tearDownTestMethod();
+ }
+ }
+ };
+ }
+
+ @Override
+ protected Statement methodInvoker(final FrameworkMethod method, final Object test) {
+ if (getTestClass().getJavaClass().isInstance(test)) {
+ wtConfig.injectAssertableProxies(test);
+ }
+
+ return super.methodInvoker(method, test);
+ }
+
+}
\ No newline at end of file
Added: myfaces/gsoc/webapptest/api/src/main/java/org/apache/myfaces/test/webapp/api/tester/WebappTester.java
URL: http://svn.apache.org/viewvc/myfaces/gsoc/webapptest/api/src/main/java/org/apache/myfaces/test/webapp/api/tester/WebappTester.java?rev=993292&view=auto
==============================================================================
--- myfaces/gsoc/webapptest/api/src/main/java/org/apache/myfaces/test/webapp/api/tester/WebappTester.java (added)
+++ myfaces/gsoc/webapptest/api/src/main/java/org/apache/myfaces/test/webapp/api/tester/WebappTester.java Tue Sep 7 09:02:52 2010
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.test.webapp.api.tester;
+
+import org.jboss.shrinkwrap.api.Archive;
+
+import javax.faces.component.UIViewRoot;
+import javax.faces.context.FacesContext;
+import javax.faces.event.PhaseId;
+
+/**
+ * @author Cosmin Martinconi, 05.08.2010
+ */
+public interface WebappTester {
+
+ public Archive<?> createArchive(Archive<?> applicationArchive);
+
+ public void setUpTestMethod();
+ public void tearDownTestMethod();
+ public void executeTestMethod();
+
+ public FacesContext getFacesContext();
+ public UIViewRoot getRoot();
+
+ public Input input(String value);
+ public void click(String clientId);
+
+ public Assertable assertThat(Object injectedAssertableValue);
+ public Call expectCall(Object injectedAssertableValue);
+ public Call expectLastCall();
+
+ public interface Assertable {
+ public PhaseAware is(String expectedValue);
+ }
+
+ public interface PhaseAware {
+ public void after(PhaseId phase);
+ public void before(PhaseId phase);
+ }
+
+ public interface Input {
+ public void into(String clientId);
+ }
+
+ public interface Call {
+ public void in(PhaseId phase);
+ }
+}
Added: myfaces/gsoc/webapptest/examples/pom.xml
URL: http://svn.apache.org/viewvc/myfaces/gsoc/webapptest/examples/pom.xml?rev=993292&view=auto
==============================================================================
--- myfaces/gsoc/webapptest/examples/pom.xml (added)
+++ myfaces/gsoc/webapptest/examples/pom.xml Tue Sep 7 09:02:52 2010
@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.myfaces.test</groupId>
+ <artifactId>webapp-tests-project</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ </parent>
+ <artifactId>webapp-tests-examples</artifactId>
+ <packaging>jar</packaging>
+ <name>MyFaces Automated Webapp Tests Examples</name>
+
+ <dependencies>
+ <!-- Internal dependency on another module -->
+ <dependency>
+ <groupId>org.apache.myfaces.test</groupId>
+ <artifactId>webapp-tests-api</artifactId>
+ <version>${project.version}</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.myfaces.test</groupId>
+ <artifactId>webapp-tests-impl</artifactId>
+ <version>${project.version}</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>2.5</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <testResources>
+ <testResource>
+ <directory>src/test/resources</directory>
+ </testResource>
+ <testResource>
+ <directory>src/main/webapp</directory>
+ </testResource>
+ </testResources>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <excludes>
+ <exclude>org/apache/myfaces/test/webapp/examples/*</exclude>
+ </excludes>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
\ No newline at end of file
Added: myfaces/gsoc/webapptest/examples/src/main/java/org/apache/myfaces/test/webapp/examples/ExampleBean.java
URL: http://svn.apache.org/viewvc/myfaces/gsoc/webapptest/examples/src/main/java/org/apache/myfaces/test/webapp/examples/ExampleBean.java?rev=993292&view=auto
==============================================================================
--- myfaces/gsoc/webapptest/examples/src/main/java/org/apache/myfaces/test/webapp/examples/ExampleBean.java (added)
+++ myfaces/gsoc/webapptest/examples/src/main/java/org/apache/myfaces/test/webapp/examples/ExampleBean.java Tue Sep 7 09:02:52 2010
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.test.webapp.examples;
+
+import java.awt.event.ActionEvent;
+
+/**
+ * @author Cosmin Martinconi, 16.06.2010
+ */
+public class ExampleBean
+{
+
+ private String input = "default value";
+
+ public String getInput()
+ {
+ return input;
+ }
+
+ public void setInput(String input)
+ {
+ this.input = input;
+ }
+
+ public String action(){
+ input = "after action value";
+ return null;
+ }
+
+ public void actionListener(ActionEvent e)
+ {
+
+ }
+
+}
Added: myfaces/gsoc/webapptest/examples/src/main/webapp/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/myfaces/gsoc/webapptest/examples/src/main/webapp/META-INF/MANIFEST.MF?rev=993292&view=auto
==============================================================================
--- myfaces/gsoc/webapptest/examples/src/main/webapp/META-INF/MANIFEST.MF (added)
+++ myfaces/gsoc/webapptest/examples/src/main/webapp/META-INF/MANIFEST.MF Tue Sep 7 09:02:52 2010
@@ -0,0 +1,2 @@
+Manifest-Version: 1.0
+
Added: myfaces/gsoc/webapptest/examples/src/main/webapp/WEB-INF/faces-config.xml
URL: http://svn.apache.org/viewvc/myfaces/gsoc/webapptest/examples/src/main/webapp/WEB-INF/faces-config.xml?rev=993292&view=auto
==============================================================================
--- myfaces/gsoc/webapptest/examples/src/main/webapp/WEB-INF/faces-config.xml (added)
+++ myfaces/gsoc/webapptest/examples/src/main/webapp/WEB-INF/faces-config.xml Tue Sep 7 09:02:52 2010
@@ -0,0 +1,34 @@
+<?xml version="1.0"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+
+-->
+
+<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
+ http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd" version="2.0">
+
+
+ <managed-bean>
+ <managed-bean-name>exampleBean</managed-bean-name>
+ <managed-bean-class>org.apache.myfaces.test.webapp.examples.ExampleBean</managed-bean-class>
+ <managed-bean-scope>request</managed-bean-scope>
+ </managed-bean>
+
+</faces-config>
Added: myfaces/gsoc/webapptest/examples/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/myfaces/gsoc/webapptest/examples/src/main/webapp/WEB-INF/web.xml?rev=993292&view=auto
==============================================================================
--- myfaces/gsoc/webapptest/examples/src/main/webapp/WEB-INF/web.xml (added)
+++ myfaces/gsoc/webapptest/examples/src/main/webapp/WEB-INF/web.xml Tue Sep 7 09:02:52 2010
@@ -0,0 +1,58 @@
+<?xml version = '1.0' encoding = 'ISO-8859-1'?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+
+-->
+<web-app xmlns="http://java.sun.com/xml/ns/javaee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
+ version="2.5">
+
+ <context-param>
+ <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
+ <param-value>.xhtml</param-value>
+ </context-param>
+
+ <servlet>
+ <servlet-name>Faces Servlet</servlet-name>
+ <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+
+ <servlet>
+ <servlet-name>ServletTestRunner</servlet-name>
+ <servlet-class>org.apache.myfaces.test.webapp.api.runner.WebappServletTestRunner</servlet-class>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>Faces Servlet</servlet-name>
+ <url-pattern>/faces/*</url-pattern>
+ <url-pattern>*.xhtml</url-pattern>
+ </servlet-mapping>
+
+ <servlet-mapping>
+ <servlet-name>ServletTestRunner</servlet-name>
+ <url-pattern>/ArquillianServletRunner</url-pattern>
+ </servlet-mapping>
+
+ <welcome-file-list>
+ <welcome-file>test.xhtml</welcome-file>
+ </welcome-file-list>
+
+</web-app>
+
\ No newline at end of file
Added: myfaces/gsoc/webapptest/examples/src/main/webapp/test.xhtml
URL: http://svn.apache.org/viewvc/myfaces/gsoc/webapptest/examples/src/main/webapp/test.xhtml?rev=993292&view=auto
==============================================================================
--- myfaces/gsoc/webapptest/examples/src/main/webapp/test.xhtml (added)
+++ myfaces/gsoc/webapptest/examples/src/main/webapp/test.xhtml Tue Sep 7 09:02:52 2010
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+
+<!DOCTYPE html
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:h="http://java.sun.com/jsf/html"
+ xmlns:f="http://java.sun.com/jsf/core">
+
+<head>
+ <title>Automated webapp testing</title>
+</head>
+<body>
+ <h:form id="testForm">
+ <h:outputText value="Input field"/>
+ <h:inputText id="fieldId" value="#{exampleBean.input}"/>
+ <h:commandButton id="buttonId" action="#{exampleBean.action}"/>
+ </h:form>
+</body>
+</html>
\ No newline at end of file
Added: myfaces/gsoc/webapptest/examples/src/test/java/org/apache/myfaces/test/webapp/examples/ExampleTestCase.java
URL: http://svn.apache.org/viewvc/myfaces/gsoc/webapptest/examples/src/test/java/org/apache/myfaces/test/webapp/examples/ExampleTestCase.java?rev=993292&view=auto
==============================================================================
--- myfaces/gsoc/webapptest/examples/src/test/java/org/apache/myfaces/test/webapp/examples/ExampleTestCase.java (added)
+++ myfaces/gsoc/webapptest/examples/src/test/java/org/apache/myfaces/test/webapp/examples/ExampleTestCase.java Tue Sep 7 09:02:52 2010
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.test.webapp.examples;
+
+import org.apache.myfaces.test.webapp.api.annotation.*;
+import org.apache.myfaces.test.webapp.api.runner.WebappTestRunner;
+import org.apache.myfaces.test.webapp.api.tester.WebappTester;
+import org.jboss.arquillian.api.Deployment;
+
+import org.jboss.shrinkwrap.api.Archive;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.faces.event.PhaseId;
+
+/**
+ * @author Cosmin Martinconi, 16.06.2010
+ */
+@View(id = "test.xhtml", pageBeans = @PageBean(clazz = ExampleBean.class))
+
+@RunWith(WebappTestRunner.class)
+public class ExampleTestCase{
+
+ @Tester
+ private static WebappTester webappTestCase;
+
+ @Assertable
+ private ExampleBean exampleBean;
+
+ @Deployment
+ public static Archive<?> createDeployment() {
+ return webappTestCase.createArchive(null);
+ }
+
+ @Test
+ public void testWithFailures() throws Exception {
+
+ webappTestCase.assertThat(exampleBean.getInput()).is("default value"). before(PhaseId.RENDER_RESPONSE);
+ webappTestCase.input("test value").into("testForm:fieldId");
+ webappTestCase.click("testForm:buttonId");
+
+ webappTestCase.assertThat(webappTestCase.getFacesContext().getExternalContext()).is("String");
+ webappTestCase.assertThat(exampleBean.getInput()).is("test value").before(PhaseId.INVOKE_APPLICATION);
+ webappTestCase.assertThat("#{exampleBean.input}").is("test value").after(PhaseId.INVOKE_APPLICATION);
+ webappTestCase.expectCall(exampleBean.action()).in(PhaseId.INVOKE_APPLICATION);
+ exampleBean.actionListener(null);
+ webappTestCase.expectLastCall().in(PhaseId.INVOKE_APPLICATION);}
+
+
+ @Test
+ public void testDummy() throws Exception {
+
+ //dummy test
+ }
+
+}
\ No newline at end of file
Added: myfaces/gsoc/webapptest/examples/src/test/java/org/apache/myfaces/test/webapp/examples/MyWebappTestCase.java
URL: http://svn.apache.org/viewvc/myfaces/gsoc/webapptest/examples/src/test/java/org/apache/myfaces/test/webapp/examples/MyWebappTestCase.java?rev=993292&view=auto
==============================================================================
--- myfaces/gsoc/webapptest/examples/src/test/java/org/apache/myfaces/test/webapp/examples/MyWebappTestCase.java (added)
+++ myfaces/gsoc/webapptest/examples/src/test/java/org/apache/myfaces/test/webapp/examples/MyWebappTestCase.java Tue Sep 7 09:02:52 2010
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.test.webapp.examples;
+
+import org.apache.myfaces.test.webapp.api.annotation.*;
+import org.apache.myfaces.test.webapp.api.runner.WebappTestRunner;
+import org.apache.myfaces.test.webapp.impl.WebappTesterImpl;
+import org.jboss.arquillian.api.Deployment;
+
+import org.jboss.shrinkwrap.api.Archive;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.faces.event.PhaseId;
+
+/**
+ * @author Jakob Korherr
+ */
+@View(id = "test.xhtml", pageBeans = @PageBean(clazz = ExampleBean.class))
+
+@RunWith(WebappTestRunner.class)
+public class MyWebappTestCase
+{
+
+ @Tester
+ private static WebappTesterImpl webappTestCase;
+
+ @Assertable
+ private ExampleBean exampleBean;
+
+ @Deployment
+ public static Archive<?> createDeployment()
+ {
+ return webappTestCase.createArchive(null);
+ }
+
+ @Test
+ public void testApplyInputValue() throws Exception
+ {
+ webappTestCase.assertThat(exampleBean.getInput()).is("default value").after(PhaseId.RENDER_RESPONSE);
+ webappTestCase.assertThat("#{exampleBean.input}").is("default value").after(PhaseId.RENDER_RESPONSE);
+
+ webappTestCase.input("test value").into("testForm:fieldId");
+ webappTestCase.click("testForm:buttonId");
+
+ webappTestCase.assertThat(exampleBean.getInput()).is("test value").after(PhaseId.UPDATE_MODEL_VALUES);
+ webappTestCase.assertThat(exampleBean.getInput()).is("after action value").after(PhaseId.INVOKE_APPLICATION);
+ }
+
+}
Added: myfaces/gsoc/webapptest/examples/src/test/resources/arquillian.xml
URL: http://svn.apache.org/viewvc/myfaces/gsoc/webapptest/examples/src/test/resources/arquillian.xml?rev=993292&view=auto
==============================================================================
--- myfaces/gsoc/webapptest/examples/src/test/resources/arquillian.xml (added)
+++ myfaces/gsoc/webapptest/examples/src/test/resources/arquillian.xml Tue Sep 7 09:02:52 2010
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<arquillian xmlns="http://jboss.com/arquillian"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:tomcat6="urn:arq:org.jboss.arquillian.container.tomcat.embedded_6">
+
+ <tomcat6:container>
+ <!-- must be true to use annotation scanning (access to WEB-INF/classes/) -->
+ <tomcat6:unpackArchive>true</tomcat6:unpackArchive>
+ </tomcat6:container>
+
+</arquillian>
Added: myfaces/gsoc/webapptest/examples/src/test/resources/jndi.properties
URL: http://svn.apache.org/viewvc/myfaces/gsoc/webapptest/examples/src/test/resources/jndi.properties?rev=993292&view=auto
==============================================================================
--- myfaces/gsoc/webapptest/examples/src/test/resources/jndi.properties (added)
+++ myfaces/gsoc/webapptest/examples/src/test/resources/jndi.properties Tue Sep 7 09:02:52 2010
@@ -0,0 +1,3 @@
+java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
+java.naming.factory.url.pkgs=org.jboss.naming\:org.jnp.interfaces
+java.naming.provider.url=jnp://localhost:1099
\ No newline at end of file
Added: myfaces/gsoc/webapptest/examples/src/test/resources/log4j.xml
URL: http://svn.apache.org/viewvc/myfaces/gsoc/webapptest/examples/src/test/resources/log4j.xml?rev=993292&view=auto
==============================================================================
--- myfaces/gsoc/webapptest/examples/src/test/resources/log4j.xml (added)
+++ myfaces/gsoc/webapptest/examples/src/test/resources/log4j.xml Tue Sep 7 09:02:52 2010
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
+
+ <appender name="console" class="org.apache.log4j.ConsoleAppender">
+ <param name="Target" value="System.out"/>
+ <layout class="org.apache.log4j.PatternLayout">
+ <param name="ConversionPattern" value="%-5p %m%n"/>
+ </layout>
+ </appender>
+
+ <category name="org">
+ <priority value="INFO"/>
+ </category>
+
+ <category name="com">
+ <priority value="INFO"/>
+ </category>
+
+ <category name="sun">
+ <priority value="INFO"/>
+ </category>
+
+ <root>
+ <priority value="debug"/>
+ <appender-ref ref="console"/>
+ </root>
+
+</log4j:configuration>
\ No newline at end of file
Added: myfaces/gsoc/webapptest/impl/pom.xml
URL: http://svn.apache.org/viewvc/myfaces/gsoc/webapptest/impl/pom.xml?rev=993292&view=auto
==============================================================================
--- myfaces/gsoc/webapptest/impl/pom.xml (added)
+++ myfaces/gsoc/webapptest/impl/pom.xml Tue Sep 7 09:02:52 2010
@@ -0,0 +1,131 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.myfaces.test</groupId>
+ <artifactId>webapp-tests-project</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ </parent>
+ <artifactId>webapp-tests-impl</artifactId>
+ <packaging>jar</packaging>
+ <name>MyFaces Automated Webapp Tests IMPL</name>
+
+ <dependencies>
+ <!-- Internal dependency on another module -->
+ <dependency>
+ <groupId>org.apache.myfaces.test</groupId>
+ <artifactId>webapp-tests-api</artifactId>
+ <version>${project.version}</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <!-- HtmlUnit compile-->
+ <dependency>
+ <groupId>commons-codec</groupId>
+ <artifactId>commons-codec</artifactId>
+ <version>1.3</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-collections</groupId>
+ <artifactId>commons-collections</artifactId>
+ <version>3.2.1</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-httpclient</groupId>
+ <artifactId>commons-httpclient</artifactId>
+ <version>3.1</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <version>1.4</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ <version>2.4</version>
+ </dependency>
+
+ <dependency>
+ <groupId>net.sourceforge.cssparser</groupId>
+ <artifactId>cssparser</artifactId>
+ <version>0.9.5</version>
+ </dependency>
+ <dependency>
+ <groupId>net.sourceforge.htmlunit</groupId>
+ <artifactId>htmlunit</artifactId>
+ <version>2.4</version>
+ </dependency>
+ <dependency>
+ <groupId>net.sourceforge.htmlunit</groupId>
+ <artifactId>htmlunit-core-js</artifactId>
+ <version>2.4</version>
+ </dependency>
+ <dependency>
+ <groupId>net.sourceforge.htmlunit</groupId>
+ <artifactId>webdriver</artifactId>
+ <version>2.6</version>
+ </dependency>
+ <dependency>
+ <groupId>net.sourceforge.nekohtml</groupId>
+ <artifactId>nekohtml</artifactId>
+ <version>1.9.11</version>
+ </dependency>
+
+ <dependency>
+ <groupId>xalan</groupId>
+ <artifactId>xalan</artifactId>
+ <version>2.7.1</version>
+ </dependency>
+ <dependency>
+ <groupId>xerces</groupId>
+ <artifactId>xercesImpl</artifactId>
+ <version>2.9.1</version>
+ </dependency>
+
+
+ <!-- Test dependencies. -->
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <version>1.2.14</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>gsbase</groupId>
+ <artifactId>gsbase</artifactId>
+ <version>2.0.1</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>commons-fileupload</groupId>
+ <artifactId>commons-fileupload</artifactId>
+ <version>1.2.1</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty</artifactId>
+ <version>6.1.14</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.seleniumhq.webdriver</groupId>
+ <artifactId>webdriver-firefox</artifactId>
+ <version>0.9.7376</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.seleniumhq.webdriver</groupId>
+ <artifactId>webdriver-htmlunit</artifactId>
+ <version>0.9.7376</version>
+ <scope>test</scope>
+ </dependency>
+
+ </dependencies>
+
+</project>
\ No newline at end of file
Added: myfaces/gsoc/webapptest/impl/src/main/java/org/apache/myfaces/test/webapp/impl/ActionListenerWrapper.java
URL: http://svn.apache.org/viewvc/myfaces/gsoc/webapptest/impl/src/main/java/org/apache/myfaces/test/webapp/impl/ActionListenerWrapper.java?rev=993292&view=auto
==============================================================================
--- myfaces/gsoc/webapptest/impl/src/main/java/org/apache/myfaces/test/webapp/impl/ActionListenerWrapper.java (added)
+++ myfaces/gsoc/webapptest/impl/src/main/java/org/apache/myfaces/test/webapp/impl/ActionListenerWrapper.java Tue Sep 7 09:02:52 2010
@@ -0,0 +1,105 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.test.webapp.impl;
+
+import net.sf.cglib.core.Signature;
+import org.apache.myfaces.test.webapp.impl.metadata.assertion.AssertableELExpression;
+import org.apache.myfaces.test.webapp.impl.metadata.assertion.AssertableProxyMethod;
+import org.apache.myfaces.test.webapp.impl.metadata.assertion.AssertableValue;
+import org.apache.myfaces.test.webapp.impl.metadata.assertion.TestAssertExpectCall;
+import org.objectweb.asm.Type;
+
+import javax.el.ExpressionFactory;
+import javax.el.MethodExpression;
+import javax.el.MethodInfo;
+import javax.faces.application.Application;
+import javax.faces.component.UICommand;
+import javax.faces.context.FacesContext;
+import javax.faces.event.AbortProcessingException;
+import javax.faces.event.ActionEvent;
+import javax.faces.event.ActionListener;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Cosmin Martinconi, 12.08.2010
+ */
+public class ActionListenerWrapper implements ActionListener {
+
+ private List<TestAssertExpectCall> expectCall;
+ private Application application;
+
+ public ActionListenerWrapper(Application application) {
+ this.application = application;
+ expectCall = new ArrayList<TestAssertExpectCall>();
+ }
+
+ public void processAction(ActionEvent actionEvent) throws AbortProcessingException {
+ getWrapped().processAction(actionEvent);
+
+ for (TestAssertExpectCall taec : expectCall) {
+ if (validateCallExpected(actionEvent, taec.getAssertableValue()))
+ taec.setCalled(true);
+ }
+ }
+
+ private boolean validateCallExpected(ActionEvent actionEvent, AssertableValue assertableValue) {
+
+ if ((assertableValue == null) || !(actionEvent.getSource() instanceof UICommand))
+ return false;
+
+ MethodExpression methExpr = ((UICommand) actionEvent.getSource()).getActionExpression();
+ FacesContext fc = FacesContext.getCurrentInstance();
+
+ if (assertableValue instanceof AssertableELExpression) {
+ AssertableELExpression elValue = (AssertableELExpression)assertableValue;
+ ExpressionFactory exprFactory = fc.getApplication().getExpressionFactory();
+ MethodExpression valueExpr = exprFactory.createMethodExpression(fc.getELContext(), elValue.getElValue(), null, new Class<?>[]{});
+
+ return methExpr.equals(valueExpr);
+ }
+
+ if (assertableValue instanceof AssertableProxyMethod) {
+ AssertableProxyMethod methodValue = (AssertableProxyMethod)assertableValue;
+ Signature sig = methodValue.getMethodProxy().getSignature();
+ String beanName = AnnotationManager.getCurrentInstance().getBeanName(methodValue.getMethodObj().getClass().getSuperclass());
+
+ MethodInfo methInfo = methExpr.getMethodInfo(fc.getELContext());
+
+ return methExpr.getExpressionString().matches("#\\{" + beanName + "\\..*}") &&
+ methInfo.getName().equals(sig.getName()) &&
+ Type.getType(methInfo.getReturnType()).equals(sig.getReturnType());
+ }
+
+ return false;
+ }
+
+
+ private ActionListener getWrapped() {
+ return application.getActionListener();
+ }
+
+ public void addExpectCall(TestAssertExpectCall eCall) {
+ this.expectCall.add(eCall);
+ }
+
+ public void removeExpectCall(TestAssertExpectCall eCall) {
+ expectCall.remove(eCall);
+ }
+}
Added: myfaces/gsoc/webapptest/impl/src/main/java/org/apache/myfaces/test/webapp/impl/AnnotationManager.java
URL: http://svn.apache.org/viewvc/myfaces/gsoc/webapptest/impl/src/main/java/org/apache/myfaces/test/webapp/impl/AnnotationManager.java?rev=993292&view=auto
==============================================================================
--- myfaces/gsoc/webapptest/impl/src/main/java/org/apache/myfaces/test/webapp/impl/AnnotationManager.java (added)
+++ myfaces/gsoc/webapptest/impl/src/main/java/org/apache/myfaces/test/webapp/impl/AnnotationManager.java Tue Sep 7 09:02:52 2010
@@ -0,0 +1,154 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.test.webapp.impl;
+
+import org.apache.myfaces.test.webapp.api.ResourceFinder;
+import org.apache.myfaces.test.webapp.api.annotation.*;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * This is the manager class for all annotations present in the Test Case.
+ *
+ * @author Cosmin Martinconi, 28.06.2010
+ */
+public class AnnotationManager {
+
+ private Class<?> testClass;
+
+ private Configuration conf;
+ private List<ConfigurationTestSuite> confTSList;
+ private View view;
+ private Field testerField;
+ private List<Field> assertFieldList;
+
+ public void initializeAnnotations() {
+ confTSList = new ArrayList<ConfigurationTestSuite>();
+ assertFieldList = new ArrayList<Field>();
+
+ do {
+ // View annotation
+ View testView = testClass.getAnnotation(View.class);
+ if (testView != null) {
+ view = testView;
+ }
+
+ // Configuration annotation
+ Configuration testConf = testClass.getAnnotation(Configuration.class);
+ if (testConf != null) {
+ conf = testConf;
+ }
+
+ // single Configuration Test Suite
+ ConfigurationTestSuite confTS = testClass.getAnnotation(ConfigurationTestSuite.class);
+ if (confTS != null) {
+ confTSList.add(confTS);
+ }
+
+ // aggregated Configuration Test Suite
+ ConfigurationTestSuite.List configTSList = testClass.getAnnotation(ConfigurationTestSuite.List.class);
+ if (configTSList != null) {
+ confTSList.addAll(Arrays.asList(configTSList.value()));
+ }
+
+ // Assertable fields and Webapp Tester annotattion
+ for(Field field: testClass.getDeclaredFields()) {
+ if(field.isAnnotationPresent(Assertable.class)) {
+ assertFieldList.add(field);
+ }
+
+ if(field.isAnnotationPresent(Tester.class)) {
+ if (testerField==null){
+ testerField = field;
+ }else {
+ throw new IllegalArgumentException("More then one field annotated with " + Tester.class.getName() + " found");
+ }
+ }
+ }
+
+ if (testerField == null) {
+ throw new IllegalArgumentException("No field annotated with " + Tester.class.getName() + " found");
+ }
+
+ if (!Modifier.isStatic(testerField.getModifiers())) {
+ throw new IllegalArgumentException("Field annotated with " + Tester.class.getName() + " is not static");
+ }
+
+ if (!testerField.getType().isAssignableFrom(WebappTesterImpl.class)) {
+ throw new IllegalArgumentException("Field annotated with " + Tester.class.getName() + " must be assignable from " + WebappTesterImpl.class.getName());
+ }
+
+ }
+ while ((testClass = testClass.getSuperclass()) != Object.class);
+
+ }
+
+
+ public static AnnotationManager getCurrentInstance() {
+ return (AnnotationManager) ResourceFinder.getResource(AnnotationManager.class.getName());
+ }
+
+
+ public String getBeanName(Class beanClass) {
+
+ for (PageBean pb : getPageBeans()) {
+ if (pb.clazz().equals(beanClass))
+ if (pb.name().equals("")) {
+ String beanName = beanClass.getSimpleName();
+ return Character.toLowerCase(beanName.charAt(0)) + beanName.substring(1);
+ } else {
+ return pb.name();
+ }
+ }
+
+ throw new IllegalArgumentException("No " + beanClass.getName() + " managed bean configured!");
+ }
+
+ public Configuration getConfigurations() {
+ return conf;
+ }
+
+ public List<ConfigurationTestSuite> getConfTestSuite() {
+ return confTSList;
+ }
+
+ public View getView() {
+ return view;
+ }
+
+ public PageBean[] getPageBeans() {
+ return getView().pageBeans();
+ }
+
+ public Field getTesterField() {
+ return testerField;
+ }
+
+ public List<Field> getAssertFieldList() {
+ return assertFieldList;
+ }
+
+ public void setTestClass(Class<?> testClass) {
+ this.testClass = testClass;
+ }
+}
Added: myfaces/gsoc/webapptest/impl/src/main/java/org/apache/myfaces/test/webapp/impl/ArchiveManager.java
URL: http://svn.apache.org/viewvc/myfaces/gsoc/webapptest/impl/src/main/java/org/apache/myfaces/test/webapp/impl/ArchiveManager.java?rev=993292&view=auto
==============================================================================
--- myfaces/gsoc/webapptest/impl/src/main/java/org/apache/myfaces/test/webapp/impl/ArchiveManager.java (added)
+++ myfaces/gsoc/webapptest/impl/src/main/java/org/apache/myfaces/test/webapp/impl/ArchiveManager.java Tue Sep 7 09:02:52 2010
@@ -0,0 +1,170 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.test.webapp.impl;
+
+import org.apache.myfaces.test.webapp.api.ResourceFinder;
+import org.apache.myfaces.test.webapp.api.annotation.*;
+import org.apache.myfaces.test.webapp.api.dependencies.WebappConfiguration;
+import org.apache.myfaces.test.webapp.impl.dependencies.HtmlUnitDependency;
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.ByteArrayAsset;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * This is the manager class for creating, adding and editing archives
+ * required for the test case to run. A WebArchive is created and then
+ * deployed on the server using ShrinkWrap.
+ *
+ * @author Cosmin Martinconi, 03.07.2010
+ */
+public class ArchiveManager {
+
+ private static final String LOCAL_MAVEN_REPO = System.getProperty("user.home") + File.separatorChar +
+ ".m2" + File.separatorChar + "repository";
+
+ private WebArchive testArchive;
+ private List<Class> suiteConfigClasses;
+
+
+ public void createArchive(Archive<?> applicationArchive, String archiveName) {
+
+ WebArchive finalArchive;
+ String warArchiveName = archiveName + ".war";
+
+ if (WebArchive.class.isInstance(applicationArchive)) {
+ throw new IllegalArgumentException(WebArchive.class.getName() + " type of "
+ + applicationArchive.getName() + " instance is not allowed.");
+ } else if (JavaArchive.class.isInstance(applicationArchive)) {
+ finalArchive = ShrinkWrap.create(WebArchive.class, warArchiveName);
+ finalArchive.addLibrary(applicationArchive);
+ } else {
+ finalArchive = ShrinkWrap.create(WebArchive.class, warArchiveName);
+ }
+
+ // TODO EnterpriseArchive support
+ /*if (EnterpriseArchive.class.isInstance(applicationArchive)) {
+ return handleArchive(EnterpriseArchive.class.cast(applicationArchive));
+ }*/
+
+ finalArchive = addDefaultDependencies(finalArchive);
+ finalArchive = addHtmlUnitDependencies(finalArchive);
+ finalArchive = addAnnotatedDependencies(finalArchive);
+
+ this.testArchive = finalArchive;
+ }
+
+ public void initializeTestSuiteArchive() {
+ suiteConfigClasses = new ArrayList<Class>();
+
+ for (ConfigurationTestSuite cts : AnnotationManager.getCurrentInstance().getConfTestSuite()) {
+ if (cts.configName().equals("all")) {
+ suiteConfigClasses.addAll(Arrays.asList(cts.value()));
+ break;
+ }
+ }
+ }
+
+ public static ArchiveManager getCurrentInstance() {
+ return (ArchiveManager) ResourceFinder.getResource(ArchiveManager.class.getName());
+ }
+
+ private WebArchive addDefaultDependencies(WebArchive archive) {
+ archive.addPackages(true,
+ View.class.getPackage(),
+ WebappConfiguration.class.getPackage(),
+ Package.getPackage("org.apache.myfaces.test.webapp.impl"));
+
+ return archive;
+ }
+
+ private WebArchive addHtmlUnitDependencies(WebArchive archive) {
+ File[] htmlUnitArtifacts = resolveConfigurationArtifacts(HtmlUnitDependency.class);
+ archive.addLibraries(htmlUnitArtifacts);
+
+ return archive;
+ }
+
+ private WebArchive addAnnotatedDependencies(WebArchive archive) {
+
+ AnnotationManager annotationManager = AnnotationManager.getCurrentInstance();
+
+ Configuration c = annotationManager.getConfigurations();
+ if (c != null) {
+ archive.addLibraries(resolveConfigurationArtifacts(c.value()));
+ }
+
+ if (annotationManager.getView().id() != null)
+ archive.addResource(annotationManager.getView().id());
+ if (annotationManager.getView().pageBeans() != null)
+ for (PageBean pb : annotationManager.getView().pageBeans())
+ archive.addClass(pb.clazz());
+
+ if (annotationManager.getView() != null) {
+ archive.setWebXML("WEB-INF/web.xml");
+ archive.setManifest("META-INF/MANIFEST.MF");
+ archive.addWebResource("WEB-INF/faces-config.xml", "faces-config.xml");
+
+ archive.addWebResource(new ByteArrayAsset(new byte[0]), "beans.xml");
+ }
+
+ return archive;
+ }
+
+ private File[] resolveConfigurationArtifacts(Class<? extends WebappConfiguration> configClass) {
+
+ List<File> artifactFiles = new ArrayList<File>();
+
+ for (WebappConfiguration w : configClass.getEnumConstants()) {
+
+ artifactFiles.add(new File(LOCAL_MAVEN_REPO + File.separatorChar +
+ w.getGroupId().replace(".", File.separator) + File.separatorChar +
+ w.getArtifactId() + File.separatorChar +
+ w.getVersion() + File.separatorChar +
+ w.getArtifactId() + "-" + w.getVersion() + ".jar"));
+ }
+
+ return artifactFiles.toArray(new File[artifactFiles.size()]);
+ }
+
+ public WebArchive getTestSuiteArchive() {
+ WebArchive suiteConfArchive = getTestArchive();
+ File[] firstSuiteArtifacts = resolveConfigurationArtifacts(suiteConfigClasses.get(0));
+
+ suiteConfArchive.addLibraries(firstSuiteArtifacts);
+ suiteConfigClasses.remove(0);
+
+ return suiteConfArchive;
+ }
+
+ public WebArchive getTestArchive() {
+ return testArchive;
+ }
+
+ public boolean isTestSuiteConfig() {
+ return suiteConfigClasses.size() != 0;
+ }
+
+}