You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by jm...@apache.org on 2007/01/13 10:14:03 UTC

svn commit: r495853 - in /incubator/tuscany/java/sca/kernel/core/src: main/java/org/apache/tuscany/core/binding/local/ test/java/org/apache/tuscany/core/binding/local/

Author: jmarino
Date: Sat Jan 13 01:14:02 2007
New Revision: 495853

URL: http://svn.apache.org/viewvc?view=rev&rev=495853
Log:
improve test coverage

Added:
    incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalBindingLoaderTestCase.java   (with props)
    incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalTargetInvokerTestCase.java   (with props)
Modified:
    incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/binding/local/LocalTargetInvoker.java

Modified: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/binding/local/LocalTargetInvoker.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/binding/local/LocalTargetInvoker.java?view=diff&rev=495853&r1=495852&r2=495853
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/binding/local/LocalTargetInvoker.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/binding/local/LocalTargetInvoker.java Sat Jan 13 01:14:02 2007
@@ -39,6 +39,7 @@
     public LocalTargetInvoker(Operation operation, OutboundWire outboundWire) {
         assert operation != null;
         chain = outboundWire.getInvocationChains().get(operation);
+        assert chain != null;
         fromAddress = (outboundWire.getContainer() == null) ? null : outboundWire.getContainer().getName();
         contractHasCallback = outboundWire.getServiceContract().getCallbackClass() != null;
     }
