You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2014/02/11 04:57:03 UTC
svn commit: r1566980 - in
/myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/mc/test/core:
annotation/SetupWebConfigParams.java runner/AbstractJsfTestContainer.java
runner/MyFacesTestRunner.java
Author: lu4242
Date: Tue Feb 11 03:57:03 2014
New Revision: 1566980
URL: http://svn.apache.org/r1566980
Log:
add @SetupWebConfigParams annotation
Added:
myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/mc/test/core/annotation/SetupWebConfigParams.java (with props)
Modified:
myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/mc/test/core/runner/AbstractJsfTestContainer.java
myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/mc/test/core/runner/MyFacesTestRunner.java
Added: myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/mc/test/core/annotation/SetupWebConfigParams.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/mc/test/core/annotation/SetupWebConfigParams.java?rev=1566980&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/mc/test/core/annotation/SetupWebConfigParams.java (added)
+++ myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/mc/test/core/annotation/SetupWebConfigParams.java Tue Feb 11 03:57:03 2014
@@ -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.mc.test.core.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ *
+ */
+@Retention(value = RetentionPolicy.RUNTIME)
+@Target(value =
+{
+ ElementType.METHOD
+})
+public @interface SetupWebConfigParams
+{
+
+}
Propchange: myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/mc/test/core/annotation/SetupWebConfigParams.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/mc/test/core/runner/AbstractJsfTestContainer.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/mc/test/core/runner/AbstractJsfTestContainer.java?rev=1566980&r1=1566979&r2=1566980&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/mc/test/core/runner/AbstractJsfTestContainer.java (original)
+++ myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/mc/test/core/runner/AbstractJsfTestContainer.java Tue Feb 11 03:57:03 2014
@@ -70,6 +70,7 @@ import org.apache.myfaces.mc.test.core.a
import org.apache.myfaces.mc.test.core.annotation.ManagedBeans;
import org.apache.myfaces.mc.test.core.annotation.TestConfig;
import org.apache.myfaces.mc.test.core.annotation.PageBean;
+import org.apache.myfaces.mc.test.core.annotation.SetupWebConfigParams;
import org.apache.myfaces.mc.test.core.annotation.TestServletListeners;
import org.apache.myfaces.shared.config.MyfacesConfig;
import org.apache.myfaces.shared.util.ClassUtils;
@@ -87,6 +88,7 @@ import org.apache.myfaces.util.ExternalS
import org.apache.myfaces.webapp.AbstractFacesInitializer;
import org.apache.myfaces.webapp.FacesInitializer;
import org.apache.myfaces.webapp.StartupServletContextListener;
+import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.TestClass;
import org.xml.sax.SAXException;
@@ -220,6 +222,22 @@ public class AbstractJsfTestContainer
servletContext.addInitParameter("org.apache.myfaces.annotation.SCAN_PACKAGES",
"org.apache.myfaces.application.contracts");
}
+
+ List<FrameworkMethod> setupWebConfigParamMethods = testClass.getAnnotatedMethods(SetupWebConfigParams.class);
+ if (setupWebConfigParamMethods != null && !setupWebConfigParamMethods.isEmpty())
+ {
+ for (FrameworkMethod fm : setupWebConfigParamMethods)
+ {
+ try
+ {
+ fm.invokeExplosively(testInstance);
+ }
+ catch (Throwable ex)
+ {
+ throw new FacesException(ex);
+ }
+ }
+ }
}
/**
Modified: myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/mc/test/core/runner/MyFacesTestRunner.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/mc/test/core/runner/MyFacesTestRunner.java?rev=1566980&r1=1566979&r2=1566980&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/mc/test/core/runner/MyFacesTestRunner.java (original)
+++ myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/mc/test/core/runner/MyFacesTestRunner.java Tue Feb 11 03:57:03 2014
@@ -78,6 +78,21 @@ public class MyFacesTestRunner extends B
{
MyFacesContainer currentTestContext = new MyFacesContainer(testClass);
+ //Inject MyFacesContainer using @TestContainer
+ List<FrameworkField> fields = testClass.getAnnotatedFields(TestContainer.class);
+ if (fields != null && !fields.isEmpty())
+ {
+ for (FrameworkField field : fields)
+ {
+ Field f = field.getField();
+ if (f.getType().equals(MyFacesContainer.class))
+ {
+ f.setAccessible(true);
+ f.set(originalTarget, currentTestContext);
+ }
+ }
+ }
+
currentTestContext.setUp(this.originalTarget);
FacesContext facesContext = null;
@@ -96,25 +111,6 @@ public class MyFacesTestRunner extends B
if (injectionProvider != null)
{
testCaseCreationMetadata = injectionProvider.inject(originalTarget);
- }
-
- //Inject MyFacesContainer using @TestContainer
- List<FrameworkField> fields = testClass.getAnnotatedFields(TestContainer.class);
- if (fields != null && !fields.isEmpty())
- {
- for (FrameworkField field : fields)
- {
- Field f = field.getField();
- if (f.getType().equals(MyFacesContainer.class))
- {
- f.setAccessible(true);
- f.set(originalTarget, currentTestContext);
- }
- }
- }
-
- if (injectionProvider != null)
- {
injectionProvider.postConstruct(originalTarget, testCaseCreationMetadata);
}
}