cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bimargul...@apache.org
Subject svn commit: r593955 - in /incubator/cxf/trunk/rt: core/src/main/java/org/apache/cxf/test/ javascript/src/test/java/org/apache/cxf/javascript/service/ javascript/src/test/java/org/apache/cxf/javascript/types/
Date Sun, 11 Nov 2007 20:54:37 GMT
Author: bimargulies
Date: Sun Nov 11 12:54:36 2007
New Revision: 593955

URL: http://svn.apache.org/viewvc?rev=593955&view=rev
Log:
AbstractDependencyInjectingBlahBlah, on the one hand, introduces
annoying JUnit 3 behavior, and on the other hand exists to provide a
feature of dubious use: injecting dependencies \into the test/. 

Add a new test Abstract class that provides a more declarative
mechanism for building tests that are wired with Spring, and which
avoids this JUnit 3 confusion. And use it for the Javascript tests.



Added:
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/test/AbstractCXFSpringTest.java
Modified:
    incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/service/DocLitWrappedTest.java
    incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/types/SerializationTest.java

Added: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/test/AbstractCXFSpringTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/test/AbstractCXFSpringTest.java?rev=593955&view=auto
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/test/AbstractCXFSpringTest.java
(added)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/test/AbstractCXFSpringTest.java
Sun Nov 11 12:54:36 2007
@@ -0,0 +1,74 @@
+/**
+ * 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.cxf.test;
+
+import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.support.GenericApplicationContext;
+import org.springframework.core.io.DefaultResourceLoader;
+import org.springframework.core.io.Resource;
+
+/**
+ * Base class for tests that use a Spring bean specification to load up components for testing.
+ * Unlike the classes that come with Spring, it doesn't drag in the JUnit 3 hierarchy, and
it 
+ * doesn't inject into the test itself from the beans.
+ */
+public abstract class AbstractCXFSpringTest extends AbstractCXFTest {
+    
+    private GenericApplicationContext applicationContext;
+    private DefaultResourceLoader resourceLoader;
+
+    /**
+     * Load up all the beans from the XML files returned by the getConfigLocations method.
+     */
+    protected AbstractCXFSpringTest() {
+        applicationContext = new GenericApplicationContext();
+        resourceLoader = new DefaultResourceLoader(getClass().getClassLoader());
+        for (String beanDefinitionPath : getConfigLocations()) {
+            XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(applicationContext);
+            Resource resource = resourceLoader.getResource(beanDefinitionPath);
+            reader.loadBeanDefinitions(resource);
+        }
+        applicationContext.refresh();
+    }
+    
+    /**
+     * Return an array of resource specifications. 
+     * @see org.springframework.core.io.DefaultResourceLoader for the syntax.
+     * @return array of resource specifications.
+     */
+    protected abstract String[] getConfigLocations();
+
+    protected ApplicationContext getApplicationContext() {
+        return applicationContext;
+    }
+    
+    /**
+     * Convenience method for the common case of retrieving a bean from the context.
+     * One would expect Spring to have this. 
+     * @param <T> Type of the bean object.
+     * @param type Type of the bean object.
+     * @param beanName ID of the bean.
+     * @return The Bean.
+     */
+    protected <T> T getBean(Class<T> type, String beanName) {
+        return type.cast(applicationContext.getBean(beanName));
+    }
+}

Modified: incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/service/DocLitWrappedTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/service/DocLitWrappedTest.java?rev=593955&r1=593954&r2=593955&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/service/DocLitWrappedTest.java
(original)
+++ incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/service/DocLitWrappedTest.java
Sun Nov 11 12:54:36 2007
@@ -43,13 +43,12 @@
 import org.apache.cxf.service.model.MessagePartInfo;
 import org.apache.cxf.service.model.SchemaInfo;
 import org.apache.cxf.service.model.ServiceInfo;
+import org.apache.cxf.test.AbstractCXFSpringTest;
 import org.junit.Ignore;
 import org.junit.Test;
 import org.mozilla.javascript.Scriptable;
-import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
 
-@Ignore
-public class DocLitWrappedTest extends AbstractDependencyInjectionSpringContextTests {
+public class DocLitWrappedTest extends AbstractCXFSpringTest {
     private static final Logger LOG = LogUtils.getL7dLogger(DocLitWrappedTest.class);
     private static final String BASIC_TYPE_FUNCTION_RETURN_STRING_SERIALIZER_NAME 
         = "org_apache_cxf_javascript_fortest_basicTypeFunctionReturnString_serializeInput";
@@ -73,6 +72,7 @@
         return new String[] {"classpath:serializationTestBeans.xml"};
     }
 
+    @Ignore
     @Test 
     public void testMessageSerialization() throws Exception {
         setupClientAndRhino("simple-dlwu-proxy-factory");
@@ -118,12 +118,12 @@
     }
 
     private void setupClientAndRhino(String clientProxyFactoryBeanId) throws IOException
{
-        testUtilities.setBus((Bus)applicationContext.getBean("cxf"));
+        testUtilities.setBus(getBean(Bus.class, "cxf"));
         
         testUtilities.initializeRhino();
         testUtilities.readResourceIntoRhino("/org/apache/cxf/javascript/cxf-utils.js");
 
-        clientProxyFactory = (JaxWsProxyFactoryBean)applicationContext.getBean(clientProxyFactoryBeanId);
+        clientProxyFactory = getBean(JaxWsProxyFactoryBean.class, clientProxyFactoryBeanId);
         client = clientProxyFactory.getClientFactoryBean().create();
         serviceInfos = client.getEndpoint().getService().getServiceInfos();
         // there can only be one.

Modified: incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/types/SerializationTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/types/SerializationTest.java?rev=593955&r1=593954&r2=593955&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/types/SerializationTest.java
(original)
+++ incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/types/SerializationTest.java
Sun Nov 11 12:54:36 2007
@@ -44,11 +44,11 @@
 import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
 import org.apache.cxf.service.model.SchemaInfo;
 import org.apache.cxf.service.model.ServiceInfo;
+import org.apache.cxf.test.AbstractCXFSpringTest;
 import org.apache.cxf.wsdl.EndpointReferenceUtils;
 import org.junit.Test;
-import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
 
-public class SerializationTest extends AbstractDependencyInjectionSpringContextTests {
+public class SerializationTest extends AbstractCXFSpringTest {
     private JavascriptTestUtilities testUtilities;
     private XMLInputFactory xmlInputFactory;
     private XMLOutputFactory xmlOutputFactory;
@@ -179,12 +179,12 @@
     }
 
     private void setupClientAndRhino(String clientProxyFactoryBeanId) throws IOException
{
-        testUtilities.setBus((Bus)applicationContext.getBean("cxf"));
+        testUtilities.setBus(getBean(Bus.class, "cxf"));
 
         testUtilities.initializeRhino();
         testUtilities.readResourceIntoRhino("/org/apache/cxf/javascript/cxf-utils.js");
 
-        clientProxyFactory = (JaxWsProxyFactoryBean)applicationContext.getBean(clientProxyFactoryBeanId);
+        clientProxyFactory = getBean(JaxWsProxyFactoryBean.class, clientProxyFactoryBeanId);
         client = clientProxyFactory.getClientFactoryBean().create();
         serviceInfos = client.getEndpoint().getService().getServiceInfos();
         // there can only be one.



Mime
View raw message