servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ff...@apache.org
Subject svn commit: r783184 - in /servicemix/components/engines/servicemix-saxon/trunk: ./ src/test/java/org/apache/servicemix/saxon/ src/test/java/org/apache/servicemix/saxon/packaging/ src/test/java/org/apache/servicemix/saxon/support/ src/test/resources/
Date Wed, 10 Jun 2009 02:46:53 GMT
Author: ffang
Date: Wed Jun 10 02:46:53 2009
New Revision: 783184

URL: http://svn.apache.org/viewvc?rev=783184&view=rev
Log:
[SMXCOMP-552]Improve test coverage - ServiceMix :: Saxon

Added:
    servicemix/components/engines/servicemix-saxon/trunk/src/test/java/org/apache/servicemix/saxon/packaging/
    servicemix/components/engines/servicemix-saxon/trunk/src/test/java/org/apache/servicemix/saxon/packaging/SaxonServiceUnitAnalyzerTest.java
  (with props)
    servicemix/components/engines/servicemix-saxon/trunk/src/test/java/org/apache/servicemix/saxon/support/
    servicemix/components/engines/servicemix-saxon/trunk/src/test/java/org/apache/servicemix/saxon/support/ExchangeTargetTest.java
  (with props)
    servicemix/components/engines/servicemix-saxon/trunk/src/test/resources/parameter-test-query.xq
Modified:
    servicemix/components/engines/servicemix-saxon/trunk/pom.xml
    servicemix/components/engines/servicemix-saxon/trunk/src/test/java/org/apache/servicemix/saxon/SaxonComponentTest.java
    servicemix/components/engines/servicemix-saxon/trunk/src/test/resources/spring.xml

Modified: servicemix/components/engines/servicemix-saxon/trunk/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-saxon/trunk/pom.xml?rev=783184&r1=783183&r2=783184&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-saxon/trunk/pom.xml (original)
+++ servicemix/components/engines/servicemix-saxon/trunk/pom.xml Wed Jun 10 02:46:53 2009
@@ -101,6 +101,11 @@
     </dependency>
     <!-- for unit/integration testing -->
     <dependency>
+      <groupId>org.easymock</groupId>
+      <artifactId>easymock</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
       <groupId>org.apache.servicemix</groupId>
       <artifactId>servicemix-core</artifactId>
       <version>${servicemix-version}</version>
@@ -140,6 +145,18 @@
           </execution>
         </executions>
       </plugin>
+      <!-- exclude generated DefaultBootstrap class from Cobertura reports -->
+      <plugin>
+        <groupId>org.codehaus.mojo</groupId>
+        <artifactId>cobertura-maven-plugin</artifactId>
+        <configuration>
+          <instrumentation>
+            <excludes>
+              <exclude>org/apache/servicemix/common/DefaultBootstrap.class</exclude>
+            </excludes>
+          </instrumentation>
+        </configuration>
+      </plugin>
     </plugins>
   </build>
   <repositories>

Modified: servicemix/components/engines/servicemix-saxon/trunk/src/test/java/org/apache/servicemix/saxon/SaxonComponentTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-saxon/trunk/src/test/java/org/apache/servicemix/saxon/SaxonComponentTest.java?rev=783184&r1=783183&r2=783184&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-saxon/trunk/src/test/java/org/apache/servicemix/saxon/SaxonComponentTest.java
(original)
+++ servicemix/components/engines/servicemix-saxon/trunk/src/test/java/org/apache/servicemix/saxon/SaxonComponentTest.java
Wed Jun 10 02:46:53 2009
@@ -59,6 +59,27 @@
         assertEquals("2005", textValueOfXPath(el, "/transformed/bookstore/book[1]/year"));
         client.done(me);
     }