@@ -51,6 +52,7 @@
     public Message invoke(Message msg) throws InvocationRuntimeException {
         try {
             TargetInvoker invoker = chain.getTargetInvoker();
+            assert invoker != null;
             // Pushing the from address only needs to happen in the outbound (forward) direction for callbacks
             if (contractHasCallback) {
                 msg.pushFromAddress(fromAddress);

Added: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalBindingLoaderTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalBindingLoaderTestCase.java?view=auto&rev=495853
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalBindingLoaderTestCase.java (added)
+++ incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalBindingLoaderTestCase.java Sat Jan 13 01:14:02 2007
@@ -0,0 +1,70 @@
+/*
+ * 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.tuscany.core.binding.local;
+
+import java.net.URI;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.spi.loader.LoaderException;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class LocalBindingLoaderTestCase extends TestCase {
+    private LocalBindingLoader loader;
+
+    public void testParse() throws Exception {
+        XMLStreamReader reader = EasyMock.createMock(XMLStreamReader.class);
+        EasyMock.expect(reader.getAttributeValue(null, "uri")).andReturn("foo");
+        EasyMock.replay(reader);
+        LocalBindingDefinition definition = loader.load(null, null, reader, null);
+        assertEquals(new URI("foo"), definition.getTargetUri());
+        EasyMock.verify(reader);
+    }
+
+    public void testNoUri() throws Exception {
+        XMLStreamReader reader = EasyMock.createMock(XMLStreamReader.class);
+        EasyMock.expect(reader.getAttributeValue(null, "uri")).andReturn(null);
+        EasyMock.replay(reader);
+        LocalBindingDefinition definition = loader.load(null, null, reader, null);
+        assertNull(definition.getTargetUri());
+        EasyMock.verify(reader);
+    }
+
+    public void testBadUri() throws Exception {
+        XMLStreamReader reader = EasyMock.createMock(XMLStreamReader.class);
+        EasyMock.expect(reader.getAttributeValue(null, "uri")).andReturn("foo foo");
+        EasyMock.replay(reader);
+        try {
+            loader.load(null, null, reader, null);
+            fail();
+        } catch (LoaderException e) {
+            // expected
+        }
+        EasyMock.verify(reader);
+    }
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        loader = new LocalBindingLoader(null);
+    }
+}

Propchange: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalBindingLoaderTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalBindingLoaderTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalTargetInvokerTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalTargetInvokerTestCase.java?view=auto&rev=495853
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalTargetInvokerTestCase.java (added)
+++ incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalTargetInvokerTestCase.java Sat Jan 13 01:14:02 2007
@@ -0,0 +1,127 @@
+/*
+ * 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.tuscany.core.binding.local;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.tuscany.spi.component.SCAObject;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.wire.Message;
+import org.apache.tuscany.spi.wire.MessageImpl;
+import org.apache.tuscany.spi.wire.OutboundInvocationChain;
+import org.apache.tuscany.spi.wire.OutboundWire;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class LocalTargetInvokerTestCase extends TestCase {
+    private ServiceContract<Object> serviceContract;
+    private Operation<Object> operation;
+
+    public void testInvoke() {
+        TargetInvoker targetInvoker = EasyMock.createMock(TargetInvoker.class);
+        EasyMock.expect(targetInvoker.invoke(EasyMock.isA(Message.class))).andReturn(new MessageImpl());
+        EasyMock.replay(targetInvoker);
+        OutboundInvocationChain chain = EasyMock.createNiceMock(OutboundInvocationChain.class);
+        EasyMock.expect(chain.getTargetInvoker()).andReturn(targetInvoker);
+        EasyMock.replay(chain);
+        Map<Operation<?>, OutboundInvocationChain> chains = new HashMap<Operation<?>, OutboundInvocationChain>();
+        chains.put(operation, chain);
+        OutboundWire wire = EasyMock.createNiceMock(OutboundWire.class);
+        wire.getInvocationChains();
+        EasyMock.expectLastCall().andReturn(chains);
+        EasyMock.expect(wire.getServiceContract()).andReturn(serviceContract);
+        EasyMock.replay(wire);
+        TargetInvoker invoker = new LocalTargetInvoker(operation, wire);
+        Message msg = invoker.invoke(new MessageImpl());
+        assertFalse(msg.isFault());
+        EasyMock.verify(targetInvoker);
+    }
+
+    public void testCallbackSetInvoke() {
+        ServiceContract<?> contract = new ServiceContract<Object>() {
+
+        };
+        contract.setCallbackClass(Object.class);
+        TargetInvoker targetInvoker = EasyMock.createMock(TargetInvoker.class);
+        EasyMock.expect(targetInvoker.invoke(EasyMock.isA(Message.class))).andReturn(new MessageImpl());
+        EasyMock.replay(targetInvoker);
+        OutboundInvocationChain chain = EasyMock.createNiceMock(OutboundInvocationChain.class);
+        EasyMock.expect(chain.getTargetInvoker()).andReturn(targetInvoker);
+        EasyMock.replay(chain);
+        Map<Operation<?>, OutboundInvocationChain> chains = new HashMap<Operation<?>, OutboundInvocationChain>();
+        chains.put(operation, chain);
+        SCAObject container = EasyMock.createMock(SCAObject.class);
+        EasyMock.expect(container.getName()).andReturn("foo").atLeastOnce();
+        EasyMock.replay(container);
+        OutboundWire wire = EasyMock.createNiceMock(OutboundWire.class);
+        EasyMock.expect(wire.getContainer()).andReturn(container).atLeastOnce();
+        wire.getInvocationChains();
+        EasyMock.expectLastCall().andReturn(chains);
+        EasyMock.expect(wire.getServiceContract()).andReturn(contract);
+        EasyMock.replay(wire);
+        TargetInvoker invoker = new LocalTargetInvoker(operation, wire);
+        Message msg = EasyMock.createMock(Message.class);
+        msg.pushFromAddress(EasyMock.eq("foo"));
+        EasyMock.replay(msg);
+        invoker.invoke(msg);
+        EasyMock.verify(msg);
+        EasyMock.verify(targetInvoker);
+    }
+
+    public void testFaultInvoke() {
+        TargetInvoker targetInvoker = EasyMock.createMock(TargetInvoker.class);
+        EasyMock.expect(targetInvoker.invoke(EasyMock.isA(Message.class))).andThrow(new TestException());
+        EasyMock.replay(targetInvoker);
+        OutboundInvocationChain chain = EasyMock.createNiceMock(OutboundInvocationChain.class);
+        EasyMock.expect(chain.getTargetInvoker()).andReturn(targetInvoker);
+        EasyMock.replay(chain);
+        Map<Operation<?>, OutboundInvocationChain> chains = new HashMap<Operation<?>, OutboundInvocationChain>();
+        chains.put(operation, chain);
+        OutboundWire wire = EasyMock.createNiceMock(OutboundWire.class);
+        wire.getInvocationChains();
+        EasyMock.expectLastCall().andReturn(chains);
+        EasyMock.expect(wire.getServiceContract()).andReturn(serviceContract);
+        EasyMock.replay(wire);
+        TargetInvoker invoker = new LocalTargetInvoker(operation, wire);
+        Message msg = invoker.invoke(new MessageImpl());
+        assertTrue(msg.isFault());
+        assertTrue(msg.getBody() instanceof TestException);
+        EasyMock.verify(targetInvoker);
+    }
+
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        serviceContract = new ServiceContract<Object>() {
+        };
+        operation = new Operation<Object>("foo", null, null, null);
+    }
+
+
+    private class TestException extends RuntimeException {
+
+    }
+}

Propchange: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalTargetInvokerTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalTargetInvokerTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org