Added: incubator/tuscany/sandbox/mobile-android/core-android/src/test/java/org/apache/tuscany/sca/core/invocation/PhaseManagerTestCase.java URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/mobile-android/core-android/src/test/java/org/apache/tuscany/sca/core/invocation/PhaseManagerTestCase.java?rev=639535&view=auto ============================================================================== --- incubator/tuscany/sandbox/mobile-android/core-android/src/test/java/org/apache/tuscany/sca/core/invocation/PhaseManagerTestCase.java (added) +++ incubator/tuscany/sandbox/mobile-android/core-android/src/test/java/org/apache/tuscany/sca/core/invocation/PhaseManagerTestCase.java Thu Mar 20 20:42:35 2008 @@ -0,0 +1,51 @@ +/* + * 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.sca.core.invocation; + +import java.util.List; + +import junit.framework.Assert; + +import org.junit.Test; + +/** + * @version $Rev: 632098 $ $Date: 2008-02-28 11:37:57 -0800 (Thu, 28 Feb 2008) $ + */ +public class PhaseManagerTestCase { + + @Test + public void testDiscovery() { + PhaseManager pm = new PhaseManager("org.apache.tuscany.sca.invocation.PhaseTest"); + List<String> phases = pm.getAllPhases(); + System.out.println(phases.size()); + System.out.println(phases); + // Assert.assertEquals(15, phases.size()); + Assert.assertEquals("reference.first", phases.get(0)); + + int rt = phases.indexOf("reference.transaction"); + Assert.assertTrue(rt > phases.indexOf("reference.interface")); + + int st = phases.indexOf("service.transaction"); + Assert.assertTrue(st > phases.indexOf("service.binding")); + + int it = phases.indexOf("implementation.transaction"); + Assert.assertTrue(it < phases.indexOf("implementation.policy")); + } +}
Added: incubator/tuscany/sandbox/mobile-android/core-android/src/test/java/org/apache/tuscany/sca/core/invocation/PhaseSorterTestCase.java URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/mobile-android/core-android/src/test/java/org/apache/tuscany/sca/core/invocation/PhaseSorterTestCase.java?rev=639535&view=auto ============================================================================== --- incubator/tuscany/sandbox/mobile-android/core-android/src/test/java/org/apache/tuscany/sca/core/invocation/PhaseSorterTestCase.java (added) +++ incubator/tuscany/sandbox/mobile-android/core-android/src/test/java/org/apache/tuscany/sca/core/invocation/PhaseSorterTestCase.java Thu Mar 20 20:42:35 2008 @@ -0,0 +1,63 @@ +/* + * 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.sca.core.invocation; + +import java.util.Arrays; +import java.util.List; + +import junit.framework.TestCase; + +public class PhaseSorterTestCase extends TestCase { + private PhaseSorter<String> graph; + + @Override + protected void setUp() throws Exception { + super.setUp(); + graph = new PhaseSorter<String>(); + } + + public void testSort() { + graph.addEdge("a", "b"); + graph.addEdge("a", "c"); + graph.addEdge("c", "d"); + graph.addEdge("b", "c"); + List<String> order = graph.topologicalSort(true); + assertEquals(Arrays.asList("a", "b", "c", "d"), order); + assertTrue(!graph.getVertices().isEmpty()); + + graph.addEdge("d", "a"); + try { + order = graph.topologicalSort(true); + assertTrue("Should have failed", false); + } catch (IllegalArgumentException e) { + assertTrue(true); + } + + graph.removeEdge("d", "a"); + order = graph.topologicalSort(false); + assertEquals(Arrays.asList("a", "b", "c", "d"), order); + assertTrue(graph.getVertices().isEmpty()); + } + + @Override + protected void tearDown() throws Exception { + super.tearDown(); + } + +} Added: incubator/tuscany/sandbox/mobile-android/core-android/src/test/java/org/apache/tuscany/sca/core/scope/AbstractScopeContainerTestCase.java URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/mobile-android/core-android/src/test/java/org/apache/tuscany/sca/core/scope/AbstractScopeContainerTestCase.java?rev=639535&view=auto ============================================================================== --- incubator/tuscany/sandbox/mobile-android/core-android/src/test/java/org/apache/tuscany/sca/core/scope/AbstractScopeContainerTestCase.java (added) +++ incubator/tuscany/sandbox/mobile-android/core-android/src/test/java/org/apache/tuscany/sca/core/scope/AbstractScopeContainerTestCase.java Thu Mar 20 20:42:35 2008 @@ -0,0 +1,69 @@ +/* + * 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.sca.core.scope; + +import java.net.URI; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.assembly.Implementation; +import org.apache.tuscany.sca.core.context.InstanceWrapper; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.easymock.EasyMock; +import org.easymock.IMocksControl; + +/** + * @version $Rev: 568826 $ $Date: 2007-08-22 22:27:34 -0700 (Wed, 22 Aug 2007) $ + */ +public abstract class AbstractScopeContainerTestCase<T, KEY> extends TestCase { + protected IMocksControl control; + protected ScopeContainer<KEY> scopeContainer; + protected URI groupId; + protected KEY contextId; + protected RuntimeComponent component; + protected ScopedImplementation implementation; + protected InstanceWrapper<T> wrapper; + + @SuppressWarnings("unchecked") + @Override + protected void setUp() throws Exception { + super.setUp(); + control = EasyMock.createStrictControl(); + component = control.createMock(RuntimeComponent.class); + wrapper = control.createMock(InstanceWrapper.class); + implementation = control.createMock(ScopedImplementation.class); + EasyMock.expect(component.getImplementation()).andReturn(implementation).anyTimes(); + } + + protected void preRegisterComponent() throws Exception { + scopeContainer.start(); + EasyMock.expect(implementation.isEagerInit()).andStubReturn(false); + } + + protected void expectCreateWrapper() throws Exception { + EasyMock.expect(implementation.createInstanceWrapper()).andReturn(wrapper); + wrapper.start(); + } + + protected static interface ScopedImplementation extends ScopedImplementationProvider, Implementation { + + } + + +} Added: incubator/tuscany/sandbox/mobile-android/core-android/src/test/java/org/apache/tuscany/sca/core/store/MemoryStoreTestCase.java URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/mobile-android/core-android/src/test/java/org/apache/tuscany/sca/core/store/MemoryStoreTestCase.java?rev=639535&view=auto ============================================================================== --- incubator/tuscany/sandbox/mobile-android/core-android/src/test/java/org/apache/tuscany/sca/core/store/MemoryStoreTestCase.java (added) +++ incubator/tuscany/sandbox/mobile-android/core-android/src/test/java/org/apache/tuscany/sca/core/store/MemoryStoreTestCase.java Thu Mar 20 20:42:35 2008 @@ -0,0 +1,165 @@ +/* + * 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.sca.core.store; + +import java.util.UUID; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.event.RuntimeEventListener; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.store.DuplicateRecordException; +import org.apache.tuscany.sca.store.Store; +import org.apache.tuscany.sca.store.StoreExpirationEvent; +import org.apache.tuscany.sca.store.StoreMonitor; +import org.easymock.EasyMock; +import org.easymock.IAnswer; + +/** + * @version $Rev: 567542 $ $Date: 2007-08-19 22:13:29 -0700 (Sun, 19 Aug 2007) $ + */ +public class MemoryStoreTestCase extends TestCase { + private StoreMonitor monitor; + + public void testEviction() throws Exception { + MemoryStore store = new MemoryStore(monitor); + store.setReaperInterval(10); + store.init(); + RuntimeComponent component = EasyMock.createNiceMock(RuntimeComponent.class); + EasyMock.replay(component); + String id = UUID.randomUUID().toString(); + Object value = new Object(); + store.insertRecord(component, id, value, 1); + Thread.sleep(200); + assertNull(store.readRecord(component, id)); + store.destroy(); + } + + public void testNotifyOnEviction() throws Exception { + final CountDownLatch latch = new CountDownLatch(1); + RuntimeEventListener listener = EasyMock.createMock(RuntimeEventListener.class); + listener.onEvent(EasyMock.isA(StoreExpirationEvent.class)); + EasyMock.expectLastCall().andStubAnswer(new IAnswer<Object>() { + public Object answer() throws Throwable { + latch.countDown(); + return null; + } + }); + EasyMock.replay(listener); + MemoryStore store = new MemoryStore(monitor); + store.addListener(listener); + store.setReaperInterval(10); + store.init(); + RuntimeComponent component = EasyMock.createNiceMock(RuntimeComponent.class); + EasyMock.replay(component); + String id = UUID.randomUUID().toString(); + Object value = new Object(); + store.insertRecord(component, id, value, 1); + if (!latch.await(1000, TimeUnit.MILLISECONDS)) { + // failed to notify listener + fail(); + } + EasyMock.verify(listener); + } + + public void testNoEviction() throws Exception { + MemoryStore store = new MemoryStore(monitor); + store.setReaperInterval(10); + store.init(); + RuntimeComponent component = EasyMock.createNiceMock(RuntimeComponent.class); + EasyMock.replay(component); + String id = UUID.randomUUID().toString(); + Object value = new Object(); + store.insertRecord(component, id, value, Store.NEVER); + Thread.sleep(100); + assertNotNull(store.readRecord(component, id)); + store.destroy(); + } + + public void testInsertRecord() throws Exception { + MemoryStore store = new MemoryStore(monitor); + store.setReaperInterval(10); + store.init(); + RuntimeComponent component = EasyMock.createNiceMock(RuntimeComponent.class); + EasyMock.replay(component); + String id = UUID.randomUUID().toString(); + Object value = new Object(); + store.insertRecord(component, id, value, Store.NEVER); + store.destroy(); + } + + public void testInsertAlreadyExists() throws Exception { + MemoryStore store = new MemoryStore(monitor); + store.setReaperInterval(10); + store.init(); + RuntimeComponent component = EasyMock.createMock(RuntimeComponent.class); + EasyMock.expect(component.getURI()).andReturn("component"); + EasyMock.replay(component); + String id = UUID.randomUUID().toString(); + Object value = new Object(); + store.insertRecord(component, id, value, Store.NEVER); + try { + store.insertRecord(component, id, value, Store.NEVER); + fail(); + } catch (DuplicateRecordException e) { + //expected + } + store.destroy(); + } + + public void testUpdateRecord() throws Exception { + MemoryStore store = new MemoryStore(monitor); + store.setReaperInterval(10); + store.init(); + RuntimeComponent component = EasyMock.createNiceMock(RuntimeComponent.class); + EasyMock.replay(component); + String id = UUID.randomUUID().toString(); + Object value = new Object(); + Object newValue = new Object(); + + store.insertRecord(component, id, value, Store.NEVER); + store.updateRecord(component, id, newValue, 1L); + assertEquals(newValue, store.readRecord(component, id)); + store.destroy(); + } + + public void testDeleteRecord() throws Exception { + MemoryStore store = new MemoryStore(monitor); + store.setReaperInterval(10); + store.init(); + RuntimeComponent component = EasyMock.createNiceMock(RuntimeComponent.class); + EasyMock.replay(component); + String id = UUID.randomUUID().toString(); + Object value = new Object(); + + store.insertRecord(component, id, value, Store.NEVER); + store.removeRecord(component, id); + assertNull(store.readRecord(component, id)); + store.destroy(); + } + + @Override + protected void setUp() throws Exception { + monitor = EasyMock.createNiceMock(StoreMonitor.class); + EasyMock.replay(monitor); + } + +} Added: incubator/tuscany/sandbox/mobile-android/core-android/src/test/java/org/apache/tuscany/sca/core/wire/CallbackInterfaceInterceptorTestCase.java URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/mobile-android/core-android/src/test/java/org/apache/tuscany/sca/core/wire/CallbackInterfaceInterceptorTestCase.java?rev=639535&view=auto ============================================================================== --- incubator/tuscany/sandbox/mobile-android/core-android/src/test/java/org/apache/tuscany/sca/core/wire/CallbackInterfaceInterceptorTestCase.java (added) +++ incubator/tuscany/sandbox/mobile-android/core-android/src/test/java/org/apache/tuscany/sca/core/wire/CallbackInterfaceInterceptorTestCase.java Thu Mar 20 20:42:35 2008 @@ -0,0 +1,62 @@ +/* + * 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.sca.core.wire; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.core.assembly.EndpointReferenceImpl; +import org.apache.tuscany.sca.core.invocation.CallbackInterfaceInterceptor; +import org.apache.tuscany.sca.core.invocation.MessageFactoryImpl; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Message; +import org.easymock.EasyMock; +import org.osoa.sca.NoRegisteredCallbackException; + +/** + * @version $Rev: 608822 $ $Date: 2008-01-04 04:59:56 -0800 (Fri, 04 Jan 2008) $ + */ +public class CallbackInterfaceInterceptorTestCase extends TestCase { + + public void testHasCallbackObject() { + CallbackInterfaceInterceptor interceptor = new CallbackInterfaceInterceptor(); + Interceptor next = EasyMock.createMock(Interceptor.class); + EasyMock.expect(next.invoke(EasyMock.isA(Message.class))).andReturn(null); + EasyMock.replay(next); + interceptor.setNext(next); + Message msg = new MessageFactoryImpl().createMessage(); + msg.setFrom(new EndpointReferenceImpl("uri")); + msg.getFrom().getReferenceParameters().setCallbackObjectID("ABC"); + interceptor.invoke(msg); + EasyMock.verify(next); + } + + public void testNoCallbackObject() { + CallbackInterfaceInterceptor interceptor = new CallbackInterfaceInterceptor(); + Message msg = new MessageFactoryImpl().createMessage(); + msg.setFrom(new EndpointReferenceImpl("uri")); + msg.getFrom().getReferenceParameters().setCallbackObjectID(null); + try { + interceptor.invoke(msg); + fail(); + } catch (NoRegisteredCallbackException e) { + // expected + } + } + +} Added: incubator/tuscany/sandbox/mobile-android/core-android/src/test/java/org/apache/tuscany/sca/core/wire/InvocationChainImplTestCase.java URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/mobile-android/core-android/src/test/java/org/apache/tuscany/sca/core/wire/InvocationChainImplTestCase.java?rev=639535&view=auto ============================================================================== --- incubator/tuscany/sandbox/mobile-android/core-android/src/test/java/org/apache/tuscany/sca/core/wire/InvocationChainImplTestCase.java (added) +++ incubator/tuscany/sandbox/mobile-android/core-android/src/test/java/org/apache/tuscany/sca/core/wire/InvocationChainImplTestCase.java Thu Mar 20 20:42:35 2008 @@ -0,0 +1,93 @@ +/* + * 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.sca.core.wire; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.core.invocation.InvocationChainImpl; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.impl.OperationImpl; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.InvocationChain; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.invocation.Phase; + +/** + * @version $Rev: 632064 $ $Date: 2008-02-28 09:18:51 -0800 (Thu, 28 Feb 2008) $ + */ +public class InvocationChainImplTestCase extends TestCase { + + public void testInsertAtEnd() throws Exception { + Operation op = newOperation("foo"); + InvocationChain chain = new InvocationChainImpl(op, op, true); + Interceptor inter2 = new MockInterceptor(); + Interceptor inter1 = new MockInterceptor(); + chain.addInterceptor(inter1); + chain.addInterceptor(inter2); + Interceptor head = (Interceptor)chain.getHeadInvoker(); + assertEquals(inter1, head); + assertEquals(inter2, head.getNext()); + assertEquals(inter2, chain.getTailInvoker()); + + } + + public void testAddByPhase() throws Exception { + Operation op = newOperation("foo"); + InvocationChain chain = new InvocationChainImpl(op, op, false); + Interceptor inter1 = new MockInterceptor(); + Interceptor inter2 = new MockInterceptor(); + Interceptor inter3 = new MockInterceptor(); + Interceptor inter4 = new MockInterceptor(); + chain.addInterceptor(inter3); // SERVICE + chain.addInterceptor(Phase.IMPLEMENTATION_POLICY, inter4); + chain.addInterceptor(Phase.SERVICE_POLICY, inter2); + chain.addInterceptor(Phase.SERVICE_BINDING, inter1); + Interceptor head = (Interceptor)chain.getHeadInvoker(); + assertEquals(inter1, head); + assertEquals(inter2, inter1.getNext()); + assertEquals(inter3, inter2.getNext()); + assertEquals(inter4, inter3.getNext()); + assertEquals(inter4, chain.getTailInvoker()); + } + + private class MockInterceptor implements Interceptor { + + private Invoker next; + + public Message invoke(Message msg) { + return null; + } + + public void setNext(Invoker next) { + this.next = next; + } + + public Invoker getNext() { + return next; + } + + } + + private static Operation newOperation(String name) { + Operation operation = new OperationImpl(); + operation.setName(name); + return operation; + } +} Added: incubator/tuscany/sandbox/mobile-android/core-android/src/test/java/org/apache/tuscany/sca/core/wire/NonBlockingInterceptorTestCase.java URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/mobile-android/core-android/src/test/java/org/apache/tuscany/sca/core/wire/NonBlockingInterceptorTestCase.java?rev=639535&view=auto ============================================================================== --- incubator/tuscany/sandbox/mobile-android/core-android/src/test/java/org/apache/tuscany/sca/core/wire/NonBlockingInterceptorTestCase.java (added) +++ incubator/tuscany/sandbox/mobile-android/core-android/src/test/java/org/apache/tuscany/sca/core/wire/NonBlockingInterceptorTestCase.java Thu Mar 20 20:42:35 2008 @@ -0,0 +1,73 @@ +/* + * 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.sca.core.wire; + +import static org.easymock.EasyMock.createMock; +import static org.easymock.EasyMock.expectLastCall; +import static org.easymock.EasyMock.getCurrentArguments; +import static org.easymock.EasyMock.isA; +import static org.easymock.EasyMock.replay; +import static org.easymock.EasyMock.verify; +import junit.framework.TestCase; + +import org.apache.tuscany.sca.core.invocation.NonBlockingInterceptor; +import org.apache.tuscany.sca.core.invocation.ThreadMessageContext; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.work.WorkScheduler; +import org.easymock.EasyMock; +import org.easymock.IAnswer; + +/** + * @version $Rev: 576235 $ $Date: 2007-09-16 19:07:54 -0700 (Sun, 16 Sep 2007) $ + */ +public class NonBlockingInterceptorTestCase extends TestCase { + + public void testInvoke() throws Exception { + WorkScheduler scheduler = createMock(WorkScheduler.class); + scheduler.scheduleWork(isA(Runnable.class)); + expectLastCall().andStubAnswer(new IAnswer<Object>() { + public Object answer() throws Throwable { + Runnable runnable = (Runnable) getCurrentArguments()[0]; + runnable.run(); + return null; + } + }); + replay(scheduler); + Message context = createMock(Message.class); + //String convID = "convID"; + //TODO port to the new way of dealing with conversation IDs later + //EasyMock.expect(context.getConversationID()).andReturn(convID); + EasyMock.replay(context); + ThreadMessageContext.setMessageContext(context); + Message msg = createMock(Message.class); + //TODO port to the new way of dealing with conversation IDs later + //msg.setConversationID(convID); + Interceptor next = EasyMock.createMock(Interceptor.class); + EasyMock.expect(next.invoke(EasyMock.eq(msg))).andReturn(msg); + EasyMock.replay(next); + EasyMock.replay(msg); + Interceptor interceptor = new NonBlockingInterceptor(scheduler, next); + interceptor.invoke(msg); + verify(context); + verify(next); + verify(msg); + } + +} Added: incubator/tuscany/sandbox/mobile-android/core-android/src/test/java/org/apache/tuscany/sca/scope/ScopeTestCase.java URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/mobile-android/core-android/src/test/java/org/apache/tuscany/sca/scope/ScopeTestCase.java?rev=639535&view=auto ============================================================================== --- incubator/tuscany/sandbox/mobile-android/core-android/src/test/java/org/apache/tuscany/sca/scope/ScopeTestCase.java (added) +++ incubator/tuscany/sandbox/mobile-android/core-android/src/test/java/org/apache/tuscany/sca/scope/ScopeTestCase.java Thu Mar 20 20:42:35 2008 @@ -0,0 +1,61 @@ +/* + * 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.sca.scope; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.core.scope.Scope; + +/** + * @version $Rev: 568826 $ $Date: 2007-08-22 22:27:34 -0700 (Wed, 22 Aug 2007) $ + */ +public class ScopeTestCase extends TestCase { + + public void testEquals() throws Exception { + Scope scope = new Scope("COMPOSITE"); + assertTrue(scope.equals(Scope.COMPOSITE)); + } + + public void testEqualsNew() throws Exception { + Scope foo = new Scope("foo"); + Scope foo2 = new Scope("FOO"); + assertTrue(foo.equals(foo2)); + } + + public void testNotEquals() throws Exception { + Scope foo = new Scope("BAR"); + Scope foo2 = new Scope("FOO"); + assertFalse(foo.equals(foo2)); + } + + public void testNotEqualsDifferent() throws Exception { + Scope foo = new Scope("FOO"); + assertFalse(foo.equals(new Bar("FOO"))); + } + + public class Bar { + String scope; + + public Bar(String scope) { + this.scope = scope; + } + } + + +} Added: incubator/tuscany/sandbox/mobile-android/core-android/src/test/resources/META-INF/services/org.apache.tuscany.sca.invocation.PhaseTest URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/mobile-android/core-android/src/test/resources/META-INF/services/org.apache.tuscany.sca.invocation.PhaseTest?rev=639535&view=auto ============================================================================== --- incubator/tuscany/sandbox/mobile-android/core-android/src/test/resources/META-INF/services/org.apache.tuscany.sca.invocation.PhaseTest (added) +++ incubator/tuscany/sandbox/mobile-android/core-android/src/test/resources/META-INF/services/org.apache.tuscany.sca.invocation.PhaseTest Thu Mar 20 20:42:35 2008 @@ -0,0 +1,5 @@ +name=implementation.last, stage=implementation, after=* +name=reference.first, stage=reference, before=* +name=reference.transaction, stage=reference, after=reference.interface +name=service.transaction, stage=service, after=service.binding, before=component.service +name=implementation.transaction, stage=implementation, before=implementation.policy \ No newline at end of file Modified: incubator/tuscany/sandbox/mobile-android/host-android/src/main/java/org/apache/tuscany/sca/host/embedded/impl/EmbeddedSCADomain.java URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/mobile-android/host-android/src/main/java/org/apache/tuscany/sca/host/embedded/impl/EmbeddedSCADomain.java?rev=639535&r1=639534&r2=639535&view=diff ============================================================================== --- incubator/tuscany/sandbox/mobile-android/host-android/src/main/java/org/apache/tuscany/sca/host/embedded/impl/EmbeddedSCADomain.java (original) +++ incubator/tuscany/sandbox/mobile-android/host-android/src/main/java/org/apache/tuscany/sca/host/embedded/impl/EmbeddedSCADomain.java Thu Mar 20 20:42:35 2008 @@ -19,8 +19,6 @@ package org.apache.tuscany.sca.host.embedded.impl; -import java.util.List; - import javax.xml.namespace.QName; import org.apache.tuscany.sca.assembly.AssemblyFactory; @@ -38,7 +36,6 @@ import org.apache.tuscany.sca.core.assembly.ActivationException; import org.apache.tuscany.sca.core.assembly.CompositeActivator; import org.apache.tuscany.sca.core.context.ServiceReferenceImpl; -import org.apache.tuscany.sca.definitions.SCADefinitions; import org.apache.tuscany.sca.host.embedded.SCADomain; import org.apache.tuscany.sca.host.embedded.management.ComponentManager; import org.apache.tuscany.sca.interfacedef.InterfaceContract; @@ -53,7 +50,7 @@ /** * An SCA domain facade implementation. * - * @version $Rev: 637129 $ $Date: 2008-03-14 08:11:59 -0700 (Fri, 14 Mar 2008) $ + * @version $Rev: 638890 $ $Date: 2008-03-19 08:52:30 -0700 (Wed, 19 Mar 2008) $ */ public class EmbeddedSCADomain extends SCADomain { Modified: incubator/tuscany/sandbox/mobile-android/host-android/src/main/java/org/apache/tuscany/sca/host/embedded/impl/ReallySmallRuntime.java URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/mobile-android/host-android/src/main/java/org/apache/tuscany/sca/host/embedded/impl/ReallySmallRuntime.java?rev=639535&r1=639534&r2=639535&view=diff ============================================================================== --- incubator/tuscany/sandbox/mobile-android/host-android/src/main/java/org/apache/tuscany/sca/host/embedded/impl/ReallySmallRuntime.java (original) +++ incubator/tuscany/sandbox/mobile-android/host-android/src/main/java/org/apache/tuscany/sca/host/embedded/impl/ReallySmallRuntime.java Thu Mar 20 20:42:35 2008 @@ -20,11 +20,9 @@ package org.apache.tuscany.sca.host.embedded.impl; import java.io.IOException; -import java.net.URL; import java.util.ArrayList; import java.util.HashSet; import java.util.List; -import java.util.Map; import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; @@ -38,10 +36,9 @@ import org.apache.tuscany.sca.context.ContextFactoryExtensionPoint; import org.apache.tuscany.sca.context.DefaultContextFactoryExtensionPoint; import org.apache.tuscany.sca.contribution.ContributionFactory; +import org.apache.tuscany.sca.contribution.DefaultModelFactoryExtensionPoint; import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint; -import org.apache.tuscany.sca.contribution.service.ContributionReadException; -import org.apache.tuscany.sca.contribution.service.ContributionResolveException; import org.apache.tuscany.sca.contribution.service.ContributionService; import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; import org.apache.tuscany.sca.core.ExtensionPointRegistry; @@ -52,7 +49,10 @@ import org.apache.tuscany.sca.core.invocation.MessageFactoryImpl; import org.apache.tuscany.sca.core.invocation.ProxyFactory; import org.apache.tuscany.sca.core.scope.ScopeRegistry; +import org.apache.tuscany.sca.core.work.Jsr237WorkScheduler; import org.apache.tuscany.sca.definitions.SCADefinitions; +import org.apache.tuscany.sca.definitions.SCADefinitionsProvider; +import org.apache.tuscany.sca.definitions.SCADefinitionsProviderExtensionPoint; import org.apache.tuscany.sca.definitions.impl.SCADefinitionsImpl; import org.apache.tuscany.sca.definitions.util.SCADefinitionsUtil; import org.apache.tuscany.sca.definitions.xml.SCADefinitionsDocumentProcessor; @@ -63,8 +63,11 @@ import org.apache.tuscany.sca.invocation.MessageFactory; import org.apache.tuscany.sca.policy.DefaultIntentAttachPointTypeFactory; import org.apache.tuscany.sca.policy.DefaultPolicyFactory; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.IntentAttachPointType; import org.apache.tuscany.sca.policy.IntentAttachPointTypeFactory; import org.apache.tuscany.sca.policy.PolicyFactory; +import org.apache.tuscany.sca.policy.PolicySet; import org.apache.tuscany.sca.work.WorkScheduler; public class ReallySmallRuntime { @@ -94,13 +97,22 @@ registry = new DefaultExtensionPointRegistry(); //Get work scheduler - workScheduler = registry.getExtensionPoint(WorkScheduler.class); + + /* + * host-embedded + workScheduler = registry.getExtensionPoint(WorkScheduler.class); */ + + workScheduler = new Jsr237WorkScheduler(); // Create an interface contract mapper InterfaceContractMapper mapper = new InterfaceContractMapperImpl(); // Get factory extension point - ModelFactoryExtensionPoint factories = registry.getExtensionPoint(ModelFactoryExtensionPoint.class); + /* + * host-embedded + ModelFactoryExtensionPoint factories = registry.getExtensionPoint(ModelFactoryExtensionPoint.class);*/ + + ModelFactoryExtensionPoint factories = new DefaultModelFactoryExtensionPoint(); // Create context factory extension point ContextFactoryExtensionPoint contextFactories = new DefaultContextFactoryExtensionPoint(); @@ -234,7 +246,44 @@ } private void loadSCADefinitions(ExtensionPointRegistry registry) throws ActivationException { - URLArtifactProcessorExtensionPoint documentProcessors = registry.getExtensionPoint(URLArtifactProcessorExtensionPoint.class); + try { + URLArtifactProcessorExtensionPoint documentProcessors = registry.getExtensionPoint(URLArtifactProcessorExtensionPoint.class); + SCADefinitionsDocumentProcessor definitionsProcessor = (SCADefinitionsDocumentProcessor)documentProcessors.getProcessor(SCADefinitions.class); + SCADefinitionsProviderExtensionPoint scaDefnProviders = registry.getExtensionPoint(SCADefinitionsProviderExtensionPoint.class); + + SCADefinitions systemSCADefinitions = new SCADefinitionsImpl(); + SCADefinitions aSCADefn = null; + for ( SCADefinitionsProvider aProvider : scaDefnProviders.getSCADefinitionsProviders() ) { + aSCADefn = aProvider.getSCADefinition(); + SCADefinitionsUtil.aggregateSCADefinitions(aSCADefn, systemSCADefinitions); + } + + //we cannot expect that providers will add the intents and policysets into the resolver + //so we do this here explicitly + for ( Intent intent : systemSCADefinitions.getPolicyIntents() ) { + definitionsProcessor.getSCADefinitionsResolver().addModel(intent); + } + + for ( PolicySet policySet : systemSCADefinitions.getPolicySets() ) { + definitionsProcessor.getSCADefinitionsResolver().addModel(policySet); + } + + for ( IntentAttachPointType attachPoinType : systemSCADefinitions.getBindingTypes() ) { + definitionsProcessor.getSCADefinitionsResolver().addModel(attachPoinType); + } + + for ( IntentAttachPointType attachPoinType : systemSCADefinitions.getImplementationTypes() ) { + definitionsProcessor.getSCADefinitionsResolver().addModel(attachPoinType); + } + + //now that all system sca definitions have been read, lets resolve them rightaway + definitionsProcessor.resolve(systemSCADefinitions, + definitionsProcessor.getSCADefinitionsResolver()); + } catch ( Exception e ) { + throw new ActivationException(e); + } + + /*URLArtifactProcessorExtensionPoint documentProcessors = registry.getExtensionPoint(URLArtifactProcessorExtensionPoint.class); SCADefinitionsDocumentProcessor definitionsProcessor = (SCADefinitionsDocumentProcessor)documentProcessors.getProcessor(SCADefinitions.class); try { @@ -257,7 +306,7 @@ throw new ActivationException(e); } catch ( IOException e ) { throw new ActivationException(e); - } + }*/ } @SuppressWarnings("unchecked") Modified: incubator/tuscany/sandbox/mobile-android/host-android/src/main/java/org/apache/tuscany/sca/host/embedded/impl/ReallySmallRuntimeBuilder.java URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/mobile-android/host-android/src/main/java/org/apache/tuscany/sca/host/embedded/impl/ReallySmallRuntimeBuilder.java?rev=639535&r1=639534&r2=639535&view=diff ============================================================================== --- incubator/tuscany/sandbox/mobile-android/host-android/src/main/java/org/apache/tuscany/sca/host/embedded/impl/ReallySmallRuntimeBuilder.java (original) +++ incubator/tuscany/sandbox/mobile-android/host-android/src/main/java/org/apache/tuscany/sca/host/embedded/impl/ReallySmallRuntimeBuilder.java Thu Mar 20 20:42:35 2008 @@ -42,6 +42,7 @@ import org.apache.tuscany.sca.contribution.ContributionFactory; import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; import org.apache.tuscany.sca.contribution.processor.DefaultValidatingXMLInputFactory; +import org.apache.tuscany.sca.contribution.processor.DefaultValidationSchemaExtensionPoint; import org.apache.tuscany.sca.contribution.processor.ExtensiblePackageProcessor; import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.ExtensibleURLArtifactProcessor; @@ -77,14 +78,12 @@ import org.apache.tuscany.sca.core.scope.ScopeRegistry; import org.apache.tuscany.sca.core.scope.ScopeRegistryImpl; import org.apache.tuscany.sca.core.scope.StatelessScopeContainerFactory; -import org.apache.tuscany.sca.definitions.SCADefinitions; import org.apache.tuscany.sca.definitions.xml.SCADefinitionsDocumentProcessor; import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; import org.apache.tuscany.sca.invocation.MessageFactory; import org.apache.tuscany.sca.policy.IntentAttachPointTypeFactory; import org.apache.tuscany.sca.policy.PolicyFactory; -import org.apache.tuscany.sca.policy.PolicySet; import org.apache.tuscany.sca.provider.ProviderFactoryExtensionPoint; import org.apache.tuscany.sca.runtime.RuntimeWireProcessor; import org.apache.tuscany.sca.runtime.RuntimeWireProcessorExtensionPoint; @@ -176,7 +175,13 @@ XMLInputFactory inputFactory = XMLInputFactory.newInstance(); // Create a validation XML schema extension point - ValidationSchemaExtensionPoint schemas = registry.getExtensionPoint(ValidationSchemaExtensionPoint.class); + + /* host-embedded + * ValidationSchemaExtensionPoint schemas = registry.getExtensionPoint(ValidationSchemaExtensionPoint.class); + */ + + ValidationSchemaExtensionPoint schemas = new DefaultValidationSchemaExtensionPoint(); + schemas.addSchema(ReallySmallRuntimeBuilder.class.getClassLoader().getResource("tuscany-sca.xsd").toString()); // Create a validating XML input factory --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