+    
+    public void testXsltString() throws Exception {
+        DefaultServiceMixClient client = new DefaultServiceMixClient(jbi);
+        InOut me = client.createInOutExchange();
+        me.setService(new QName("urn:test", "xslt-string"));
+        me.getInMessage().setContent(new StreamSource(getClass().getResourceAsStream("/books.xml")));
+        client.sendSync(me);
+        if (me.getStatus() == ExchangeStatus.ERROR) {
+            if (me.getError() != null) {
+                throw me.getError();
+            } else {
+                fail("Received ERROR status");
+            }
+        } else if (me.getFault() != null) {
+            fail("Received fault: " + new SourceTransformer().toString(me.getFault().getContent()));
+        }
+        log.info(transformer.toString(me.getOutMessage().getContent()));
+        Element el = transformer.toDOMElement(me.getOutMessage());
+        assertEquals("2005", textValueOfXPath(el, "/transformed/bookstore/book[1]/year"));
+        client.done(me);
+    }
 
     public void testXsltWithElement() throws Exception {
         DefaultServiceMixClient client = new DefaultServiceMixClient(jbi);
@@ -129,6 +150,26 @@
         assertEquals("cheeseyCheese", textValueOfXPath(el, "//param"));
         assertEquals("4002", textValueOfXPath(el, "//integer"));
     }
+    
+    public void testXQueryWithParam() throws Exception {
+        DefaultServiceMixClient client = new DefaultServiceMixClient(jbi);
+        InOut me = client.createInOutExchange();
+        me.setService(new QName("urn:test", "xquery-params"));
+        me.getInMessage().setContent(new StringSource("<sample id='777888' sent='"
+                + new Date() + "'>hello world!</sample>"));
+        client.sendSync(me);
+        if (me.getStatus() == ExchangeStatus.ERROR) {
+            if (me.getError() != null) {
+                throw me.getError();
+            } else {
+                fail("Received ERROR status");
+            }
+        } else if (me.getFault() != null) {
+            fail("Received fault: " + new SourceTransformer().toString(me.getFault().getContent()));
+        }
+        log.info(transformer.toString(me.getOutMessage().getContent()));
+        client.done(me);
+    }
 
     public void testXsltWithDocCall() throws Exception {
         DefaultServiceMixClient client = new DefaultServiceMixClient(jbi);
@@ -169,6 +210,28 @@
         assertEquals("XQuery Kick Start", textValueOfXPath(el, "/titles/title[1]"));
         client.done(me);
     }
+    
+    public void testXQueryString() throws Exception {
+        DefaultServiceMixClient client = new DefaultServiceMixClient(jbi);
+        InOut me = client.createInOutExchange();
+        me.setService(new QName("urn:test", "xquery-string"));
+        me.getInMessage().setContent(new StreamSource(getClass().getResourceAsStream("/books.xml")));
+        client.sendSync(me);
+        if (me.getStatus() == ExchangeStatus.ERROR) {
+            if (me.getError() != null) {
+                throw me.getError();
+            } else {
+                fail("Received ERROR status");
+            }
+        } else if (me.getFault() != null) {
+            fail("Received fault: " + new SourceTransformer().toString(me.getFault().getContent()));
+        }
+        log.info(transformer.toString(me.getOutMessage().getContent()));
+        Element el = transformer.toDOMElement(me.getOutMessage());
+        assertEquals("XQuery Kick Start", textValueOfXPath(el, "/titles/title[1]"));
+        client.done(me);
+    }
+    
 
     public void testXQueryInline() throws Exception {
         DefaultServiceMixClient client = new DefaultServiceMixClient(jbi);
@@ -238,7 +301,70 @@
         client.done(me);
         assertEquals("skcotSyub", el.getLocalName());
     }
