cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bimargul...@apache.org
Subject svn commit: r809421 - in /cxf/trunk: parent/ rt/core/ rt/testsupport/src/main/java/org/apache/cxf/test/
Date Sun, 30 Aug 2009 21:40:13 GMT
Author: bimargulies
Date: Sun Aug 30 21:40:12 2009
New Revision: 809421

URL: http://svn.apache.org/viewvc?rev=809421&view=rev
Log:
Try to resolve build problems. Never again forget to delete my maven repo and run a build
after rearranging things.

Added:
    cxf/trunk/rt/testsupport/src/main/java/org/apache/cxf/test/
    cxf/trunk/rt/testsupport/src/main/java/org/apache/cxf/test/AbstractCXFSpringTest.java
  (with props)
    cxf/trunk/rt/testsupport/src/main/java/org/apache/cxf/test/AbstractCXFTest.java   (with
props)
    cxf/trunk/rt/testsupport/src/main/java/org/apache/cxf/test/XPathAssert.java   (with props)
Modified:
    cxf/trunk/parent/pom.xml
    cxf/trunk/rt/core/pom.xml

Modified: cxf/trunk/parent/pom.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/parent/pom.xml?rev=809421&r1=809420&r2=809421&view=diff
==============================================================================
--- cxf/trunk/parent/pom.xml (original)
+++ cxf/trunk/parent/pom.xml Sun Aug 30 21:40:12 2009
@@ -1195,7 +1195,7 @@
         <profile>
             <id>fastinstall</id>
             <properties>
-                <maven.test.skip>true</maven.test.skip>
+                <maven.test.skip.exec>true</maven.test.skip.exec>
                 <pmd.skip>true</pmd.skip>
                 <checkstyle.skip>true</checkstyle.skip>
             </properties>

Modified: cxf/trunk/rt/core/pom.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/pom.xml?rev=809421&r1=809420&r2=809421&view=diff
==============================================================================
--- cxf/trunk/rt/core/pom.xml (original)
+++ cxf/trunk/rt/core/pom.xml Sun Aug 30 21:40:12 2009
@@ -39,6 +39,7 @@
                 <executions>
                     <execution>
                         <id>create-test-jar</id>
+                        <phase>install</phase>
                         <goals>
                             <goal>test-jar</goal>
                         </goals>