-
+    
+    public void testProxyString() throws Exception {
+        DefaultServiceMixClient client = new DefaultServiceMixClient(jbi);
+        InOut me = client.createInOutExchange();
+        me.setService(new QName("urn:test", "proxy-string"));
+        me.getInMessage().setContent(new StreamSource(getClass().getResourceAsStream("/order.xml")));
+        client.sendSync(me);
+        if (me.getStatus() == ExchangeStatus.ERROR) {
+            if (me.getError() != null) {
+                throw me.getError();
+            } else {
+                fail("Received ERROR status");
+            }
+        } else if (me.getFault() != null) {
+            fail("Received fault: " + new SourceTransformer().toString(me.getFault().getContent()));
+        }
+        log.info(transformer.toString(me.getOutMessage().getContent()));
+        Element el = transformer.toDOMElement(me.getOutMessage());
+        client.done(me);
+        assertEquals("buyStocks", el.getLocalName());
+    }
+    
+    public void testProxyBytes() throws Exception {
+        DefaultServiceMixClient client = new DefaultServiceMixClient(jbi);
+        InOut me = client.createInOutExchange();
+        me.setService(new QName("urn:test", "proxy-bytes"));
+        me.getInMessage().setContent(new StreamSource(getClass().getResourceAsStream("/order.xml")));
+        client.sendSync(me);
+        if (me.getStatus() == ExchangeStatus.ERROR) {
+            if (me.getError() != null) {
+                throw me.getError();
+            } else {
+                fail("Received ERROR status");
+            }
+        } else if (me.getFault() != null) {
+            fail("Received fault: " + new SourceTransformer().toString(me.getFault().getContent()));
+        }
+        log.info(transformer.toString(me.getOutMessage().getContent()));
+        Element el = transformer.toDOMElement(me.getOutMessage());
+        client.done(me);
+        assertEquals("buyStocks", el.getLocalName());
+    }
+    
+    public void testProxyParams() throws Exception {
+        DefaultServiceMixClient client = new DefaultServiceMixClient(jbi);
+        InOut me = client.createInOutExchange();
+        me.setService(new QName("urn:test", "xslt-proxy-params"));
+        me.getInMessage().setContent(new StreamSource(getClass().getResourceAsStream("/order.xml")));
+        client.sendSync(me);
+        if (me.getStatus() == ExchangeStatus.ERROR) {
+            if (me.getError() != null) {
+                throw me.getError();
+            } else {
+                fail("Received ERROR status");
+            }
+        } else if (me.getFault() != null) {
+            fail("Received fault: " + new SourceTransformer().toString(me.getFault().getContent()));
+        }
+        log.info(transformer.toString(me.getOutMessage().getContent()));
+        Element el = transformer.toDOMElement(me.getOutMessage());
+        client.done(me);
+        assertEquals("buyStocks", el.getLocalName());
+    }
+    
     protected AbstractXmlApplicationContext createBeanFactory() {
         return new ClassPathXmlApplicationContext("spring.xml");
     }

Added: servicemix/components/engines/servicemix-saxon/trunk/src/test/java/org/apache/servicemix/saxon/packaging/SaxonServiceUnitAnalyzerTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-saxon/trunk/src/test/java/org/apache/servicemix/saxon/packaging/SaxonServiceUnitAnalyzerTest.java?rev=783184&view=auto
==============================================================================
--- servicemix/components/engines/servicemix-saxon/trunk/src/test/java/org/apache/servicemix/saxon/packaging/SaxonServiceUnitAnalyzerTest.java
(added)
+++ servicemix/components/engines/servicemix-saxon/trunk/src/test/java/org/apache/servicemix/saxon/packaging/SaxonServiceUnitAnalyzerTest.java
Wed Jun 10 02:46:53 2009
@@ -0,0 +1,52 @@
+/*
+ * 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.servicemix.saxon.packaging;
+
+import javax.jbi.JBIException;
+
+import junit.framework.TestCase;
+
+import org.apache.servicemix.saxon.XQueryEndpoint;
+import org.apache.servicemix.saxon.XsltEndpoint;
+import org.apache.servicemix.saxon.XsltProxyEndpoint;
+
+public class SaxonServiceUnitAnalyzerTest extends TestCase {
+
+	private SaxonServiceUnitAnalyzer analyzer;
+
+	@Override
+	protected void setUp() throws Exception {
+		super.setUp();
+		analyzer = new SaxonServiceUnitAnalyzer();
+	}
+
+	public void testGetConsumes() throws JBIException {
+		assertNotNull("Collection should not be null", analyzer.getConsumes(new XsltEndpoint()));
+		assertTrue("Collection should be empty", analyzer.getConsumes().isEmpty());
+	}
+
+	public void testGetXBeanFile() throws Exception {
+		assertEquals("xbean.xml", analyzer.getXBeanFile());
+	}
+
+	public void testIsValidEndpoint() throws Exception {
+		assertTrue(analyzer.isValidEndpoint(new XsltEndpoint()));
+        assertTrue(analyzer.isValidEndpoint(new XQueryEndpoint()));
+		assertTrue(analyzer.isValidEndpoint(new XsltProxyEndpoint()));
+
+	}
+}

Propchange: servicemix/components/engines/servicemix-saxon/trunk/src/test/java/org/apache/servicemix/saxon/packaging/SaxonServiceUnitAnalyzerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: servicemix/components/engines/servicemix-saxon/trunk/src/test/java/org/apache/servicemix/saxon/packaging/SaxonServiceUnitAnalyzerTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: servicemix/components/engines/servicemix-saxon/trunk/src/test/java/org/apache/servicemix/saxon/support/ExchangeTargetTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-saxon/trunk/src/test/java/org/apache/servicemix/saxon/support/ExchangeTargetTest.java?rev=783184&view=auto
==============================================================================
--- servicemix/components/engines/servicemix-saxon/trunk/src/test/java/org/apache/servicemix/saxon/support/ExchangeTargetTest.java
(added)
+++ servicemix/components/engines/servicemix-saxon/trunk/src/test/java/org/apache/servicemix/saxon/support/ExchangeTargetTest.java
Wed Jun 10 02:46:53 2009
@@ -0,0 +1,89 @@
+/*
+ * 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.servicemix.saxon.support;
+
+import javax.jbi.component.ComponentContext;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessagingException;
+import javax.jbi.servicedesc.ServiceEndpoint;
+import javax.xml.namespace.QName;
+
+import junit.framework.TestCase;
+
+import org.apache.servicemix.tck.mock.MockMessageExchange;
+import org.easymock.EasyMock;
+
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+
+public class ExchangeTargetTest extends TestCase {
+    
+    private static final String ENDPOINT = "endpoint";
+    private static final QName INTERFACE = new QName("urn:test", "interface");
+    private static final QName OPERATION = new QName("urn:test", "operation");
+    private static final QName SERVICE = new QName("urn:test", "service");
+    
+    private ExchangeTarget target;
+    
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        target = new ExchangeTarget();
+    }
+  
+    public void testMessagingExceptionWhenNoTargetSet() throws Exception {
+        try {
+            target.afterPropertiesSet();
+            fail("Should have thrown a MessagingException");
+        } catch (MessagingException e) {
+            //this is OK
+        }
+        try {
+            target.configureTarget(null, null);
+            fail("Should have thrown a MessagingException");
+        } catch (MessagingException e) {
+            //this is OK
+        }
+    }
+    
+    public void testInterfaceAndOperation() throws Exception {
+        target.setInterface(INTERFACE);
+        target.setOperation(OPERATION);
+        
+        MessageExchange exchange = new MockMessageExchange();
+        target.configureTarget(exchange, null);
+        assertEquals(INTERFACE, exchange.getInterfaceName());
+        assertEquals(OPERATION, exchange.getOperation());
+    }
+    
+    public void testServiceAndEndpoint() throws Exception {
+        target.setService(SERVICE);
+        target.setEndpoint(ENDPOINT);
+        
+        ComponentContext context = EasyMock.createMock(ComponentContext.class);
+        ServiceEndpoint endpoint = EasyMock.createMock(ServiceEndpoint.class);
+        expect(context.getEndpoint(SERVICE, ENDPOINT)).andReturn(endpoint);
+        replay(context);
+                
+        MessageExchange exchange = new MockMessageExchange();
+        target.configureTarget(exchange, context);
+        assertEquals(SERVICE, exchange.getService());
+        assertEquals(endpoint, exchange.getEndpoint());
+    }
+
+}    
+

Propchange: servicemix/components/engines/servicemix-saxon/trunk/src/test/java/org/apache/servicemix/saxon/support/ExchangeTargetTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: servicemix/components/engines/servicemix-saxon/trunk/src/test/java/org/apache/servicemix/saxon/support/ExchangeTargetTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: servicemix/components/engines/servicemix-saxon/trunk/src/test/resources/parameter-test-query.xq
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-saxon/trunk/src/test/resources/parameter-test-query.xq?rev=783184&view=auto
==============================================================================
--- servicemix/components/engines/servicemix-saxon/trunk/src/test/resources/parameter-test-query.xq
(added)
+++ servicemix/components/engines/servicemix-saxon/trunk/src/test/resources/parameter-test-query.xq
Wed Jun 10 02:46:53 2009
@@ -0,0 +1,26 @@
+(:
+
+    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.
+
+:)
+declare variable $max_price as xs:integer external;
+<titles>
+{
+  for $x in /bookstore/book
+  where $x/price > $max_price
+  return $x/title
+}
+</titles>
\ No newline at end of file

Modified: servicemix/components/engines/servicemix-saxon/trunk/src/test/resources/spring.xml
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-saxon/trunk/src/test/resources/spring.xml?rev=783184&r1=783183&r2=783184&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-saxon/trunk/src/test/resources/spring.xml (original)
+++ servicemix/components/engines/servicemix-saxon/trunk/src/test/resources/spring.xml Wed
Jun 10 02:46:53 2009
@@ -29,6 +29,12 @@
       <saxon:xslt service="test:xslt" endpoint="endpoint"
                   resource="classpath:transform.xsl" />
       <!-- END SNIPPET: xslt -->
+      
+      <!-- START SNIPPET: xslt-string -->
+      <saxon:xslt service="test:xslt-string" endpoint="endpoint"
+                  resource="classpath:transform.xsl" result="string" />
+      <!-- END SNIPPET: xslt-string -->
+ 
       	      
       <!-- START SNIPPET: xslt-params -->
       <saxon:xslt service="test:xslt-params" endpoint="endpoint"
@@ -67,6 +73,27 @@
       <saxon:xquery service="test:xquery" endpoint="endpoint"
                     resource="classpath:query.xq" />
       <!-- END SNIPPET: xquery -->
+      
+      <!-- START SNIPPET: xquery-string -->
+      <saxon:xquery service="test:xquery-string" endpoint="endpoint"
+                    resource="classpath:query.xq" result="string" />
+      <!-- END SNIPPET: xquery-string -->
+      
+      <!-- START SNIPPET: xquery-params -->
+      <saxon:xquery service="test:xquery-params" endpoint="endpoint"
+                  resource="classpath:parameter-test-query.xq" result="bytes">
+        <property name="parameters">
+          <map>
+            <entry key="max_price">
+              <bean class="java.lang.Integer">
+                <constructor-arg index="0" value="30"/>
+              </bean>
+            </entry>
+          </map>
+        </property>
+      </saxon:xquery>
+      <!-- END SNIPPET: xquery-params -->
+   
       	      
       <!-- START SNIPPET: xquery-inline -->
       <saxon:xquery service="test:xquery-inline" endpoint="endpoint" reload="true">
@@ -105,7 +132,50 @@
         </saxon:target>
       </saxon:proxy>
       <!-- END SNIPPET: xslt-proxy -->
-
+      
+      <!--  START SNIPPET: xslt-proxy-string -->
+      <saxon:proxy service="test:proxy-string" endpoint="endpoint"
+                   useDomSourceForXslt="false"
+                   useDomSourceForContent="false"
+                   result="string"
+                   resource="classpath:transform-in.xsl" >
+        <saxon:target>
+          <saxon:exchange-target service="test:echo" />
+        </saxon:target>
+      </saxon:proxy>
+      <!-- END SNIPPET: xslt-proxy-string -->
+      
+      <!--  START SNIPPET: xslt-proxy-bytes -->
+      <saxon:proxy service="test:proxy-bytes" endpoint="endpoint"
+                   useDomSourceForXslt="true"
+                   useDomSourceForContent="true"
+                   result="bytes"
+                   resource="classpath:transform-in.xsl" >
+        <saxon:target>
+          <saxon:exchange-target service="test:echo" />
+        </saxon:target>
+      </saxon:proxy>
+      <!-- END SNIPPET: xslt-proxy-bytes -->
+      
+      <!-- START SNIPPET: xslt-proxy-params -->
+      <saxon:proxy service="test:xslt-proxy-params" endpoint="endpoint"
+                  resource="classpath:transform-in.xsl">
+        <property name="parameters">
+          <map>
+            <entry key="symbol" value="IBM"/>
+            <entry key="volume">
+              <bean class="java.lang.Integer">
+                <constructor-arg index="0" value="10"/>
+              </bean>
+            </entry>
+          </map>
+        </property>
+        <saxon:target>
+          <saxon:exchange-target service="test:echo" />
+        </saxon:target>
+      </saxon:proxy>
+      <!-- END SNIPPET: xslt-proxy-params -->
+      
     </sm:endpoints>
     <sm:activationSpecs>
         <sm:activationSpec service="test:echo" endpoint="endpoint">



Mime
View raw message