Added: cxf/trunk/rt/testsupport/src/main/java/org/apache/cxf/test/AbstractCXFSpringTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/testsupport/src/main/java/org/apache/cxf/test/AbstractCXFSpringTest.java?rev=809421&view=auto
==============================================================================
--- cxf/trunk/rt/testsupport/src/main/java/org/apache/cxf/test/AbstractCXFSpringTest.java
(added)
+++ cxf/trunk/rt/testsupport/src/main/java/org/apache/cxf/test/AbstractCXFSpringTest.java
Sun Aug 30 21:40:12 2009
@@ -0,0 +1,118 @@
+/**
+ * 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.apache.cxf.Bus;
+import org.apache.cxf.BusException;
+import org.junit.After;
+import org.junit.Before;
+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 {
+    // subvert JUnit. We want to set up the application context ONCE, since it
+    // is likely to include a Jetty or something else that we can't get rid of.
+    private static GenericApplicationContext applicationContext;
+    private DefaultResourceLoader resourceLoader;
+    private Class<?> configContextClass = AbstractCXFSpringTest.class;
+    /**
+     * Load up all the beans from the XML files returned by the getConfigLocations method.
+     * @throws Exception 
+     */
+    protected AbstractCXFSpringTest() {
+    }
+    
+    @Before
+    public void setupBeans() throws Exception {
+        if (applicationContext != null) {
+            return;
+        }
+        applicationContext = new GenericApplicationContext();
+        resourceLoader = new DefaultResourceLoader(configContextClass.getClassLoader());
+        for (String beanDefinitionPath : getConfigLocations()) {
+            XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(applicationContext);
+            Resource resource = resourceLoader.getResource(beanDefinitionPath);
+            reader.loadBeanDefinitions(resource);
+        }
+        additionalSpringConfiguration(applicationContext);
+        applicationContext.refresh();
+        super.setUpBus();
+    }
+    
+    @Before
+    public void setUpBus() throws Exception {
+        // override the super before method
+    }
+    
+    public Bus createBus() throws BusException {        
+        return getBean(Bus.class, "cxf");
+    }
+    
+    @After
+    public void teardownBeans() {
+        applicationContext.close();
+        applicationContext.destroy();
+        applicationContext = null;
+    }
+    
+    /**
+     * 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;
+    }
+    
+    /**
+     * subclasses may override this.
+     * @param context
+     * @throws Exception 
+     */
+    protected void additionalSpringConfiguration(GenericApplicationContext context) throws
Exception {
+        //default - do nothing
+    }
+
+    /**
+     * 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));
+    }
+
+    protected void setConfigContextClass(Class<?> configContextClass) {
+        this.configContextClass = configContextClass;
+    }
+}

Propchange: cxf/trunk/rt/testsupport/src/main/java/org/apache/cxf/test/AbstractCXFSpringTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cxf/trunk/rt/testsupport/src/main/java/org/apache/cxf/test/AbstractCXFTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/testsupport/src/main/java/org/apache/cxf/test/AbstractCXFTest.java?rev=809421&view=auto
==============================================================================
--- cxf/trunk/rt/testsupport/src/main/java/org/apache/cxf/test/AbstractCXFTest.java (added)
+++ cxf/trunk/rt/testsupport/src/main/java/org/apache/cxf/test/AbstractCXFTest.java Sun Aug
30 21:40:12 2009
@@ -0,0 +1,197 @@
+/**
+ * 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 java.io.File;
+import java.io.InputStream;
+import java.io.Reader;
+import java.util.Map;
+
+import javax.wsdl.WSDLException;
+import javax.xml.namespace.NamespaceContext;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.BusException;
+import org.apache.cxf.BusFactory;
+import org.apache.cxf.endpoint.Server;
+import org.apache.cxf.helpers.MapNamespaceContext;
+
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+
+
+/**
+ * A basic test case meant for helping users unit test their services.
+ * @see TestUtilities
+ */
+@org.junit.Ignore
+public class AbstractCXFTest extends Assert {
+    
+    protected TestUtilities testUtilities;
+    protected Bus bus;
+    
+    protected AbstractCXFTest() {
+        testUtilities = new TestUtilities(getClass());
+        testUtilities.addDefaultNamespaces();
+    }
+    
+    @Before
+    public void setUpBus() throws Exception {
+        if (bus == null) {
+            bus = createBus();
+            testUtilities.setBus(bus);
+        }
+    }
+    
+    public Bus getBus() {
+        return bus;
+    }
+    
+    @After
+    public void shutdownBus() {       
+        if (bus != null) {
+            bus.shutdown(false);
+            bus = null;
+        } 
+        BusFactory.setDefaultBus(null);
+    }
+
+
+    protected Bus createBus() throws BusException {
+        return BusFactory.newInstance().createBus();
+    }
+
+    protected byte[] invokeBytes(String address, 
+                                 String transport,
+                                 String message) throws Exception {
+        return testUtilities.invokeBytes(address, transport, message);
+    }
+    
+    protected Node invoke(String address, 
+                          String transport,
+                          String message) throws Exception {
+        return testUtilities.invoke(address, transport, message);
+    }
+
+    protected Node invoke(String address, 
+                          String transport,
+                          byte[] message) throws Exception {
+        return testUtilities.invoke(address, transport, message);
+    }
+
+    /**
+     * Assert that the following XPath query selects one or more nodes.
+     * 
+     * @param xpath
+     * @throws Exception 
+     */
+    public NodeList assertValid(String xpath, Node node) throws Exception {
+        return testUtilities.assertValid(xpath, node);
+    }
+
+    /**
+     * Assert that the following XPath query selects a boolean value.
+     * 
+     * @param xpath
+     * @throws Exception 
+     */
+    public void assertValidBoolean(String xpath, Node node) throws Exception {
+        testUtilities.assertValidBoolean(xpath, node);
+    }
+    /**
+     * Assert that the following XPath query selects no nodes.
+     * 
+     * @param xpath
+     */
+    public NodeList assertInvalid(String xpath, Node node) throws Exception {
+        return testUtilities.assertInvalid(xpath, node);
+    }
+
+    /**
+     * Assert that the text of the xpath node retrieved is equal to the value
+     * specified.
+     * 
+     * @param xpath
+     * @param value
+     * @param node
+     */
+    public void assertXPathEquals(String xpath, String value, Node node) throws Exception
{
+        testUtilities.assertXPathEquals(xpath, value, node);
+    }
+
+    /**
+     * Assert that this node is not a SOAP fault part.
+     * @param node
+     * @throws Exception
+     */
+    public void assertNoFault(Node node) throws Exception {
+        testUtilities.assertNoFault(node);
+    }
+    
+    /**
+     * Add a namespace that will be used for XPath expressions.
+     * 
+     * @param ns Namespace name.
+     * @param uri The namespace uri.
+     */
+    public void addNamespace(String ns, String uri) {
+        testUtilities.addNamespace(ns, uri);
+    }
+    
+    public NamespaceContext getNamespaceContext() {
+        return new MapNamespaceContext(testUtilities.getNamespaces());
+    }
+
+    public Map<String, String> getNamespaces() {
+        return testUtilities.getNamespaces();
+    }
+
+    protected InputStream getResourceAsStream(String resource) {
+        return testUtilities.getResourceAsStream(resource);
+    }
+
+    protected Reader getResourceAsReader(String resource) {
+        return testUtilities.getResourceAsReader(resource);
+    }
+
+    public File getTestFile(String relativePath) {
+        return testUtilities.getTestFile(relativePath);
+    }
+
+    public static String getBasedir() {
+        return TestUtilities.getBasedir();
+    }
+
+    protected Document getWSDLDocument(Server server) throws WSDLException {
+        return testUtilities.getWSDLDocument(server);
+    }
+    
+    public static class TestMessageObserver extends TestUtilities.TestMessageObserver {
+
+        public TestMessageObserver() {
+            super();
+        }
+    }
+}

Propchange: cxf/trunk/rt/testsupport/src/main/java/org/apache/cxf/test/AbstractCXFTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cxf/trunk/rt/testsupport/src/main/java/org/apache/cxf/test/XPathAssert.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/testsupport/src/main/java/org/apache/cxf/test/XPathAssert.java?rev=809421&view=auto
==============================================================================
--- cxf/trunk/rt/testsupport/src/main/java/org/apache/cxf/test/XPathAssert.java (added)
+++ cxf/trunk/rt/testsupport/src/main/java/org/apache/cxf/test/XPathAssert.java Sun Aug 30
21:40:12 2009
@@ -0,0 +1,211 @@
+/**
+ * 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 java.io.ByteArrayOutputStream;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.transform.TransformerException;
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathFactory;
+
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+import junit.framework.Assert;
+import junit.framework.AssertionFailedError;
+
+import org.apache.cxf.helpers.DOMUtils;
+
+/**
+ * XPath test assertions.
+ * 
+ * @author <a href="mailto:dan@envoisolutions.com">Dan Diephouse</a>
+ */
+public final class XPathAssert {
+    private XPathAssert() {
+    }
+
+    /**
+     * Assert that the following XPath query selects one or more nodes.
+     * 
+     * @param xpath
+     */
+    public static NodeList assertValid(String xpath, Node node, Map<String, String>
namespaces)
+        throws Exception {
+        if (node == null) {
+            throw new NullPointerException("Node cannot be null.");
+        }
+
+        NodeList nodes = (NodeList)createXPath(namespaces).evaluate(xpath, node, XPathConstants.NODESET);
+
+        if (nodes.getLength() == 0) {
+            throw new AssertionFailedError("Failed to select any nodes for expression:\n"
+ xpath
+                                           + " from document:\n" + writeNodeToString(node));
+        }
+
+        return nodes;
+    }
+    /**
+     * Assert that the following XPath query selects one or more nodes.
+     * 
+     * @param xpath
+     */
+    public static void assertValidBoolean(String xpath, Node node, Map<String, String>
namespaces)
+        throws Exception {
+        if (node == null) {
+            throw new NullPointerException("Node cannot be null.");
+        }
+
+        Boolean b = (Boolean)createXPath(namespaces).evaluate(xpath, node, XPathConstants.BOOLEAN);
+
+        if (b == null) {
+            throw new AssertionFailedError("Failed to select any nodes for expression:\n"
+ xpath
+                                           + " from document:\n" + writeNodeToString(node));
+        }
+        
+        if (!b.booleanValue()) {
+            throw new AssertionFailedError("Boolean XPath assertion evaluated to false:\n"
+                                           + xpath
+                                           + " from document:\n" + writeNodeToString(node));
+        }
+    }
+
+    private static String writeNodeToString(Node node) {
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        try {
+            DOMUtils.writeXml(node, bos);
+        } catch (TransformerException e) {
+            throw new RuntimeException(e);
+        }
+        return bos.toString();
+    }
+
+    /**
+     * Assert that the following XPath query selects no nodes.
+     * 
+     * @param xpath
+     */
+    public static NodeList assertInvalid(String xpath, Node node, Map<String, String>
namespaces)
+        throws Exception {
+        if (node == null) {
+            throw new NullPointerException("Node cannot be null.");
+        }
+
+        NodeList nodes = (NodeList)createXPath(namespaces).evaluate(xpath, node, XPathConstants.NODESET);
+
+        if (nodes.getLength() > 0) {
+            String value = writeNodeToString(node);
+
+            throw new AssertionFailedError("Found multiple nodes for expression:\n" + xpath
+ "\n" + value);
+        }
+
+        return nodes;
+    }
+
+    /**
+     * Asser that the text of the xpath node retrieved is equal to the value
+     * specified.
+     * 
+     * @param xpath
+     * @param value
+     * @param node
+     */
+    public static void assertXPathEquals(String xpath, 
+                                         String value, 
+                                         Node node, 
+                                         Map<String, String> namespaces)
+        throws Exception {
+        Node result = (Node)createXPath(namespaces).evaluate(xpath, node, XPathConstants.NODE);
+        if (result == null) {
+            throw new AssertionFailedError("No nodes were found for expression: " 
+                                           + xpath 
+                                           + " in document " 
+                                           + writeNodeToString(node));
+        }
+
+        String value2 = DOMUtils.getContent(result);
+
+        Assert.assertEquals(value, value2);
+    }
+
+    public static void assertNoFault(Node node) throws Exception {
+        Map<String, String> namespaces = new HashMap<String, String>();
+        namespaces.put("s", "http://schemas.xmlsoap.org/soap/envelope/");
+        namespaces.put("s12", "http://www.w3.org/2003/05/soap-envelope");
+
+        assertInvalid("/s:Envelope/s:Body/s:Fault", node, namespaces);
+        assertInvalid("/s12:Envelope/s12:Body/s12:Fault", node, namespaces);
+    }
+
+    public static void assertFault(Node node) throws Exception {
+        Map<String, String> namespaces = new HashMap<String, String>();
+        namespaces.put("s", "http://schemas.xmlsoap.org/soap/envelope/");
+        namespaces.put("s12", "http://www.w3.org/2003/05/soap-envelope");
+
+        assertValid("/s:Envelope/s:Body/s:Fault", node, namespaces);
+        assertValid("/s12:Envelope/s12:Body/s12:Fault", node, namespaces);
+    }
+
+    /**
+     * Create the specified XPath expression with the namespaces added via
+     * addNamespace().
+     */
+    public static XPath createXPath(Map<String, String> namespaces) throws Exception
{
+        XPath xpath = XPathFactory.newInstance().newXPath();
+
+        if (namespaces != null) {
+            xpath.setNamespaceContext(new MapNamespaceContext(namespaces));
+        }
+
+        return xpath;
+    }
+
+    static class MapNamespaceContext implements NamespaceContext {
+        private Map<String, String> namespaces;
+
+        public MapNamespaceContext(Map<String, String> namespaces) {
+            super();
+            this.namespaces = namespaces;
+        }
+
+        public String getNamespaceURI(String prefix) {
+            return namespaces.get(prefix);
+        }
+
+        public String getPrefix(String namespaceURI) {
+            for (Map.Entry<String, String> e : namespaces.entrySet()) {
+                if (e.getValue().equals(namespaceURI)) {
+                    return e.getKey();
+                }
+            }
+            return null;
+        }
+
+        public Iterator getPrefixes(String namespaceURI) {
+            return null;
+        }
+
+    }
+}

Propchange: cxf/trunk/rt/testsupport/src/main/java/org/apache/cxf/test/XPathAssert.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message