diff options
Diffstat (limited to 'branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany')
92 files changed, 0 insertions, 8407 deletions
diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/async/invocation/AsyncInvocationConfigurationTestCase.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/async/invocation/AsyncInvocationConfigurationTestCase.java deleted file mode 100644 index 6f55182c2b..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/async/invocation/AsyncInvocationConfigurationTestCase.java +++ /dev/null @@ -1,197 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * Licensed 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.async.invocation; - -import java.lang.reflect.Method; -import java.util.concurrent.CountDownLatch; - -import junit.framework.Assert; -import junit.framework.TestCase; - -import org.apache.tuscany.core.async.wire.mock.MockHandler; -import org.apache.tuscany.core.async.wire.mock.MockStaticInvoker; -import org.apache.tuscany.core.async.wire.mock.MockSyncInterceptor; -import org.apache.tuscany.core.async.wire.mock.SimpleTarget; -import org.apache.tuscany.core.async.wire.mock.SimpleTargetImpl; -import org.apache.tuscany.core.async.work.DefaultWorkManager; -import org.apache.tuscany.core.message.Message; -import org.apache.tuscany.core.message.MessageFactory; -import org.apache.tuscany.core.message.impl.MessageFactoryImpl; -import org.apache.tuscany.core.wire.SourceInvocationConfiguration; -import org.apache.tuscany.core.wire.TargetInvocationConfiguration; -import org.apache.tuscany.core.wire.impl.InvokerInterceptor; -import org.apache.tuscany.core.wire.impl.MessageChannelImpl; - -public class AsyncInvocationConfigurationTestCase extends TestCase { - - private DefaultWorkManager workManager; - private Method hello; - - private MessageFactory factory = new MessageFactoryImpl(); - - public AsyncInvocationConfigurationTestCase() { - super(); - } - - public AsyncInvocationConfigurationTestCase(String arg0) { - super(arg0); - } - - protected void setUp() throws Exception { - hello = SimpleTarget.class.getMethod("hello", String.class); - - workManager=new DefaultWorkManager(); - workManager.setScheduledMaximumPoolSize(5); - workManager.init(); - } - - protected void tearDown() throws Exception { - workManager.destroy(); - - super.tearDown(); - } - - /** - * Tests basic wiring of a source to a target, including handlers and interceptors - */ - public void testInvokeWithHandlers() throws Exception { - SourceInvocationConfiguration source = new SourceInvocationConfiguration(hello); - - source.addInterceptor(new AsyncInterceptor(workManager, factory)); - - MockHandler sourceRequestHandler = new MockHandler(); - MockHandler sourceResponseHandler = new MockHandler(); - MockSyncInterceptor sourceInterceptor = new MockSyncInterceptor(); - source.addRequestHandler(sourceRequestHandler); - source.addResponseHandler(sourceResponseHandler); - source.addInterceptor(sourceInterceptor); - - TargetInvocationConfiguration target = new TargetInvocationConfiguration(hello); - MockHandler targetRequestHandler = new MockHandler(); - MockHandler targetResponseHandler = new MockHandler(); - MockSyncInterceptor targetInterceptor = new MockSyncInterceptor(); - target.addRequestHandler(targetRequestHandler); - target.addResponseHandler(targetResponseHandler); - target.addInterceptor(targetInterceptor); - target.addInterceptor(new InvokerInterceptor()); - - // connect the source to the target - source.setTargetRequestChannel(new MessageChannelImpl(target.getRequestHandlers())); - source.setTargetResponseChannel(new MessageChannelImpl(target.getResponseHandlers())); - source.build(); - target.build(); - - CountDownLatch startSignal = new CountDownLatch(1); - CountDownLatch doneSignal = new CountDownLatch(1); - MockStaticInvoker invoker = new MockStaticInvoker(hello, new SimpleTargetImpl(startSignal, doneSignal)); - source.setTargetInvoker(invoker); - - Message msg = factory.createMessage(); - msg.setBody("foo"); - msg.setTargetInvoker(invoker); - Message response = source.getHeadInterceptor().invoke(msg); - startSignal.countDown(); - doneSignal.await(); - - Assert.assertEquals(null, response.getBody()); - Assert.assertEquals(1, sourceRequestHandler.getCount()); - //FIXME why isn't the responseHandler invoked? - //Assert.assertEquals(1, sourceResponseHandler.getCount()); - Assert.assertEquals(1, sourceInterceptor.getCount()); - Assert.assertEquals(1, targetRequestHandler.getCount()); - //FIXME - //Assert.assertEquals(1, targetResponseHandler.getCount()); - Assert.assertEquals(1, targetInterceptor.getCount()); - } - - public void testInvokeWithRequestHandlers() throws Exception { - SourceInvocationConfiguration source = new SourceInvocationConfiguration(hello); - - source.addInterceptor(new AsyncInterceptor(workManager, factory)); - - MockHandler sourceRequestHandler = new MockHandler(); - MockSyncInterceptor sourceInterceptor = new MockSyncInterceptor(); - source.addRequestHandler(sourceRequestHandler); - source.addInterceptor(sourceInterceptor); - - TargetInvocationConfiguration target = new TargetInvocationConfiguration(hello); - MockHandler targetRequestHandler = new MockHandler(); - MockSyncInterceptor targetInterceptor = new MockSyncInterceptor(); - target.addRequestHandler(targetRequestHandler); - target.addInterceptor(targetInterceptor); - target.addInterceptor(new InvokerInterceptor()); - - // connect the source to the target - source.setTargetRequestChannel(new MessageChannelImpl(target.getRequestHandlers())); - source.setTargetResponseChannel(new MessageChannelImpl(target.getResponseHandlers())); - source.build(); - target.build(); - - CountDownLatch startSignal = new CountDownLatch(1); - CountDownLatch doneSignal = new CountDownLatch(1); - MockStaticInvoker invoker = new MockStaticInvoker(hello, new SimpleTargetImpl(startSignal, doneSignal)); - source.setTargetInvoker(invoker); - - Message msg = factory.createMessage(); - msg.setBody("foo"); - msg.setTargetInvoker(invoker); - Message response = source.getHeadInterceptor().invoke(msg); - startSignal.countDown(); - doneSignal.await(); - - Assert.assertEquals(null, response.getBody()); - Assert.assertEquals(1, sourceRequestHandler.getCount()); - Assert.assertEquals(1, sourceInterceptor.getCount()); - Assert.assertEquals(1, targetRequestHandler.getCount()); - Assert.assertEquals(1, targetInterceptor.getCount()); - } - - /** - * Tests basic wiring of a source to a target, including handlers and interceptors - */ - public void testInvokeWithInterceptorsOnly() throws Exception { - SourceInvocationConfiguration source = new SourceInvocationConfiguration(hello); - - source.addInterceptor(new AsyncInterceptor(workManager, factory)); - - MockSyncInterceptor sourceInterceptor = new MockSyncInterceptor(); - source.addInterceptor(sourceInterceptor); - - TargetInvocationConfiguration target = new TargetInvocationConfiguration(hello); - MockSyncInterceptor targetInterceptor = new MockSyncInterceptor(); - target.addInterceptor(targetInterceptor); - target.addInterceptor(new InvokerInterceptor()); - - // connect the source to the target - source.setTargetInterceptor(target.getHeadInterceptor()); - source.build(); - target.build(); - - CountDownLatch startSignal = new CountDownLatch(1); - CountDownLatch doneSignal = new CountDownLatch(1); - MockStaticInvoker invoker = new MockStaticInvoker(hello, new SimpleTargetImpl(startSignal, doneSignal)); - source.setTargetInvoker(invoker); - - Message msg = factory.createMessage(); - msg.setBody("foo"); - msg.setTargetInvoker(invoker); - Message response = source.getHeadInterceptor().invoke(msg); - startSignal.countDown(); - doneSignal.await(); - - Assert.assertEquals(null, response.getBody()); - Assert.assertEquals(1, sourceInterceptor.getCount()); - Assert.assertEquals(1, targetInterceptor.getCount()); - } -} diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/async/wire/mock/MockHandler.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/async/wire/mock/MockHandler.java deleted file mode 100644 index 4f17dc2a76..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/async/wire/mock/MockHandler.java +++ /dev/null @@ -1,38 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation - * - * Licensed 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.async.wire.mock; - -import org.apache.tuscany.core.wire.MessageHandler; -import org.apache.tuscany.core.message.Message; - -/** - * - */ -public class MockHandler implements MessageHandler { - - private int count =0; - - public boolean processMessage(Message message) { - //System.out.println("Invoking handler"); - count++; - return true; - } - - public int getCount(){ - return count; - } -} diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/async/wire/mock/MockStaticInvoker.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/async/wire/mock/MockStaticInvoker.java deleted file mode 100644 index e32de0eec1..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/async/wire/mock/MockStaticInvoker.java +++ /dev/null @@ -1,86 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation - * - * Licensed 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.async.wire.mock; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - -import org.apache.tuscany.core.message.Message; -import org.apache.tuscany.core.wire.Interceptor; -import org.apache.tuscany.core.wire.InvocationRuntimeException; -import org.apache.tuscany.core.wire.TargetInvoker; - -/** - * Caches component instances that do not need to be resolved for every wire, e.g. an wire originating from - * a lesser scope intended for a target with a wider scope - * - * @version $Rev: 377006 $ $Date: 2006-02-11 09:41:59 -0800 (Sat, 11 Feb 2006) $ - */ -public class MockStaticInvoker implements TargetInvoker { - - private Object instance; - - private Method operation; - - public MockStaticInvoker(Method operation, Object instance) { - this.operation = operation; - this.instance = instance; - } - - public boolean isCacheable() { - return true; - } - - public Object invokeTarget(Object payload) throws InvocationTargetException { - try { - if (payload != null && !payload.getClass().isArray()) { - return operation.invoke(instance, payload); - } else { - return operation.invoke(instance, (Object[]) payload); - } - } catch (IllegalAccessException e) { - throw new InvocationRuntimeException(e); - } - } - - public Message invoke(Message msg) { - try { - Object resp = invokeTarget(msg.getBody()); - msg.setBody(resp); - } catch (InvocationTargetException e) { - msg.setBody(e.getCause()); - } catch (Throwable e) { - msg.setBody(e); - } - return msg; - } - - public void setNext(Interceptor next) { - throw new IllegalStateException("This interceptor must be the last interceptor in an interceptor chain"); - } - - public Object clone() throws CloneNotSupportedException { - try { - MockStaticInvoker invoker = (MockStaticInvoker) super.clone(); - invoker.instance = this.instance; - invoker.operation = this.operation; - return invoker; - } catch (CloneNotSupportedException e) { - return null; // will not happen - } - } -} diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/async/wire/mock/MockSyncInterceptor.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/async/wire/mock/MockSyncInterceptor.java deleted file mode 100644 index 5b70848d06..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/async/wire/mock/MockSyncInterceptor.java +++ /dev/null @@ -1,45 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * Licensed 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.async.wire.mock; - -import org.apache.tuscany.core.wire.Interceptor; -import org.apache.tuscany.core.message.Message; - -public class MockSyncInterceptor implements Interceptor { - - private int count; - - private Interceptor next; - - public MockSyncInterceptor() { - } - - public Message invoke(Message msg) { - ++count; - //System.out.println("Invoking interceptor"); - return next.invoke(msg); - } - - public int getCount() { - return count; - } - - public void setNext(Interceptor next) { - this.next=next; - } -} - diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/async/wire/mock/SimpleTarget.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/async/wire/mock/SimpleTarget.java deleted file mode 100644 index 2147a3a4db..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/async/wire/mock/SimpleTarget.java +++ /dev/null @@ -1,28 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * Licensed 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.async.wire.mock; - -public interface SimpleTarget { - - public void hello(String message) throws Exception; - - public void goodbye(String message) throws Exception; - - public void echo(String message) throws Exception; - -} - diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/async/wire/mock/SimpleTargetImpl.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/async/wire/mock/SimpleTargetImpl.java deleted file mode 100644 index e6f76494f6..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/async/wire/mock/SimpleTargetImpl.java +++ /dev/null @@ -1,54 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * Licensed 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.async.wire.mock; - -import java.util.concurrent.CountDownLatch; - -public class SimpleTargetImpl implements SimpleTarget { - - private final CountDownLatch startSignal; - private final CountDownLatch doneSignal; - - public SimpleTargetImpl(CountDownLatch startSignal, CountDownLatch doneSignal) { - this.startSignal = startSignal; - this.doneSignal = doneSignal; - } - - public void hello(String message) throws Exception { - try { - startSignal.await(); - doneSignal.countDown(); - } catch (InterruptedException ex) {} - } - - public void goodbye(String message) throws Exception { - try { - startSignal.await(); - doneSignal.countDown(); - } catch (InterruptedException ex) {} - } - - public void echo(String message) throws Exception { - try { - startSignal.await(); - doneSignal.countDown(); - } catch (InterruptedException ex) {} - } - - -} - diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/async/work/DefaultWorkManagerTestCase.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/async/work/DefaultWorkManagerTestCase.java deleted file mode 100644 index 964564f3ee..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/async/work/DefaultWorkManagerTestCase.java +++ /dev/null @@ -1,98 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * Licensed 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.async.work; - -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; -import java.util.concurrent.CountDownLatch; - -import javax.resource.spi.work.Work; - -import junit.framework.TestCase; - -import org.apache.tuscany.core.async.work.DefaultWorkManager; - -/** - * Test the PooledWorkManager. - */ -public class DefaultWorkManagerTestCase extends TestCase { - - private Set<Thread> done; - private int count; - - public void testScheduleWork() throws Exception { - - DefaultWorkManager workManager = new DefaultWorkManager(); - workManager.setScheduledMaximumPoolSize(3); - workManager.init(); - - int max=workManager.getScheduledMaximumPoolSize()*5; - done=Collections.synchronizedSet(new HashSet<Thread>()); - count=0; - - CountDownLatch startSignal = new CountDownLatch(1); - CountDownLatch doneSignal = new CountDownLatch(max); - for (int i = 0; i < max; ++i) { - workManager.scheduleWork(new Worker(startSignal, doneSignal)); - } - startSignal.countDown(); - doneSignal.await(); - - assertFalse(done.contains(Thread.currentThread())); - assert(done.size()==workManager.getScheduledMaximumPoolSize()); - assert(count==max); - - done=null; - count=0; - - workManager.destroy(); - - } - - private synchronized void done(Thread thread) { - done.add(thread); - count++; - } - - private class Worker implements Work { - private final CountDownLatch startSignal; - private final CountDownLatch doneSignal; - - Worker(CountDownLatch startSignal, CountDownLatch doneSignal) { - this.startSignal = startSignal; - this.doneSignal = doneSignal; - } - - public void run() { - try { - startSignal.await(); - - DefaultWorkManagerTestCase.this.done(Thread.currentThread()); - //System.out.println(Thread.currentThread()); - - doneSignal.countDown(); - } catch (InterruptedException ex) { - } - } - - public void release() { - } - - } - -} diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/async/work/GeronimoWorkManagerTestCase.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/async/work/GeronimoWorkManagerTestCase.java deleted file mode 100644 index 18570d54c3..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/async/work/GeronimoWorkManagerTestCase.java +++ /dev/null @@ -1,138 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * Licensed 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.async.work; - -import javax.resource.spi.work.Work; -import javax.resource.spi.work.WorkEvent; -import javax.resource.spi.work.WorkListener; - -import junit.framework.TestCase; - -import org.apache.geronimo.connector.work.GeronimoWorkManager; -import org.apache.geronimo.transaction.context.TransactionContextManager; - -/** - * Tests the Geronimo work manager - * - * @version $Rev$ $Date$ - */ -public class GeronimoWorkManagerTestCase extends TestCase { - - private GeronimoWorkManager workManager; - - protected void setUp() throws Exception { - TransactionContextManager transactionContextManager = new TransactionContextManager(); - - workManager = new GeronimoWorkManager(2, transactionContextManager); - workManager.doStart(); - } - - public void testScheduleWork() throws Exception { - TestThread threads[] = startTestThreads(5, 10000, 100); - int accepted = 0; - int started = 0; - for (int i = 0; i < threads.length; i++) { - if (null != threads[i].listener.acceptedEvent) { - accepted++; - } else if (null != threads[i].listener.startedEvent) { - started++; - } else { - fail("incorrect state, expecting accepted or started"); - } - } - assertTrue(accepted > 0); - } - - private TestThread[] startTestThreads(int count, int timeout, int delay) throws Exception { - TestThread threads[] = new TestThread[count]; - for (int i = 0; i < count; i++) { - TestWorkListener listener=new TestWorkListener(); - threads[i] = new TestThread(listener, timeout, delay); - } - for (int i = 0; i < count; i++) { - threads[i].start(); - } - for (int i = 0; i < count; i++) { - threads[i].join(); - } - return threads; - } - - private class TestThread extends Thread { - public final TestWorkListener listener; - private final int timeout; - private final int delay; - - public TestThread(TestWorkListener listener, int timeout, int delay) { - this.listener = listener; - this.timeout = timeout; - this.delay = delay; - } - - public void run() { - try { - workManager.scheduleWork(new TestWorker(delay), timeout, null, listener); - } catch (Exception e) { - e.printStackTrace(); - } - } - - } - - public class TestWorker implements Work { - private final int delay; - - public TestWorker(int delay) { - this.delay = delay; - } - - public void release() { - } - - public void run() { - try { - Thread.sleep(delay); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - } - - public class TestWorkListener implements WorkListener { - public WorkEvent acceptedEvent; - public WorkEvent rejectedEvent; - public WorkEvent startedEvent; - public WorkEvent completedEvent; - - public void workAccepted(WorkEvent e) { - acceptedEvent = e; - } - - public void workRejected(WorkEvent e) { - rejectedEvent = e; - } - - public void workStarted(WorkEvent e) { - startedEvent = e; - } - - public void workCompleted(WorkEvent e) { - completedEvent = e; - } - } -} diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/builder/impl/DefaultWireBuilderTestCase.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/builder/impl/DefaultWireBuilderTestCase.java deleted file mode 100644 index e4aaad62d1..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/builder/impl/DefaultWireBuilderTestCase.java +++ /dev/null @@ -1,465 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation - * - * Licensed 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.builder.impl; - -import junit.framework.Assert; -import junit.framework.TestCase; -import org.apache.tuscany.core.context.QualifiedName; -import org.apache.tuscany.core.wire.MethodHashMap; -import org.apache.tuscany.core.wire.WireSourceConfiguration; -import org.apache.tuscany.core.wire.WireTargetConfiguration; -import org.apache.tuscany.core.wire.SourceInvocationConfiguration; -import org.apache.tuscany.core.wire.TargetInvocationConfiguration; -import org.apache.tuscany.core.wire.SourceWireFactory; -import org.apache.tuscany.core.wire.WireFactoryFactory; -import org.apache.tuscany.core.wire.TargetWireFactory; -import org.apache.tuscany.core.wire.mock.SimpleTarget; -import org.apache.tuscany.core.wire.mock.MockHandler; -import org.apache.tuscany.core.wire.mock.MockSyncInterceptor; -import org.apache.tuscany.core.wire.mock.MockStaticInvoker; -import org.apache.tuscany.core.wire.mock.SimpleTargetImpl; -import org.apache.tuscany.core.wire.impl.InvokerInterceptor; -import org.apache.tuscany.core.wire.jdk.JDKWireFactoryFactory; -import org.apache.tuscany.core.message.Message; -import org.apache.tuscany.core.message.MessageFactory; -import org.apache.tuscany.core.message.impl.MessageFactoryImpl; - -import java.lang.reflect.Method; -import java.util.Map; - -public class DefaultWireBuilderTestCase extends TestCase { - - private Method hello; - - private WireFactoryFactory wireFactoryFactory = new JDKWireFactoryFactory(); - - public DefaultWireBuilderTestCase() { - super(); - } - - public DefaultWireBuilderTestCase(String arg0) { - super(arg0); - } - - public void setUp() throws Exception { - hello = SimpleTarget.class.getMethod("hello", String.class); - } - - public void testWireWithInterceptorsAndHandlers() throws Exception { - MessageFactory msgFactory = new MessageFactoryImpl(); - - SourceInvocationConfiguration source = new SourceInvocationConfiguration(hello); - MockHandler sourceRequestHandler = new MockHandler(); - MockHandler sourceResponseHandler = new MockHandler(); - MockSyncInterceptor sourceInterceptor = new MockSyncInterceptor(); - source.addRequestHandler(sourceRequestHandler); - source.addResponseHandler(sourceResponseHandler); - source.addInterceptor(sourceInterceptor); - - SourceWireFactory sourceFactory = wireFactoryFactory.createSourceWireFactory(); - Map<Method, SourceInvocationConfiguration> sourceInvocationConfigs = new MethodHashMap<SourceInvocationConfiguration>(); - sourceInvocationConfigs.put(hello, source); - WireSourceConfiguration sourceConfig = new WireSourceConfiguration("foo",new QualifiedName("target/SimpleTarget"), - sourceInvocationConfigs, Thread.currentThread().getContextClassLoader(), msgFactory); - sourceFactory.setConfiguration(sourceConfig); - sourceFactory.setBusinessInterface(SimpleTarget.class); - - TargetInvocationConfiguration target = new TargetInvocationConfiguration(hello); - MockHandler targetRequestHandler = new MockHandler(); - MockHandler targetResponseHandler = new MockHandler(); - MockSyncInterceptor targetInterceptor = new MockSyncInterceptor(); - target.addRequestHandler(targetRequestHandler); - target.addResponseHandler(targetResponseHandler); - target.addInterceptor(targetInterceptor); - target.addInterceptor(new InvokerInterceptor()); - - TargetWireFactory targetFactory = wireFactoryFactory.createTargetWireFactory(); - Map<Method, TargetInvocationConfiguration> targetInvocationConfigs = new MethodHashMap<TargetInvocationConfiguration>(); - targetInvocationConfigs.put(hello, target); - WireTargetConfiguration targetConfig = new WireTargetConfiguration(new QualifiedName("target/SimpleTarget"), - targetInvocationConfigs, Thread.currentThread().getContextClassLoader(), msgFactory); - targetFactory.setConfiguration(targetConfig); - targetFactory.setBusinessInterface(SimpleTarget.class); - - // connect the source to the target - DefaultWireBuilder builder = new DefaultWireBuilder(); - // no need for scopes since we use a static invoker - builder.connect(sourceFactory, targetFactory, null, true, null); - // source.buildSource(); - target.build(); - // set a static invoker - MockStaticInvoker invoker = new MockStaticInvoker(hello, new SimpleTargetImpl()); - source.setTargetInvoker(invoker); - - Message msg = msgFactory.createMessage(); - msg.setBody("foo"); - msg.setTargetInvoker(invoker); - Message response = source.getHeadInterceptor().invoke(msg); - Assert.assertEquals("foo", response.getBody()); - Assert.assertEquals(1, sourceRequestHandler.getCount()); - Assert.assertEquals(1, sourceResponseHandler.getCount()); - Assert.assertEquals(1, sourceInterceptor.getCount()); - Assert.assertEquals(1, targetRequestHandler.getCount()); - Assert.assertEquals(1, targetResponseHandler.getCount()); - Assert.assertEquals(1, targetInterceptor.getCount()); - } - - public void testWireWithSourceInterceptorTargetHandlersAndTargetInterceptor() throws Exception { - MessageFactory msgFactory = new MessageFactoryImpl(); - - SourceInvocationConfiguration source = new SourceInvocationConfiguration(hello); - MockSyncInterceptor sourceInterceptor = new MockSyncInterceptor(); - source.addInterceptor(sourceInterceptor); - - SourceWireFactory sourceFactory = new JDKWireFactoryFactory().createSourceWireFactory(); - Map<Method, SourceInvocationConfiguration> sourceInvocationConfigs = new MethodHashMap<SourceInvocationConfiguration>(); - sourceInvocationConfigs.put(hello, source); - WireSourceConfiguration sourceConfig = new WireSourceConfiguration("foo",new QualifiedName("target/SimpleTarget"), - sourceInvocationConfigs, Thread.currentThread().getContextClassLoader(), msgFactory); - sourceFactory.setConfiguration(sourceConfig); - sourceFactory.setBusinessInterface(SimpleTarget.class); - - TargetInvocationConfiguration target = new TargetInvocationConfiguration(hello); - MockHandler targetRequestHandler = new MockHandler(); - MockHandler targetResponseHandler = new MockHandler(); - MockSyncInterceptor targetInterceptor = new MockSyncInterceptor(); - target.addRequestHandler(targetRequestHandler); - target.addResponseHandler(targetResponseHandler); - target.addInterceptor(targetInterceptor); - target.addInterceptor(new InvokerInterceptor()); - - TargetWireFactory targetFactory = wireFactoryFactory.createTargetWireFactory(); - Map<Method, TargetInvocationConfiguration> targetInvocationConfigs = new MethodHashMap<TargetInvocationConfiguration>(); - targetInvocationConfigs.put(hello, target); - WireTargetConfiguration targetConfig = new WireTargetConfiguration(new QualifiedName("target/SimpleTarget"), - targetInvocationConfigs, Thread.currentThread().getContextClassLoader(), msgFactory); - targetFactory.setConfiguration(targetConfig); - targetFactory.setBusinessInterface(SimpleTarget.class); - - // connect the source to the target - DefaultWireBuilder builder = new DefaultWireBuilder(); - // no need for scopes since we use a static invoker - builder.connect(sourceFactory, targetFactory, null, true, null); - // source.buildSource(); - target.build(); - // set a static invoker - MockStaticInvoker invoker = new MockStaticInvoker(hello, new SimpleTargetImpl()); - source.setTargetInvoker(invoker); - - Message msg = msgFactory.createMessage(); - msg.setBody("foo"); - msg.setTargetInvoker(invoker); - Message response = source.getHeadInterceptor().invoke(msg); - Assert.assertEquals("foo", response.getBody()); - Assert.assertEquals(1, sourceInterceptor.getCount()); - Assert.assertEquals(1, targetRequestHandler.getCount()); - Assert.assertEquals(1, targetResponseHandler.getCount()); - Assert.assertEquals(1, targetInterceptor.getCount()); - } - - public void testWireWithInterceptorsAndRequestHandlers() throws Exception { - MessageFactory msgFactory = new MessageFactoryImpl(); - - SourceInvocationConfiguration source = new SourceInvocationConfiguration(hello); - MockHandler sourceRequestHandler = new MockHandler(); - MockSyncInterceptor sourceInterceptor = new MockSyncInterceptor(); - source.addRequestHandler(sourceRequestHandler); - source.addInterceptor(sourceInterceptor); - - SourceWireFactory sourceFactory = new JDKWireFactoryFactory().createSourceWireFactory(); - Map<Method, SourceInvocationConfiguration> sourceInvocationConfigs = new MethodHashMap<SourceInvocationConfiguration>(); - sourceInvocationConfigs.put(hello, source); - WireSourceConfiguration sourceConfig = new WireSourceConfiguration("foo",new QualifiedName("target/SimpleTarget"), - sourceInvocationConfigs, Thread.currentThread().getContextClassLoader(), msgFactory); - sourceFactory.setConfiguration(sourceConfig); - sourceFactory.setBusinessInterface(SimpleTarget.class); - - TargetInvocationConfiguration target = new TargetInvocationConfiguration(hello); - MockHandler targetRequestHandler = new MockHandler(); - MockSyncInterceptor targetInterceptor = new MockSyncInterceptor(); - target.addRequestHandler(targetRequestHandler); - target.addInterceptor(targetInterceptor); - target.addInterceptor(new InvokerInterceptor()); - - TargetWireFactory targetFactory = wireFactoryFactory.createTargetWireFactory(); - Map<Method, TargetInvocationConfiguration> targetInvocationConfigs = new MethodHashMap<TargetInvocationConfiguration>(); - targetInvocationConfigs.put(hello, target); - WireTargetConfiguration targetConfig = new WireTargetConfiguration(new QualifiedName("target/SimpleTarget"), - targetInvocationConfigs, Thread.currentThread().getContextClassLoader(), msgFactory); - targetFactory.setConfiguration(targetConfig); - targetFactory.setBusinessInterface(SimpleTarget.class); - - // connect the source to the target - DefaultWireBuilder builder = new DefaultWireBuilder(); - // no need for scopes since we use a static invoker - builder.connect(sourceFactory, targetFactory, null, true, null); - // source.buildSource(); - target.build(); - // set a static invoker - MockStaticInvoker invoker = new MockStaticInvoker(hello, new SimpleTargetImpl()); - source.setTargetInvoker(invoker); - - Message msg = msgFactory.createMessage(); - msg.setBody("foo"); - msg.setTargetInvoker(invoker); - Message response = source.getHeadInterceptor().invoke(msg); - Assert.assertEquals("foo", response.getBody()); - Assert.assertEquals(1, sourceRequestHandler.getCount()); - Assert.assertEquals(1, sourceInterceptor.getCount()); - Assert.assertEquals(1, targetRequestHandler.getCount()); - Assert.assertEquals(1, targetInterceptor.getCount()); - } - - public void testWireWithSourceAndTargetInterceptors() throws Exception { - MessageFactory msgFactory = new MessageFactoryImpl(); - - SourceInvocationConfiguration source = new SourceInvocationConfiguration(hello); - MockSyncInterceptor sourceInterceptor = new MockSyncInterceptor(); - source.addInterceptor(sourceInterceptor); - - SourceWireFactory sourceFactory = new JDKWireFactoryFactory().createSourceWireFactory(); - Map<Method, SourceInvocationConfiguration> sourceInvocationConfigs = new MethodHashMap<SourceInvocationConfiguration>(); - sourceInvocationConfigs.put(hello, source); - WireSourceConfiguration sourceConfig = new WireSourceConfiguration("foo",new QualifiedName("target/SimpleTarget"), - sourceInvocationConfigs, Thread.currentThread().getContextClassLoader(), msgFactory); - sourceFactory.setConfiguration(sourceConfig); - sourceFactory.setBusinessInterface(SimpleTarget.class); - - TargetInvocationConfiguration target = new TargetInvocationConfiguration(hello); - MockSyncInterceptor targetInterceptor = new MockSyncInterceptor(); - target.addInterceptor(targetInterceptor); - target.addInterceptor(new InvokerInterceptor()); - - TargetWireFactory targetFactory = wireFactoryFactory.createTargetWireFactory(); - Map<Method, TargetInvocationConfiguration> targetInvocationConfigs = new MethodHashMap<TargetInvocationConfiguration>(); - targetInvocationConfigs.put(hello, target); - WireTargetConfiguration targetConfig = new WireTargetConfiguration(new QualifiedName("target/SimpleTarget"), - targetInvocationConfigs, Thread.currentThread().getContextClassLoader(), msgFactory); - targetFactory.setConfiguration(targetConfig); - targetFactory.setBusinessInterface(SimpleTarget.class); - - // connect the source to the target - DefaultWireBuilder builder = new DefaultWireBuilder(); - // no need for scopes since we use a static invoker - builder.connect(sourceFactory, targetFactory, null, true, null); - // source.buildSource(); - target.build(); - // set a static invoker - MockStaticInvoker invoker = new MockStaticInvoker(hello, new SimpleTargetImpl()); - source.setTargetInvoker(invoker); - - Message msg = msgFactory.createMessage(); - msg.setBody("foo"); - msg.setTargetInvoker(invoker); - Message response = source.getHeadInterceptor().invoke(msg); - Assert.assertEquals("foo", response.getBody()); - Assert.assertEquals(1, sourceInterceptor.getCount()); - Assert.assertEquals(1, targetInterceptor.getCount()); - } - - public void testWireWithSourceInterceptorSourceHandlersAndTargetInterceptor() throws Exception { - MessageFactory msgFactory = new MessageFactoryImpl(); - - SourceInvocationConfiguration source = new SourceInvocationConfiguration(hello); - MockHandler sourceRequestHandler = new MockHandler(); - MockHandler sourceResponseHandler = new MockHandler(); - MockSyncInterceptor sourceInterceptor = new MockSyncInterceptor(); - source.addRequestHandler(sourceRequestHandler); - source.addResponseHandler(sourceResponseHandler); - source.addInterceptor(sourceInterceptor); - - SourceWireFactory sourceFactory = new JDKWireFactoryFactory().createSourceWireFactory(); - Map<Method, SourceInvocationConfiguration> sourceInvocationConfigs = new MethodHashMap<SourceInvocationConfiguration>(); - sourceInvocationConfigs.put(hello, source); - WireSourceConfiguration sourceConfig = new WireSourceConfiguration("foo",new QualifiedName("target/SimpleTarget"), - sourceInvocationConfigs, Thread.currentThread().getContextClassLoader(), msgFactory); - sourceFactory.setConfiguration(sourceConfig); - sourceFactory.setBusinessInterface(SimpleTarget.class); - - TargetInvocationConfiguration target = new TargetInvocationConfiguration(hello); - MockSyncInterceptor targetInterceptor = new MockSyncInterceptor(); - target.addInterceptor(targetInterceptor); - target.addInterceptor(new InvokerInterceptor()); - - TargetWireFactory targetFactory = wireFactoryFactory.createTargetWireFactory(); - Map<Method, TargetInvocationConfiguration> targetInvocationConfigs = new MethodHashMap<TargetInvocationConfiguration>(); - targetInvocationConfigs.put(hello, target); - WireTargetConfiguration targetConfig = new WireTargetConfiguration(new QualifiedName("target/SimpleTarget"), - targetInvocationConfigs, Thread.currentThread().getContextClassLoader(), msgFactory); - targetFactory.setConfiguration(targetConfig); - targetFactory.setBusinessInterface(SimpleTarget.class); - - // connect the source to the target - DefaultWireBuilder builder = new DefaultWireBuilder(); - // no need for scopes since we use a static invoker - builder.connect(sourceFactory, targetFactory, null, true, null); - // source.buildSource(); - target.build(); - // set a static invoker - MockStaticInvoker invoker = new MockStaticInvoker(hello, new SimpleTargetImpl()); - source.setTargetInvoker(invoker); - - Message msg = msgFactory.createMessage(); - msg.setBody("foo"); - msg.setTargetInvoker(invoker); - Message response = source.getHeadInterceptor().invoke(msg); - Assert.assertEquals("foo", response.getBody()); - Assert.assertEquals(1, sourceRequestHandler.getCount()); - Assert.assertEquals(1, sourceResponseHandler.getCount()); - Assert.assertEquals(1, sourceInterceptor.getCount()); - Assert.assertEquals(1, targetInterceptor.getCount()); - } - - public void testWireWithTargetInterceptorAndTargetHandlers() throws Exception { - MessageFactory msgFactory = new MessageFactoryImpl(); - - SourceInvocationConfiguration source = new SourceInvocationConfiguration(hello); - - SourceWireFactory sourceFactory = new JDKWireFactoryFactory().createSourceWireFactory(); - Map<Method, SourceInvocationConfiguration> sourceInvocationConfigs = new MethodHashMap<SourceInvocationConfiguration>(); - sourceInvocationConfigs.put(hello, source); - WireSourceConfiguration sourceConfig = new WireSourceConfiguration("foo",new QualifiedName("target/SimpleTarget"), - sourceInvocationConfigs, Thread.currentThread().getContextClassLoader(), msgFactory); - sourceFactory.setConfiguration(sourceConfig); - sourceFactory.setBusinessInterface(SimpleTarget.class); - - TargetInvocationConfiguration target = new TargetInvocationConfiguration(hello); - MockHandler targetRequestHandler = new MockHandler(); - MockHandler targetResponseHandler = new MockHandler(); - MockSyncInterceptor targetInterceptor = new MockSyncInterceptor(); - target.addRequestHandler(targetRequestHandler); - target.addResponseHandler(targetResponseHandler); - target.addInterceptor(targetInterceptor); - target.addInterceptor(new InvokerInterceptor()); - - TargetWireFactory targetFactory = wireFactoryFactory.createTargetWireFactory(); - Map<Method, TargetInvocationConfiguration> targetInvocationConfigs = new MethodHashMap<TargetInvocationConfiguration>(); - targetInvocationConfigs.put(hello, target); - WireTargetConfiguration targetConfig = new WireTargetConfiguration(new QualifiedName("target/SimpleTarget"), - targetInvocationConfigs, Thread.currentThread().getContextClassLoader(), msgFactory); - targetFactory.setConfiguration(targetConfig); - targetFactory.setBusinessInterface(SimpleTarget.class); - - // connect the source to the target - DefaultWireBuilder builder = new DefaultWireBuilder(); - // no need for scopes since we use a static invoker - builder.connect(sourceFactory, targetFactory, null, true, null); - // source.buildSource(); - target.build(); - // set a static invoker - MockStaticInvoker invoker = new MockStaticInvoker(hello, new SimpleTargetImpl()); - source.setTargetInvoker(invoker); - - Message msg = msgFactory.createMessage(); - msg.setBody("foo"); - msg.setTargetInvoker(invoker); - Message response = source.getHeadInterceptor().invoke(msg); - Assert.assertEquals("foo", response.getBody()); - Assert.assertEquals(1, targetRequestHandler.getCount()); - Assert.assertEquals(1, targetResponseHandler.getCount()); - Assert.assertEquals(1, targetInterceptor.getCount()); - } - - public void testWireWithTargetInterceptor() throws Exception { - MessageFactory msgFactory = new MessageFactoryImpl(); - - SourceInvocationConfiguration source = new SourceInvocationConfiguration(hello); - - SourceWireFactory sourceFactory = new JDKWireFactoryFactory().createSourceWireFactory(); - Map<Method, SourceInvocationConfiguration> sourceInvocationConfigs = new MethodHashMap<SourceInvocationConfiguration>(); - sourceInvocationConfigs.put(hello, source); - WireSourceConfiguration sourceConfig = new WireSourceConfiguration("foo",new QualifiedName("target/SimpleTarget"), - sourceInvocationConfigs, Thread.currentThread().getContextClassLoader(), msgFactory); - sourceFactory.setConfiguration(sourceConfig); - sourceFactory.setBusinessInterface(SimpleTarget.class); - - TargetInvocationConfiguration target = new TargetInvocationConfiguration(hello); - MockSyncInterceptor targetInterceptor = new MockSyncInterceptor(); - target.addInterceptor(targetInterceptor); - target.addInterceptor(new InvokerInterceptor()); - - TargetWireFactory targetFactory = wireFactoryFactory.createTargetWireFactory(); - Map<Method, TargetInvocationConfiguration> targetInvocationConfigs = new MethodHashMap<TargetInvocationConfiguration>(); - targetInvocationConfigs.put(hello, target); - WireTargetConfiguration targetConfig = new WireTargetConfiguration(new QualifiedName("target/SimpleTarget"), - targetInvocationConfigs, Thread.currentThread().getContextClassLoader(), msgFactory); - targetFactory.setConfiguration(targetConfig); - targetFactory.setBusinessInterface(SimpleTarget.class); - - // connect the source to the target - DefaultWireBuilder builder = new DefaultWireBuilder(); - // no need for scopes since we use a static invoker - builder.connect(sourceFactory, targetFactory, null, true, null); - target.build(); - // set a static invoker - MockStaticInvoker invoker = new MockStaticInvoker(hello, new SimpleTargetImpl()); - source.setTargetInvoker(invoker); - - Message msg = msgFactory.createMessage(); - msg.setBody("foo"); - msg.setTargetInvoker(invoker); - Message response = source.getHeadInterceptor().invoke(msg); - Assert.assertEquals("foo", response.getBody()); - Assert.assertEquals(1, targetInterceptor.getCount()); - } - - /** - * When there are only {@link InvokerInterceptor}s in the source and target chain, we need to bypass one during - * wire up so they are not chained together - */ - public void testWireWithOnlyInvokerInterceptors() throws Exception { - MessageFactory msgFactory = new MessageFactoryImpl(); - - SourceInvocationConfiguration source = new SourceInvocationConfiguration(hello); - source.setTargetInterceptor(new InvokerInterceptor()); - - SourceWireFactory sourceFactory = new JDKWireFactoryFactory().createSourceWireFactory(); - Map<Method, SourceInvocationConfiguration> sourceInvocationConfigs = new MethodHashMap<SourceInvocationConfiguration>(); - sourceInvocationConfigs.put(hello, source); - WireSourceConfiguration sourceConfig = new WireSourceConfiguration("foo",new QualifiedName("target/SimpleTarget"), - sourceInvocationConfigs, Thread.currentThread().getContextClassLoader(), msgFactory); - sourceFactory.setConfiguration(sourceConfig); - sourceFactory.setBusinessInterface(SimpleTarget.class); - - TargetInvocationConfiguration target = new TargetInvocationConfiguration(hello); - target.addInterceptor(new InvokerInterceptor()); - - TargetWireFactory targetFactory = wireFactoryFactory.createTargetWireFactory(); - Map<Method, TargetInvocationConfiguration> targetInvocationConfigs = new MethodHashMap<TargetInvocationConfiguration>(); - targetInvocationConfigs.put(hello, target); - WireTargetConfiguration targetConfig = new WireTargetConfiguration(new QualifiedName("target/SimpleTarget"), - targetInvocationConfigs, Thread.currentThread().getContextClassLoader(), msgFactory); - targetFactory.setConfiguration(targetConfig); - targetFactory.setBusinessInterface(SimpleTarget.class); - - // connect the source to the target - DefaultWireBuilder builder = new DefaultWireBuilder(); - // no need for scopes since we use a static invoker - builder.connect(sourceFactory, targetFactory, null, true, null); - target.build(); - // set a static invoker - MockStaticInvoker invoker = new MockStaticInvoker(hello, new SimpleTargetImpl()); - source.setTargetInvoker(invoker); - - Message msg = msgFactory.createMessage(); - msg.setBody("foo"); - msg.setTargetInvoker(invoker); - Message response = source.getHeadInterceptor().invoke(msg); - Assert.assertEquals("foo", response.getBody()); - } - -} diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/builder/impl/NegativeDefaultWireBuilderTestCase.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/builder/impl/NegativeDefaultWireBuilderTestCase.java deleted file mode 100644 index 983dc577c4..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/builder/impl/NegativeDefaultWireBuilderTestCase.java +++ /dev/null @@ -1,89 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation - * - * Licensed 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.builder.impl; - -import junit.framework.TestCase; -import org.apache.tuscany.core.builder.BuilderConfigException; -import org.apache.tuscany.core.context.QualifiedName; -import org.apache.tuscany.core.wire.MethodHashMap; -import org.apache.tuscany.core.wire.WireSourceConfiguration; -import org.apache.tuscany.core.wire.WireTargetConfiguration; -import org.apache.tuscany.core.wire.SourceInvocationConfiguration; -import org.apache.tuscany.core.wire.TargetInvocationConfiguration; -import org.apache.tuscany.core.wire.SourceWireFactory; -import org.apache.tuscany.core.wire.TargetWireFactory; -import org.apache.tuscany.core.wire.WireFactoryFactory; -import org.apache.tuscany.core.wire.jdk.JDKWireFactoryFactory; -import org.apache.tuscany.core.wire.mock.SimpleTarget; -import org.apache.tuscany.core.message.MessageFactory; -import org.apache.tuscany.core.message.impl.MessageFactoryImpl; - -import java.lang.reflect.Method; -import java.util.Map; - -public class NegativeDefaultWireBuilderTestCase extends TestCase { - - private Method hello; - - private WireFactoryFactory wireFactoryFactory = new JDKWireFactoryFactory(); - - public NegativeDefaultWireBuilderTestCase() { - super(); - } - - public NegativeDefaultWireBuilderTestCase(String arg0) { - super(arg0); - } - - public void setUp() throws Exception { - hello = SimpleTarget.class.getMethod("hello", String.class); - } - - public void testNoTargetInterceptorOrHandler() throws Exception { - MessageFactory msgFactory = new MessageFactoryImpl(); - - SourceInvocationConfiguration source = new SourceInvocationConfiguration(hello); - - SourceWireFactory sourceFactory = new JDKWireFactoryFactory().createSourceWireFactory(); - Map<Method, SourceInvocationConfiguration> sourceInvocationConfigs = new MethodHashMap<SourceInvocationConfiguration>(); - sourceInvocationConfigs.put(hello, source); - WireSourceConfiguration sourceConfig = new WireSourceConfiguration("foo",new QualifiedName("target/SimpleTarget"), - sourceInvocationConfigs, Thread.currentThread().getContextClassLoader(), msgFactory); - sourceFactory.setConfiguration(sourceConfig); - sourceFactory.setBusinessInterface(SimpleTarget.class); - - TargetInvocationConfiguration target = new TargetInvocationConfiguration(hello); - - TargetWireFactory targetFactory = wireFactoryFactory.createTargetWireFactory(); - Map<Method, TargetInvocationConfiguration> targetInvocationConfigs = new MethodHashMap<TargetInvocationConfiguration>(); - targetInvocationConfigs.put(hello, target); - WireTargetConfiguration targetConfig = new WireTargetConfiguration(new QualifiedName("target/SimpleTarget"), - targetInvocationConfigs, Thread.currentThread().getContextClassLoader(), msgFactory); - targetFactory.setConfiguration(targetConfig); - targetFactory.setBusinessInterface(SimpleTarget.class); - - // connect the source to the target - DefaultWireBuilder builder = new DefaultWireBuilder(); - try { - builder.connect(sourceFactory, targetFactory, null, true, null); - fail("Expected " + BuilderConfigException.class.getName()); - } catch (BuilderConfigException e) { - // success - } - } - -} diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/config/Bean1.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/config/Bean1.java deleted file mode 100644 index c02961e5f4..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/config/Bean1.java +++ /dev/null @@ -1,45 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation - * - * Licensed 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.config; - - -public class Bean1 extends SuperBean { - - public static final int ALL_BEAN1_FIELDS = 6 + ALL_SUPER_FIELDS; - public static final int ALL_BEAN1_PUBLIC_PROTECTED_FIELDS = 5 + ALL_SUPER_PUBLIC_PROTECTED_FIELDS; - - public static final int ALL__BEAN1_METHODS = 4 + ALL_SUPER_METHODS - 1; - - private String field1; - protected String field2; - public String field3; - - public void setMethod1(String param) { - } - - public void setMethod1(int param) { - } - - public void override(String param) throws Exception { - } - - - public void noOverride(String param) throws Exception { - } - - -} diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/config/Bean2.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/config/Bean2.java deleted file mode 100644 index eaba545d8e..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/config/Bean2.java +++ /dev/null @@ -1,46 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation - * - * Licensed 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.config; - -import junit.framework.AssertionFailedError; - -import java.util.List; - -public class Bean2 { - - private List methodList; - - public List getMethodList() { - return methodList; - } - - public void setMethodList(List list) { - methodList = list; - } - - private List fieldList; - - public List getfieldList() { - return fieldList; - } - - public void setfieldList(List list) { - throw new AssertionFailedError("setter inadvertantly called"); - } - - -} diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/config/JavaIntrospectionHelperTestCase.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/config/JavaIntrospectionHelperTestCase.java deleted file mode 100644 index 8a95a6c7b0..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/config/JavaIntrospectionHelperTestCase.java +++ /dev/null @@ -1,163 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation - * - * Licensed 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.config; - -import junit.framework.Assert; -import junit.framework.TestCase; -import org.apache.tuscany.core.mock.component.Target; - -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.util.List; -import java.util.Map; -import java.util.Set; - -public class JavaIntrospectionHelperTestCase extends TestCase { - - public JavaIntrospectionHelperTestCase() { - super(); - } - - public JavaIntrospectionHelperTestCase(String arg0) { - super(arg0); - } - - public void testGetSuperAllFields() throws Exception { - Set<Field> superBeanFields = JavaIntrospectionHelper.getAllFields(SuperBean.class); - Assert.assertEquals(SuperBean.ALL_SUPER_FIELDS, superBeanFields.size()); - } - - public void testBean1AllPublicProtectedFields() throws Exception { - Set<Field> beanFields = JavaIntrospectionHelper.getAllPublicAndProtectedFields(Bean1.class); - Assert.assertEquals(4, beanFields.size()); //Bean1.ALL_BEAN1_PUBLIC_PROTECTED_FIELDS - } - - public void testBean1AllFields() throws Exception { - Set<Field> beanFields = JavaIntrospectionHelper.getAllFields(Bean1.class); - Assert.assertEquals(Bean1.ALL_BEAN1_FIELDS, beanFields.size()); - } - - public void testGetSuperAllMethods() throws Exception { - Set<Method> superBeanMethods = JavaIntrospectionHelper.getAllUniqueMethods(SuperBean.class); - Assert.assertEquals(SuperBean.ALL_SUPER_METHODS, superBeanMethods.size()); - } - - public void testGetBean1AllMethods() throws Exception { - Set<Method> beanMethods = JavaIntrospectionHelper.getAllUniqueMethods(Bean1.class); - Assert.assertEquals(Bean1.ALL__BEAN1_METHODS, beanMethods.size()); - } - - public void testOverrideMethod() throws Exception { - Set<Method> beanFields = JavaIntrospectionHelper.getAllUniqueMethods(Bean1.class); - boolean invoked = false; - for (Method method : beanFields) { - if (method.getName().equals("override")) { - method.invoke(new Bean1(), "foo"); - invoked = true; - } - } - if (!invoked) { - throw new Exception("Override never invoked"); - } - } - - public void testNoOverrideMethod() throws Exception { - Set<Method> beanFields = JavaIntrospectionHelper.getAllUniqueMethods(Bean1.class); - boolean found = false; - for (Method method : beanFields) { - if (method.getName().equals("noOverride") && method.getParameterTypes().length == 0) { - found = true; - } - } - if (!found) { - throw new Exception("No override not found"); - } - } - - public void testGetBean1AllFields() throws Exception { - Set<Field> bean1 = JavaIntrospectionHelper.getAllFields(Bean1.class); - Assert.assertEquals(Bean1.ALL_BEAN1_FIELDS, bean1.size()); - } - - public void testDefaultConstructor() throws Exception { - Constructor ctr = JavaIntrospectionHelper.getDefaultConstructor(Bean2.class); - Assert.assertEquals(ctr, Bean2.class.getConstructor()); - Assert.assertTrue(Bean2.class == ctr.newInstance((Object[]) null).getClass()); - } - - - public void testFindMultiplicityByFieldName() throws Exception{ - Set<Field> fields = JavaIntrospectionHelper.getAllFields(getClass()); - Set<Method> methods = JavaIntrospectionHelper.getAllUniqueMethods(getClass()); - - Assert.assertNotNull(JavaIntrospectionHelper.findMultiplicityFieldByName("testList",fields)); - Assert.assertNotNull(JavaIntrospectionHelper.findMultiplicityMethodByName("fooMethod",methods)); - - // this array is not an interface - Assert.assertNull(JavaIntrospectionHelper.findMultiplicityFieldByName("testStringArray",fields)); - Assert.assertNotNull(JavaIntrospectionHelper.findMultiplicityFieldByName("testArray",fields)); - Assert.assertNotNull(JavaIntrospectionHelper.findMultiplicityMethodByName("setTestArray",methods)); - } - - /** - * Tests generics introspection capabilities - */ - public void testGenerics() throws Exception{ - - List classes = JavaIntrospectionHelper.getGenerics(getClass().getDeclaredField("testList").getGenericType()); - Assert.assertEquals(1,classes.size()); - Assert.assertEquals(String.class,classes.get(0)); - - classes = JavaIntrospectionHelper.getGenerics(getClass().getDeclaredField("testNoGenericsList").getGenericType()); - Assert.assertEquals(0,classes.size()); - - classes = JavaIntrospectionHelper.getGenerics(getClass().getDeclaredField("testMap").getGenericType()); - Assert.assertEquals(2,classes.size()); - Assert.assertEquals(String.class,classes.get(0)); - Assert.assertEquals(Bean1.class,classes.get(1)); - - classes = JavaIntrospectionHelper.getGenerics(getClass().getDeclaredMethod("fooMethod", Map.class).getGenericParameterTypes()[0]); - Assert.assertEquals(2,classes.size()); - Assert.assertEquals(String.class,classes.get(0)); - Assert.assertEquals(Bean1.class,classes.get(1)); - - classes = JavaIntrospectionHelper.getGenerics(getClass().getDeclaredMethod("fooMethod", List.class).getGenericParameterTypes()[0]); - Assert.assertEquals(1,classes.size()); - Assert.assertEquals(String.class,classes.get(0)); - - } - - private List testNoGenericsList; - - private List<String> testList; - - private Map<String,Bean1> testMap; - - private void fooMethod(List<String> foo){ - - } - - private void fooMethod(Map<String, Bean1> foo){ - - } - - private Target[] testArray; - private String[] testStringArray; - - public void setTestArray(Target[] array){} -} diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/config/SuperBean.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/config/SuperBean.java deleted file mode 100644 index 0a4e0cca0c..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/config/SuperBean.java +++ /dev/null @@ -1,48 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation - * - * Licensed 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.config; - -/** - * @version $Rev: 368822 $ $Date: 2006-01-13 10:54:38 -0800 (Fri, 13 Jan 2006) $ - */ -public class SuperBean { - - public static final int ALL_SUPER_FIELDS = 6; - public static final int ALL_SUPER_PUBLIC_PROTECTED_FIELDS = 5; - - public static final int ALL_SUPER_METHODS = 4; - - private String superField1; - - public String superField2; - - protected String superField3; - - public void setSuperMethod1(String param) { - } - - public void setSuperMethod1(int param) { - } - - public void override(String param) throws Exception { - throw new Exception("Override not handled"); - } - - public void noOverride() throws Exception { - } - -} diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/config/impl/CoreAnnotationsProcessingTestCase.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/config/impl/CoreAnnotationsProcessingTestCase.java deleted file mode 100644 index aeb614e9c6..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/config/impl/CoreAnnotationsProcessingTestCase.java +++ /dev/null @@ -1,173 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * Licensed 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.config.impl; - -import java.util.List; - -import junit.framework.TestCase; -import org.apache.tuscany.core.config.ComponentTypeIntrospector; -import org.apache.tuscany.core.config.JavaIntrospectionHelper; -import org.apache.tuscany.core.config.processor.ProcessorUtils; -import org.apache.tuscany.core.system.assembly.impl.SystemAssemblyFactoryImpl; -import org.apache.tuscany.model.assembly.AssemblyFactory; -import org.apache.tuscany.model.assembly.ComponentType; -import org.apache.tuscany.model.assembly.Multiplicity; -import org.apache.tuscany.model.assembly.Reference; -import org.apache.tuscany.model.assembly.Scope; -import org.apache.tuscany.model.assembly.Service; -import org.apache.tuscany.model.assembly.ServiceContract; - -/** - * @version $$Rev$$ $$Date$$ - */ -public class CoreAnnotationsProcessingTestCase extends TestCase { - - private ComponentTypeIntrospector introspector; - private AssemblyFactory factory; - - public void testServiceBasicProcessing() throws Exception { - ComponentType type = factory.createComponentType(); - introspector.introspect(TestComponentImpl.class, type); - assertEquals(1, type.getServices().size()); - ServiceContract contract = type.getServices().get(0).getServiceContract(); - assertEquals(TestComponent.class, contract.getInterface()); - assertEquals(Scope.MODULE, contract.getScope()); - } - - public void testServiceNameSet() throws Exception { - ComponentType type = factory.createComponentType(); - introspector.introspect(TestComponentImpl.class, type); - assertEquals(1, type.getServices().size()); - Service service = type.getServices().get(0); - assertEquals(JavaIntrospectionHelper.getBaseName(TestComponent.class), service.getName()); - } - - /** - * Tests the case where a class implements one interface not marked as with <code>Remotable</code> - */ - public void testSingleServiceProcessing() throws Exception { - ComponentType type = factory.createComponentType(); - introspector.introspect(TestLocalComponentImpl.class, type); - assertEquals(1, type.getServices().size()); - ServiceContract contract = type.getServices().get(0).getServiceContract(); - assertEquals(TestLocalComponent.class, contract.getInterface()); - assertEquals(Scope.MODULE, contract.getScope()); - } - - /** - * Tests the case where an implementation specifies a service interface of its parent as opposed to the - * single interface it directly implements - */ - public void testInteraceHierarchyServiceProcessing() throws Exception { - ComponentType type = factory.createComponentType(); - introspector.introspect(SuperFooImpl.class, type); - assertEquals(1, type.getServices().size()); - ServiceContract contract = type.getServices().get(0).getServiceContract(); - assertEquals(SuperSuperFoo.class, contract.getInterface()); - } - - /** - * Tests the case where a class implements two interfaces, with one specified using <code>@Service</code> - * and one marked with <code>@Remotable</code> - */ - public void testMutlipleServiceProcessing() throws Exception { - ComponentType type = factory.createComponentType(); - introspector.introspect(TestMultipleInterfacesComponentImpl.class, type); - assertEquals(2, type.getServices().size()); - for (Service service : type.getServices()) { - if (!service.getServiceContract().equals(TestComponent.class) && - service.getServiceContract().equals(TestLocalComponent.class)) { - fail("Expected multiple interfaces not found"); - } - } - } - - /** - * Test case when an class implements two non-Remotable interfaces and does not specify one with - * <code>@Service</code> - */ - public void testNonServiceProcessing() throws Exception { - ComponentType type = factory.createComponentType(); - introspector.introspect(TestNonServiceInterfacesImpl.class, type); - assertEquals(1, type.getServices().size()); - ServiceContract contract = type.getServices().get(0).getServiceContract(); - assertEquals(TestNonServiceInterfacesImpl.class, contract.getInterface()); - assertEquals(Scope.MODULE, contract.getScope()); - } - - /** - * Tests the case where a class implements two non-Remotable interfaces, with one specified using - * <code>@Service</code> - */ - public void testNonServiceSpecifiedProcessing() throws Exception { - ComponentType type = factory.createComponentType(); - introspector.introspect(TestNonServiceSpecifiedImpl.class, type); - assertEquals(1, type.getServices().size()); - ServiceContract contract = type.getServices().get(0).getServiceContract(); - assertEquals(TestNonServiceInterface.class, contract.getInterface()); - assertEquals(Scope.MODULE, contract.getScope()); - } - - /** - * Tests the case where a component's scope is specified by its superclass - */ - public void testParentScopeEvaluation() throws Exception { - ComponentType type = factory.createComponentType(); - introspector.introspect(ScopeTestComponent.class, type); - assertEquals(1, type.getServices().size()); - ServiceContract contract = type.getServices().get(0).getServiceContract(); - assertEquals(Scope.MODULE, contract.getScope()); - } - - /** - * FIXME JFM - temporarily disabled until non-annotated properties are fixed public void - * testPropertyProcessing() throws Exception { ComponentType type = factory.createComponentType(); - * introspector.introspect(TestComponentImpl.class, type); List<Property>properties = - * type.getProperties(); assertEquals(3, properties.size()); for (Property property : properties) { if - * (!property.getName().equals("foo") && !property.getName().equals("fooRequired") && - * !property.getName().equals("baz")) { fail("Property names not handled properly"); } if - * (property.getName().equals("fooRequired")) { assertTrue(property.isRequired()); } else { - * assertFalse(property.isRequired()); } } } * - */ - - public void testReferenceProcessing() throws Exception { - ComponentType type = factory.createComponentType(); - introspector.introspect(TestComponentImpl.class, type); - List<Reference>references = type.getReferences(); - assertEquals(5, references.size()); - for (Reference reference : references) { - if (reference.getName().equals("setBarRequired")) { - assertTrue(reference.getMultiplicity() == Multiplicity.ONE_N); - } else if (reference.getName().equals("setBar")) { - assertTrue(reference.getMultiplicity() == Multiplicity.ZERO_N); - } else if (reference.getName().equals("bazRefeference")) { - assertTrue(reference.getMultiplicity() == Multiplicity.ZERO_ONE); - } else if (reference.getName().equals("wombat")) { - assertTrue(reference.getMultiplicity() == Multiplicity.ONE_ONE); - } else if (reference.getName().equals("bar")) { - assertTrue(reference.getMultiplicity() == Multiplicity.ZERO_ONE); - } else { - fail("Reference names not handled properly"); - } - } - } - - - protected void setUp() throws Exception { - super.setUp(); - factory = new SystemAssemblyFactoryImpl(); - introspector = ProcessorUtils.createCoreIntrospector(factory); - } - -} diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/config/impl/ScopeTestComponent.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/config/impl/ScopeTestComponent.java deleted file mode 100644 index 1ae24b6b74..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/config/impl/ScopeTestComponent.java +++ /dev/null @@ -1,24 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation - * - * Licensed 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.config.impl; - -/** - * @version $$Rev$$ $$Date$$ - */ -public class ScopeTestComponent extends ScopedParent { - -} diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/config/impl/ScopedParent.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/config/impl/ScopedParent.java deleted file mode 100644 index 0507af1a8a..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/config/impl/ScopedParent.java +++ /dev/null @@ -1,26 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation - * - * Licensed 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.config.impl; - -import org.osoa.sca.annotations.Scope; - -/** - * @version $$Rev$$ $$Date$$ - */ -@Scope("MODULE") -public class ScopedParent { -} diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/config/impl/SuperFoo.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/config/impl/SuperFoo.java deleted file mode 100644 index e8a5079184..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/config/impl/SuperFoo.java +++ /dev/null @@ -1,23 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation - * - * Licensed 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.config.impl; - -/** - * @version $$Rev$$ $$Date$$ - */ -public interface SuperFoo { -} diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/config/impl/SuperFooImpl.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/config/impl/SuperFooImpl.java deleted file mode 100644 index 1d964cca8d..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/config/impl/SuperFooImpl.java +++ /dev/null @@ -1,26 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation - * - * Licensed 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.config.impl; - -import org.osoa.sca.annotations.Service; - -/** - * @version $$Rev$$ $$Date$$ - */ -@Service(SuperSuperFoo.class) -public class SuperFooImpl extends SuperSuperFooImpl implements SuperFoo{ -} diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/config/impl/SuperSuperFoo.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/config/impl/SuperSuperFoo.java deleted file mode 100644 index 893c2c5607..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/config/impl/SuperSuperFoo.java +++ /dev/null @@ -1,23 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation - * - * Licensed 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.config.impl; - -/** - * @version $$Rev$$ $$Date$$ - */ -public interface SuperSuperFoo { -} diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/config/impl/SuperSuperFooImpl.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/config/impl/SuperSuperFooImpl.java deleted file mode 100644 index 2025dd1cdd..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/config/impl/SuperSuperFooImpl.java +++ /dev/null @@ -1,20 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * Licensed 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.config.impl; - -/** - * @version $$Rev$$ $$Date$$ - */ -public class SuperSuperFooImpl implements SuperSuperFoo { -} diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/config/impl/TestComponent.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/config/impl/TestComponent.java deleted file mode 100644 index 8a462ff405..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/config/impl/TestComponent.java +++ /dev/null @@ -1,30 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation - * - * Licensed 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.config.impl; - -import org.osoa.sca.annotations.Remotable; -import org.osoa.sca.annotations.Scope; - -/** - * @version $$Rev$$ $$Date$$ - */ -@Remotable -@Scope("MODULE") -public interface TestComponent { - - -} diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/config/impl/TestComponentImpl.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/config/impl/TestComponentImpl.java deleted file mode 100644 index 691bf18b3f..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/config/impl/TestComponentImpl.java +++ /dev/null @@ -1,66 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * Licensed 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.config.impl; - -import java.util.List; - -import org.osoa.sca.annotations.Property; -import org.osoa.sca.annotations.Reference; -import org.osoa.sca.annotations.Service; - -/** - * @version $$Rev$$ $$Date$$ - */ -@Service(interfaces = {TestComponent.class}) -public class TestComponentImpl implements TestComponent { - - @Property - protected String baz; - - @Reference (name="bazRefeference") - protected TestComponent bazRef; - - @Reference (required = true) - protected TestComponent wombat; - - @Property - public void setFoo(String foo){ - - } - - @Property(name = "fooRequired",required = true) - public void setFooRequiredRename(String foo){ - - } - - @Reference - public void bar(String bar){ - - } - - @Reference(name ="setBarRequired", required = true) - public void setBar(List bar){ - - } - - @Reference(name ="setBar", required = false) - public void setBarNonRequired(List bar){ - - } - - public void someSetter(String val){ - - } - -} diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/config/impl/TestLocalComponent.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/config/impl/TestLocalComponent.java deleted file mode 100644 index 15b88547f7..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/config/impl/TestLocalComponent.java +++ /dev/null @@ -1,29 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation - * - * Licensed 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.config.impl; - -import org.osoa.sca.annotations.Remotable; -import org.osoa.sca.annotations.Scope; - -/** - * @version $$Rev$$ $$Date$$ - */ -@Scope("MODULE") -public interface TestLocalComponent { - - -} diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/config/impl/TestLocalComponentImpl.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/config/impl/TestLocalComponentImpl.java deleted file mode 100644 index 86aca3b1bf..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/config/impl/TestLocalComponentImpl.java +++ /dev/null @@ -1,32 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation - * - * Licensed 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.config.impl; - -import java.util.List; - -import org.osoa.sca.annotations.Service; -import org.osoa.sca.annotations.Property; -import org.osoa.sca.annotations.Reference; - -/** - * @version $$Rev$$ $$Date$$ - */ - -public class TestLocalComponentImpl implements TestLocalComponent { - - -} diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/config/impl/TestMultipleInterfacesComponentImpl.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/config/impl/TestMultipleInterfacesComponentImpl.java deleted file mode 100644 index b395fd5442..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/config/impl/TestMultipleInterfacesComponentImpl.java +++ /dev/null @@ -1,29 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation - * - * Licensed 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.config.impl; - -import org.osoa.sca.annotations.Service; - -/** - * @version $$Rev$$ $$Date$$ - */ - -@Service(interfaces = {TestLocalComponent.class}) -public class TestMultipleInterfacesComponentImpl implements TestComponent, TestLocalComponent { - - -} diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/config/impl/TestNonServiceInterface.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/config/impl/TestNonServiceInterface.java deleted file mode 100644 index 1a595573ae..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/config/impl/TestNonServiceInterface.java +++ /dev/null @@ -1,20 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * Licensed 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.config.impl; - -/** - * @version $$Rev$$ $$Date$$ - */ -public interface TestNonServiceInterface { -} diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/config/impl/TestNonServiceInterface2.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/config/impl/TestNonServiceInterface2.java deleted file mode 100644 index 8aa6e6cb19..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/config/impl/TestNonServiceInterface2.java +++ /dev/null @@ -1,23 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation - * - * Licensed 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.config.impl; - -/** - * @version $$Rev$$ $$Date$$ - */ -public interface TestNonServiceInterface2 { -} diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/config/impl/TestNonServiceInterfacesImpl.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/config/impl/TestNonServiceInterfacesImpl.java deleted file mode 100644 index 4f6f07b239..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/config/impl/TestNonServiceInterfacesImpl.java +++ /dev/null @@ -1,23 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * Licensed 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.config.impl; - -import org.osoa.sca.annotations.Scope; - -/** - * @version $$Rev$$ $$Date$$ - */ -@Scope("MODULE") -public class TestNonServiceInterfacesImpl implements TestNonServiceInterface, TestNonServiceInterface2{ -} diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/config/impl/TestNonServiceSpecifiedImpl.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/config/impl/TestNonServiceSpecifiedImpl.java deleted file mode 100644 index b8c0d6a7e8..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/config/impl/TestNonServiceSpecifiedImpl.java +++ /dev/null @@ -1,28 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation - * - * Licensed 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.config.impl; - -import org.osoa.sca.annotations.Scope; -import org.osoa.sca.annotations.Service; - -/** - * @version $$Rev$$ $$Date$$ - */ -@Scope("MODULE") -@Service(TestNonServiceInterface.class) -public class TestNonServiceSpecifiedImpl implements TestNonServiceInterface, TestNonServiceInterface2{ -} diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/context/AbstractCompositeHierarchyTests.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/context/AbstractCompositeHierarchyTests.java deleted file mode 100644 index f529595dae..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/context/AbstractCompositeHierarchyTests.java +++ /dev/null @@ -1,109 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * Licensed 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.context; - -import junit.framework.Assert; -import junit.framework.TestCase; -import org.apache.tuscany.core.builder.ContextFactoryBuilder; -import org.apache.tuscany.core.context.impl.CompositeContextImpl; -import org.apache.tuscany.core.context.impl.EventContextImpl; -import org.apache.tuscany.core.context.scope.DefaultScopeStrategy; -import org.apache.tuscany.core.context.event.ModuleStart; -import org.apache.tuscany.core.context.event.ModuleStop; -import org.apache.tuscany.core.mock.MockConfigContext; -import org.apache.tuscany.core.mock.MockFactory; -import org.apache.tuscany.core.mock.component.ModuleScopeSystemComponent; -import org.apache.tuscany.core.mock.component.ModuleScopeSystemComponentImpl; -import org.apache.tuscany.core.system.assembly.SystemAssemblyFactory; -import org.apache.tuscany.core.system.assembly.impl.SystemAssemblyFactoryImpl; -import org.apache.tuscany.model.assembly.Component; -import org.apache.tuscany.model.assembly.EntryPoint; -import org.apache.tuscany.model.assembly.Scope; -import org.osoa.sca.ModuleContext; - -import java.util.List; - -/** - * Performs testing of various hierarchical scenarios - * - * @version $Rev$ $Date$ - */ -public abstract class AbstractCompositeHierarchyTests extends TestCase { - protected List<ContextFactoryBuilder> builders; - protected SystemAssemblyFactory factory; - - public void testParentContextIsolation() throws Exception { - CompositeContext parent = createContextHierachy(); - CompositeContext child = (CompositeContext) parent.getContext("test.child"); - Component component = factory.createSystemComponent("TestService1", ModuleScopeSystemComponent.class, ModuleScopeSystemComponentImpl.class, Scope.MODULE); - parent.registerModelObject(component); - EntryPoint ep = MockFactory.createEPSystemBinding("TestService1EP", ModuleScopeSystemComponent.class, "TestService1", component); - parent.registerModelObject(ep); - parent.publish(new ModuleStart(this)); - child.publish(new ModuleStart(this)); - Assert.assertNotNull(parent.getContext("TestService1EP").getInstance(null)); - try { - ((ModuleContext) child).locateService("TestService1EP"); - fail("Expexcted " + ServiceNotFoundException.class.getName()); - } catch (ServiceNotFoundException e) { - // expect exception to be thrown - } - parent.publish(new ModuleStop(this)); - child.publish(new ModuleStop(this)); - parent.stop(); - - } - - /** - * Checks that registration of duplicate named model objects before context start throws an exception - */ - public void testRegisterSameName() throws Exception { - CompositeContext parent = new CompositeContextImpl("test.parent", null, new DefaultScopeStrategy(), - new EventContextImpl(), new MockConfigContext(builders)); - parent.registerModelObject(MockFactory.createSystemCompositeComponent("test.child")); - try { - parent.registerModelObject(MockFactory.createSystemCompositeComponent("test.child")); - parent.start(); - fail("Expected " + DuplicateNameException.class.getName()); - } catch (DuplicateNameException e) { - // expected - } - } - - /** - * Checks that registration of duplicate named model objects after context start throws an exception - */ - public void testRegisterSameNameAfterStart() throws Exception { - CompositeContext parent = new CompositeContextImpl("test.parent", null, new DefaultScopeStrategy(), - new EventContextImpl(), new MockConfigContext(builders)); - parent.registerModelObject(MockFactory.createSystemCompositeComponent("test.child")); - parent.start(); - CompositeContext child = (CompositeContext) parent.getContext("test.child"); - Assert.assertNotNull(child); - try { - parent.registerModelObject(MockFactory.createSystemCompositeComponent("test.child")); - fail("Expected " + DuplicateNameException.class.getName()); - } catch (DuplicateNameException e) { - // expected - } - } - - protected abstract CompositeContext createContextHierachy() throws Exception; - - protected void setUp() throws Exception { - super.setUp(); - factory = new SystemAssemblyFactoryImpl(); - builders = MockFactory.createSystemBuilders(); - } -} diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/context/CompositeContextRegisterTestCase.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/context/CompositeContextRegisterTestCase.java deleted file mode 100644 index b6e7f69daf..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/context/CompositeContextRegisterTestCase.java +++ /dev/null @@ -1,132 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * Licensed 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.context; - -import junit.framework.Assert; -import junit.framework.TestCase; -import org.apache.tuscany.core.builder.ContextFactoryBuilder; -import org.apache.tuscany.core.context.impl.CompositeContextImpl; -import org.apache.tuscany.core.context.impl.EventContextImpl; -import org.apache.tuscany.core.context.scope.DefaultScopeStrategy; -import org.apache.tuscany.core.context.event.ModuleStart; -import org.apache.tuscany.core.context.event.ModuleStop; -import org.apache.tuscany.core.mock.MockConfigContext; -import org.apache.tuscany.core.mock.MockFactory; -import org.apache.tuscany.core.mock.component.GenericSystemComponent; -import org.apache.tuscany.core.mock.component.ModuleScopeSystemComponent; -import org.apache.tuscany.core.mock.component.ModuleScopeSystemComponentImpl; -import org.apache.tuscany.core.system.assembly.SystemAssemblyFactory; -import org.apache.tuscany.core.system.assembly.impl.SystemAssemblyFactoryImpl; -import org.apache.tuscany.model.assembly.Component; -import org.apache.tuscany.model.assembly.EntryPoint; -import org.apache.tuscany.model.assembly.Module; -import org.apache.tuscany.model.assembly.Scope; - -import java.util.List; - -/** - * Tests registration of model objects for an composite context - * - * @version $Rev$ $Date$ - */ -public class CompositeContextRegisterTestCase extends TestCase { - private SystemAssemblyFactory factory; - - public void testModuleRegistration() throws Exception { - CompositeContext moduleContext = createContext(); - Module module = MockFactory.createSystemModule(); - moduleContext.registerModelObject(module); - moduleContext.start(); - moduleContext.publish(new ModuleStart(this)); - GenericSystemComponent component = (GenericSystemComponent) moduleContext.getContext("TestService1").getInstance(null); - Assert.assertNotNull(component); - GenericSystemComponent ep = (GenericSystemComponent) moduleContext.getContext("TestService1EP").getInstance(null); - Assert.assertNotNull(ep); - moduleContext.publish(new ModuleStop(this)); - moduleContext.stop(); - } - - public void testModuleRegistrationAfterStart() throws Exception { - CompositeContext moduleContext = createContext(); - moduleContext.start(); - Module module = MockFactory.createSystemModule(); - moduleContext.registerModelObject(module); - moduleContext.publish(new ModuleStart(this)); - GenericSystemComponent component = (GenericSystemComponent) moduleContext.getContext("TestService1").getInstance(null); - Assert.assertNotNull(component); - GenericSystemComponent ep = (GenericSystemComponent) moduleContext.getContext("TestService1EP").getInstance(null); - Assert.assertNotNull(ep); - moduleContext.publish(new ModuleStop(this)); - moduleContext.stop(); - } - - public void testRegistration() throws Exception { - CompositeContext moduleContext = createContext(); - Component component = factory.createSystemComponent("TestService1", ModuleScopeSystemComponent.class, ModuleScopeSystemComponentImpl.class, Scope.MODULE); - moduleContext.registerModelObject(component); - EntryPoint ep = MockFactory.createEPSystemBinding("TestService1EP", ModuleScopeSystemComponent.class, "TestService1", component); - moduleContext.registerModelObject(ep); - moduleContext.start(); - moduleContext.publish(new ModuleStart(this)); - GenericSystemComponent test = (GenericSystemComponent) moduleContext.getContext("TestService1").getInstance(null); - Assert.assertNotNull(test); - GenericSystemComponent testEP = (GenericSystemComponent) moduleContext.getContext("TestService1EP").getInstance(null); - Assert.assertNotNull(testEP); - moduleContext.publish(new ModuleStop(this)); - moduleContext.stop(); - } - - public void testRegistrationAfterStart() throws Exception { - CompositeContext moduleContext = createContext(); - Component component = factory.createSystemComponent("TestService1", ModuleScopeSystemComponent.class, ModuleScopeSystemComponentImpl.class, Scope.MODULE); - moduleContext.start(); - moduleContext.registerModelObject(component); - EntryPoint ep = MockFactory.createEPSystemBinding("TestService1EP", ModuleScopeSystemComponent.class, "TestService1", component); - moduleContext.registerModelObject(ep); - moduleContext.publish(new ModuleStart(this)); - GenericSystemComponent test = (GenericSystemComponent) moduleContext.getContext("TestService1").getInstance(null); - Assert.assertNotNull(test); - GenericSystemComponent testEP = (GenericSystemComponent) moduleContext.getContext("TestService1EP").getInstance(null); - Assert.assertNotNull(testEP); - moduleContext.publish(new ModuleStop(this)); - moduleContext.stop(); - } - - public void testEPRegistrationAfterModuleStart() throws Exception { - CompositeContext moduleContext = createContext(); - Component component = factory.createSystemComponent("TestService1", ModuleScopeSystemComponent.class, ModuleScopeSystemComponentImpl.class, Scope.MODULE); - moduleContext.start(); - moduleContext.registerModelObject(component); - moduleContext.publish(new ModuleStart(this)); - GenericSystemComponent test = (GenericSystemComponent) moduleContext.getContext("TestService1").getInstance(null); - Assert.assertNotNull(test); - EntryPoint ep = MockFactory.createEPSystemBinding("TestService1EP", ModuleScopeSystemComponent.class, "TestService1", component); - moduleContext.registerModelObject(ep); - GenericSystemComponent testEP = (GenericSystemComponent) moduleContext.getContext("TestService1EP").getInstance(null); - Assert.assertNotNull(testEP); - moduleContext.publish(new ModuleStop(this)); - moduleContext.stop(); - } - - protected CompositeContext createContext() { - List<ContextFactoryBuilder> builders = MockFactory.createSystemBuilders(); - return new CompositeContextImpl("test.context", null, new DefaultScopeStrategy(), new EventContextImpl(), - new MockConfigContext(builders)); - } - - protected void setUp() throws Exception { - factory = new SystemAssemblyFactoryImpl(); - super.setUp(); - } -} diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/context/CompositeHierarchyTestCase.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/context/CompositeHierarchyTestCase.java deleted file mode 100644 index bd56a88658..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/context/CompositeHierarchyTestCase.java +++ /dev/null @@ -1,99 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * Licensed 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.context; - -import junit.framework.Assert; -import org.apache.tuscany.core.builder.ContextFactoryBuilder; -import org.apache.tuscany.core.context.impl.CompositeContextImpl; -import org.apache.tuscany.core.context.impl.EventContextImpl; -import org.apache.tuscany.core.context.scope.DefaultScopeStrategy; -import org.apache.tuscany.core.context.event.ModuleStop; -import org.apache.tuscany.core.context.event.ModuleStart; -import org.apache.tuscany.core.mock.MockConfigContext; -import org.apache.tuscany.core.mock.MockFactory; -import org.apache.tuscany.core.mock.component.ModuleScopeSystemComponent; -import org.apache.tuscany.core.mock.component.ModuleScopeSystemComponentImpl; -import org.apache.tuscany.model.assembly.Component; -import org.apache.tuscany.model.assembly.EntryPoint; -import org.apache.tuscany.model.assembly.Scope; -import org.apache.tuscany.model.assembly.impl.AssemblyContextImpl; -import org.osoa.sca.ModuleContext; -import org.osoa.sca.ServiceUnavailableException; -import org.osoa.sca.ServiceRuntimeException; - -import java.util.List; - -/** - * Performs testing of various hierarchical scenarios - * - * @version $Rev$ $Date$ - */ -public class CompositeHierarchyTestCase extends AbstractCompositeHierarchyTests { - - /** - * FIXME model Tests adding a component, accessing it and then exposing it as an entry point after the first access - * - * @throws Exception - */ - public void testChildContextIsolation() throws Exception { - CompositeContext parent = createContextHierachy(); - CompositeContext child = (CompositeContext) parent.getContext("test.child"); - Component component = factory.createSystemComponent("TestService1", ModuleScopeSystemComponent.class, ModuleScopeSystemComponentImpl.class, Scope.MODULE); - - component.initialize(new AssemblyContextImpl(factory, null, null)); - child.registerModelObject(component); - parent.publish(new ModuleStart(this)); - child.publish(new ModuleStart(this)); - Assert.assertNotNull(child.getContext("TestService1").getInstance(null)); - try { - ((ModuleContext) parent).locateService("test.child/TestService1"); - fail("Expected " + ServiceUnavailableException.class.getName() - + " since [test.child/TestService1] is not an entry point"); - } catch (ServiceRuntimeException e) { - // should throw an exception since it is not an entry point - } - - // now expose the service as an entry point - // FIXME hack to get around initialization of component - just create another one ;-) - component = factory.createSystemComponent("TestService1", ModuleScopeSystemComponent.class, ModuleScopeSystemComponentImpl.class, Scope.MODULE); - EntryPoint ep = MockFactory.createEPSystemBinding("TestService1EP", ModuleScopeSystemComponent.class, "TestService1", - component); - child.registerModelObject(ep); - Assert.assertNotNull(child.getContext("TestService1EP").getInstance(null)); - Assert.assertNotNull(parent.getContext("test.child").getInstance(new QualifiedName("./TestService1EP"))); - - // now expose the child entry point from the parent context - EntryPoint parentEp = MockFactory.createEntryPointWithStringRef("TestService1EP", ModuleScopeSystemComponent.class, - "TestService1", "test.child/TestService1EP"); - parent.registerModelObject(parentEp); - Assert.assertNotNull(parent.getContext("TestService1EP").getInstance(null)); - - parent.publish(new ModuleStop(this)); - child.publish(new ModuleStop(this)); - parent.stop(); - } - - protected CompositeContext createContextHierachy() throws Exception { - List<ContextFactoryBuilder> systemBuilders = MockFactory.createSystemBuilders(); - CompositeContext parent = new CompositeContextImpl("test.parent", null, new DefaultScopeStrategy(), - new EventContextImpl(), new MockConfigContext(systemBuilders)); - Component component = MockFactory.createCompositeComponent("test.child"); - parent.registerModelObject(component); - parent.start(); - CompositeContext child = (CompositeContext) parent.getContext("test.child"); - Assert.assertNotNull(child); - return parent; - } - -} diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/context/QualifiedNameTestCase.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/context/QualifiedNameTestCase.java deleted file mode 100644 index 4f86d1aed5..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/context/QualifiedNameTestCase.java +++ /dev/null @@ -1,52 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * Licensed 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.context; - -import junit.framework.TestCase; - -/** - * Tests parsing of naming patters - * - * @version $Rev$ $Date$ - */ -public class QualifiedNameTestCase extends TestCase { - - public void testSimpleName() throws Exception { - QualifiedName name = new QualifiedName("Foo"); - assertEquals("Foo", name.getPartName()); - assertEquals(null, name.getPortName()); - } - - public void testCompoundName() throws Exception { - QualifiedName name = new QualifiedName("Foo/Bar"); - assertEquals("Foo", name.getPartName()); - assertEquals("Bar", name.getPortName()); - } - - public void testCompoundMultiName() throws Exception { - QualifiedName name = new QualifiedName("Foo/Bar/Baz"); - assertEquals("Foo", name.getPartName()); - assertEquals("Bar/Baz", name.getPortName()); - } - - public void testInvalidName() throws Exception { - try { - QualifiedName name = new QualifiedName("/Foo/Bar"); - fail("Invalid name exception not thrown"); - } catch (InvalidNameException e) { - - } - } - -} diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/context/scope/DefaultScopeStrategyTestCase.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/context/scope/DefaultScopeStrategyTestCase.java deleted file mode 100644 index c9e6736833..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/context/scope/DefaultScopeStrategyTestCase.java +++ /dev/null @@ -1,51 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * Licensed 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.context.scope; - -import junit.framework.Assert; -import junit.framework.TestCase; -import org.apache.tuscany.model.assembly.Scope; - -/** - * Basic scope strategy tests, including downscope referencing - * - * @version $Rev$ $Date$ - */ -public class DefaultScopeStrategyTestCase extends TestCase { - - public void testDownScopeReferences() throws Exception{ - DefaultScopeStrategy strategy = new DefaultScopeStrategy(); - - Assert.assertTrue(!strategy.downScopeReference(Scope.MODULE,Scope.MODULE)); - Assert.assertTrue(strategy.downScopeReference(Scope.MODULE,Scope.SESSION)); - Assert.assertTrue(strategy.downScopeReference(Scope.MODULE,Scope.REQUEST)); - Assert.assertTrue(strategy.downScopeReference(Scope.MODULE,Scope.INSTANCE)); - - Assert.assertTrue(!strategy.downScopeReference(Scope.SESSION,Scope.MODULE)); - Assert.assertTrue(!strategy.downScopeReference(Scope.SESSION,Scope.SESSION)); - Assert.assertTrue(strategy.downScopeReference(Scope.SESSION,Scope.REQUEST)); - Assert.assertTrue(strategy.downScopeReference(Scope.SESSION,Scope.INSTANCE)); - - Assert.assertTrue(!strategy.downScopeReference(Scope.REQUEST,Scope.MODULE)); - Assert.assertTrue(!strategy.downScopeReference(Scope.REQUEST,Scope.SESSION)); - Assert.assertTrue(!strategy.downScopeReference(Scope.REQUEST,Scope.REQUEST)); - Assert.assertTrue(strategy.downScopeReference(Scope.REQUEST,Scope.INSTANCE)); - - Assert.assertTrue(!strategy.downScopeReference(Scope.REQUEST,Scope.MODULE)); - Assert.assertTrue(!strategy.downScopeReference(Scope.REQUEST,Scope.SESSION)); - Assert.assertTrue(!strategy.downScopeReference(Scope.REQUEST,Scope.REQUEST)); - Assert.assertTrue(!strategy.downScopeReference(Scope.INSTANCE,Scope.INSTANCE)); - } -} - diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/extension/ContextFactorySupportTestCase.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/extension/ContextFactorySupportTestCase.java deleted file mode 100644 index 765d6efee4..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/extension/ContextFactorySupportTestCase.java +++ /dev/null @@ -1,80 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation - * - * Licensed 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.extension; - -import junit.framework.TestCase; -import org.apache.tuscany.core.builder.ContextFactory; -import org.apache.tuscany.model.assembly.Implementation; -import org.apache.tuscany.model.assembly.Scope; -import org.apache.tuscany.model.assembly.impl.AtomicImplementationImpl; - -/** - * @version $$Rev$$ $$Date$$ - */ -public class ContextFactorySupportTestCase extends TestCase { - - public void testGenericReflection() throws Exception { - TestFactoryBuilder b = new TestFactoryBuilder(); - assertEquals(TestImplementation.class, b.getImplementationClass()); - } - - public void testNegativeGenericReflection() throws Exception { - try { - new NonGenericFactoryBuilder(); - fail("AssertionError expected on non-genericized subclass of " + ContextFactoryBuilderSupport.class.getName()); - } catch (AssertionError e) { - // indicates success - } - } - - protected void setUp() throws Exception { - super.setUp(); - } - - protected void tearDown() throws Exception { - super.tearDown(); - } - - - private class TestFactoryBuilder extends ContextFactoryBuilderSupport<TestImplementation> { - - - public Class getImplementationClass() { - return implementationClass; - } - - protected ContextFactory createContextFactory(String componentName, TestImplementation implementation, Scope scope) { - return null; - } - } - - private class NonGenericFactoryBuilder extends ContextFactoryBuilderSupport { - - - public Class getImplementationClass() { - return implementationClass; - } - - protected ContextFactory createContextFactory(String componentName, Implementation implementation, Scope scope) { - return null; - } - } - - private class TestImplementation extends AtomicImplementationImpl { - - } -} diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/extension/EntryPointBuilderSupportTestCase.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/extension/EntryPointBuilderSupportTestCase.java deleted file mode 100644 index 2f911fefa5..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/extension/EntryPointBuilderSupportTestCase.java +++ /dev/null @@ -1,78 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation - * - * Licensed 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.extension; - -import junit.framework.TestCase; -import org.apache.tuscany.core.extension.EntryPointContextFactory; -import org.apache.tuscany.core.message.MessageFactory; -import org.apache.tuscany.model.assembly.Binding; -import org.apache.tuscany.model.assembly.EntryPoint; - -/** - * @version $$Rev$$ $$Date$$ - */ -public class EntryPointBuilderSupportTestCase extends TestCase { - - public void testGenericReflection() throws Exception { - EntryPointBuilderSupportTestCase.TestEntryPointBuilder b = new EntryPointBuilderSupportTestCase.TestEntryPointBuilder(); - assertEquals(EntryPointBuilderSupportTestCase.TestBinding.class, b.getImplementationClass()); - } - - public void testNegativeGenericReflection() throws Exception { - try { - new EntryPointBuilderSupportTestCase.NonGenericFactoryBuilder(); - fail("AssertionError expected on non-genericized subclass of " + ContextFactoryBuilderSupport.class.getName()); - } catch (AssertionError e) { - // indicates success - } - } - - protected void setUp() throws Exception { - super.setUp(); - } - - protected void tearDown() throws Exception { - super.tearDown(); - } - - - private class TestEntryPointBuilder extends EntryPointBuilderSupport<EntryPointBuilderSupportTestCase.TestBinding> { - - public Class getImplementationClass() { - return bindingClass; - } - - protected EntryPointContextFactory createEntryPointContextFactory(EntryPoint entryPoint, MessageFactory msgFactory) { - return null; - } - } - - private class NonGenericFactoryBuilder extends EntryPointBuilderSupport { - - public Class getImplementationClass() { - return bindingClass; - } - - protected EntryPointContextFactory createEntryPointContextFactory(EntryPoint entryPoint, MessageFactory msgFactory) { - return null; - } - } - - private interface TestBinding extends Binding { - - } -} diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/extension/ExternalServiceBuilderSupportTestCase.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/extension/ExternalServiceBuilderSupportTestCase.java deleted file mode 100644 index a1c758c526..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/extension/ExternalServiceBuilderSupportTestCase.java +++ /dev/null @@ -1,80 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation - * - * Licensed 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.extension; - -import junit.framework.TestCase; -import org.apache.tuscany.core.extension.ExternalServiceContextFactory; -import org.apache.tuscany.model.assembly.Binding; -import org.apache.tuscany.model.assembly.ExternalService; - -/** - * @version $$Rev$$ $$Date$$ - */ -public class ExternalServiceBuilderSupportTestCase extends TestCase { - - public void testGenericReflection() throws Exception { - ExternalServiceBuilderSupportTestCase.TestExternalServiceBuilder b = new ExternalServiceBuilderSupportTestCase.TestExternalServiceBuilder(); - assertEquals(ExternalServiceBuilderSupportTestCase.TestBinding.class, b.getImplementationClass()); - } - - public void testNegativeGenericReflection() throws Exception { - try { - new ExternalServiceBuilderSupportTestCase.NonGenericFactoryBuilder(); - fail("AssertionError expected on non-genericized subclass of " + ContextFactoryBuilderSupport.class.getName()); - } catch (AssertionError e) { - // indicates success - } - } - - protected void setUp() throws Exception { - super.setUp(); - } - - protected void tearDown() throws Exception { - super.tearDown(); - } - - - private class TestExternalServiceBuilder extends ExternalServiceBuilderSupport<ExternalServiceBuilderSupportTestCase.TestBinding> { - - - public Class getImplementationClass() { - return bindingClass; - } - - protected ExternalServiceContextFactory createExternalServiceContextFactory(ExternalService externalService) { - return null; - } - } - - private class NonGenericFactoryBuilder extends ExternalServiceBuilderSupport { - - - public Class getImplementationClass() { - return bindingClass; - } - - - protected ExternalServiceContextFactory createExternalServiceContextFactory(ExternalService externalService) { - return null; - } - } - - private interface TestBinding extends Binding { - - } -} diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/extension/WireBuilderSupportTestCase.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/extension/WireBuilderSupportTestCase.java deleted file mode 100644 index 0fd80c51af..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/extension/WireBuilderSupportTestCase.java +++ /dev/null @@ -1,261 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation - * - * Licensed 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.extension; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import junit.framework.TestCase; -import org.apache.tuscany.core.builder.ContextCreationException; -import org.apache.tuscany.core.builder.ContextFactory; -import org.apache.tuscany.core.builder.impl.DefaultWireBuilder; -import org.apache.tuscany.core.context.CompositeContext; -import org.apache.tuscany.core.context.Context; -import org.apache.tuscany.core.context.QualifiedName; -import org.apache.tuscany.core.context.ScopeContext; -import org.apache.tuscany.core.context.AtomicContext; -import org.apache.tuscany.core.message.Message; -import org.apache.tuscany.core.wire.Interceptor; -import org.apache.tuscany.core.wire.SourceWireFactory; -import org.apache.tuscany.core.wire.TargetInvocationConfiguration; -import org.apache.tuscany.core.wire.TargetInvoker; -import org.apache.tuscany.core.wire.TargetWireFactory; -import org.apache.tuscany.core.wire.WireTargetConfiguration; -import org.apache.tuscany.core.wire.jdk.JDKTargetWireFactory; -import org.apache.tuscany.core.wire.mock.MockScopeContext; -import org.apache.tuscany.model.assembly.Implementation; -import org.apache.tuscany.model.assembly.Scope; - -/** - * @version $$Rev$$ $$Date$$ - */ -public class WireBuilderSupportTestCase extends TestCase { - private Method m; - - /** - * Tests that {@link WireBuilderSupport} only processes connect operations and sets target invokers for - * the correct target type. - * <p/> - * Verifies TUSCANY-218 - * - * @throws Exception - */ - public void testTargetInvokerSet() throws Exception { - FooWireBuilder fooBuilder = new FooWireBuilder(); - BarWireBuilder barBuilder = new BarWireBuilder(); - DefaultWireBuilder defaultBuilder = new DefaultWireBuilder(); - defaultBuilder.addWireBuilder(fooBuilder); - defaultBuilder.addWireBuilder(barBuilder); - TargetWireFactory targetFooFactory = new JDKTargetWireFactory(); - Map<Method, TargetInvocationConfiguration> fooConfigs = new HashMap<Method, TargetInvocationConfiguration>(); - TargetInvocationConfiguration fooInvocation = new TargetInvocationConfiguration(m); - fooConfigs.put(m, fooInvocation); - Map<Method, TargetInvocationConfiguration> barConfigs = new HashMap<Method, TargetInvocationConfiguration>(); - TargetInvocationConfiguration barInvocation = new TargetInvocationConfiguration(m); - barConfigs.put(m, barInvocation); - targetFooFactory.setConfiguration(new WireTargetConfiguration(null, fooConfigs, null, null)); - TargetWireFactory targetBarFactory = new JDKTargetWireFactory(); - targetBarFactory.setConfiguration(new WireTargetConfiguration(null, barConfigs, null, null)); - ScopeContext ctx = new MockScopeContext(); - defaultBuilder.completeTargetChain(targetFooFactory, FooContextFactory.class, ctx); - defaultBuilder.completeTargetChain(targetBarFactory, BarContextFactory.class, ctx); - assertEquals(FooInvoker.class, targetFooFactory.getConfiguration().getInvocationConfigurations().get(m).getTargetInvoker().getClass()); - assertEquals(BarInvoker.class, targetBarFactory.getConfiguration().getInvocationConfigurations().get(m).getTargetInvoker().getClass()); - - } - - - protected void setUp() throws Exception { - super.setUp(); - m = SomeInterface.class.getMethod("test", (Class[]) null); - } - - protected void tearDown() throws Exception { - super.tearDown(); - } - - private interface SomeInterface { - void test(); - } - - private interface Foo extends Implementation { - - } - - private interface Bar extends Implementation { - - } - - private class FooWireBuilder extends WireBuilderSupport<FooContextFactory> { - - protected TargetInvoker createInvoker(QualifiedName targetName, Method operation, ScopeContext context, boolean downScope) { - return new FooInvoker(); - } - } - - private class BarWireBuilder extends WireBuilderSupport<BarContextFactory> { - - protected TargetInvoker createInvoker(QualifiedName targetName, Method operation, ScopeContext context, boolean downScope) { - return new BarInvoker(); - } - } - - private class FooInvoker implements TargetInvoker { - - public Object invokeTarget(Object payload) throws InvocationTargetException { - return null; - } - - public boolean isCacheable() { - return false; - } - - public Object clone() throws CloneNotSupportedException { - return super.clone(); - } - - public Message invoke(Message msg) { - return null; - } - - public void setNext(Interceptor next) { - - } - } - - - private class BarInvoker implements TargetInvoker { - - public Object invokeTarget(Object payload) throws InvocationTargetException { - return null; - } - - public boolean isCacheable() { - return false; - } - - public Object clone() throws CloneNotSupportedException { - return super.clone(); - } - - public Message invoke(Message msg) { - return null; - } - - public void setNext(Interceptor next) { - - } - } - - private class FooContextFactory implements ContextFactory<AtomicContext> { - - public AtomicContext createContext() throws ContextCreationException { - return null; - } - - public Scope getScope() { - return null; - } - - public String getName() { - return null; - } - - public void addProperty(String propertyName, Object value) { - - } - - public void addTargetWireFactory(String serviceName, TargetWireFactory factory) { - - } - - public TargetWireFactory getTargetWireFactory(String serviceName) { - return null; - } - - public Map getTargetWireFactories() { - return null; - } - - public void addSourceWireFactory(String referenceName, SourceWireFactory factory) { - - } - - public List getSourceWireFactories() { - return null; - } - - public void prepare(CompositeContext parent) { - - } - - public void addSourceWireFactories(String referenceName, Class referenceInterface, List factory, boolean multiplicity) { - - } - } - - - private class BarContextFactory implements ContextFactory<Context> { - public Context createContext() throws ContextCreationException { - return null; - } - - public Scope getScope() { - return null; - } - - public String getName() { - return null; - } - - public void addProperty(String propertyName, Object value) { - - } - - public void addTargetWireFactory(String serviceName, TargetWireFactory factory) { - - } - - public TargetWireFactory getTargetWireFactory(String serviceName) { - return null; - } - - public Map getTargetWireFactories() { - return null; - } - - public void addSourceWireFactory(String referenceName, SourceWireFactory factory) { - - } - - public void addSourceWireFactories(String referenceName, Class referenceInterface, List factory, boolean multiplicity) { - - } - - public List getSourceWireFactories() { - return null; - } - - public void prepare(CompositeContext parent) { - - } - } - -} diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/integration/IntraCompositeWireIntegrationTestCase.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/integration/IntraCompositeWireIntegrationTestCase.java deleted file mode 100644 index 44be759b69..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/integration/IntraCompositeWireIntegrationTestCase.java +++ /dev/null @@ -1,107 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * Licensed 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.integration; - -import junit.framework.Assert; -import junit.framework.TestCase; - -import org.apache.tuscany.core.config.ConfigurationException; -import org.apache.tuscany.core.context.AtomicContext; -import org.apache.tuscany.core.context.CompositeContext; -import org.apache.tuscany.core.context.event.ModuleStop; -import org.apache.tuscany.core.context.event.ModuleStart; -import org.apache.tuscany.core.mock.MockFactory; -import org.apache.tuscany.core.mock.component.Source; -import org.apache.tuscany.core.mock.component.Target; -import org.apache.tuscany.core.runtime.RuntimeContext; -import org.apache.tuscany.core.system.assembly.SystemAssemblyFactory; -import org.apache.tuscany.core.system.assembly.SystemModule; -import org.apache.tuscany.core.system.assembly.impl.SystemAssemblyFactoryImpl; -import org.apache.tuscany.core.system.context.SystemCompositeContextImpl; -import org.apache.tuscany.model.assembly.Module; -import org.apache.tuscany.model.assembly.ModuleComponent; -import org.apache.tuscany.model.assembly.Scope; -import org.apache.tuscany.model.assembly.Service; -import org.apache.tuscany.model.types.java.JavaServiceContract; - -/** - * Tests intra-composite system wires are properly constructed in the runtime - * - * @version $Rev$ $Date$ - */ -public class IntraCompositeWireIntegrationTestCase extends TestCase { - - - public void testWireConstruction2() throws Exception { - RuntimeContext runtime = MockFactory.createCoreRuntime(); - ModuleComponent moduleComponent = createSystemCompositeComponent("test.system"); - Module module = MockFactory.createSystemModuleWithWiredComponents("system.module",Scope.MODULE, Scope.MODULE); - moduleComponent.setImplementation(module); - runtime.getSystemContext().registerModelObject(moduleComponent); - CompositeContext context = (CompositeContext) runtime.getSystemContext().getContext("test.system"); - context.publish(new ModuleStart(this)); - //context.registerModelObject(module); - Source source = (Source) ((AtomicContext)context.getContext("source")).getTargetInstance(); - Assert.assertNotNull(source); - Target targetRef = source.getTarget(); - Assert.assertNotNull(targetRef); - Target target = (Target) ((AtomicContext)context.getContext("target")).getTargetInstance(); - Assert.assertSame(target, targetRef); - Source source2 = (Source) ((AtomicContext)context.getContext("source")).getTargetInstance(); - Assert.assertSame(target, source2.getTarget()); - context.publish(new ModuleStop(this)); - context.stop(); - } - - private static SystemAssemblyFactory systemFactory = new SystemAssemblyFactoryImpl(); - - /** - * Creates an composite component with the given name - */ - public static ModuleComponent createSystemCompositeComponent(String name) { - ModuleComponent sc = systemFactory.createModuleComponent(); - SystemModule impl = systemFactory.createSystemModule(); - impl.setImplementationClass(SystemCompositeContextImpl.class); - sc.setImplementation(impl); - Service s = systemFactory.createService(); - JavaServiceContract ji = systemFactory.createJavaServiceContract(); - s.setServiceContract(ji); - ji.setScope(Scope.AGGREGATE); - impl.setComponentType(systemFactory.createComponentType()); - impl.getComponentType().getServices().add(s); - sc.setName(name); - sc.setImplementation(impl); - return sc; - } - - - public void testWireConstruction() throws ConfigurationException { - RuntimeContext runtime = MockFactory.createCoreRuntime(); - runtime.getSystemContext().registerModelObject(MockFactory.createSystemCompositeComponent("test.system")); - CompositeContext context = (CompositeContext) runtime.getSystemContext().getContext("test.system"); - - context.publish(new ModuleStart(this)); - context.registerModelObject(MockFactory.createSystemModuleWithWiredComponents("system.module",Scope.MODULE,Scope.MODULE)); - Source source = (Source) ((AtomicContext)context.getContext("source")).getTargetInstance(); - Assert.assertNotNull(source); - Target targetRef = source.getTarget(); - Assert.assertNotNull(targetRef); - Target target = (Target) ((AtomicContext)context.getContext("target")).getTargetInstance(); - Assert.assertSame(target, targetRef); - Source source2 = (Source) ((AtomicContext)context.getContext("source")).getTargetInstance(); - Assert.assertSame(target, source2.getTarget()); - context.publish(new ModuleStop(this)); - context.stop(); - } -} diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/loader/JNDIPropertyFactoryTestCase.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/loader/JNDIPropertyFactoryTestCase.java deleted file mode 100644 index c17d96a145..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/loader/JNDIPropertyFactoryTestCase.java +++ /dev/null @@ -1,210 +0,0 @@ -/** - * - * Copyright 2006 The Apache Software Foundation - * - * Licensed 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.loader; - -import static javax.naming.Context.INITIAL_CONTEXT_FACTORY; -import java.io.StringReader; -import java.util.Hashtable; -import javax.xml.stream.XMLInputFactory; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; -import javax.naming.Context; -import javax.naming.NamingException; -import javax.naming.Name; -import javax.naming.NameClassPair; -import javax.naming.NamingEnumeration; -import javax.naming.Binding; -import javax.naming.NameParser; -import javax.naming.spi.InitialContextFactory; - -import junit.framework.TestCase; - -import org.apache.tuscany.core.builder.ObjectFactory; -import org.apache.tuscany.core.config.ConfigurationLoadException; -import org.apache.tuscany.core.loader.impl.JNDIPropertyFactory; -import org.apache.tuscany.model.assembly.AssemblyFactory; -import org.apache.tuscany.model.assembly.Property; -import org.apache.tuscany.model.assembly.impl.AssemblyFactoryImpl; - -/** - * @version $Rev$ $Date$ - */ -@SuppressWarnings({"AccessOfSystemProperties"}) -public class JNDIPropertyFactoryTestCase extends TestCase { - private JNDIPropertyFactory factory; - private XMLInputFactory xmlFactory; - private Property property; - private String oldICF; - - public void testLookup() throws XMLStreamException, ConfigurationLoadException { - String instance = getInstance(String.class, "<foo>foo:/hello</foo>"); - assertEquals("Hello World", instance); - } - - private <T> T getInstance(Class<T> type, String xml) throws XMLStreamException, ConfigurationLoadException { - property.setType(type); - XMLStreamReader reader = xmlFactory.createXMLStreamReader(new StringReader(xml)); - reader.next(); - ObjectFactory<T> objectFactory = (ObjectFactory<T>) factory.createObjectFactory(reader, property); - return objectFactory.getInstance(); - } - - protected void setUp() throws Exception { - super.setUp(); - factory = new JNDIPropertyFactory(); - xmlFactory = XMLInputFactory.newInstance(); - AssemblyFactory assemblyFactory = new AssemblyFactoryImpl(); - property = assemblyFactory.createProperty(); - - oldICF = System.getProperty(INITIAL_CONTEXT_FACTORY); - System.setProperty(INITIAL_CONTEXT_FACTORY, MockContextFactory.class.getName()); - } - - protected void tearDown() throws Exception { - if (oldICF != null) { - System.getProperty(INITIAL_CONTEXT_FACTORY, oldICF); - } - super.tearDown(); - } - - public static class MockContextFactory implements InitialContextFactory { - public Context getInitialContext(Hashtable<?, ?> environment) throws NamingException { - return new MockContext(); - } - } - - public static class MockContext implements Context { - public Object lookup(String name) throws NamingException { - if ("foo:/hello".equals(name)) { - return "Hello World"; - } - throw new AssertionError(); - } - - public Object lookup(Name name) throws NamingException { - throw new UnsupportedOperationException(); - } - - public void bind(Name name, Object obj) throws NamingException { - throw new UnsupportedOperationException(); - } - - public void bind(String name, Object obj) throws NamingException { - throw new UnsupportedOperationException(); - } - - public void rebind(Name name, Object obj) throws NamingException { - throw new UnsupportedOperationException(); - } - - public void rebind(String name, Object obj) throws NamingException { - throw new UnsupportedOperationException(); - } - - public void unbind(Name name) throws NamingException { - throw new UnsupportedOperationException(); - } - - public void unbind(String name) throws NamingException { - throw new UnsupportedOperationException(); - } - - public void rename(Name oldName, Name newName) throws NamingException { - throw new UnsupportedOperationException(); - } - - public void rename(String oldName, String newName) throws NamingException { - throw new UnsupportedOperationException(); - } - - public NamingEnumeration<NameClassPair> list(Name name) throws NamingException { - throw new UnsupportedOperationException(); - } - - public NamingEnumeration<NameClassPair> list(String name) throws NamingException { - throw new UnsupportedOperationException(); - } - - public NamingEnumeration<Binding> listBindings(Name name) throws NamingException { - throw new UnsupportedOperationException(); - } - - public NamingEnumeration<Binding> listBindings(String name) throws NamingException { - throw new UnsupportedOperationException(); - } - - public void destroySubcontext(Name name) throws NamingException { - throw new UnsupportedOperationException(); - } - - public void destroySubcontext(String name) throws NamingException { - throw new UnsupportedOperationException(); - } - - public Context createSubcontext(Name name) throws NamingException { - throw new UnsupportedOperationException(); - } - - public Context createSubcontext(String name) throws NamingException { - throw new UnsupportedOperationException(); - } - - public Object lookupLink(Name name) throws NamingException { - throw new UnsupportedOperationException(); - } - - public Object lookupLink(String name) throws NamingException { - throw new UnsupportedOperationException(); - } - - public NameParser getNameParser(Name name) throws NamingException { - throw new UnsupportedOperationException(); - } - - public NameParser getNameParser(String name) throws NamingException { - throw new UnsupportedOperationException(); - } - - public Name composeName(Name name, Name prefix) throws NamingException { - throw new UnsupportedOperationException(); - } - - public String composeName(String name, String prefix) throws NamingException { - throw new UnsupportedOperationException(); - } - - public Object addToEnvironment(String propName, Object propVal) throws NamingException { - throw new UnsupportedOperationException(); - } - - public Object removeFromEnvironment(String propName) throws NamingException { - throw new UnsupportedOperationException(); - } - - public Hashtable<?, ?> getEnvironment() throws NamingException { - throw new UnsupportedOperationException(); - } - - public void close() throws NamingException { - throw new UnsupportedOperationException(); - } - - public String getNameInNamespace() throws NamingException { - throw new UnsupportedOperationException(); - } - } -} diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/loader/MockReaderSupport.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/loader/MockReaderSupport.java deleted file mode 100644 index 542a4d7b2b..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/loader/MockReaderSupport.java +++ /dev/null @@ -1,210 +0,0 @@ -/** - * - * Copyright 2006 The Apache Software Foundation - * - * Licensed 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.loader; - -import javax.xml.stream.XMLStreamReader; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.Location; -import javax.xml.namespace.QName; -import javax.xml.namespace.NamespaceContext; - -/** - * Base class for a mock XMLStreamReader. - * - * @version $Rev$ $Date$ - */ -public class MockReaderSupport implements XMLStreamReader { - public QName getName() { - throw new UnsupportedOperationException(); - } - - public Object getProperty(String name) throws IllegalArgumentException { - throw new UnsupportedOperationException(); - } - - public int next() throws XMLStreamException { - throw new UnsupportedOperationException(); - } - - public void require(int i, String name, String name1) throws XMLStreamException { - throw new UnsupportedOperationException(); - } - - public String getElementText() throws XMLStreamException { - throw new UnsupportedOperationException(); - } - - public int nextTag() throws XMLStreamException { - throw new UnsupportedOperationException(); - } - - public boolean hasNext() throws XMLStreamException { - throw new UnsupportedOperationException(); - } - - public void close() throws XMLStreamException { - throw new UnsupportedOperationException(); - } - - public String getNamespaceURI(String name) { - throw new UnsupportedOperationException(); - } - - public boolean isStartElement() { - throw new UnsupportedOperationException(); - } - - public boolean isEndElement() { - throw new UnsupportedOperationException(); - } - - public boolean isCharacters() { - throw new UnsupportedOperationException(); - } - - public boolean isWhiteSpace() { - throw new UnsupportedOperationException(); - } - - public String getAttributeValue(String name, String name1) { - throw new UnsupportedOperationException(); - } - - public int getAttributeCount() { - throw new UnsupportedOperationException(); - } - - public QName getAttributeName(int i) { - throw new UnsupportedOperationException(); - } - - public String getAttributeNamespace(int i) { - throw new UnsupportedOperationException(); - } - - public String getAttributeLocalName(int i) { - throw new UnsupportedOperationException(); - } - - public String getAttributePrefix(int i) { - throw new UnsupportedOperationException(); - } - - public String getAttributeType(int i) { - throw new UnsupportedOperationException(); - } - - public String getAttributeValue(int i) { - throw new UnsupportedOperationException(); - } - - public boolean isAttributeSpecified(int i) { - throw new UnsupportedOperationException(); - } - - public int getNamespaceCount() { - throw new UnsupportedOperationException(); - } - - public String getNamespacePrefix(int i) { - throw new UnsupportedOperationException(); - } - - public String getNamespaceURI(int i) { - throw new UnsupportedOperationException(); - } - - public NamespaceContext getNamespaceContext() { - throw new UnsupportedOperationException(); - } - - public int getEventType() { - throw new UnsupportedOperationException(); - } - - public String getText() { - throw new UnsupportedOperationException(); - } - - public char[] getTextCharacters() { - throw new UnsupportedOperationException(); - } - - public int getTextCharacters(int i, char[] chars, int i1, int i2) throws XMLStreamException { - throw new UnsupportedOperationException(); - } - - public int getTextStart() { - throw new UnsupportedOperationException(); - } - - public int getTextLength() { - throw new UnsupportedOperationException(); - } - - public String getEncoding() { - throw new UnsupportedOperationException(); - } - - public boolean hasText() { - throw new UnsupportedOperationException(); - } - - public Location getLocation() { - throw new UnsupportedOperationException(); - } - - public String getLocalName() { - throw new UnsupportedOperationException(); - } - - public boolean hasName() { - throw new UnsupportedOperationException(); - } - - public String getNamespaceURI() { - throw new UnsupportedOperationException(); - } - - public String getPrefix() { - throw new UnsupportedOperationException(); - } - - public String getVersion() { - throw new UnsupportedOperationException(); - } - - public boolean isStandalone() { - throw new UnsupportedOperationException(); - } - - public boolean standaloneSet() { - throw new UnsupportedOperationException(); - } - - public String getCharacterEncodingScheme() { - throw new UnsupportedOperationException(); - } - - public String getPITarget() { - throw new UnsupportedOperationException(); - } - - public String getPIData() { - throw new UnsupportedOperationException(); - } -} diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/loader/StAXLoaderRegistryTestCase.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/loader/StAXLoaderRegistryTestCase.java deleted file mode 100644 index 177e4e5005..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/loader/StAXLoaderRegistryTestCase.java +++ /dev/null @@ -1,145 +0,0 @@ -/** - * - * Copyright 2006 The Apache Software Foundation - * - * Licensed 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.loader; - -import java.util.List; -import java.util.ArrayList; -import javax.xml.namespace.QName; -import javax.xml.stream.XMLStreamReader; -import javax.xml.stream.XMLStreamException; - -import junit.framework.TestCase; - -import org.apache.tuscany.core.loader.impl.StAXLoaderRegistryImpl; -import org.apache.tuscany.core.config.ConfigurationLoadException; -import org.apache.tuscany.model.assembly.AssemblyObject; -import org.apache.tuscany.model.assembly.AssemblyContext; -import org.apache.tuscany.model.assembly.AssemblyInitializationException; -import org.apache.tuscany.model.assembly.AssemblyVisitor; -import org.apache.tuscany.common.resource.impl.ResourceLoaderImpl; - -/** - * @version $Rev$ $Date$ - */ -public class StAXLoaderRegistryTestCase extends TestCase { - private StAXLoaderRegistryImpl registry; - private MockElementLoader loader; - private MockObject mockObject; - private MockReader reader; - private MockMonitor monitor; - private QName qname; - private ResourceLoaderImpl rl; - private LoaderContext loaderContext; - - public void testRegistrationEvents() throws XMLStreamException, ConfigurationLoadException { - reader.name = qname; - registry.registerLoader(qname, loader); - assertTrue(monitor.registered.contains(qname)); - assertEquals(1, monitor.registered.size()); - assertTrue(monitor.unregistered.isEmpty()); - assertTrue(monitor.loading.isEmpty()); - - registry.unregisterLoader(qname, loader); - assertTrue(monitor.registered.contains(qname)); - assertEquals(1, monitor.registered.size()); - assertTrue(monitor.unregistered.contains(qname)); - assertEquals(1, monitor.unregistered.size()); - assertTrue(monitor.loading.isEmpty()); - } - - public void testSuccessfulLoad() throws XMLStreamException, ConfigurationLoadException { - reader.name = qname; - registry.registerLoader(qname, loader); - assertSame(mockObject, registry.load(reader, loaderContext)); - assertEquals(1, monitor.loading.size()); - assertTrue(monitor.loading.contains(qname)); - } - - public void testFailedLoad() throws XMLStreamException, ConfigurationLoadException { - registry.registerLoader(qname, loader); - reader.name = new QName("foo"); - try { - registry.load(reader, loaderContext); - fail(); - } catch (ConfigurationLoadException e) { - assertEquals(1, monitor.loading.size()); - assertTrue(monitor.loading.contains(reader.name)); - } - } - - protected void setUp() throws Exception { - super.setUp(); - qname = new QName("test"); - monitor = new MockMonitor(); - registry = new StAXLoaderRegistryImpl(); - registry.setMonitor(monitor); - mockObject = new MockObject(); - loader = new MockElementLoader(); - reader = new MockReader(); - rl = new ResourceLoaderImpl(getClass().getClassLoader()); - loaderContext = new LoaderContext(rl); - } - - public static class MockMonitor implements StAXLoaderRegistryImpl.Monitor { - private List<QName> registered = new ArrayList<QName>(); - private List<QName> unregistered = new ArrayList<QName>(); - private List<QName> loading = new ArrayList<QName>(); - - public void registeringLoader(QName xmlType) { - registered.add(xmlType); - } - - public void unregisteringLoader(QName xmlType) { - unregistered.add(xmlType); - } - - public void elementLoad(QName xmlType) { - loading.add(xmlType); - } - } - - @SuppressWarnings({"NonStaticInnerClassInSecureContext"}) - public class MockElementLoader<MockObject> implements StAXElementLoader { - public AssemblyObject load(XMLStreamReader reader, LoaderContext loaderContext) throws XMLStreamException, ConfigurationLoadException { - assertEquals(qname, reader.getName()); - assertSame(rl, loaderContext.getResourceLoader()); - return mockObject; - } - } - - public static class MockObject implements AssemblyObject { - public void initialize(AssemblyContext modelContext) throws AssemblyInitializationException { - throw new UnsupportedOperationException(); - } - - public void freeze() { - throw new UnsupportedOperationException(); - } - - public boolean accept(AssemblyVisitor visitor) { - throw new UnsupportedOperationException(); - } - } - - private static class MockReader extends MockReaderSupport { - private QName name; - - public QName getName() { - return name; - } - } -} diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/loader/StringParserPropertyFactoryTestCase.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/loader/StringParserPropertyFactoryTestCase.java deleted file mode 100644 index 0efe1ae82a..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/loader/StringParserPropertyFactoryTestCase.java +++ /dev/null @@ -1,111 +0,0 @@ -/** - * - * Copyright 2006 The Apache Software Foundation - * - * Licensed 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.loader; - -import junit.framework.TestCase; -import org.apache.tuscany.core.builder.ObjectFactory; -import org.apache.tuscany.core.config.ConfigurationLoadException; -import org.apache.tuscany.core.loader.impl.StringParserPropertyFactory; -import org.apache.tuscany.model.assembly.AssemblyFactory; -import org.apache.tuscany.model.assembly.Property; -import org.apache.tuscany.model.assembly.impl.AssemblyFactoryImpl; - -import javax.xml.stream.XMLInputFactory; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; -import java.beans.PropertyEditorManager; -import java.beans.PropertyEditorSupport; -import java.io.StringReader; -import java.net.URI; -import java.util.Arrays; - -/** - * @version $Rev$ $Date$ - */ -public class StringParserPropertyFactoryTestCase extends TestCase { - private StringParserPropertyFactory factory; - private XMLInputFactory xmlFactory; - private Property property; - - public void testSimpleString() throws XMLStreamException, ConfigurationLoadException { - String instance = getInstance(String.class, "<foo>Hello World</foo>"); - assertEquals("Hello World", instance); - } - - public void testByteArray() throws XMLStreamException, ConfigurationLoadException { - byte[] instance = getInstance(byte[].class, "<foo>01020304</foo>"); - assertTrue(Arrays.equals(new byte[]{1, 2, 3, 4}, instance)); - } - - public void testInteger() throws XMLStreamException, ConfigurationLoadException { - Integer instance = getInstance(Integer.class, "<foo>1234</foo>"); - assertEquals(Integer.valueOf(1234), instance); - } - - public void testInt() throws XMLStreamException, ConfigurationLoadException { - int instance = getInstance(Integer.TYPE, "<foo>1234</foo>"); - assertEquals(1234, instance); - } - - public void testBoolean() throws XMLStreamException, ConfigurationLoadException { - Boolean instance = getInstance(Boolean.class, "<foo>true</foo>"); - assertSame(Boolean.TRUE, instance); - } - - public void testConstructor() throws XMLStreamException, ConfigurationLoadException { - // java.net.URI has a ctr that takes a String - URI instance = getInstance(URI.class, "<foo>http://www.apache.org</foo>"); - assertEquals(URI.create("http://www.apache.org"), instance); - } - - public void testPropertyEditor() throws XMLStreamException, ConfigurationLoadException { - // register a property editor for java.lang.Class - PropertyEditorManager.registerEditor(Class.class, ClassEditor.class); - try { - Class<?> instance = getInstance(Class.class, "<foo>java.lang.Integer</foo>"); - assertEquals(Integer.class, instance); - } finally{ - PropertyEditorManager.registerEditor(Class.class, null); - } - } - - private <T> T getInstance(Class<T> type, String xml) throws XMLStreamException, ConfigurationLoadException { - property.setType(type); - XMLStreamReader reader = xmlFactory.createXMLStreamReader(new StringReader(xml)); - reader.next(); - ObjectFactory<T> objectFactory = (ObjectFactory<T>) factory.createObjectFactory(reader, property); - return objectFactory.getInstance(); - } - - protected void setUp() throws Exception { - super.setUp(); - factory = new StringParserPropertyFactory(); - xmlFactory = XMLInputFactory.newInstance(); - AssemblyFactory assemblyFactory = new AssemblyFactoryImpl(); - property = assemblyFactory.createProperty(); - } - - public static class ClassEditor extends PropertyEditorSupport { - public void setAsText(String text) throws IllegalArgumentException { - try { - setValue(Class.forName(text)); - } catch (ClassNotFoundException e) { - throw new IllegalArgumentException(text); - } - } - } -} diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/loader/assembly/ComponentLoaderTestCase.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/loader/assembly/ComponentLoaderTestCase.java deleted file mode 100644 index 37056b3283..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/loader/assembly/ComponentLoaderTestCase.java +++ /dev/null @@ -1,151 +0,0 @@ -/** - * - * Copyright 2006 The Apache Software Foundation - * - * Licensed 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.loader.assembly; - -import java.util.List; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; - -import org.apache.tuscany.core.builder.ObjectFactory; -import org.apache.tuscany.core.config.ComponentTypeIntrospector; -import org.apache.tuscany.core.config.ConfigurationException; -import org.apache.tuscany.core.config.ConfigurationLoadException; -import org.apache.tuscany.core.extension.config.ImplementationProcessor; -import org.apache.tuscany.core.config.impl.Java5ComponentTypeIntrospector; -import org.apache.tuscany.core.config.processor.ProcessorUtils; -import org.apache.tuscany.core.injection.SingletonObjectFactory; -import org.apache.tuscany.core.loader.StAXPropertyFactory; -import org.apache.tuscany.core.loader.impl.StringParserPropertyFactory; -import org.apache.tuscany.core.system.assembly.SystemImplementation; -import org.apache.tuscany.model.assembly.Component; -import org.apache.tuscany.model.assembly.ConfiguredProperty; -import org.apache.tuscany.model.assembly.Property; -import org.apache.tuscany.model.assembly.AtomicComponent; - -/** - * @version $Rev$ $Date$ - */ -public class ComponentLoaderTestCase extends LoaderTestSupport { - private ComponentLoader loader; - private ComponentTypeIntrospector introspector; - - public void testStringProperty() throws XMLStreamException, ConfigurationLoadException { - String xml = "<properties><propString>HelloWorld</propString></properties>"; - Component component = createFooComponent(); - loadProperties(xml, component); - ConfiguredProperty prop = component.getConfiguredProperty("propString"); - assertEquals("HelloWorld", prop.getValue()); - } - - public void testIntProperty() throws XMLStreamException, ConfigurationLoadException { - String xml = "<properties><propInt>1234</propInt></properties>"; - Component component = createFooComponent(); - loadProperties(xml, component); - ConfiguredProperty prop = component.getConfiguredProperty("propInt"); - assertEquals(1234, prop.getValue()); - } - - public void testIntegerProperty() throws XMLStreamException, ConfigurationLoadException { - String xml = "<properties><propInteger>1234</propInteger></properties>"; - Component component = createFooComponent(); - loadProperties(xml, component); - ConfiguredProperty prop = component.getConfiguredProperty("propInteger"); - assertEquals(Integer.valueOf(1234), prop.getValue()); - } - - public void testCustomProperty() throws XMLStreamException, ConfigurationLoadException { - String xml = "<properties><propFoo factory='" + FooFactory.class.getName() + "'><name>Hello</name></propFoo></properties>"; - Component component = createFooComponent(); - loadProperties(xml, component); - ConfiguredProperty prop = component.getConfiguredProperty("propFoo"); - Foo instance = (Foo) prop.getValue(); - assertEquals("Hello", instance.name); - } - - private void loadProperties(String xml, Component component) throws XMLStreamException, ConfigurationLoadException { - XMLStreamReader reader = getReader(xml); - loader.loadProperties(reader, resourceLoader, component); - component.initialize(modelContext); - } - - private Component createFooComponent() { - SystemImplementation impl = assemblyFactory.createSystemImplementation(); - impl.setImplementationClass(ServiceImpl.class); - try { - impl.setComponentType(introspector.introspect(ServiceImpl.class)); - } catch (ConfigurationException e) { - throw new AssertionError(); - } - impl.initialize(null); - AtomicComponent component = assemblyFactory.createSimpleComponent(); - component.setImplementation(impl); - return component; - } - - protected void setUp() throws Exception { - super.setUp(); - loader = new ComponentLoader(); - loader.setFactory(assemblyFactory); - loader.setDefaultPropertyFactory(new StringParserPropertyFactory()); - introspector = ProcessorUtils.createCoreIntrospector(assemblyFactory); - } - - public static interface Service { - } - - public static class ServiceImpl implements Service { - public String propString; - public int propInt; - public Integer propInteger; - public Foo propFoo; - } - - public static class Foo { - public Foo() { - } - - private String name; - private Foo foo; - - public void setName(String val) { - name = val; - } - - public void setFoo(Foo val) { - foo = val; - } -/* - - private MyJaxBThing jaxBThing; - - public void setMyJaxBThing(MyJaxBThing thing) { - jaxBthing = thing; - } -*/ - } - - public static class FooFactory implements StAXPropertyFactory<Foo> { - public ObjectFactory<Foo> createObjectFactory(XMLStreamReader reader, Property property) throws XMLStreamException, ConfigurationLoadException { - reader.nextTag(); - String name = reader.getElementText(); - reader.next(); - Foo foo = new Foo(); - foo.setName(name); - return new SingletonObjectFactory<Foo>(foo); - } - } -} diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/loader/assembly/ComponentTypeLoaderTestCase.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/loader/assembly/ComponentTypeLoaderTestCase.java deleted file mode 100644 index 43b5bec143..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/loader/assembly/ComponentTypeLoaderTestCase.java +++ /dev/null @@ -1,49 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation - * - * Licensed 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.loader.assembly; - -import javax.xml.stream.XMLStreamConstants; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; - -import org.apache.tuscany.core.config.ConfigurationLoadException; -import org.apache.tuscany.model.assembly.ComponentType; -import org.apache.tuscany.model.assembly.Service; - -/** - * @version $Rev$ $Date$ - */ -public class ComponentTypeLoaderTestCase extends LoaderTestSupport { - - public void testMinimal() throws XMLStreamException, ConfigurationLoadException { - XMLStreamReader reader = getReader("<componentType xmlns='http://www.osoa.org/xmlns/sca/0.9'><service name='service1'/></componentType>"); - ComponentType type = (ComponentType) registry.load(reader, loaderContext); - type.initialize(null); - assertNotNull(type); - assertEquals(1, type.getServices().size()); - Service service = type.getService("service1"); - assertEquals("service1", service.getName()); - assertEquals(XMLStreamConstants.END_DOCUMENT, reader.next()); - } - - protected void setUp() throws Exception { - super.setUp(); - registerLoader(new ComponentTypeLoader()); - registerLoader(new ServiceLoader()); - } - -} diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/loader/assembly/EntryPointLoaderTestCase.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/loader/assembly/EntryPointLoaderTestCase.java deleted file mode 100644 index 8f207261fb..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/loader/assembly/EntryPointLoaderTestCase.java +++ /dev/null @@ -1,63 +0,0 @@ -/** - * - * Copyright 2006 The Apache Software Foundation - * - * Licensed 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.loader.assembly; - -import javax.xml.stream.XMLStreamConstants; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; - -import org.apache.tuscany.core.config.ConfigurationLoadException; -import static org.apache.tuscany.core.loader.assembly.AssemblyConstants.ENTRY_POINT; -import org.apache.tuscany.model.assembly.ConfiguredService; -import org.apache.tuscany.model.assembly.EntryPoint; -import org.apache.tuscany.model.types.java.JavaServiceContract; - -/** - * @version $Rev$ $Date$ - */ -public class EntryPointLoaderTestCase extends LoaderTestSupport { - - public void testMinimal() throws XMLStreamException, ConfigurationLoadException { - String xml = "<entryPoint xmlns='http://www.osoa.org/xmlns/sca/0.9' name='test'></entryPoint>"; - XMLStreamReader reader = getReader(xml); - EntryPoint ep = (EntryPoint) registry.load(reader, loaderContext); - reader.require(XMLStreamConstants.END_ELEMENT, ENTRY_POINT.getNamespaceURI(), ENTRY_POINT.getLocalPart()); - assertEquals(XMLStreamConstants.END_DOCUMENT, reader.next()); - assertNotNull(ep); - assertEquals("test", ep.getName()); - } - - public void testInterface() throws XMLStreamException, ConfigurationLoadException { - String interfaceName = MockService.class.getName(); - String xml = "<entryPoint xmlns='http://www.osoa.org/xmlns/sca/0.9' name='test'><interface.java interface='" + interfaceName + "'/></entryPoint>"; - XMLStreamReader reader = getReader(xml); - EntryPoint ep = (EntryPoint) registry.load(reader, loaderContext); - reader.require(XMLStreamConstants.END_ELEMENT, ENTRY_POINT.getNamespaceURI(), ENTRY_POINT.getLocalPart()); - assertEquals(XMLStreamConstants.END_DOCUMENT, reader.next()); - assertNotNull(ep); - assertEquals("test", ep.getName()); - ConfiguredService configuredService = ep.getConfiguredService(); - JavaServiceContract serviceContract = (JavaServiceContract) configuredService.getPort().getServiceContract(); - assertEquals(interfaceName, serviceContract.getInterfaceName()); - } - - protected void setUp() throws Exception { - super.setUp(); - registerLoader(new EntryPointLoader()); - registerLoader(new InterfaceJavaLoader()); - } -} diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/loader/assembly/ExternalServiceLoaderTestCase.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/loader/assembly/ExternalServiceLoaderTestCase.java deleted file mode 100644 index 1fc5b367d5..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/loader/assembly/ExternalServiceLoaderTestCase.java +++ /dev/null @@ -1,64 +0,0 @@ -/** - * - * Copyright 2006 The Apache Software Foundation - * - * Licensed 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.loader.assembly; - -import static org.apache.tuscany.core.loader.assembly.AssemblyConstants.EXTERNAL_SERVICE; - -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; -import javax.xml.stream.XMLStreamConstants; - -import org.apache.tuscany.core.config.ConfigurationLoadException; -import org.apache.tuscany.model.assembly.ConfiguredService; -import org.apache.tuscany.model.assembly.ExternalService; -import org.apache.tuscany.model.types.java.JavaServiceContract; - -/** - * @version $Rev$ $Date$ - */ -public class ExternalServiceLoaderTestCase extends LoaderTestSupport { - - public void testMinimal() throws XMLStreamException, ConfigurationLoadException { - String xml = "<externalService xmlns='http://www.osoa.org/xmlns/sca/0.9' name='test'></externalService>"; - XMLStreamReader reader = getReader(xml); - ExternalService es = (ExternalService) registry.load(reader, loaderContext); - assertNotNull(es); - assertEquals("test", es.getName()); - reader.require(XMLStreamConstants.END_ELEMENT, EXTERNAL_SERVICE.getNamespaceURI(), EXTERNAL_SERVICE.getLocalPart()); - assertEquals(XMLStreamConstants.END_DOCUMENT, reader.next()); - } - - public void testInterface() throws XMLStreamException, ConfigurationLoadException { - String interfaceName = MockService.class.getName(); - String xml = "<externalService xmlns='http://www.osoa.org/xmlns/sca/0.9' name='test'><interface.java interface='" + interfaceName + "'/></externalService>"; - XMLStreamReader reader = getReader(xml); - ExternalService es = (ExternalService) registry.load(reader, loaderContext); - reader.require(XMLStreamConstants.END_ELEMENT, EXTERNAL_SERVICE.getNamespaceURI(), EXTERNAL_SERVICE.getLocalPart()); - assertEquals(XMLStreamConstants.END_DOCUMENT, reader.next()); - assertNotNull(es); - assertEquals("test", es.getName()); - ConfiguredService configuredService = es.getConfiguredService(); - JavaServiceContract serviceContract = (JavaServiceContract) configuredService.getPort().getServiceContract(); - assertEquals(interfaceName, serviceContract.getInterfaceName()); - } - - protected void setUp() throws Exception { - super.setUp(); - registerLoader(new ExternalServiceLoader()); - registerLoader(new InterfaceJavaLoader()); - } -} diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/loader/assembly/InterfaceWSDLLoaderInterfaceStylesTestCase.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/loader/assembly/InterfaceWSDLLoaderInterfaceStylesTestCase.java deleted file mode 100644 index 8b4f840f71..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/loader/assembly/InterfaceWSDLLoaderInterfaceStylesTestCase.java +++ /dev/null @@ -1,101 +0,0 @@ -/** - * - * Copyright 2006 The Apache Software Foundation - * - * Licensed 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.loader.assembly; - -import static org.apache.tuscany.core.loader.assembly.AssemblyConstants.INTERFACE_WSDL; - -import java.io.InputStream; -import java.net.URL; - -import javax.xml.stream.XMLStreamConstants; -import javax.xml.stream.XMLStreamReader; - -import org.apache.tuscany.common.resource.ResourceLoader; -import org.apache.tuscany.common.resource.impl.ResourceLoaderImpl; -import org.apache.tuscany.core.loader.impl.WSDLDefinitionRegistryImpl; -import org.apache.tuscany.model.types.wsdl.WSDLServiceContract; -import org.apache.tuscany.sdo.util.SDOUtil; - -import commonj.sdo.helper.XSDHelper; - -/** - * @version $Rev$ $Date$ - */ -public class InterfaceWSDLLoaderInterfaceStylesTestCase extends LoaderTestSupport { - private WSDLDefinitionRegistryImpl wsdlRegistry; - private ResourceLoader resourceLoader; - private ClassLoader oldCL; - - public void testInterface() throws Exception { - wsdlRegistry.loadDefinition("http://www.interfacestyles.org", getClass().getResource("interfacestyles.wsdl"), resourceLoader); - String xml = "<interface.wsdl xmlns='http://www.osoa.org/xmlns/sca/0.9' interface='http://www.interfacestyles.org#TestInterfaceStylesService'></interface.wsdl>"; - XMLStreamReader reader = getReader(xml); - WSDLServiceContract sc = (WSDLServiceContract) registry.load(reader, loaderContext); - reader.require(XMLStreamConstants.END_ELEMENT, INTERFACE_WSDL.getNamespaceURI(), INTERFACE_WSDL.getLocalPart()); - assertEquals(XMLStreamConstants.END_DOCUMENT, reader.next()); - assertNotNull(sc); - - sc.initialize(modelContext); - - Class scInterface = sc.getInterface(); - assertNotNull(scInterface); - - assertNotNull(scInterface.getMethod("getAccountReportWrapped0", new Class[0])); - assertNotNull(scInterface.getMethod("getAccountReportWrapped1", new Class[] {String.class})); - assertNotNull(scInterface.getMethod("getAccountReportWrappedN", new Class[] {String.class, int.class})); - assertNotNull(scInterface.getMethod("getAccountReportBare0", new Class[0])); - assertNotNull(scInterface.getMethod("getAccountReportBare1Simple", new Class[]{String.class})); - assertNotNull(scInterface.getMethod("getAccountReportBare1Complex", new Class[]{Object.class})); - - } - - protected void setUp() throws Exception { - oldCL = Thread.currentThread().getContextClassLoader(); - Thread.currentThread().setContextClassLoader(getClass().getClassLoader()); - resourceLoader = new ResourceLoaderImpl(getClass().getClassLoader()); - super.setUp(); - - wsdlRegistry = new WSDLDefinitionRegistryImpl(); - wsdlRegistry.setMonitor(NULL_MONITOR); - URL wsdlURL = getClass().getResource("interfacestyles.wsdl"); - wsdlRegistry.loadDefinition("http://www.interfacestyles.org", wsdlURL, resourceLoader); - InterfaceWSDLLoader loader = new InterfaceWSDLLoader(); - loader.setWsdlRegistry(wsdlRegistry); - registerLoader(loader); - - InputStream xsdInputStream = wsdlURL.openStream(); - try { - XSDHelper xsdHelper = SDOUtil.createXSDHelper(modelContext.getTypeHelper()); - xsdHelper.define(xsdInputStream, null); - } finally { - xsdInputStream.close(); - } - } - - protected void tearDown() throws Exception { - Thread.currentThread().setContextClassLoader(oldCL); - super.tearDown(); - } - - private static final WSDLDefinitionRegistryImpl.Monitor NULL_MONITOR = new WSDLDefinitionRegistryImpl.Monitor() { - public void readingWSDL(String namespace, URL location) { - } - - public void cachingDefinition(String namespace, URL location) { - } - }; -} diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/loader/assembly/InterfaceWSDLLoaderTestCase.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/loader/assembly/InterfaceWSDLLoaderTestCase.java deleted file mode 100644 index f97f13a1f7..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/loader/assembly/InterfaceWSDLLoaderTestCase.java +++ /dev/null @@ -1,88 +0,0 @@ -/** - * - * Copyright 2006 The Apache Software Foundation - * - * Licensed 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.loader.assembly; - -import java.net.URL; -import javax.xml.stream.XMLStreamConstants; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; - -import org.apache.tuscany.common.resource.ResourceLoader; -import org.apache.tuscany.common.resource.impl.ResourceLoaderImpl; -import org.apache.tuscany.core.config.ConfigurationLoadException; -import static org.apache.tuscany.core.loader.assembly.AssemblyConstants.INTERFACE_WSDL; -import org.apache.tuscany.core.loader.impl.WSDLDefinitionRegistryImpl; -import org.apache.tuscany.model.types.wsdl.WSDLServiceContract; - -/** - * @version $Rev$ $Date$ - */ -public class InterfaceWSDLLoaderTestCase extends LoaderTestSupport { - private WSDLDefinitionRegistryImpl wsdlRegistry; - private ResourceLoader resourceLoader; - - public void testMinimal() throws XMLStreamException, ConfigurationLoadException { - String xml = "<interface.wsdl xmlns='http://www.osoa.org/xmlns/sca/0.9'></interface.wsdl>"; - XMLStreamReader reader = getReader(xml); - WSDLServiceContract sc = (WSDLServiceContract) registry.load(reader, loaderContext); - reader.require(XMLStreamConstants.END_ELEMENT, INTERFACE_WSDL.getNamespaceURI(), INTERFACE_WSDL.getLocalPart()); - assertEquals(XMLStreamConstants.END_DOCUMENT, reader.next()); - assertNotNull(sc); - } - - public void testInterface() throws Exception { - wsdlRegistry.loadDefinition("http://www.example.org", getClass().getResource("example.wsdl"), resourceLoader); - String xml = "<interface.wsdl xmlns='http://www.osoa.org/xmlns/sca/0.9' interface='http://www.example.org#HelloWorld'></interface.wsdl>"; - XMLStreamReader reader = getReader(xml); - WSDLServiceContract sc = (WSDLServiceContract) registry.load(reader, loaderContext); - reader.require(XMLStreamConstants.END_ELEMENT, INTERFACE_WSDL.getNamespaceURI(), INTERFACE_WSDL.getLocalPart()); - assertEquals(XMLStreamConstants.END_DOCUMENT, reader.next()); - assertNotNull(sc); - } - - public void testInterfaceWithLocation() throws Exception { - wsdlRegistry.loadDefinition("http://www.example.org", getClass().getResource("example.wsdl"), resourceLoader); - String xml = "<interface.wsdl xmlns='http://www.osoa.org/xmlns/sca/0.9' xmlns:wsdli='http://www.w3.org/2006/01/wsdl-instance' " + - "wsdli:wsdlLocation='http://www.example.org " + getClass().getResource("example.wsdl") + "' "+ - "interface='http://www.example.org#HelloWorld'"+ - "></interface.wsdl>"; - XMLStreamReader reader = getReader(xml); - WSDLServiceContract sc = (WSDLServiceContract) registry.load(reader, loaderContext); - reader.require(XMLStreamConstants.END_ELEMENT, INTERFACE_WSDL.getNamespaceURI(), INTERFACE_WSDL.getLocalPart()); - assertEquals(XMLStreamConstants.END_DOCUMENT, reader.next()); - assertNotNull(sc); - } - - protected void setUp() throws Exception { - super.setUp(); - wsdlRegistry = new WSDLDefinitionRegistryImpl(); - wsdlRegistry.setMonitor(NULL_MONITOR); - resourceLoader = new ResourceLoaderImpl(getClass().getClassLoader()); - wsdlRegistry.loadDefinition("http://www.example.org", getClass().getResource("example.wsdl"), resourceLoader); - InterfaceWSDLLoader loader = new InterfaceWSDLLoader(); - loader.setWsdlRegistry(wsdlRegistry); - registerLoader(loader); - } - - private static final WSDLDefinitionRegistryImpl.Monitor NULL_MONITOR = new WSDLDefinitionRegistryImpl.Monitor() { - public void readingWSDL(String namespace, URL location) { - } - - public void cachingDefinition(String namespace, URL location) { - } - }; -} diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/loader/assembly/LoaderTestSupport.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/loader/assembly/LoaderTestSupport.java deleted file mode 100644 index 4e2aea5e83..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/loader/assembly/LoaderTestSupport.java +++ /dev/null @@ -1,82 +0,0 @@ -/** - * - * Copyright 2006 The Apache Software Foundation - * - * Licensed 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.loader.assembly; - -import java.io.StringReader; -import javax.xml.stream.XMLInputFactory; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; -import javax.xml.namespace.QName; - -import junit.framework.TestCase; - -import org.apache.tuscany.common.resource.ResourceLoader; -import org.apache.tuscany.common.resource.impl.ResourceLoaderImpl; -import org.apache.tuscany.core.system.assembly.SystemAssemblyFactory; -import org.apache.tuscany.core.system.assembly.impl.SystemAssemblyFactoryImpl; -import org.apache.tuscany.core.loader.impl.StAXLoaderRegistryImpl; -import org.apache.tuscany.core.loader.LoaderContext; -import org.apache.tuscany.model.assembly.AssemblyContext; -import org.apache.tuscany.model.assembly.impl.AssemblyContextImpl; - -/** - * Base class for loader tests with common fixture elements. - * - * @version $Rev$ $Date$ - */ -public abstract class LoaderTestSupport extends TestCase { - protected SystemAssemblyFactory assemblyFactory; - protected ResourceLoader resourceLoader; - protected LoaderContext loaderContext; - protected AssemblyContext modelContext; - protected XMLInputFactory xmlFactory; - protected StAXLoaderRegistryImpl registry; - - protected static final StAXLoaderRegistryImpl.Monitor NULL_MONITOR = new StAXLoaderRegistryImpl.Monitor() { - public void registeringLoader(QName xmlType) { - } - - public void unregisteringLoader(QName xmlType) { - } - - public void elementLoad(QName xmlType) { - } - }; - - protected void setUp() throws Exception { - super.setUp(); - assemblyFactory = new SystemAssemblyFactoryImpl(); - resourceLoader = new ResourceLoaderImpl(getClass().getClassLoader()); - loaderContext = new LoaderContext(resourceLoader); - modelContext = new AssemblyContextImpl(assemblyFactory, null, resourceLoader); - xmlFactory = XMLInputFactory.newInstance(); - registry = new StAXLoaderRegistryImpl(); - registry.setMonitor(NULL_MONITOR); - } - - protected XMLStreamReader getReader(String xml) throws XMLStreamException { - XMLStreamReader reader = xmlFactory.createXMLStreamReader(new StringReader(xml)); - reader.next(); - return reader; - } - - protected void registerLoader(AbstractLoader<?> loader) { - loader.setFactory(assemblyFactory); - loader.setRegistry(registry); - loader.start(); - } -} diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/loader/assembly/MockService.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/loader/assembly/MockService.java deleted file mode 100644 index c1ea3dbc1e..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/loader/assembly/MockService.java +++ /dev/null @@ -1,23 +0,0 @@ -/** - * - * Copyright 2006 The Apache Software Foundation - * - * Licensed 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.loader.assembly; - -/** - * @version $Rev$ $Date$ - */ -public interface MockService { -} diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/loader/assembly/WSDLDefinitionRegistryTestCase.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/loader/assembly/WSDLDefinitionRegistryTestCase.java deleted file mode 100644 index 5543a41f91..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/loader/assembly/WSDLDefinitionRegistryTestCase.java +++ /dev/null @@ -1,76 +0,0 @@ -/** - * - * Copyright 2006 The Apache Software Foundation or its licensors as applicable - * - * Licensed 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.loader.assembly; - -import java.net.URL; -import java.io.IOException; - -import javax.wsdl.Definition; -import javax.wsdl.WSDLException; -import javax.xml.namespace.QName; - -import junit.framework.TestCase; -import org.apache.tuscany.core.loader.impl.WSDLDefinitionRegistryImpl; -import org.apache.tuscany.common.resource.ResourceLoader; -import org.apache.tuscany.common.resource.impl.ResourceLoaderImpl; - -/** - * @version $Rev$ $Date$ - */ -public class WSDLDefinitionRegistryTestCase extends TestCase { - private static final String NS = "http://www.example.org"; - private WSDLDefinitionRegistryImpl wsdlRegistry; - private ResourceLoader rl; - - - public void testLoadFromAbsoluteWSDLLocation() { - try { - Definition def = wsdlRegistry.loadDefinition(NS + ' ' + rl.getResource("org/apache/tuscany/core/loader/assembly/example.wsdl"), rl); - assertNotNull(def.getPortType(new QName(NS, "HelloWorld"))); - } catch (IOException e) { - fail(e.getMessage()); - } catch (WSDLException e) { - fail(e.getMessage()); - } - } - - public void testLoadFromRelativeWSDLLocation() { - try { - Definition def = wsdlRegistry.loadDefinition(NS + " org/apache/tuscany/core/loader/assembly/example.wsdl", rl); - assertNotNull(def.getPortType(new QName(NS, "HelloWorld"))); - } catch (IOException e) { - fail(e.getMessage()); - } catch (WSDLException e) { - fail(e.getMessage()); - } - } - - protected void setUp() throws Exception { - super.setUp(); - wsdlRegistry = new WSDLDefinitionRegistryImpl(); - wsdlRegistry.setMonitor(NULL_MONITOR); - rl = new ResourceLoaderImpl(getClass().getClassLoader()); - } - - private static final WSDLDefinitionRegistryImpl.Monitor NULL_MONITOR = new WSDLDefinitionRegistryImpl.Monitor() { - public void readingWSDL(String namespace, URL location) { - } - - public void cachingDefinition(String namespace, URL location) { - } - }; -} diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/loader/assembly/WireLoaderTestCase.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/loader/assembly/WireLoaderTestCase.java deleted file mode 100644 index 3a0331150d..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/loader/assembly/WireLoaderTestCase.java +++ /dev/null @@ -1,60 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation - * - * Licensed 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.loader.assembly; - -import javax.xml.stream.XMLStreamConstants; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; - -import org.apache.tuscany.core.config.ConfigurationLoadException; -import org.apache.tuscany.model.assembly.Wire; - -/** - * @version $Rev$ $Date$ - */ -public class WireLoaderTestCase extends LoaderTestSupport { - - public void testMinimal() throws XMLStreamException, ConfigurationLoadException { - String xml = "<wire xmlns='http://www.osoa.org/xmlns/sca/0.9'><source.uri>foo/fooService</source.uri><target.uri>bar</target.uri></wire>"; - XMLStreamReader reader = getReader(xml); - Wire wire = (Wire) registry.load(reader, loaderContext); - reader.require(XMLStreamConstants.END_ELEMENT, AssemblyConstants.WIRE.getNamespaceURI(), AssemblyConstants.WIRE.getLocalPart()); - assertEquals(XMLStreamConstants.END_DOCUMENT, reader.next()); - assertNotNull(wire); - assertEquals("foo", wire.getSource().getPartName()); - assertEquals("fooService", wire.getSource().getServiceName()); - assertEquals("bar", wire.getTarget().getPartName()); - } - - public void testCompound() throws XMLStreamException, ConfigurationLoadException { - String xml = "<wire xmlns='http://www.osoa.org/xmlns/sca/0.9'><source.uri>foo/fooService</source.uri><target.uri>bar/bazService</target.uri></wire>"; - XMLStreamReader reader = getReader(xml); - Wire wire = (Wire) registry.load(reader, loaderContext); - reader.require(XMLStreamConstants.END_ELEMENT, AssemblyConstants.WIRE.getNamespaceURI(), AssemblyConstants.WIRE.getLocalPart()); - assertEquals(XMLStreamConstants.END_DOCUMENT, reader.next()); - assertNotNull(wire); - assertEquals("foo", wire.getSource().getPartName()); - assertEquals("fooService", wire.getSource().getServiceName()); - assertEquals("bar", wire.getTarget().getPartName()); - assertEquals("bazService", wire.getTarget().getServiceName()); - } - - protected void setUp() throws Exception { - super.setUp(); - registerLoader(new WireLoader()); - } -} diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/mock/MockConfigContext.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/mock/MockConfigContext.java deleted file mode 100644 index 820e4d36d8..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/mock/MockConfigContext.java +++ /dev/null @@ -1,53 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * Licensed 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.mock; - -import org.apache.tuscany.core.builder.BuilderConfigException; -import org.apache.tuscany.core.builder.ContextFactoryBuilder; -import org.apache.tuscany.core.builder.impl.AssemblyVisitorImpl; -import org.apache.tuscany.core.context.ConfigurationContext; -import org.apache.tuscany.core.context.ScopeContext; -import org.apache.tuscany.core.wire.SourceWireFactory; -import org.apache.tuscany.core.wire.TargetWireFactory; -import org.apache.tuscany.model.assembly.AssemblyObject; - -import java.util.ArrayList; -import java.util.List; - -/** - * A mock configuration context - * - * @version $Rev$ $Date$ - */ -public class MockConfigContext implements ConfigurationContext { - - private List<ContextFactoryBuilder> builders = new ArrayList<ContextFactoryBuilder>(); - - public MockConfigContext(List<ContextFactoryBuilder> builders) { - this.builders = builders; - } - - public void build(AssemblyObject model) throws BuilderConfigException { - AssemblyVisitorImpl visitor = new AssemblyVisitorImpl(builders); - visitor.start(model); - } - - public void connect(SourceWireFactory sourceFactory, TargetWireFactory targetFactory, Class targetType, boolean downScope, - ScopeContext targetScopeContext) throws BuilderConfigException { - } - - public void completeTargetChain(TargetWireFactory targetFactory, Class targetType, ScopeContext targetScopeContext) throws BuilderConfigException { - } - -} diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/mock/MockFactory.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/mock/MockFactory.java deleted file mode 100644 index 87e92d783c..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/mock/MockFactory.java +++ /dev/null @@ -1,413 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * Licensed 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.mock; - -import java.util.ArrayList; -import java.util.List; -import java.lang.reflect.Method; - -import org.apache.tuscany.common.monitor.impl.NullMonitorFactory; -import org.apache.tuscany.core.builder.ContextFactoryBuilder; -import org.apache.tuscany.core.client.BootstrapHelper; -import org.apache.tuscany.core.config.ComponentTypeIntrospector; -import org.apache.tuscany.core.config.ConfigurationLoadException; -import org.apache.tuscany.core.config.impl.Java5ComponentTypeIntrospector; -import org.apache.tuscany.core.config.processor.ProcessorUtils; -import org.apache.tuscany.core.context.impl.CompositeContextImpl; -import org.apache.tuscany.core.extension.config.ImplementationProcessor; -import org.apache.tuscany.core.extension.config.extensibility.DestroyInvokerExtensibilityElement; -import org.apache.tuscany.core.mock.component.ModuleScopeSystemComponent; -import org.apache.tuscany.core.mock.component.ModuleScopeSystemComponentImpl; -import org.apache.tuscany.core.mock.component.Source; -import org.apache.tuscany.core.mock.component.SourceImpl; -import org.apache.tuscany.core.mock.component.Target; -import org.apache.tuscany.core.mock.component.TargetImpl; -import org.apache.tuscany.core.runtime.RuntimeContext; -import org.apache.tuscany.core.runtime.RuntimeContextImpl; -import org.apache.tuscany.core.system.assembly.SystemAssemblyFactory; -import org.apache.tuscany.core.system.assembly.SystemBinding; -import org.apache.tuscany.core.system.assembly.SystemModule; -import org.apache.tuscany.core.system.assembly.impl.SystemAssemblyFactoryImpl; -import org.apache.tuscany.core.system.builder.SystemContextFactoryBuilder; -import org.apache.tuscany.core.system.builder.SystemEntryPointBuilder; -import org.apache.tuscany.core.system.builder.SystemExternalServiceBuilder; -import org.apache.tuscany.core.system.context.SystemCompositeContextImpl; -import org.apache.tuscany.core.injection.MethodEventInvoker; -import org.apache.tuscany.model.assembly.AssemblyContext; -import org.apache.tuscany.model.assembly.Component; -import org.apache.tuscany.model.assembly.ComponentType; -import org.apache.tuscany.model.assembly.ConfiguredReference; -import org.apache.tuscany.model.assembly.ConfiguredService; -import org.apache.tuscany.model.assembly.EntryPoint; -import org.apache.tuscany.model.assembly.ExternalService; -import org.apache.tuscany.model.assembly.Module; -import org.apache.tuscany.model.assembly.ModuleComponent; -import org.apache.tuscany.model.assembly.Multiplicity; -import org.apache.tuscany.model.assembly.Part; -import org.apache.tuscany.model.assembly.Reference; -import org.apache.tuscany.model.assembly.Scope; -import org.apache.tuscany.model.assembly.Service; -import org.apache.tuscany.model.assembly.impl.AssemblyContextImpl; -import org.apache.tuscany.model.types.java.JavaServiceContract; - -/** - * Generates test components, modules, and runtime artifacts - * - * @version $Rev$ $Date$ - */ -public class MockFactory { - - private static SystemAssemblyFactory systemFactory = new SystemAssemblyFactoryImpl(); - private static AssemblyContext assemblyContext = new AssemblyContextImpl(systemFactory, null, null); - private static ComponentTypeIntrospector introspector; - private static ComponentType systemComponentType; - private static ComponentType compositeComponentType; - - private MockFactory() { - } - - public static ComponentType getComponentType() throws ConfigurationLoadException { - if (systemComponentType == null) { - systemComponentType = getIntrospector().introspect(SystemCompositeContextImpl.class); - } - return systemComponentType; - } - - public static ComponentType getCompositeComponentType() throws ConfigurationLoadException { - if (compositeComponentType == null) { - compositeComponentType = getIntrospector().introspect(CompositeContextImpl.class); - } - return compositeComponentType; - } - - public static ComponentTypeIntrospector getIntrospector() { - if (introspector == null) { - introspector = ProcessorUtils.createCoreIntrospector(systemFactory); - } - return introspector; - } - - /** - * Creates an composite component with the given name - */ - public static ModuleComponent createCompositeComponent(String name) throws ConfigurationLoadException { - ModuleComponent sc = systemFactory.createModuleComponent(); - Module impl = systemFactory.createModule(); - impl.setName(name); - //impl.setImplementationClass(CompositeContextImpl.class); - sc.setImplementation(impl); - impl.setImplementationClass(CompositeContextImpl.class); - impl.setComponentType(getCompositeComponentType()); - Service s = systemFactory.createService(); - JavaServiceContract ji = systemFactory.createJavaServiceContract(); - s.setServiceContract(ji); - ji.setScope(Scope.AGGREGATE); -// impl.setComponentType(systemFactory.createComponentType()); - impl.getComponentType().getServices().add(s); - sc.setName(name); - sc.setImplementation(impl); - return sc; - } - - /** - * Creates an composite component with the given name - */ - public static ModuleComponent createSystemCompositeComponent(String name) throws ConfigurationLoadException { - ModuleComponent sc = systemFactory.createModuleComponent(); - SystemModule impl = systemFactory.createSystemModule(); - impl.setName(name); - impl.setImplementationClass(SystemCompositeContextImpl.class); - impl.setComponentType(getComponentType()); - sc.setImplementation(impl); - Service s = systemFactory.createService(); - JavaServiceContract ji = systemFactory.createJavaServiceContract(); - s.setServiceContract(ji); - ji.setScope(Scope.AGGREGATE); - //impl.setComponentType(systemFactory.createComponentType()); - impl.getComponentType().getServices().add(s); - sc.setName(name); - sc.setImplementation(impl); - return sc; - } - - /** - * Creates a basic entry point with no configured reference using the system binding - * - * @param name the name of the entry point - * @param interfaz the inteface exposed by the entry point - * @param refName the name of the entry point reference - */ - public static EntryPoint createEPSystemBinding(String name, Class interfaz, String refName) { - return createEPSystemBinding(name, interfaz, refName, null); - } - - /** - * Creates an entry point wired to the given target (e.g. component, external service) using the system - * binding - * - * @param name the name of the entry point - * @param interfaz the inteface exposed by the entry point - * @param refName the name of the entry point reference - * @param target the target the entry point is wired to - */ - public static EntryPoint createEPSystemBinding(String name, Class interfaz, String refName, Part target) { - JavaServiceContract contract = systemFactory.createJavaServiceContract(); - contract.setInterface(interfaz); - - EntryPoint ep = systemFactory.createEntryPoint(); - ep.setName(name); - - Reference ref = systemFactory.createReference(); - ref.setName(refName); - ref.setServiceContract(contract); - ConfiguredReference configuredReference = systemFactory.createConfiguredReference(); - configuredReference.setPort(ref); - Service service = systemFactory.createService(); - service.setServiceContract(contract); - - ConfiguredService cService = systemFactory.createConfiguredService(); - cService.setPort(service); - cService.initialize(assemblyContext); - - configuredReference.getTargetConfiguredServices().add(cService); - ep.setConfiguredReference(configuredReference); - - Service epService = systemFactory.createService(); - epService.setServiceContract(contract); - - ConfiguredService epCService = systemFactory.createConfiguredService(); - epCService.initialize(assemblyContext); - epCService.setPort(epService); - - ep.setConfiguredService(epCService); - SystemBinding binding = systemFactory.createSystemBinding(); - ep.getBindings().add(binding); - if (target != null) { - if (target instanceof Component) { - ((Component) target).getConfiguredServices().add(cService); - // cService. - } else if (target instanceof ExternalService) { - ((ExternalService) target).setConfiguredService(cService); - } - target.initialize(assemblyContext); - } - ep.initialize(null); - return ep; - } - - /** - * Creates an entry point that should be wired to the given target (e.g. component, external service) - * using the system binding. The system assembly process should resolve the target name to an actual - * target configuration. - * - * @param name the name of the entry point - * @param interfaz the inteface exposed by the entry point - * @param refName the name of the entry point reference - * @param componentName the name of the target to resolve - */ - public static EntryPoint createEntryPointWithStringRef(String name, Class interfaz, String refName, String componentName) { - EntryPoint ep = createEPSystemBinding(name, interfaz, refName, null); - ConfiguredReference cRef = systemFactory.createConfiguredReference(); - Reference ref = systemFactory.createReference(); - cRef.setPort(ref); - Service service = systemFactory.createService(); - service.setName(componentName); - ConfiguredService cService = systemFactory.createConfiguredService(); - cService.setPort(service); - cRef.getTargetConfiguredServices().add(cService); - cRef.initialize(assemblyContext); - cService.initialize(assemblyContext); - JavaServiceContract contract = systemFactory.createJavaServiceContract(); - contract.setInterface(interfaz); - ref.setServiceContract(contract); - ep.setConfiguredReference(cRef); - ep.initialize(assemblyContext); - return ep; - } - - /** - * Creates an external service configured with a {@link SystemBinding} - */ - public static ExternalService createESSystemBinding(String name, String refName) { - ExternalService es = systemFactory.createExternalService(); - es.setName(name); - ConfiguredService configuredService = systemFactory.createConfiguredService(); - es.setConfiguredService(configuredService); - SystemBinding binding = systemFactory.createSystemBinding(); - binding.setTargetName(refName); - es.getBindings().add(binding); - es.initialize(null); - return es; - } - - /** - * Creates an external service that specifies an autowire of the given type - */ - public static ExternalService createAutowirableExternalService(String name, Class type) { - ExternalService es = systemFactory.createExternalService(); - es.setName(name); - JavaServiceContract inter = systemFactory.createJavaServiceContract(); - inter.setInterface(type); - Service service = systemFactory.createService(); - service.setServiceContract(inter); - ConfiguredService cService = systemFactory.createConfiguredService(); - cService.setPort(service); - cService.initialize(assemblyContext); - es.setConfiguredService(cService); - es.getBindings().add(systemFactory.createSystemBinding()); - es.initialize(null); - return es; - } - - /** - * Creates a test system module with a module-scoped component and entry point - */ - public static Module createSystemModule() throws ConfigurationLoadException { - Module module = systemFactory.createSystemModule(); - module.setName("system.module"); - - // create test component - Component component = systemFactory.createSystemComponent("TestService1", ModuleScopeSystemComponent.class, - ModuleScopeSystemComponentImpl.class, Scope.MODULE); - component.getImplementation().setComponentType(getIntrospector().introspect(ModuleScopeSystemComponent.class)); - module.getComponents().add(component); - - // create the entry point - EntryPoint ep = createEPSystemBinding("TestService1EP", ModuleScopeSystemComponent.class, "target", component); - module.getEntryPoints().add(ep); - - module.initialize(assemblyContext); - module.setImplementationClass(SystemCompositeContextImpl.class); - module.setComponentType(getComponentType()); - return module; - } - - public static <T> Component createSystemComponent(String name, Class<T> service, Class<? extends T> impl, Scope scope) throws ConfigurationLoadException { - Component c = systemFactory.createSystemComponent(name, service, impl, scope); - c.getImplementation().setComponentType(getIntrospector().introspect(impl)); - for (Service s : c.getImplementation().getComponentType().getServices()) { - s.getServiceContract().setScope(scope); //hack - } - - return c; - } - - /** - * Creates a test system module with source and target components wired together. - * - * @see org.apache.tuscany.core.mock.component.Source - * @see org.apache.tuscany.core.mock.component.Target - */ - public static Module createSystemModuleWithWiredComponents(String moduleName, Scope sourceScope, Scope targetScope) throws ConfigurationLoadException { - - // create the target component - Component target = systemFactory.createSystemComponent("target", Target.class, TargetImpl.class, targetScope); - target.initialize(assemblyContext); - - // create the source componentType - Component source = systemFactory.createSystemComponent("source", Source.class, SourceImpl.class, sourceScope); - ComponentType sourceComponentType = source.getImplementation().getComponentType(); - List<Reference> references = sourceComponentType.getReferences(); - List<ConfiguredReference> configuredReferences = source.getConfiguredReferences(); - - // wire source to target - references.add(systemFactory.createReference("setTarget", Target.class)); - ConfiguredReference configuredReference = systemFactory.createConfiguredReference("setTarget", "target"); - configuredReferences.add(configuredReference); - - // wire multiplicity using a setter - references.add(systemFactory.createReference("setTargets", Target.class, Multiplicity.ONE_N)); - configuredReference = systemFactory.createConfiguredReference("setTargets", "target"); - configuredReferences.add(configuredReference); - - // wire multiplicity using a field - references.add(systemFactory.createReference("targetsThroughField", Target.class, Multiplicity.ONE_N)); - configuredReference = systemFactory.createConfiguredReference("targetsThroughField", "target"); - configuredReferences.add(configuredReference); - - // wire multiplicity using a setter - references.add(systemFactory.createReference("setArrayOfTargets", Target.class, Multiplicity.ONE_N)); - configuredReference = systemFactory.createConfiguredReference("setArrayOfTargets", "target"); - configuredReferences.add(configuredReference); - - source.initialize(assemblyContext); - - Module module = systemFactory.createSystemModule(); - module.setImplementationClass(SystemCompositeContextImpl.class); - module.setComponentType(getComponentType()); - module.setName(moduleName); - module.getComponents().add(source); - module.getComponents().add(target); - module.initialize(assemblyContext); - return module; - } - - /** - * Creates a test system module component with source and target components wired together. - * - * @see org.apache.tuscany.core.mock.component.Source - * @see org.apache.tuscany.core.mock.component.Target - */ - public static ModuleComponent createSystemModuleComponentWithWiredComponents(String moduleComponentName, Scope sourceScope, - Scope targetScope) throws ConfigurationLoadException { - ModuleComponent mc = systemFactory.createModuleComponent(); - mc.setName(moduleComponentName); - mc.setImplementation(createSystemModuleWithWiredComponents(moduleComponentName + ".module", sourceScope, targetScope)); - return mc; - } - - /** - * Creates a test system module component with a module-scoped component and entry point - */ - public static Module createSystemChildModule() throws ConfigurationLoadException { - Module module = systemFactory.createSystemModule(); - module.setName("system.test.module"); - module.setImplementationClass(SystemCompositeContextImpl.class); - module.setComponentType(getComponentType()); - - // create test component - Component component = systemFactory.createSystemComponent("TestService2", ModuleScopeSystemComponent.class, - ModuleScopeSystemComponentImpl.class, Scope.MODULE); - module.getComponents().add(component); - - // create the entry point - EntryPoint ep = createEPSystemBinding("TestService2EP", ModuleScopeSystemComponent.class, "target", component); - module.getEntryPoints().add(ep); - - module.initialize(assemblyContext); - return module; - } - - /** - * Returns a collection of bootstrap configuration builders - */ - public static List<ContextFactoryBuilder> createSystemBuilders() { - List<ContextFactoryBuilder> builders = new ArrayList<ContextFactoryBuilder>(); - builders.add((new SystemContextFactoryBuilder(null))); - builders.add(new SystemEntryPointBuilder()); - builders.add(new SystemExternalServiceBuilder()); - return builders; - } - - /** - * Creates a default {@link RuntimeContext} configured with support for Java component implementations - */ - public static RuntimeContext createCoreRuntime() { - NullMonitorFactory monitorFactory = new NullMonitorFactory(); - RuntimeContext runtime = new RuntimeContextImpl(monitorFactory, BootstrapHelper.bootstrapContextFactoryBuilders(monitorFactory), null); - runtime.start(); - return runtime; - } - -} diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/mock/component/AutowireSourceImpl.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/mock/component/AutowireSourceImpl.java deleted file mode 100644 index fb1cb86873..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/mock/component/AutowireSourceImpl.java +++ /dev/null @@ -1,64 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * Licensed 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.mock.component; - -import org.apache.tuscany.core.system.annotation.Autowire; - -import java.util.List; - -/** - * Mock system component implementation used in autowire tests - * - * @version $Rev$ $Date$ - */ -public class AutowireSourceImpl implements Source { - - @Autowire - protected Target target; - - private List<Target> targets; - - private List<Target> targetsThroughField; - - public void setTarget(Target target) { - this.target = target; - } - - public Target getTarget() { - return target; - } - - public List<Target> getTargets() { - return targets; - } - - public void setTargets(List<Target> targets) { - this.targets = targets; - } - - public List<Target> getTargetsThroughField() { - return targetsThroughField; - } - - private Target[] targetsArray; - - public Target[] getArrayOfTargets() { - return targetsArray; - } - - public void setArrayOfTargets(Target[] targets) { - targetsArray = targets; - } - -} diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/mock/component/GenericSystemComponent.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/mock/component/GenericSystemComponent.java deleted file mode 100644 index 1fd02de992..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/mock/component/GenericSystemComponent.java +++ /dev/null @@ -1,22 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation - * - * Licensed 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.mock.component; - -public interface GenericSystemComponent { - -} - diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/mock/component/ModuleScopeSystemComponent.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/mock/component/ModuleScopeSystemComponent.java deleted file mode 100644 index dabbd9e4ef..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/mock/component/ModuleScopeSystemComponent.java +++ /dev/null @@ -1,28 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * Licensed 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.mock.component; - -import org.osoa.sca.annotations.Scope; - -/** - * @version $Rev$ $Date$ - */ -@Scope("MODULE") -public interface ModuleScopeSystemComponent extends GenericSystemComponent { - -} - diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/mock/component/ModuleScopeSystemComponentImpl.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/mock/component/ModuleScopeSystemComponentImpl.java deleted file mode 100644 index 58afde9354..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/mock/component/ModuleScopeSystemComponentImpl.java +++ /dev/null @@ -1,25 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * Licensed 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.mock.component; - -/** - * @version $Rev$ $Date$ - */ -public class ModuleScopeSystemComponentImpl implements ModuleScopeSystemComponent { - - -} diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/mock/component/Source.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/mock/component/Source.java deleted file mode 100644 index 6ce1059db1..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/mock/component/Source.java +++ /dev/null @@ -1,34 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * Licensed 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.mock.component; - -import java.util.List; - -/** - * Implementations are used in wiring tests - * - * @version $Rev$ $Date$ - */ -public interface Source { - - public Target getTarget(); - - public List<Target> getTargets(); - - public List<Target> getTargetsThroughField(); - - public Target[] getArrayOfTargets(); - -} - diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/mock/component/SourceImpl.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/mock/component/SourceImpl.java deleted file mode 100644 index 075e70699e..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/mock/component/SourceImpl.java +++ /dev/null @@ -1,67 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * Licensed 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.mock.component; - -import java.util.List; - -import org.osoa.sca.annotations.Destroy; - -/** - * Mock system component implementation used in wiring tests - * - * @version $Rev$ $Date$ - */ -public class SourceImpl implements Source { - - private Target target; - - private List<Target> targets; - - private List<Target> targetsThroughField; - - @Destroy - public void foo(){ - } - - public void setTarget(Target target) { - this.target = target; - } - - public Target getTarget() { - return target; - } - - public List<Target> getTargets() { - return targets; - } - - public void setTargets(List<Target> targets) { - this.targets = targets; - } - - public List<Target> getTargetsThroughField() { - return targetsThroughField; - } - - private Target[] targetsArray; - - public Target[] getArrayOfTargets() { - return targetsArray; - } - - public void setArrayOfTargets(Target[] targets) { - targetsArray = targets; - } - -} diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/mock/component/Target.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/mock/component/Target.java deleted file mode 100644 index fb3642a495..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/mock/component/Target.java +++ /dev/null @@ -1,27 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * Licensed 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.mock.component; - -/** - * Implementations are used in wiring tests - * - * @version $Rev$ $Date$ - */ -public interface Target { - - public String getString(); - - public void setString(String val); -} - diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/mock/component/TargetImpl.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/mock/component/TargetImpl.java deleted file mode 100644 index 323bee0713..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/mock/component/TargetImpl.java +++ /dev/null @@ -1,33 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * Licensed 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.mock.component; - -/** - * Mock system component implementation used in wiring tests - * - * @version $Rev$ $Date$ - */ -public class TargetImpl implements Target { - - private String theString; - - public String getString() { - return theString; - } - - public void setString(String val) { - theString = val; - } - -} diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/runtime/RuntimeBootTestCase.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/runtime/RuntimeBootTestCase.java deleted file mode 100644 index c4e1ea9962..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/runtime/RuntimeBootTestCase.java +++ /dev/null @@ -1,99 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * Licensed 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.runtime; - -import junit.framework.Assert; -import junit.framework.TestCase; - -import org.apache.tuscany.common.monitor.impl.NullMonitorFactory; -import org.apache.tuscany.core.builder.ContextFactoryBuilderRegistry; -import org.apache.tuscany.core.builder.impl.DefaultWireBuilder; -import org.apache.tuscany.core.client.BootstrapHelper; -import org.apache.tuscany.core.context.CompositeContext; -import org.apache.tuscany.core.context.Lifecycle; -import org.apache.tuscany.core.context.event.ModuleStart; -import org.apache.tuscany.core.context.event.ModuleStop; -import org.apache.tuscany.core.mock.MockFactory; - -/** - * Tests runtime boot scenarios - * - * @version $Rev$ $Date$ - */ -public class RuntimeBootTestCase extends TestCase { - private RuntimeContext runtime; - private NullMonitorFactory monitorFactory; - private ContextFactoryBuilderRegistry builderRegistry; - private DefaultWireBuilder wireBuilder; - - public void testContextParents() { - CompositeContext rootContext = runtime.getRootContext(); - assertNotNull(rootContext); - assertEquals("tuscany.root", rootContext.getName()); - assertSame(runtime, rootContext.getParent()); - assertSame(rootContext, runtime.getContext("tuscany.root")); - - CompositeContext systemContext = runtime.getSystemContext(); - assertNotNull(systemContext); - assertEquals("tuscany.system", systemContext.getName()); - assertSame(runtime, systemContext.getParent()); - assertSame(systemContext, runtime.getContext("tuscany.system")); - } - - public void testRuntimeLifecycle() { - assertEquals(Lifecycle.RUNNING, runtime.getLifecycleState()); - runtime.stop(); - - assertEquals(Lifecycle.STOPPED, runtime.getLifecycleState()); - } - - public void testIncrementalBoot() throws Exception{ - - // start the runtime context - RuntimeContext runtimeContext = new RuntimeContextImpl(monitorFactory, builderRegistry, wireBuilder); - runtimeContext.start(); - - CompositeContext system = runtimeContext.getSystemContext(); - Assert.assertNotNull(system); - // register system components - system.registerModelObject(MockFactory.createSystemModule()); - // start the module scope - system.publish(new ModuleStart(this)); - // register the first module - - // register the second module - - // start the modules - - system.publish(new ModuleStop(this)); - runtimeContext.stop(); - Assert.assertEquals(Lifecycle.STOPPED,system.getLifecycleState()); - } - - protected void setUp() throws Exception { - super.setUp(); - - monitorFactory = new NullMonitorFactory(); - builderRegistry = BootstrapHelper.bootstrapContextFactoryBuilders(monitorFactory); - wireBuilder = new DefaultWireBuilder(); - runtime = new RuntimeContextImpl(monitorFactory, builderRegistry, wireBuilder); - runtime.start(); - } - - protected void tearDown() throws Exception { - runtime.stop(); - super.tearDown(); - } -} - diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/runtime/RuntimeContextImplTestCase.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/runtime/RuntimeContextImplTestCase.java deleted file mode 100644 index d9596239fa..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/runtime/RuntimeContextImplTestCase.java +++ /dev/null @@ -1,286 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * Licensed 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.runtime; - -import junit.framework.Assert; -import junit.framework.TestCase; -import org.apache.tuscany.common.monitor.MonitorFactory; -import org.apache.tuscany.common.monitor.impl.NullMonitorFactory; -import org.apache.tuscany.core.builder.ContextFactoryBuilder; -import org.apache.tuscany.core.builder.ContextFactoryBuilderRegistry; -import org.apache.tuscany.core.client.BootstrapHelper; -import org.apache.tuscany.core.config.ConfigurationException; -import org.apache.tuscany.core.context.CompositeContext; -import org.apache.tuscany.core.context.Lifecycle; -import org.apache.tuscany.core.context.ServiceNotFoundException; -import org.apache.tuscany.core.context.event.ModuleStart; -import org.apache.tuscany.core.context.event.ModuleStop; -import org.apache.tuscany.core.context.impl.CompositeContextImpl; -import org.apache.tuscany.core.mock.MockFactory; -import org.apache.tuscany.core.mock.component.ModuleScopeSystemComponent; -import org.apache.tuscany.core.mock.component.ModuleScopeSystemComponentImpl; -import org.apache.tuscany.core.system.assembly.SystemAssemblyFactory; -import org.apache.tuscany.core.system.assembly.impl.SystemAssemblyFactoryImpl; -import org.apache.tuscany.core.system.context.TestBuilder; -import org.apache.tuscany.model.assembly.Component; -import org.apache.tuscany.model.assembly.EntryPoint; -import org.apache.tuscany.model.assembly.ExternalService; -import org.apache.tuscany.model.assembly.Scope; -import org.apache.tuscany.model.assembly.Service; -import org.apache.tuscany.model.types.java.JavaServiceContract; - -/** - * Performs basic tests on the runtime context - * - * @version $Rev$ $Date$ - */ -public class RuntimeContextImplTestCase extends TestCase { - - private SystemAssemblyFactory systemFactory = new SystemAssemblyFactoryImpl(); - - private ContextFactoryBuilderRegistry builderRegistry; - - private SystemAssemblyFactory factory; - private MonitorFactory monitorFactory; - private RuntimeContext runtime; - - /** - * Tests explicit wiring of an external service to a system entry point that is wired to a child system - * module entry point - */ - public void testSystemExplicitWiring() throws Exception { - CompositeContext root = runtime.getRootContext(); - Assert.assertNotNull(root); - Assert.assertTrue(root.getLifecycleState() == Lifecycle.RUNNING); - - CompositeContext system = runtime.getSystemContext(); - Assert.assertNotNull(system); - system.registerModelObject(MockFactory.createSystemModule()); - - // register a child system context - system.registerModelObject(MockFactory.createSystemCompositeComponent("system.child")); - CompositeContext systemChild = (CompositeContext) system.getContext("system.child"); - systemChild.registerModelObject(MockFactory.createSystemChildModule()); - - // register a top-level system entry point that exposes the child entry point - EntryPoint ep = MockFactory.createEPSystemBinding("TestService2EP", ModuleScopeSystemComponent.class, "ref"); - ep.getBindings().add(systemFactory.createSystemBinding()); - Service service = systemFactory.createService(); - service.setName("system.child/TestService2EP"); - ep.getConfiguredReference().getTargetConfiguredServices().get(0).setPort(service); - JavaServiceContract inter = systemFactory.createJavaServiceContract(); - inter.setInterface(ModuleScopeSystemComponentImpl.class); - service.setServiceContract(inter); - system.registerModelObject(ep); - system.publish(new ModuleStart(this)); - Assert.assertNotNull(system.getContext("TestService1").getInstance(null)); - Assert.assertNotNull(system.getContext("TestService2EP").getInstance(null)); - - // create a test module and wire an external service to the system entry point - Component moduleComponent = MockFactory.createCompositeComponent("test.module"); - runtime.registerModelObject(moduleComponent); - CompositeContextImpl moduleContext = (CompositeContextImpl) runtime.getContext("test.module"); - Assert.assertNotNull(moduleContext); - ExternalService es = MockFactory.createESSystemBinding("TestService2ES", "tuscany.system/TestService2EP"); - moduleContext.registerModelObject(es); - moduleContext.publish(new ModuleStart(this)); - Assert.assertNotNull(moduleContext.getContext("TestService2ES").getInstance(null)); - - moduleContext.publish(new ModuleStop(this)); - system.publish(new ModuleStop(this)); - } - - /** - * Tests autowiring an external service to a system entry point - */ - public void testSystemAutoWiring() throws Exception { - CompositeContext root = runtime.getRootContext(); - Assert.assertNotNull(root); - Assert.assertTrue(root.getLifecycleState() == Lifecycle.RUNNING); - - CompositeContext system = runtime.getSystemContext(); - Assert.assertNotNull(system); - system.registerModelObject(MockFactory.createSystemModule()); - - // create a test module and wire an external service to the system entry point - Component moduleComponent = MockFactory.createCompositeComponent("test.module"); - runtime.registerModelObject(moduleComponent); - CompositeContextImpl moduleContext = (CompositeContextImpl) runtime.getContext("test.module"); - Assert.assertNotNull(moduleContext); - ExternalService es = MockFactory.createAutowirableExternalService("TestService2ES", ModuleScopeSystemComponent.class); - moduleContext.registerModelObject(es); - - system.publish(new ModuleStart(this)); - moduleContext.publish(new ModuleStart(this)); - // test that the autowire was resolved - Assert.assertNotNull(moduleContext.getContext("TestService2ES").getInstance(null)); - - moduleContext.publish(new ModuleStop(this)); - system.publish(new ModuleStop(this)); - } - - public void testServiceNotFound() throws Exception { - // create a test module - Component moduleComponent = MockFactory.createCompositeComponent("module"); - runtime.registerModelObject(moduleComponent); - CompositeContextImpl moduleContext = (CompositeContextImpl) runtime.getContext("module"); - moduleContext.publish(new ModuleStart(this)); - try { - moduleContext.locateService("TestService"); - fail("Expected " + ServiceNotFoundException.class.getName()); - } catch (ServiceNotFoundException e) { - // expected - } - moduleContext.publish(new ModuleStop(this)); - } - - public void testExternalServiceReferenceNotFound() throws Exception { - CompositeContext system = runtime.getSystemContext(); - - // create a test module - Component moduleComponent = MockFactory.createCompositeComponent("module"); - runtime.registerModelObject(moduleComponent); - CompositeContextImpl moduleContext = (CompositeContextImpl) runtime.getContext("module"); - ExternalService es = MockFactory.createESSystemBinding("TestServiceES", "tuscany.system/TestService1xEP"); - moduleContext.registerModelObject(es); - - // start the modules and test inter-module system wires - system.publish(new ModuleStart(this)); - moduleContext.publish(new ModuleStart(this)); - try { - moduleContext.locateService("TestServiceES"); - fail("Expected " + ServiceNotFoundException.class.getName()); - } catch (ServiceNotFoundException e) { - // expected - } - moduleContext.publish(new ModuleStop(this)); - system.publish(new ModuleStop(this)); - } - - public void testEntryPointReferenceNotFound() throws Exception { - // create a test module - Component moduleComponent = MockFactory.createCompositeComponent("module"); - runtime.registerModelObject(moduleComponent); - - Component component = factory.createSystemComponent("NoService", ModuleScopeSystemComponent.class, ModuleScopeSystemComponentImpl.class, Scope.MODULE); - // do not register the above component! - - CompositeContextImpl moduleContext = (CompositeContextImpl) runtime.getContext("module"); - EntryPoint epSystemBinding = MockFactory.createEPSystemBinding("TestServiceEP", ModuleScopeSystemComponent.class, "NoReference", component); - moduleContext.registerModelObject(epSystemBinding); - - moduleContext.publish(new ModuleStart(this)); - try { - moduleContext.locateService("TestServiceEP"); - fail("Expected " + ServiceNotFoundException.class.getName()); - } catch (ServiceNotFoundException e) { - // expected - } - moduleContext.publish(new ModuleStop(this)); - } - - /** - * Test two module components that have external services wired to entry points contained in each - */ - public void testCircularWires() throws Exception { - // create a test modules - Component module1 = MockFactory.createCompositeComponent("module1"); - runtime.registerModelObject(module1); - Component module2 = MockFactory.createCompositeComponent("module2"); - runtime.registerModelObject(module2); - - CompositeContextImpl moduleContext1 = (CompositeContextImpl) runtime.getContext("module1"); - CompositeContextImpl moduleContext2 = (CompositeContextImpl) runtime.getContext("module2"); - - Component component1 = factory.createSystemComponent("Component1", ModuleScopeSystemComponent.class, ModuleScopeSystemComponentImpl.class, Scope.MODULE); - EntryPoint entryPoint1 = MockFactory.createEPSystemBinding("EntryPoint1", ModuleScopeSystemComponent.class, "Component1", component1); - ExternalService externalService1 = MockFactory.createESSystemBinding("ExternalService1", "module2/EntryPoint2"); - moduleContext1.registerModelObject(component1); - moduleContext1.registerModelObject(entryPoint1); - moduleContext1.registerModelObject(externalService1); - - Component component2 = factory.createSystemComponent("Component2", ModuleScopeSystemComponent.class, ModuleScopeSystemComponentImpl.class, Scope.MODULE); - EntryPoint entryPoint2 = MockFactory.createEPSystemBinding("EntryPoint2", ModuleScopeSystemComponent.class, "Component2", component2); - ExternalService externalService2 = MockFactory.createESSystemBinding("ExternalService2", "module1/EntryPoint1"); - moduleContext2.registerModelObject(component2); - moduleContext2.registerModelObject(entryPoint2); - moduleContext2.registerModelObject(externalService2); - - moduleContext1.publish(new ModuleStart(this)); - moduleContext2.publish(new ModuleStart(this)); - Assert.assertNotNull(moduleContext2.getContext("ExternalService2").getInstance(null)); - Assert.assertNotNull(moduleContext1.getContext("ExternalService1").getInstance(null)); - } - - /** - * Tests that a circular reference between an external service in one module and an entry point in another - * is caught as an error condition FIXME this must be implemented - */ - public void testInterModuleCircularReference() throws Exception { - // create a test modules - Component module1 = MockFactory.createCompositeComponent("module1"); - runtime.registerModelObject(module1); - Component module2 = MockFactory.createCompositeComponent("module2"); - runtime.registerModelObject(module2); - - CompositeContextImpl moduleContext1 = (CompositeContextImpl) runtime.getContext("module1"); - CompositeContextImpl moduleContext2 = (CompositeContextImpl) runtime.getContext("module2"); - ExternalService externalService1 = MockFactory.createESSystemBinding("ExternalService1", "module2/EntryPoint2"); - EntryPoint entryPoint1 = MockFactory.createEPSystemBinding("EntryPoint1", ModuleScopeSystemComponent.class, - "ExternalService1", externalService1); - ExternalService externalService2 = MockFactory.createESSystemBinding("ExternalService2", "module1/EntryPoint1"); - EntryPoint entryPoint2 = MockFactory.createEPSystemBinding("EntryPoint2", ModuleScopeSystemComponent.class, - "ExternalService2", externalService2); - try { - // FIXME this should throw a circular reference exception - moduleContext1.registerModelObject(externalService1); - moduleContext1.registerModelObject(entryPoint1); - moduleContext2.registerModelObject(externalService2); - moduleContext2.registerModelObject(entryPoint2); - // FIXME implement fail("Expected " + ConfigurationException.class.getName()); - } catch (ConfigurationException e) { - // expected - } - } - - public void testRuntimeBuilderAutowire() throws Exception { - - - CompositeContext system = runtime.getSystemContext(); - Component builder = factory.createSystemComponent("TestBuilder", ContextFactoryBuilder.class, TestBuilder.class, Scope.MODULE); - builder.getImplementation().setComponentType(MockFactory.getIntrospector().introspect(TestBuilder.class)); - system.registerModelObject(builder); - system.publish(new ModuleStart(this)); - Component module1 = MockFactory.createCompositeComponent("module1"); - runtime.registerModelObject(module1); - runtime.getContext("module1"); - Assert.assertTrue(((TestBuilder) system.getContext("TestBuilder").getInstance(null)).invoked()); - system.publish(new ModuleStop(this)); - } - - protected void setUp() throws Exception { - super.setUp(); - monitorFactory = new NullMonitorFactory(); - builderRegistry = BootstrapHelper.bootstrapContextFactoryBuilders(monitorFactory); - factory = new SystemAssemblyFactoryImpl(); - - runtime = new RuntimeContextImpl(monitorFactory, builderRegistry, null); - runtime.start(); - } - - protected void tearDown() throws Exception { - runtime.stop(); - super.tearDown(); - } -} diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/runtime/SystemBootstrapTestCase.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/runtime/SystemBootstrapTestCase.java deleted file mode 100644 index 45af495239..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/runtime/SystemBootstrapTestCase.java +++ /dev/null @@ -1,127 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * Licensed 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.runtime; - -import junit.framework.Assert; -import junit.framework.TestCase; - -import org.apache.tuscany.common.monitor.impl.NullMonitorFactory; -import org.apache.tuscany.core.builder.ContextFactoryBuilderRegistry; -import org.apache.tuscany.core.client.BootstrapHelper; -import org.apache.tuscany.core.context.AutowireContext; -import org.apache.tuscany.core.context.CompositeContext; -import org.apache.tuscany.core.context.event.ModuleStart; -import org.apache.tuscany.core.context.event.ModuleStop; -import org.apache.tuscany.core.context.impl.CompositeContextImpl; -import org.apache.tuscany.core.mock.MockFactory; -import org.apache.tuscany.core.mock.component.GenericSystemComponent; -import org.apache.tuscany.core.mock.component.ModuleScopeSystemComponent; -import org.apache.tuscany.core.mock.component.ModuleScopeSystemComponentImpl; -import org.apache.tuscany.core.system.assembly.SystemAssemblyFactory; -import org.apache.tuscany.core.system.assembly.impl.SystemAssemblyFactoryImpl; -import org.apache.tuscany.model.assembly.Component; -import org.apache.tuscany.model.assembly.EntryPoint; -import org.apache.tuscany.model.assembly.ExternalService; -import org.apache.tuscany.model.assembly.Module; -import org.apache.tuscany.model.assembly.Service; -import org.apache.tuscany.model.types.java.JavaServiceContract; - -/** - * Tests bootstrapping a system module - * - * @version $Rev: 385834 $ $Date: 2006-03-14 08:57:08 -0800 (Tue, 14 Mar 2006) $ - */ -public class SystemBootstrapTestCase extends TestCase { - private ContextFactoryBuilderRegistry builderRegistry; - - private SystemAssemblyFactory factory = new SystemAssemblyFactoryImpl(); - - /** - * Simulates booting a runtime process - */ - public void testBoot() throws Exception { - RuntimeContext runtimeContext = new RuntimeContextImpl(new NullMonitorFactory(), builderRegistry,null); - runtimeContext.start(); - - CompositeContext systemContext = runtimeContext.getSystemContext(); - Assert.assertNotNull(systemContext); - Module systemModule = MockFactory.createSystemModule(); - // MockSystemAssemblyFactory.buildModule(systemModule, systemContext); - systemContext.registerModelObject(systemModule); - - // create a test module - Component moduleComponent = MockFactory.createCompositeComponent("module"); - runtimeContext.registerModelObject(moduleComponent); - CompositeContextImpl moduleContext = (CompositeContextImpl) runtimeContext.getContext("module"); - Assert.assertNotNull(moduleContext); - ExternalService es = MockFactory.createESSystemBinding("TestServiceES", "tuscany.system/TestService1EP"); - moduleContext.registerModelObject(es); - - // start the modules and test inter-module system wires - systemContext.publish(new ModuleStart(this)); - moduleContext.publish(new ModuleStart(this)); - - Assert.assertNotNull(systemContext.getContext("TestService1EP").getInstance(null)); - GenericSystemComponent testService = (GenericSystemComponent) systemContext.getContext("TestService1").getInstance(null); - Assert.assertNotNull(testService); - GenericSystemComponent testES = (GenericSystemComponent) moduleContext.getContext("TestServiceES").getInstance(null); - Assert.assertNotNull(testES); - Assert.assertSame(testService, testES); - } - - public void testRuntimeBoot() throws Exception { - RuntimeContext runtime = new RuntimeContextImpl(new NullMonitorFactory(), builderRegistry,null); - runtime.start(); - runtime.getRootContext(); - - CompositeContext system = runtime.getSystemContext(); - system.registerModelObject(MockFactory.createSystemModule()); - system.registerModelObject(MockFactory.createSystemCompositeComponent("module2")); - CompositeContext systemModule2 = (CompositeContext) system.getContext("module2"); - systemModule2.registerModelObject(MockFactory.createSystemChildModule()); - - EntryPoint ep = MockFactory.createEPSystemBinding("TestService2EP", ModuleScopeSystemComponent.class, "ref"); - ep.getBindings().add(factory.createSystemBinding()); - Service service = factory.createService(); - service.setName("module2/TestService2EP"); - JavaServiceContract inter = factory.createJavaServiceContract(); - inter.setInterface(ModuleScopeSystemComponentImpl.class); - service.setServiceContract(inter); - ep.getConfiguredReference().getTargetConfiguredServices().get(0).setPort(service); - system.registerModelObject(ep); - system.publish(new ModuleStart(this)); - Assert.assertNotNull(system.getContext("TestService1").getInstance(null)); - Assert.assertNotNull(system.getContext("TestService2EP").getInstance(null)); - - Assert.assertNotNull(((AutowireContext) system).resolveInstance(ModuleScopeSystemComponent.class)); - // create a test module - Component moduleComponent = MockFactory.createCompositeComponent("test.module"); - runtime.registerModelObject(moduleComponent); - CompositeContextImpl moduleContext = (CompositeContextImpl) runtime.getContext("test.module"); - Assert.assertNotNull(moduleContext); - ExternalService es = MockFactory.createESSystemBinding("TestService2ES", "tuscany.system/TestService2EP"); - moduleContext.registerModelObject(es); - moduleContext.publish(new ModuleStart(this)); - Assert.assertNotNull(moduleContext.getContext("TestService2ES").getInstance(null)); - - moduleContext.publish(new ModuleStop(this)); - system.publish(new ModuleStop(this)); - runtime.stop(); - } - - protected void setUp() throws Exception { - super.setUp(); - builderRegistry = BootstrapHelper.bootstrapContextFactoryBuilders(null); - } -} diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/system/builder/MonitorInjectionTestCase.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/system/builder/MonitorInjectionTestCase.java deleted file mode 100644 index fe6bff635a..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/system/builder/MonitorInjectionTestCase.java +++ /dev/null @@ -1,106 +0,0 @@ -/** - * - * Copyright 2006 The Apache Software Foundation - * - * Licensed 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.system.builder; - -import junit.framework.Assert; -import junit.framework.TestCase; - -import org.apache.tuscany.common.monitor.MonitorFactory; -import org.apache.tuscany.core.builder.ContextFactory; -import org.apache.tuscany.core.context.CompositeContext; -import org.apache.tuscany.core.context.Context; -import org.apache.tuscany.core.context.impl.CompositeContextImpl; -import org.apache.tuscany.core.context.impl.EventContextImpl; -import org.apache.tuscany.core.context.scope.DefaultScopeStrategy; -import org.apache.tuscany.core.mock.MockConfigContext; -import org.apache.tuscany.core.mock.MockFactory; -import org.apache.tuscany.core.system.annotation.Monitor; -import org.apache.tuscany.core.system.assembly.SystemAssemblyFactory; -import org.apache.tuscany.core.system.assembly.impl.SystemAssemblyFactoryImpl; -import org.apache.tuscany.model.assembly.Component; -import org.apache.tuscany.model.assembly.Scope; - -/** - * @version $Rev$ $Date$ - */ -public class MonitorInjectionTestCase extends TestCase { - private SystemContextFactoryBuilder builder; - private Component component; - - public static interface TestService { - } - - public static class TestComponent implements TestService { - @Monitor - protected Monitor1 monitor1; - Monitor2 monitor2; - - @Monitor - public void setMonitor2(Monitor2 monitor2) { - this.monitor2 = monitor2; - } - } - - public static interface Monitor1 { - } - - public static interface Monitor2 { - } - - public void testMonitorInjection() { - builder.build(component); - ContextFactory<?> contextFactory = (ContextFactory<?>) component.getContextFactory(); - Assert.assertNotNull(contextFactory); - contextFactory.prepare(createContext()); - Context ctx = contextFactory.createContext(); - - ctx.start(); - TestComponent instance = (TestComponent) ctx.getInstance(null); - assertSame(MONITOR1, instance.monitor1); - assertSame(MONITOR2, instance.monitor2); - } - - protected void setUp() throws Exception { - super.setUp(); - SystemAssemblyFactory factory = new SystemAssemblyFactoryImpl(); - MockMonitorFactory monitorFactory = new MockMonitorFactory(); - builder = new SystemContextFactoryBuilder(monitorFactory); - component = factory.createSystemComponent("test", TestService.class, TestComponent.class, Scope.MODULE); - component.getImplementation().setComponentType(MockFactory.getIntrospector().introspect(TestComponent.class)); - } - - private static final Monitor1 MONITOR1 = new Monitor1() { - }; - private static final Monitor2 MONITOR2 = new Monitor2() { - }; - - public static class MockMonitorFactory implements MonitorFactory { - public <T> T getMonitor(Class<T> monitorInterface) { - if (Monitor1.class.equals(monitorInterface)) { - return monitorInterface.cast(MONITOR1); - } else if (Monitor2.class.equals(monitorInterface)) { - return monitorInterface.cast(MONITOR2); - } else { - throw new AssertionError(); - } - } - } - - private static CompositeContext createContext() { - return new CompositeContextImpl("test.parent", null, new DefaultScopeStrategy(), new EventContextImpl(), new MockConfigContext(null)); - } -} diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/system/builder/SystemComponentImpl.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/system/builder/SystemComponentImpl.java deleted file mode 100644 index 3398a010e9..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/system/builder/SystemComponentImpl.java +++ /dev/null @@ -1,167 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * Licensed 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.system.builder; - -import org.apache.tuscany.core.context.CompositeContext; -import org.apache.tuscany.core.context.AutowireContext; -import org.apache.tuscany.core.context.ConfigurationContext; -import org.apache.tuscany.core.system.annotation.Autowire; -import org.apache.tuscany.core.system.annotation.ParentContext; -import org.osoa.sca.annotations.Destroy; -import org.osoa.sca.annotations.Init; -import org.osoa.sca.annotations.Property; -import org.osoa.sca.annotations.Scope; - -/** - * A system component used for unit testing - * - * @version $Rev$ $Date$ - */ -@Scope("MODULE") -public class SystemComponentImpl { - - @Autowire - protected ConfigurationContext ctx; - - @ParentContext - protected CompositeContext parent; - - @Autowire - protected AutowireContext autowireCtx; - - private ConfigurationContext ctxSetter; - - private CompositeContext parentSetter; - - private AutowireContext autowireCtxSetter; - - public ConfigurationContext getConfigContext() { - return ctx; - } - - public CompositeContext getParentContext() { - return parent; - } - - public AutowireContext getAutowireContext() { - return autowireCtx; - } - - @Autowire - public void setConfigContext(ConfigurationContext configCtx) { - ctxSetter = configCtx; - } - - public ConfigurationContext getConfigContextSetter() { - return ctxSetter; - } - - @ParentContext - public void setParentContex(CompositeContext ctx) { - parentSetter = ctx; - } - - public CompositeContext getParentContextSetter() { - return parentSetter; - } - - @Autowire - public void setAutowireContext(AutowireContext ctx) { - autowireCtxSetter = ctx; - } - - public AutowireContext getAutowireContextSetter() { - return autowireCtx; - } - - private boolean inited; - - @Init - public void init(){ - inited=true; - } - - public boolean initialized(){ - return (inited); - } - - private boolean destroyed; - - @Destroy - public void destroy(){ - destroyed=true; - } - - public boolean destroyed(){ - return (destroyed); - } - - @Property - protected int testInt; - - public int getTestInt(){ - return testInt; - } - - @Property - protected double testDouble; - - public double getTestDouble(){ - return testDouble; - } - - @Property - protected float testFloat; - - public float getTestFloat(){ - return testFloat; - } - - @Property - protected short testShort; - - public short getTestShort(){ - return testShort; - } - - @Property - protected boolean testBoolean; - - public boolean getTestBoolean(){ - return testBoolean; - } - - @Property - protected byte testByte; - - public byte getTestByte(){ - return testByte; - } - - @Property - protected char testChar; - - public char getTestChar(){ - return testChar; - } - - @Property - protected String testString; - - public String getTestString(){ - return testString; - } - - -} diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/system/builder/SystemContextFactoryBuilderTestCase.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/system/builder/SystemContextFactoryBuilderTestCase.java deleted file mode 100644 index f7543911a6..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/system/builder/SystemContextFactoryBuilderTestCase.java +++ /dev/null @@ -1,173 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * Licensed 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.system.builder; - -import junit.framework.Assert; -import junit.framework.TestCase; -import org.apache.tuscany.core.builder.ContextFactory; -import org.apache.tuscany.core.context.CompositeContext; -import org.apache.tuscany.core.context.Context; -import org.apache.tuscany.core.context.AtomicContext; -import org.apache.tuscany.core.context.impl.CompositeContextImpl; -import org.apache.tuscany.core.context.impl.EventContextImpl; -import org.apache.tuscany.core.context.scope.DefaultScopeStrategy; -import org.apache.tuscany.core.mock.MockConfigContext; -import org.apache.tuscany.core.mock.MockFactory; -import org.apache.tuscany.core.system.assembly.SystemAssemblyFactory; -import org.apache.tuscany.core.system.assembly.SystemImplementation; -import org.apache.tuscany.core.system.assembly.impl.SystemAssemblyFactoryImpl; -import org.apache.tuscany.model.assembly.Component; -import org.apache.tuscany.model.assembly.ConfiguredProperty; -import org.apache.tuscany.model.assembly.Property; -import org.apache.tuscany.model.assembly.Scope; -import org.apache.tuscany.model.assembly.Service; -import org.apache.tuscany.model.assembly.ComponentType; -import org.apache.tuscany.model.types.java.JavaServiceContract; - -/** - * Tests to system components are built properly - * - * @version $Rev$ $Date$ - */ -public class SystemContextFactoryBuilderTestCase extends TestCase { - - private SystemAssemblyFactory factory = new SystemAssemblyFactoryImpl(); - - public void testComponentContextBuilder() throws Exception { - SystemContextFactoryBuilder builder = new SystemContextFactoryBuilder(null); - Component component = factory.createSystemComponent("test", null, SystemComponentImpl.class, Scope.AGGREGATE); - component.getImplementation().setComponentType(MockFactory.getIntrospector().introspect(SystemComponentImpl.class)); - ConfiguredProperty cProp = factory.createConfiguredProperty(); - Property prop = factory.createProperty(); - prop.setName("testInt"); - cProp.setValue(1); - cProp.setProperty(prop); - component.getConfiguredProperties().add(cProp); - - cProp = factory.createConfiguredProperty(); - prop = factory.createProperty(); - prop.setName("testString"); - cProp.setValue("test"); - cProp.setProperty(prop); - component.getConfiguredProperties().add(cProp); - - cProp = factory.createConfiguredProperty(); - prop = factory.createProperty(); - prop.setName("testDouble"); - cProp.setValue(1d); - cProp.setProperty(prop); - component.getConfiguredProperties().add(cProp); - - cProp = factory.createConfiguredProperty(); - prop = factory.createProperty(); - prop.setName("testFloat"); - cProp.setValue(1f); - cProp.setProperty(prop); - component.getConfiguredProperties().add(cProp); - - cProp = factory.createConfiguredProperty(); - prop = factory.createProperty(); - prop.setName("testShort"); - cProp.setValue((short) 1); - cProp.setProperty(prop); - component.getConfiguredProperties().add(cProp); - - cProp = factory.createConfiguredProperty(); - prop = factory.createProperty(); - prop.setName("testByte"); - cProp.setValue((byte) 1); - cProp.setProperty(prop); - component.getConfiguredProperties().add(cProp); - - cProp = factory.createConfiguredProperty(); - prop = factory.createProperty(); - prop.setName("testBoolean"); - cProp.setValue(Boolean.TRUE); - cProp.setProperty(prop); - component.getConfiguredProperties().add(cProp); - - cProp = factory.createConfiguredProperty(); - prop = factory.createProperty(); - prop.setName("testChar"); - cProp.setValue('1'); - cProp.setProperty(prop); - component.getConfiguredProperties().add(cProp); - - builder.build(component); - ContextFactory<AtomicContext> contextFactory = (ContextFactory<AtomicContext>) component.getContextFactory(); - Assert.assertNotNull(contextFactory); - contextFactory.prepare(createContext()); - AtomicContext ctx = contextFactory.createContext(); - - ctx.start(); - SystemComponentImpl instance = (SystemComponentImpl) ctx.getInstance(null); - Assert.assertNotNull(instance.getConfigContext()); - Assert.assertNotNull(instance.getParentContext()); - Assert.assertNotNull(instance.getAutowireContext()); - Assert.assertNotNull(instance.getConfigContextSetter()); - Assert.assertNotNull(instance.getParentContextSetter()); - Assert.assertNotNull(instance.getAutowireContextSetter()); - Assert.assertEquals(1, instance.getTestInt()); - Assert.assertEquals(1d, instance.getTestDouble()); - Assert.assertEquals(1f, instance.getTestFloat()); - Assert.assertEquals((short) 1, instance.getTestShort()); - Assert.assertTrue(instance.getTestBoolean()); - Assert.assertEquals('1', instance.getTestChar()); - Assert.assertEquals((byte) 1, instance.getTestByte()); - Assert.assertEquals("test", instance.getTestString()); - - Assert.assertTrue(instance.initialized()); - ctx.destroy(); - ctx.stop(); - Assert.assertTrue(instance.destroyed()); - } - - - public void testDefaultScopeIsModuleScope() throws Exception { - SystemContextFactoryBuilder builder = new SystemContextFactoryBuilder(null); - Component component = createSystemComponentWithNoScope("test", null, SystemComponentImpl.class); - builder.build(component); - ContextFactory<AtomicContext> contextFactory = (ContextFactory<AtomicContext>) component.getContextFactory(); - Assert.assertEquals(Scope.MODULE, contextFactory.getScope()); - } - - - - - private static CompositeContext createContext() { - return new CompositeContextImpl("test.parent", null, new DefaultScopeStrategy(), new EventContextImpl(), - new MockConfigContext(null)); - } - - private <T> Component createSystemComponentWithNoScope(String name, Class<T> service, Class<? extends T> impl) { - JavaServiceContract jsc = factory.createJavaServiceContract(); - jsc.setInterface(service); - Service s = factory.createService(); - s.setServiceContract(jsc); - - ComponentType componentType = factory.createComponentType(); - componentType.getServices().add(s); - - SystemImplementation sysImpl = factory.createSystemImplementation(); - sysImpl.setImplementationClass(impl); - sysImpl.setComponentType(componentType); - - Component sc = factory.createSimpleComponent(); - sc.setName(name); - sc.setImplementation(sysImpl); - return sc; - } - - -} diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/system/builder/impl/AssemblyVisitorTestCase.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/system/builder/impl/AssemblyVisitorTestCase.java deleted file mode 100644 index 3d63664848..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/system/builder/impl/AssemblyVisitorTestCase.java +++ /dev/null @@ -1,136 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * Licensed 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.system.builder.impl; - -import java.util.ArrayList; -import java.util.List; - -import junit.framework.Assert; -import junit.framework.TestCase; - -import org.apache.tuscany.core.builder.BuilderException; -import org.apache.tuscany.core.builder.ContextFactoryBuilder; -import org.apache.tuscany.core.builder.impl.AssemblyVisitorImpl; -import org.apache.tuscany.core.mock.component.ModuleScopeSystemComponent; -import org.apache.tuscany.core.system.assembly.SystemAssemblyFactory; -import org.apache.tuscany.core.system.assembly.SystemBinding; -import org.apache.tuscany.core.system.assembly.SystemImplementation; -import org.apache.tuscany.core.system.assembly.impl.SystemAssemblyFactoryImpl; -import org.apache.tuscany.model.assembly.AssemblyContext; -import org.apache.tuscany.model.assembly.AssemblyObject; -import org.apache.tuscany.model.assembly.Component; -import org.apache.tuscany.model.assembly.ComponentType; -import org.apache.tuscany.model.assembly.ConfiguredPort; -import org.apache.tuscany.model.assembly.ConfiguredReference; -import org.apache.tuscany.model.assembly.ConfiguredService; -import org.apache.tuscany.model.assembly.ContextFactoryHolder; -import org.apache.tuscany.model.assembly.EntryPoint; -import org.apache.tuscany.model.assembly.Module; -import org.apache.tuscany.model.assembly.Reference; -import org.apache.tuscany.model.assembly.Service; -import org.apache.tuscany.model.assembly.impl.AssemblyContextImpl; -import org.apache.tuscany.model.types.java.JavaServiceContract; - -/** - * Tests decorating a logical configuration model - * - * @version $Rev$ $Date$ - */ -public class AssemblyVisitorTestCase extends TestCase { - - private static final Object MARKER = new Object(); - - private SystemAssemblyFactory factory = new SystemAssemblyFactoryImpl(); - private AssemblyContext assemblyContext = new AssemblyContextImpl(factory, null, null); - - public void testModelVisit() throws Exception { - ComponentType componentType; - Service service; - SystemImplementation impl; - Component component; - - Module module = factory.createModule(); - - // create target component - componentType = factory.createComponentType(); - service = factory.createService(); - service.setName("target"); - componentType.getServices().add(service); - impl = factory.createSystemImplementation(); - impl.setComponentType(componentType); - component = factory.createSimpleComponent(); - component.setName("target"); - component.setImplementation(impl); - component.initialize(assemblyContext); - module.getComponents().add(component); - - // create source component - componentType = factory.createComponentType(); - Reference ref = factory.createReference(); - ref.setName("ref"); - componentType.getReferences().add(ref); - impl = factory.createSystemImplementation(); - impl.setComponentType(componentType); - component = factory.createSimpleComponent(); - component.setName("source"); - component.setImplementation(impl); - ConfiguredReference cRef = factory.createConfiguredReference("ref", "target"); - component.getConfiguredReferences().add(cRef); - component.initialize(assemblyContext); - module.getComponents().add(component); - - EntryPoint ep = factory.createEntryPoint(); - JavaServiceContract contract = factory.createJavaServiceContract(); - contract.setInterface(ModuleScopeSystemComponent.class); - service = factory.createService(); - service.setServiceContract(contract); - ConfiguredService cService = factory.createConfiguredService(); - cService.setPort(service); - cService.initialize(assemblyContext); - ep.setConfiguredService(cService); - SystemBinding binding = factory.createSystemBinding(); - ep.getBindings().add(binding); - ConfiguredReference cEpRef = factory.createConfiguredReference(); - Reference epRef = factory.createReference(); - cEpRef.setPort(epRef); - ep.setConfiguredReference(cEpRef); - ep.initialize(assemblyContext); - module.getEntryPoints().add(ep); - - List<ContextFactoryBuilder> builders = new ArrayList<ContextFactoryBuilder>(); - builders.add(new TestBuilder()); - AssemblyVisitorImpl visitor = new AssemblyVisitorImpl(builders); - module.initialize(assemblyContext); - visitor.start(module); - - Assert.assertSame(MARKER, component.getContextFactory()); - Assert.assertSame(MARKER, cRef.getProxyFactory()); - Assert.assertSame(MARKER, ep.getContextFactory()); - Assert.assertSame(MARKER, cEpRef.getProxyFactory()); - - } - - private static class TestBuilder implements ContextFactoryBuilder { - public void build(AssemblyObject model) throws BuilderException { - if (model instanceof ConfiguredPort) { - ((ConfiguredPort) model).setProxyFactory(MARKER); - } - if (model instanceof ContextFactoryHolder) { - ((ContextFactoryHolder) model).setContextFactory(MARKER); - } - } - - } - -} diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/system/context/AutowireTestCase.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/system/context/AutowireTestCase.java deleted file mode 100644 index 6316fe3a67..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/system/context/AutowireTestCase.java +++ /dev/null @@ -1,310 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * Licensed 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.system.context; - -import junit.framework.TestCase; -import org.apache.tuscany.core.context.CompositeContext; -import org.apache.tuscany.core.context.SystemCompositeContext; -import org.apache.tuscany.core.context.impl.CompositeContextImpl; -import org.apache.tuscany.core.context.event.ModuleStop; -import org.apache.tuscany.core.context.event.ModuleStart; -import org.apache.tuscany.core.mock.MockFactory; -import org.apache.tuscany.core.mock.component.AutowireSourceImpl; -import org.apache.tuscany.core.mock.component.Source; -import org.apache.tuscany.core.mock.component.Target; -import org.apache.tuscany.core.mock.component.TargetImpl; -import org.apache.tuscany.core.runtime.RuntimeContext; -import org.apache.tuscany.core.system.assembly.SystemAssemblyFactory; -import org.apache.tuscany.core.system.assembly.impl.SystemAssemblyFactoryImpl; -import org.apache.tuscany.core.config.ConfigurationLoadException; -import org.apache.tuscany.model.assembly.AssemblyContext; -import org.apache.tuscany.model.assembly.Component; -import org.apache.tuscany.model.assembly.EntryPoint; -import org.apache.tuscany.model.assembly.Module; -import org.apache.tuscany.model.assembly.ModuleComponent; -import org.apache.tuscany.model.assembly.Scope; -import org.apache.tuscany.model.assembly.Service; -import org.apache.tuscany.model.assembly.impl.AssemblyContextImpl; - -/** - * Tests autowiring for serveral scenarios according to the following runtime scheme: - * - * <code> - * tuscany.runtime - * | - * + tuscany.system - * | | - * | + system1 - * | | | - * | | + system1a - * | | - * | + system2 - * | - * + tuscany.root - * | - * + app1 - * | - * + app1a - * | - * + app1b - * </code> - * - * @version $Rev$ $Date$ - */ -public class AutowireTestCase extends TestCase { - - private static SystemAssemblyFactory systemFactory = new SystemAssemblyFactoryImpl(); - - /** - * Covers the case where a component in app1a requests autowire, which is resolved by the runtime to a service - * exposed on an entry point in tuscany.system. The entry point is wired to an entry point on system1, which itself - * is wired to a component in system1 - */ - public void testScenario1() throws Exception { - RuntimeContext runtime = createScenario1Runtime(); - CompositeContext root = runtime.getRootContext(); - SystemCompositeContext system = runtime.getSystemContext(); - CompositeContext system1 = (CompositeContext) system.getContext("system1"); - system1.publish(new ModuleStart(this)); - Target target = (Target) system.getContext("target.system.ep").getInstance(null); - assertNotNull(target); - CompositeContext app1 = (CompositeContext) root.getContext("app1"); - app1.publish(new ModuleStart(this)); - CompositeContext app1a = (CompositeContext) app1.getContext("app1a"); - app1a.publish(new ModuleStart(this)); - app1a.publish(new ModuleStop(this)); - app1.publish(new ModuleStop(this)); - Source source = (Source) app1a.getContext("source").getInstance(null); - assertEquals(target, source.getTarget()); - source.getTarget().getString(); - runtime.stop(); - } - - /** - * Covers the case where a component in app1a requests autowire, which is resolved to service exposed as an entry - * point on app1b. The entry point is wired to a component in app1b. - */ - public void testScenario2() throws Exception { - RuntimeContext runtime = createScenario2Runtime(); - CompositeContext root = runtime.getRootContext(); - CompositeContext app1 = (CompositeContext) root.getContext("app1"); - app1.publish(new ModuleStart(this)); - CompositeContext app1b = (CompositeContext) app1.getContext("app1b"); - app1b.publish(new ModuleStart(this)); - CompositeContext app1a = (CompositeContext) app1.getContext("app1a"); - app1a.publish(new ModuleStart(this)); - Target target = (Target) app1b.getContext("target.ep").getInstance(null); - assertNotNull(target); - Source source = (Source) app1a.getContext("source").getInstance(null); - assertEquals(target, source.getTarget()); - source.getTarget().getString(); - runtime.stop(); - } - - /** - * Covers the case where a component in system1a requests autowire, which is resolved to an entry point exposed on - * system2. The entry point is wired to a component in system2. - */ - public void testScenario3() throws Exception { - RuntimeContext runtime = createScenario3Runtime(); - SystemCompositeContext system = runtime.getSystemContext(); - - CompositeContext system2 = (CompositeContext) system.getContext("system2"); - system2.publish(new ModuleStart(this)); - Target target = (Target) system2.getContext("target.ep").getInstance(null); - assertNotNull(target); - - CompositeContext system1 = (CompositeContext) system.getContext("system1"); - system1.publish(new ModuleStart(this)); - CompositeContext system1a = (CompositeContext) system1.getContext("system1a"); - system1a.publish(new ModuleStart(this)); - - Source source = (Source) system1a.getContext("source").getInstance(null); - assertEquals(target, source.getTarget()); - source.getTarget().getString(); - runtime.stop(); - } - - /** - * Covers the case where a component in system1a requests autowire, which is resolved to component in its parent, - * system1. - */ - public void testScenario4() throws Exception { - RuntimeContext runtime = createScenario4Runtime(); - SystemCompositeContext system = runtime.getSystemContext(); - CompositeContext system1 = (CompositeContext) system.getContext("system1"); - system1.publish(new ModuleStart(this)); - Target target = (Target) system1.getContext("target").getInstance(null); - assertNotNull(target); - CompositeContext system1a = (CompositeContext) system1.getContext("system1a"); - system1a.publish(new ModuleStart(this)); - - Source source = (Source) system1a.getContext("source").getInstance(null); - assertEquals(target, source.getTarget()); - source.getTarget().getString(); - runtime.stop(); - } - - /** - * Covers the case where a component in system1a requests autowire, which is resolved to component in the parent of - * its parent (grandparent), system. - */ - public void testScenario5() throws Exception { - RuntimeContext runtime = createScenario5Runtime(); - SystemCompositeContext system = runtime.getSystemContext(); - CompositeContext system1 = (CompositeContext) system.getContext("system1"); - system1.publish(new ModuleStart(this)); - Target target = (Target) system.getContext("target").getInstance(null); - assertNotNull(target); - CompositeContext system1a = (CompositeContext) system1.getContext("system1a"); - system1a.publish(new ModuleStart(this)); - - Source source = (Source) system1a.getContext("source").getInstance(null); - assertEquals(target, source.getTarget()); - source.getTarget().getString(); - runtime.stop(); - } - - private RuntimeContext createScenario1Runtime() throws Exception { - RuntimeContext runtime = MockFactory.createCoreRuntime(); - runtime.start(); - SystemCompositeContext system = runtime.getSystemContext(); - ModuleComponent system1Component = MockFactory.createSystemCompositeComponent("system1"); - ModuleComponent system1aComponent = MockFactory.createSystemCompositeComponent("system1a"); - system1Component.getImplementation().getComponents().add(system1aComponent); - Component target = MockFactory.createSystemComponent("target", Target.class, TargetImpl.class, Scope.MODULE); - system1Component.getImplementation().getComponents().add(target); - - EntryPoint ep = MockFactory.createEPSystemBinding("target.ep", Target.class, "target", target); - system1Component.getImplementation().getEntryPoints().add(ep); - system.registerModelObject(system1Component); - EntryPoint systemEp = MockFactory.createEPSystemBinding("target.system.ep", Target.class, "ref"); - - systemEp.getBindings().add(systemFactory.createSystemBinding()); - Service service = systemFactory.createService(); - service.setName("system1/target.ep"); - (systemEp.getConfiguredReference().getTargetConfiguredServices().get(0)).setPort(service); - - system.registerModelObject(systemEp); - ModuleComponent app1Component = createAppModuleComponent("app1"); - ModuleComponent app1aComponent = createAppModuleComponent("app1a"); - Component source = MockFactory.createSystemComponent("source", Source.class, AutowireSourceImpl.class, Scope.MODULE); - app1aComponent.getImplementation().getComponents().add(source); - app1Component.getImplementation().getComponents().add(app1aComponent); - CompositeContext root = runtime.getRootContext(); - root.registerModelObject(app1Component); - system.publish(new ModuleStart(this)); - return runtime; - } - - private RuntimeContext createScenario2Runtime() throws Exception { - RuntimeContext runtime = MockFactory.createCoreRuntime(); - runtime.start(); - - ModuleComponent app1Component = createAppModuleComponent("app1"); - ModuleComponent app1aComponent = createAppModuleComponent("app1a"); - ModuleComponent app1bComponent = createAppModuleComponent("app1b"); - Component source = MockFactory.createSystemComponent("source", Source.class, AutowireSourceImpl.class, Scope.MODULE); - app1aComponent.getImplementation().getComponents().add(source); - app1Component.getImplementation().getComponents().add(app1aComponent); - app1Component.getImplementation().getComponents().add(app1bComponent); - - Component target = MockFactory.createSystemComponent("target", Target.class, TargetImpl.class, Scope.MODULE); - app1bComponent.getImplementation().getComponents().add(target); - - EntryPoint ep = MockFactory.createEPSystemBinding("target.ep", Target.class, "target", target); - ep.getBindings().add(systemFactory.createSystemBinding()); - Service service = systemFactory.createService(); - service.setName("target.ep"); - ep.getConfiguredReference().getTargetConfiguredServices().get(0).setPort(service); - app1bComponent.getImplementation().getEntryPoints().add(ep); - - CompositeContext root = runtime.getRootContext(); - root.registerModelObject(app1Component); - return runtime; - } - - private RuntimeContext createScenario3Runtime() throws Exception { - RuntimeContext runtime = MockFactory.createCoreRuntime(); - runtime.start(); - SystemCompositeContext system = runtime.getSystemContext(); - ModuleComponent system1Component = MockFactory.createSystemCompositeComponent("system1"); - ModuleComponent system2Component = MockFactory.createSystemCompositeComponent("system2"); - ModuleComponent system1aComponent = MockFactory.createSystemCompositeComponent("system1a"); - system1Component.getImplementation().getComponents().add(system1aComponent); - - Component target = MockFactory.createSystemComponent("target", Target.class, TargetImpl.class, Scope.MODULE); - system2Component.getImplementation().getComponents().add(target); - EntryPoint ep = MockFactory.createEPSystemBinding("target.ep", Target.class, "target", target); - system2Component.getImplementation().getEntryPoints().add(ep); - system.registerModelObject(system2Component); - - Component source = MockFactory.createSystemComponent("source", Source.class, AutowireSourceImpl.class, Scope.MODULE); - system1aComponent.getImplementation().getComponents().add(source); - system.registerModelObject(system1Component); - system.publish(new ModuleStart(this)); - return runtime; - } - - private RuntimeContext createScenario4Runtime() throws Exception { - RuntimeContext runtime = MockFactory.createCoreRuntime(); - runtime.start(); - SystemCompositeContext system = runtime.getSystemContext(); - ModuleComponent system1Component = MockFactory.createSystemCompositeComponent("system1"); - ModuleComponent system1aComponent = MockFactory.createSystemCompositeComponent("system1a"); - system1Component.getImplementation().getComponents().add(system1aComponent); - - Component target = MockFactory.createSystemComponent("target", Target.class, TargetImpl.class, Scope.MODULE); - system1Component.getImplementation().getComponents().add(target); - - Component source = MockFactory.createSystemComponent("source", Source.class, AutowireSourceImpl.class, Scope.MODULE); - system1aComponent.getImplementation().getComponents().add(source); - system.registerModelObject(system1Component); - system.publish(new ModuleStart(this)); - return runtime; - } - - private RuntimeContext createScenario5Runtime() throws Exception { - RuntimeContext runtime = MockFactory.createCoreRuntime(); - runtime.start(); - SystemCompositeContext system = runtime.getSystemContext(); - ModuleComponent system1Component = MockFactory.createSystemCompositeComponent("system1"); - ModuleComponent system1aComponent = MockFactory.createSystemCompositeComponent("system1a"); - system1Component.getImplementation().getComponents().add(system1aComponent); - - Component target = MockFactory.createSystemComponent("target", Target.class, TargetImpl.class, Scope.MODULE); - system.registerModelObject(target); - - Component source = MockFactory.createSystemComponent("source", Source.class, AutowireSourceImpl.class, Scope.MODULE); - system1aComponent.getImplementation().getComponents().add(source); - system.registerModelObject(system1Component); - system.publish(new ModuleStart(this)); - return runtime; - } - - private ModuleComponent createAppModuleComponent(String name) throws ConfigurationLoadException { - AssemblyContext assemblyContext = new AssemblyContextImpl(systemFactory, null, null); - ModuleComponent mc = systemFactory.createModuleComponent(); - mc.setName(name); - Module module = systemFactory.createModule(); - module.setImplementationClass(CompositeContextImpl.class); - module.setComponentType(MockFactory.getComponentType()); - module.setName(name); - module.initialize(assemblyContext); - mc.setImplementation(module); - return mc; - } - -} diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/system/context/CompositeNestingTestCase.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/system/context/CompositeNestingTestCase.java deleted file mode 100644 index 27ffc5794e..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/system/context/CompositeNestingTestCase.java +++ /dev/null @@ -1,98 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * Licensed 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.system.context; - -import junit.framework.Assert; -import junit.framework.TestCase; -import org.apache.tuscany.core.context.CompositeContext; -import org.apache.tuscany.core.context.event.ModuleStart; -import org.apache.tuscany.core.context.event.ModuleStop; -import org.apache.tuscany.core.mock.MockFactory; -import org.apache.tuscany.core.mock.component.Source; -import org.apache.tuscany.core.mock.component.Target; -import org.apache.tuscany.core.runtime.RuntimeContext; -import org.apache.tuscany.core.config.ConfigurationLoadException; -import org.apache.tuscany.model.assembly.ModuleComponent; -import org.apache.tuscany.model.assembly.Scope; - -/** - * Tests registering arbirarily deep child composite contexts - * - * @version $Rev$ $Date$ - */ -public class CompositeNestingTestCase extends TestCase { - - /** - * Tests registration of a 3-level deep hierarchy under the top-level system composite context - */ - public void testSystemContext() throws Exception { - RuntimeContext runtime = MockFactory.createCoreRuntime(); - ModuleComponent child1 = createHierarchy(); - runtime.getSystemContext().registerModelObject(child1); - CompositeContext child1Ctx = (CompositeContext) runtime.getSystemContext().getContext("child1"); - Assert.assertNotNull(child1Ctx); - child1Ctx.publish(new ModuleStart(this)); - analyzeLeafComponents(child1Ctx); - CompositeContext child2Ctx = (CompositeContext) child1Ctx.getContext("child2"); - Assert.assertNotNull(child2Ctx); - child2Ctx.publish(new ModuleStart(this)); - analyzeLeafComponents(child2Ctx); - CompositeContext child3Ctx = (CompositeContext) child2Ctx.getContext("child3"); - Assert.assertNotNull(child3Ctx); - child3Ctx.publish(new ModuleStart(this)); - analyzeLeafComponents(child3Ctx); - - Assert.assertNull(child1Ctx.getContext("child3")); // sanity check - } - - /** - * Tests registration of a 3-level deep hierarchy under the root application composite context - */ - public void testRootContext() throws Exception { - RuntimeContext runtime = MockFactory.createCoreRuntime(); - ModuleComponent child1 = createHierarchy(); - runtime.getRootContext().registerModelObject(child1); - CompositeContext child1Ctx = (CompositeContext) runtime.getRootContext().getContext("child1"); - Assert.assertNotNull(child1Ctx); - child1Ctx.publish(new ModuleStart(this)); - analyzeLeafComponents(child1Ctx); - CompositeContext child2Ctx = (CompositeContext) child1Ctx.getContext("child2"); - Assert.assertNotNull(child2Ctx); - child2Ctx.publish(new ModuleStart(this)); - analyzeLeafComponents(child2Ctx); - CompositeContext child3Ctx = (CompositeContext) child2Ctx.getContext("child3"); - Assert.assertNotNull(child3Ctx); - child3Ctx.publish(new ModuleStart(this)); - analyzeLeafComponents(child3Ctx); - - Assert.assertNull(child1Ctx.getContext("child3")); // sanity check - child1Ctx.publish(new ModuleStop(this)); - } - - private ModuleComponent createHierarchy() throws ConfigurationLoadException { - ModuleComponent child3 = MockFactory.createSystemModuleComponentWithWiredComponents("child3", Scope.MODULE, Scope.MODULE); - ModuleComponent child2 = MockFactory.createSystemModuleComponentWithWiredComponents("child2", Scope.MODULE, Scope.MODULE); - child2.getImplementation().getComponents().add(child3); - ModuleComponent child1 = MockFactory.createSystemModuleComponentWithWiredComponents("child1", Scope.MODULE, Scope.MODULE); - child1.getImplementation().getComponents().add(child2); - return child1; - } - - private void analyzeLeafComponents(CompositeContext ctx) throws Exception { - Source source = (Source) ctx.getContext("source").getInstance(null); - Assert.assertNotNull(source); - Target target = source.getTarget(); - Assert.assertNotNull(target); - } -} diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/system/context/IntraCompositeWireTestCase.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/system/context/IntraCompositeWireTestCase.java deleted file mode 100644 index a956263cc8..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/system/context/IntraCompositeWireTestCase.java +++ /dev/null @@ -1,125 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * Licensed 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.system.context; - -import junit.framework.Assert; -import junit.framework.TestCase; -import org.apache.tuscany.core.context.AtomicContext; -import org.apache.tuscany.core.context.SystemCompositeContext; -import org.apache.tuscany.core.context.event.ModuleStart; -import org.apache.tuscany.core.context.event.ModuleStop; -import org.apache.tuscany.core.mock.MockConfigContext; -import org.apache.tuscany.core.mock.MockFactory; -import org.apache.tuscany.core.mock.component.Source; -import org.apache.tuscany.core.mock.component.Target; -import org.apache.tuscany.model.assembly.Scope; - -import java.util.List; - -/** - * Tests intra-composite system component wiring scenarios - * - * @version $Rev$ $Date$ - */ -public class IntraCompositeWireTestCase extends TestCase { - - public void testModuleToModuleScope() throws Exception { - SystemCompositeContext context = createContext(); - context.start(); - context.registerModelObject(MockFactory.createSystemModuleWithWiredComponents("system.module",Scope.MODULE, Scope.MODULE)); - context.publish(new ModuleStart(this)); - Source source = (Source) ((AtomicContext) context.getContext("source")).getTargetInstance(); - Assert.assertNotNull(source); - Target targetRef = source.getTarget(); - Assert.assertNotNull(targetRef); - Target target = (Target) ((AtomicContext) context.getContext("target")).getTargetInstance(); - Assert.assertSame(target, targetRef); - Assert.assertSame(target, source.getTarget()); - context.publish(new ModuleStop(this)); - context.stop(); - } - - public void testStatelessToModuleScope() throws Exception { - SystemCompositeContext context = createContext(); - context.start(); - context.registerModelObject(MockFactory.createSystemModuleWithWiredComponents("system.module",Scope.INSTANCE, Scope.MODULE)); - context.publish(new ModuleStart(this)); - Source source = (Source) ((AtomicContext) context.getContext("source")).getTargetInstance(); - Assert.assertNotNull(source); - Target targetRef = source.getTarget(); - Assert.assertNotNull(targetRef); - source = (Source) ((AtomicContext) context.getContext("source")).getTargetInstance(); - Target target = (Target) ((AtomicContext) context.getContext("target")).getTargetInstance(); - Assert.assertSame(target, targetRef); - Assert.assertSame(target, source.getTarget()); - context.publish(new ModuleStop(this)); - context.stop(); - } - - public void testModuleToStatelessScope() throws Exception { - SystemCompositeContext context = createContext(); - context.start(); - context.registerModelObject(MockFactory.createSystemModuleWithWiredComponents("system.module",Scope.MODULE, Scope.INSTANCE)); - context.publish(new ModuleStart(this)); - Source source = (Source) ((AtomicContext) context.getContext("source")).getTargetInstance(); - Assert.assertNotNull(source); - Target targetRef = source.getTarget(); - Assert.assertNotNull(targetRef); - Target target = (Target) ((AtomicContext) context.getContext("target")).getTargetInstance(); - Assert.assertNotSame(target, targetRef); - Source source2 = (Source) ((AtomicContext) context.getContext("source")).getTargetInstance(); - // should be the same since the module scope component was alreadyy created and the stateless - // component will be "attached" to it - Assert.assertSame(source.getTarget(), source2.getTarget()); - context.publish(new ModuleStop(this)); - context.stop(); - } - - public void testMultiplicity() throws Exception { - SystemCompositeContext context = createContext(); - context.start(); - context.registerModelObject(MockFactory.createSystemModuleWithWiredComponents("system.module",Scope.MODULE, Scope.MODULE)); - context.publish(new ModuleStart(this)); - Source source = (Source) ((AtomicContext) context.getContext("source")).getTargetInstance(); - Assert.assertNotNull(source); - Target target = (Target) ((AtomicContext) context.getContext("target")).getTargetInstance(); - Assert.assertNotNull(target); - // test setter injection - List<Target> targets = source.getTargets(); - Assert.assertEquals(1,targets.size()); - assertSame(target,targets.get(0)); - - // test field injection - targets = source.getTargetsThroughField(); - Assert.assertEquals(1,targets.size()); - assertSame(target,targets.get(0)); - - // test array injection - Target[] targetArray = source.getArrayOfTargets(); - Assert.assertEquals(1,targetArray.length); - assertSame(target,targetArray[0]); - - - } - - private SystemCompositeContext createContext() { - SystemCompositeContextImpl context = new SystemCompositeContextImpl(); - context.setName("system.context"); - context.setConfigurationContext(new MockConfigContext(MockFactory.createSystemBuilders())); - return context; - } - - - -} diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/system/context/SystemCompositeComponentContextTestCase.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/system/context/SystemCompositeComponentContextTestCase.java deleted file mode 100644 index 75208f47b6..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/system/context/SystemCompositeComponentContextTestCase.java +++ /dev/null @@ -1,108 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * Licensed 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.system.context; - -import junit.framework.Assert; -import junit.framework.TestCase; -import org.apache.tuscany.core.builder.ContextFactoryBuilder; -import org.apache.tuscany.core.context.CompositeContext; -import org.apache.tuscany.core.context.QualifiedName; -import org.apache.tuscany.core.context.event.ModuleStart; -import org.apache.tuscany.core.context.event.ModuleStop; -import org.apache.tuscany.core.context.impl.EventContextImpl; -import org.apache.tuscany.core.mock.MockConfigContext; -import org.apache.tuscany.core.mock.MockFactory; -import org.apache.tuscany.core.mock.component.ModuleScopeSystemComponent; -import org.apache.tuscany.core.mock.component.ModuleScopeSystemComponentImpl; -import org.apache.tuscany.core.system.assembly.SystemAssemblyFactory; -import org.apache.tuscany.core.system.assembly.impl.SystemAssemblyFactoryImpl; -import org.apache.tuscany.model.assembly.Component; -import org.apache.tuscany.model.assembly.EntryPoint; -import org.apache.tuscany.model.assembly.Scope; - -import java.util.List; - -/** - * Tests the system composite context - * - * @version $Rev$ $Date$ - */ -public class SystemCompositeComponentContextTestCase extends TestCase { - private SystemAssemblyFactory factory; - private SystemCompositeContextImpl system; - - public void testChildLocate() throws Exception { - system.start(); - Component compositeComponent = MockFactory.createCompositeComponent("system.child"); - system.registerModelObject(compositeComponent); - CompositeContext childContext = (CompositeContext) system.getContext("system.child"); - Assert.assertNotNull(childContext); - - Component component = factory.createSystemComponent("TestService1", ModuleScopeSystemComponent.class, ModuleScopeSystemComponentImpl.class, Scope.MODULE); - EntryPoint ep = MockFactory.createEPSystemBinding("TestService1EP", ModuleScopeSystemComponent.class, "TestService1", component); - childContext.registerModelObject(component); - childContext.registerModelObject(ep); - childContext.publish(new ModuleStart(this)); - Assert.assertNotNull(system.getContext("system.child").getInstance(new QualifiedName("./TestService1EP"))); - childContext.publish(new ModuleStop(this)); - } - - public void testAutowireRegisterBeforeStart() throws Exception { - Component component = factory.createSystemComponent("TestService1", ModuleScopeSystemComponent.class, ModuleScopeSystemComponentImpl.class, Scope.MODULE); - EntryPoint ep = MockFactory.createEPSystemBinding("TestService1EP", ModuleScopeSystemComponent.class, "TestService1", component); - system.registerModelObject(component); - system.registerModelObject(ep); - system.start(); - system.publish(new ModuleStart(this)); - Assert.assertSame(system.getContext("TestService1EP").getInstance(null), system.resolveInstance(ModuleScopeSystemComponent.class)); - } - - public void testAutowireRegisterAfterStart() throws Exception { - Component component = factory.createSystemComponent("TestService1", ModuleScopeSystemComponent.class, ModuleScopeSystemComponentImpl.class, Scope.MODULE); - system.registerModelObject(component); - system.start(); - system.publish(new ModuleStart(this)); - EntryPoint ep = MockFactory.createEPSystemBinding("TestService1EP", ModuleScopeSystemComponent.class, "TestService1", component); - system.registerModelObject(ep); - Assert.assertSame(system.getContext("TestService1EP").getInstance(null), system.resolveInstance(ModuleScopeSystemComponent.class)); - } - - public void testAutowireModuleRegisterBeforeStart() throws Exception { - system.registerModelObject(MockFactory.createSystemModule()); - system.start(); - system.publish(new ModuleStart(this)); - Assert.assertSame(system.getContext("TestService1EP").getInstance(null), system.resolveInstance(ModuleScopeSystemComponent.class)); - } - - public void testAutowireModuleRegisterAfterStart() throws Exception { - system.start(); - system.publish(new ModuleStart(this)); - system.registerModelObject(MockFactory.createSystemModule()); - Assert.assertSame(system.getContext("TestService1EP").getInstance(null), system.resolveInstance(ModuleScopeSystemComponent.class)); - } - - protected void setUp() throws Exception { - super.setUp(); - factory = new SystemAssemblyFactoryImpl(); - List<ContextFactoryBuilder> builders = MockFactory.createSystemBuilders(); - - system = new SystemCompositeContextImpl("system", null, null, new SystemScopeStrategy(), new EventContextImpl(), new MockConfigContext(builders)); - } - - protected void tearDown() throws Exception { - system.publish(new ModuleStop(this)); - system.stop(); - super.tearDown(); - } -} diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/system/context/SystemCompositeContextRegisterTestCase.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/system/context/SystemCompositeContextRegisterTestCase.java deleted file mode 100644 index 4397e39bec..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/system/context/SystemCompositeContextRegisterTestCase.java +++ /dev/null @@ -1,37 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * Licensed 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.system.context; - -import org.apache.tuscany.core.builder.ContextFactoryBuilder; -import org.apache.tuscany.core.context.CompositeContextRegisterTestCase; -import org.apache.tuscany.core.context.CompositeContext; -import org.apache.tuscany.core.context.impl.EventContextImpl; -import org.apache.tuscany.core.context.scope.DefaultScopeStrategy; -import org.apache.tuscany.core.mock.MockConfigContext; -import org.apache.tuscany.core.mock.MockFactory; - -import java.util.List; - -/** - * Tests registration of model objects for an system composite context - * - * @version $Rev$ $Date$ - */ -public class SystemCompositeContextRegisterTestCase extends CompositeContextRegisterTestCase { - - protected CompositeContext createContext() { - List<ContextFactoryBuilder> builders = MockFactory.createSystemBuilders(); - return new SystemCompositeContextImpl("test.context", null, null, new DefaultScopeStrategy(), new EventContextImpl(), new MockConfigContext(builders)); - } -} diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/system/context/SystemCompositeHierarchyTestCase.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/system/context/SystemCompositeHierarchyTestCase.java deleted file mode 100644 index ba7a3ba5da..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/system/context/SystemCompositeHierarchyTestCase.java +++ /dev/null @@ -1,46 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * Licensed 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.system.context; - -import junit.framework.Assert; -import org.apache.tuscany.core.builder.ContextFactoryBuilder; -import org.apache.tuscany.core.context.AbstractCompositeHierarchyTests; -import org.apache.tuscany.core.context.CompositeContext; -import org.apache.tuscany.core.context.impl.EventContextImpl; -import org.apache.tuscany.core.context.scope.DefaultScopeStrategy; -import org.apache.tuscany.core.mock.MockConfigContext; -import org.apache.tuscany.core.mock.MockFactory; - -import java.util.List; - -/** - * Performs testing of various hierarchical scenarios - * - * @version $Rev$ $Date$ - */ -public class SystemCompositeHierarchyTestCase extends AbstractCompositeHierarchyTests { - - - - protected CompositeContext createContextHierachy() throws Exception { - List<ContextFactoryBuilder> mockBuilders = MockFactory.createSystemBuilders(); - CompositeContext parent = new SystemCompositeContextImpl("test.parent", null, null, new DefaultScopeStrategy(), new EventContextImpl(), new MockConfigContext(mockBuilders)); - parent.registerModelObject(MockFactory.createCompositeComponent("test.child")); - parent.start(); - CompositeContext child = (CompositeContext) parent.getContext("test.child"); - Assert.assertNotNull(child); - return parent; - } - -} diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/system/context/SystemObjectRegistrationTestCase.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/system/context/SystemObjectRegistrationTestCase.java deleted file mode 100644 index 241346e24f..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/system/context/SystemObjectRegistrationTestCase.java +++ /dev/null @@ -1,84 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation - * - * Licensed 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.system.context; - -import junit.framework.TestCase; -import org.apache.tuscany.core.config.ConfigurationException; -import org.apache.tuscany.core.context.SystemCompositeContext; -import org.apache.tuscany.core.context.DuplicateNameException; -import org.apache.tuscany.core.context.event.ModuleStart; -import org.apache.tuscany.core.runtime.RuntimeContext; -import org.apache.tuscany.core.runtime.RuntimeContextImpl; -import org.apache.tuscany.core.builder.ContextFactoryBuilderRegistry; -import org.apache.tuscany.core.builder.impl.DefaultWireBuilder; -import org.apache.tuscany.core.client.BootstrapHelper; -import org.apache.tuscany.common.monitor.MonitorFactory; -import org.apache.tuscany.common.monitor.impl.NullMonitorFactory; - -/** - * @version $Rev$ $Date$ - */ -public class SystemObjectRegistrationTestCase extends TestCase { - private RuntimeContext runtime; - private SystemCompositeContext systemContext; - - public void testRegistration() throws ConfigurationException { - MockComponent instance = new MockComponent(); - systemContext.registerJavaObject("foo", MockComponent.class, instance); - assertSame(instance, systemContext.getContext("foo").getInstance(null)); - } - - public void testDuplicateRegistration() throws ConfigurationException { - MockComponent instance = new MockComponent(); - systemContext.registerJavaObject("foo", MockComponent.class, instance); - try { - systemContext.registerJavaObject("foo", MockComponent.class, instance); - fail(); - } catch (DuplicateNameException e) { - // ok - } - } - - public void testAutowireToObject() throws ConfigurationException { - MockComponent instance = new MockComponent(); - systemContext.registerJavaObject("foo", MockComponent.class, instance); - assertSame(instance, systemContext.resolveInstance(MockComponent.class)); - assertNull(systemContext.resolveExternalInstance(MockComponent.class)); - } - - protected void setUp() throws Exception { - super.setUp(); - MonitorFactory monitorFactory = new NullMonitorFactory(); - ContextFactoryBuilderRegistry builderRegistry = BootstrapHelper.bootstrapContextFactoryBuilders(monitorFactory); - DefaultWireBuilder wireBuilder = new DefaultWireBuilder(); - runtime = new RuntimeContextImpl(monitorFactory, builderRegistry, wireBuilder); - runtime.start(); - systemContext = runtime.getSystemContext(); - systemContext.publish(new ModuleStart(this)); - } - - protected void tearDown() throws Exception { - runtime.stop(); - super.tearDown(); - } - - private static class MockComponent { - public String hello(String message) { - return message; - } - } -} diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/system/context/TestBuilder.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/system/context/TestBuilder.java deleted file mode 100644 index c531c8f7f9..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/system/context/TestBuilder.java +++ /dev/null @@ -1,55 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation - * - * Licensed 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.system.context; - -import org.osoa.sca.annotations.Init; -import org.osoa.sca.annotations.Scope; - -import org.apache.tuscany.core.builder.BuilderException; -import org.apache.tuscany.core.builder.ContextFactoryBuilder; -import org.apache.tuscany.core.builder.ContextFactoryBuilderRegistry; -import org.apache.tuscany.core.system.annotation.Autowire; -import org.apache.tuscany.model.assembly.AssemblyObject; - -@Scope("MODULE") -public class TestBuilder implements ContextFactoryBuilder { - private ContextFactoryBuilderRegistry builderRegistry; - - private boolean invoked = false; - - public TestBuilder() { - super(); - } - - @Init(eager = true) - public void init() { - builderRegistry.register(this); - } - - @Autowire - public void setBuilderRegistry(ContextFactoryBuilderRegistry builderRegistry) { - this.builderRegistry = builderRegistry; - } - - public void build(AssemblyObject object) throws BuilderException { - invoked = true; - } - - public boolean invoked() { - return invoked; - } -} diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/wire/InvocationConfigurationErrorTestCase.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/wire/InvocationConfigurationErrorTestCase.java deleted file mode 100644 index 5e4b3e2f9e..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/wire/InvocationConfigurationErrorTestCase.java +++ /dev/null @@ -1,155 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * Licensed 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.wire; - -import junit.framework.Assert; -import junit.framework.TestCase; -import org.apache.tuscany.core.wire.impl.InvokerInterceptor; -import org.apache.tuscany.core.wire.impl.MessageChannelImpl; -import org.apache.tuscany.core.wire.mock.MockHandler; -import org.apache.tuscany.core.wire.mock.SimpleTarget; -import org.apache.tuscany.core.wire.mock.MockSyncInterceptor; -import org.apache.tuscany.core.wire.mock.SimpleTargetImpl; -import org.apache.tuscany.core.wire.mock.MockStaticInvoker; -import org.apache.tuscany.core.message.Message; -import org.apache.tuscany.core.message.MessageFactory; -import org.apache.tuscany.core.message.impl.MessageFactoryImpl; - -import java.lang.reflect.Method; - -/** - * Tests error propagation through an innvocation - * - * @version $Rev$ $Date$ - */ -public class InvocationConfigurationErrorTestCase extends TestCase { - - - private Method hello; - - private MessageFactory factory = new MessageFactoryImpl(); - - public InvocationConfigurationErrorTestCase() { - super(); - } - - public InvocationConfigurationErrorTestCase(String arg0) { - super(arg0); - } - - public void setUp() throws Exception { - hello = SimpleTarget.class.getMethod("hello", String.class); - } - - public void testInvokeWithHandlers() throws Exception{ - SourceInvocationConfiguration source = new SourceInvocationConfiguration(hello); - MockHandler sourceRequestHandler = new MockHandler(); - MockHandler sourceResponseHandler = new MockHandler(); - MockSyncInterceptor sourceInterceptor = new MockSyncInterceptor(); - source.addRequestHandler(sourceRequestHandler); - source.addResponseHandler(sourceResponseHandler); - source.addInterceptor(sourceInterceptor); - - TargetInvocationConfiguration target = new TargetInvocationConfiguration(hello); - MockHandler targetRequestHandler = new MockHandler(); - MockHandler targetResponseHandler = new MockHandler(); - MockSyncInterceptor targetInterceptor = new MockSyncInterceptor(); - target.addRequestHandler(targetRequestHandler); - target.addResponseHandler(targetResponseHandler); - target.addInterceptor(targetInterceptor); - target.addInterceptor(new InvokerInterceptor()); - - // connect the source to the target - source.setTargetRequestChannel(new MessageChannelImpl(target.getRequestHandlers())); - source.setTargetResponseChannel(new MessageChannelImpl(target.getResponseHandlers())); - source.build(); - target.build(); - MockStaticInvoker invoker = new MockStaticInvoker(hello, new SimpleTargetImpl()); - source.setTargetInvoker(invoker); - - Message msg = factory.createMessage(); - msg.setTargetInvoker(invoker); - Message response = source.getHeadInterceptor().invoke(msg); - Assert.assertTrue(response.getBody() instanceof IllegalArgumentException); - Assert.assertEquals(1,sourceRequestHandler.getCount()); - Assert.assertEquals(1,sourceResponseHandler.getCount()); - Assert.assertEquals(1,sourceInterceptor.getCount()); - Assert.assertEquals(1,targetRequestHandler.getCount()); - Assert.assertEquals(1,targetResponseHandler.getCount()); - Assert.assertEquals(1,targetInterceptor.getCount()); - } - - public void testInvokeWithRequestHandlers() throws Exception{ - SourceInvocationConfiguration source = new SourceInvocationConfiguration(hello); - MockHandler sourceRequestHandler = new MockHandler(); - MockSyncInterceptor sourceInterceptor = new MockSyncInterceptor(); - source.addRequestHandler(sourceRequestHandler); - source.addInterceptor(sourceInterceptor); - - TargetInvocationConfiguration target = new TargetInvocationConfiguration(hello); - MockHandler targetRequestHandler = new MockHandler(); - MockSyncInterceptor targetInterceptor = new MockSyncInterceptor(); - target.addRequestHandler(targetRequestHandler); - target.addInterceptor(targetInterceptor); - target.addInterceptor(new InvokerInterceptor()); - - // connect the source to the target - source.setTargetRequestChannel(new MessageChannelImpl(target.getRequestHandlers())); - source.setTargetResponseChannel(new MessageChannelImpl(target.getResponseHandlers())); - source.build(); - target.build(); - MockStaticInvoker invoker = new MockStaticInvoker(hello, new SimpleTargetImpl()); - source.setTargetInvoker(invoker); - - Message msg = factory.createMessage(); - msg.setTargetInvoker(invoker); - Message response = source.getHeadInterceptor().invoke(msg); - Assert.assertTrue(response.getBody() instanceof IllegalArgumentException); - Assert.assertEquals(1,sourceRequestHandler.getCount()); - Assert.assertEquals(1,sourceInterceptor.getCount()); - Assert.assertEquals(1,targetRequestHandler.getCount()); - Assert.assertEquals(1,targetInterceptor.getCount()); - } - - /** - * Tests basic wiring of a source to a target, including handlers and interceptors - */ - public void testInvokeWithInterceptorsOnly() throws Exception{ - SourceInvocationConfiguration source = new SourceInvocationConfiguration(hello); - MockSyncInterceptor sourceInterceptor = new MockSyncInterceptor(); - source.addInterceptor(sourceInterceptor); - - TargetInvocationConfiguration target = new TargetInvocationConfiguration(hello); - MockSyncInterceptor targetInterceptor = new MockSyncInterceptor(); - target.addInterceptor(targetInterceptor); - target.addInterceptor(new InvokerInterceptor()); - - // connect the source to the target - source.setTargetInterceptor(target.getHeadInterceptor()); - source.build(); - target.build(); - MockStaticInvoker invoker = new MockStaticInvoker(hello, new SimpleTargetImpl()); - source.setTargetInvoker(invoker); - - Message msg = factory.createMessage(); - msg.setTargetInvoker(invoker); - Message response = source.getHeadInterceptor().invoke(msg); - Assert.assertTrue(response.getBody() instanceof IllegalArgumentException); - Assert.assertEquals(1,sourceInterceptor.getCount()); - Assert.assertEquals(1,targetInterceptor.getCount()); - - } - -} - diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/wire/InvocationConfigurationTestCase.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/wire/InvocationConfigurationTestCase.java deleted file mode 100644 index 0519573439..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/wire/InvocationConfigurationTestCase.java +++ /dev/null @@ -1,153 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * Licensed 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.wire; - -import junit.framework.Assert; -import junit.framework.TestCase; -import org.apache.tuscany.core.wire.impl.InvokerInterceptor; -import org.apache.tuscany.core.wire.impl.MessageChannelImpl; -import org.apache.tuscany.core.wire.mock.SimpleTarget; -import org.apache.tuscany.core.wire.mock.MockHandler; -import org.apache.tuscany.core.wire.mock.MockSyncInterceptor; -import org.apache.tuscany.core.wire.mock.MockStaticInvoker; -import org.apache.tuscany.core.wire.mock.SimpleTargetImpl; -import org.apache.tuscany.core.message.Message; -import org.apache.tuscany.core.message.MessageFactory; -import org.apache.tuscany.core.message.impl.MessageFactoryImpl; - -import java.lang.reflect.Method; - -public class InvocationConfigurationTestCase extends TestCase { - - private Method hello; - - - private MessageFactory factory = new MessageFactoryImpl(); - - public InvocationConfigurationTestCase() { - super(); - } - - public InvocationConfigurationTestCase(String arg0) { - super(arg0); - } - - public void setUp() throws Exception { - hello = SimpleTarget.class.getMethod("hello", String.class); - } - - /** - * Tests basic wiring of a source to a target, including handlers and interceptors - */ - public void testInvokeWithHandlers() throws Exception { - SourceInvocationConfiguration source = new SourceInvocationConfiguration(hello); - MockHandler sourceRequestHandler = new MockHandler(); - MockHandler sourceResponseHandler = new MockHandler(); - MockSyncInterceptor sourceInterceptor = new MockSyncInterceptor(); - source.addRequestHandler(sourceRequestHandler); - source.addResponseHandler(sourceResponseHandler); - source.addInterceptor(sourceInterceptor); - - TargetInvocationConfiguration target = new TargetInvocationConfiguration(hello); - MockHandler targetRequestHandler = new MockHandler(); - MockHandler targetResponseHandler = new MockHandler(); - MockSyncInterceptor targetInterceptor = new MockSyncInterceptor(); - target.addRequestHandler(targetRequestHandler); - target.addResponseHandler(targetResponseHandler); - target.addInterceptor(targetInterceptor); - target.addInterceptor(new InvokerInterceptor()); - - // connect the source to the target - source.setTargetRequestChannel(new MessageChannelImpl(target.getRequestHandlers())); - source.setTargetResponseChannel(new MessageChannelImpl(target.getResponseHandlers())); - source.build(); - target.build(); - MockStaticInvoker invoker = new MockStaticInvoker(hello, new SimpleTargetImpl()); - source.setTargetInvoker(invoker); - - Message msg = factory.createMessage(); - msg.setBody("foo"); - msg.setTargetInvoker(invoker); - Message response = source.getHeadInterceptor().invoke(msg); - Assert.assertEquals("foo", response.getBody()); - Assert.assertEquals(1, sourceRequestHandler.getCount()); - Assert.assertEquals(1, sourceResponseHandler.getCount()); - Assert.assertEquals(1, sourceInterceptor.getCount()); - Assert.assertEquals(1, targetRequestHandler.getCount()); - Assert.assertEquals(1, targetResponseHandler.getCount()); - Assert.assertEquals(1, targetInterceptor.getCount()); - } - - public void testInvokeWithRequestHandlers() throws Exception { - SourceInvocationConfiguration source = new SourceInvocationConfiguration(hello); - MockHandler sourceRequestHandler = new MockHandler(); - MockSyncInterceptor sourceInterceptor = new MockSyncInterceptor(); - source.addRequestHandler(sourceRequestHandler); - source.addInterceptor(sourceInterceptor); - - TargetInvocationConfiguration target = new TargetInvocationConfiguration(hello); - MockHandler targetRequestHandler = new MockHandler(); - MockSyncInterceptor targetInterceptor = new MockSyncInterceptor(); - target.addRequestHandler(targetRequestHandler); - target.addInterceptor(targetInterceptor); - target.addInterceptor(new InvokerInterceptor()); - - // connect the source to the target - source.setTargetRequestChannel(new MessageChannelImpl(target.getRequestHandlers())); - source.setTargetResponseChannel(new MessageChannelImpl(target.getResponseHandlers())); - source.build(); - target.build(); - MockStaticInvoker invoker = new MockStaticInvoker(hello, new SimpleTargetImpl()); - source.setTargetInvoker(invoker); - - Message msg = factory.createMessage(); - msg.setBody("foo"); - msg.setTargetInvoker(invoker); - Message response = source.getHeadInterceptor().invoke(msg); - Assert.assertEquals("foo", response.getBody()); - Assert.assertEquals(1, sourceRequestHandler.getCount()); - Assert.assertEquals(1, sourceInterceptor.getCount()); - Assert.assertEquals(1, targetRequestHandler.getCount()); - Assert.assertEquals(1, targetInterceptor.getCount()); - } - - /** - * Tests basic wiring of a source to a target, including handlers and interceptors - */ - public void testInvokeWithInterceptorsOnly() throws Exception { - SourceInvocationConfiguration source = new SourceInvocationConfiguration(hello); - MockSyncInterceptor sourceInterceptor = new MockSyncInterceptor(); - source.addInterceptor(sourceInterceptor); - - TargetInvocationConfiguration target = new TargetInvocationConfiguration(hello); - MockSyncInterceptor targetInterceptor = new MockSyncInterceptor(); - target.addInterceptor(targetInterceptor); - target.addInterceptor(new InvokerInterceptor()); - - // connect the source to the target - source.setTargetInterceptor(target.getHeadInterceptor()); - source.build(); - target.build(); - MockStaticInvoker invoker = new MockStaticInvoker(hello, new SimpleTargetImpl()); - source.setTargetInvoker(invoker); - - Message msg = factory.createMessage(); - msg.setBody("foo"); - msg.setTargetInvoker(invoker); - Message response = source.getHeadInterceptor().invoke(msg); - Assert.assertEquals("foo", response.getBody()); - Assert.assertEquals(1, sourceInterceptor.getCount()); - Assert.assertEquals(1, targetInterceptor.getCount()); - } -} diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/wire/InvocationErrorTestCase.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/wire/InvocationErrorTestCase.java deleted file mode 100644 index 1d04e18757..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/wire/InvocationErrorTestCase.java +++ /dev/null @@ -1,122 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * Licensed 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.wire; - -import junit.framework.Assert; -import junit.framework.TestCase; -import org.apache.tuscany.core.wire.impl.InvokerInterceptor; -import org.apache.tuscany.core.wire.jdk.JDKInvocationHandler; -import org.apache.tuscany.core.wire.mock.MockHandler; -import org.apache.tuscany.core.wire.mock.MockStaticInvoker; -import org.apache.tuscany.core.wire.mock.MockSyncInterceptor; -import org.apache.tuscany.core.message.impl.MessageFactoryImpl; - -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Method; -import java.lang.reflect.Proxy; -import java.util.Map; - -/** - * Tests handling of exceptions thrown during an wire - * - * @version $Rev: 377006 $ $Date: 2006-02-11 09:41:59 -0800 (Sat, 11 Feb 2006) $ - */ -public class InvocationErrorTestCase extends TestCase { - - private Method checkedMethod; - private Method runtimeMethod; - - public InvocationErrorTestCase() { - super(); - } - - public InvocationErrorTestCase(String arg0) { - super(arg0); - } - - public void setUp() throws Exception { - checkedMethod = TestBean.class.getDeclaredMethod("checkedException", (Class[]) null); - runtimeMethod = TestBean.class.getDeclaredMethod("runtimeException", (Class[]) null); - Assert.assertNotNull(checkedMethod); - Assert.assertNotNull(runtimeMethod); - } - - public void testCheckedException() throws Exception { - Map<Method, InvocationConfiguration> config = new MethodHashMap(); - config.put(checkedMethod, getConfiguration(checkedMethod)); - InvocationHandler handler = new JDKInvocationHandler(new MessageFactoryImpl(), config); - try { - TestBean proxy = (TestBean) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), - new Class[]{TestBean.class}, handler); - proxy.checkedException(); - } catch (TestException e) { - return; - } - Assert.fail(TestException.class.getName() + " should have been thrown"); - } - - public void testRuntimeException() throws Exception { - Map<Method, InvocationConfiguration> config = new MethodHashMap<InvocationConfiguration>(); - config.put(runtimeMethod, getConfiguration(runtimeMethod)); - InvocationHandler handler = new JDKInvocationHandler(new MessageFactoryImpl(), config); - try { - TestBean proxy = (TestBean) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), - new Class[]{TestBean.class}, handler); - proxy.runtimeException(); - } catch (TestRuntimeException e) { - return; - } - Assert.fail(TestException.class.getName() + " should have been thrown"); - } - - private InvocationConfiguration getConfiguration(Method m) { - MockStaticInvoker invoker = new MockStaticInvoker(m, new TestBeanImpl()); - SourceInvocationConfiguration invocationConfiguration=new SourceInvocationConfiguration(m); - invocationConfiguration.addInterceptor(new MockSyncInterceptor()); - invocationConfiguration.addRequestHandler(new MockHandler()); - invocationConfiguration.setTargetInvoker(invoker); - invocationConfiguration.setTargetInterceptor(new InvokerInterceptor()); - invocationConfiguration.build(); - return invocationConfiguration; - } - - public interface TestBean { - - public void checkedException() throws TestException; - - public void runtimeException() throws TestRuntimeException; - - } - - public class TestBeanImpl implements TestBean { - - public void checkedException() throws TestException { - throw new TestException(); - } - - public void runtimeException() throws TestRuntimeException { - throw new TestRuntimeException(); - } - } - - public class TestException extends Exception { - } - - public class TestRuntimeException extends RuntimeException { - } - -} diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKInvocationHandlerTestCase.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKInvocationHandlerTestCase.java deleted file mode 100644 index 28a2da23b5..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKInvocationHandlerTestCase.java +++ /dev/null @@ -1,126 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation - * - * Licensed 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.wire.jdk; - -import junit.framework.Assert; -import junit.framework.TestCase; -import org.apache.tuscany.core.wire.InvocationConfiguration; -import org.apache.tuscany.core.wire.MethodHashMap; -import org.apache.tuscany.core.wire.SourceInvocationConfiguration; -import org.apache.tuscany.core.wire.TargetInvocationConfiguration; -import org.apache.tuscany.core.wire.mock.SimpleTarget; -import org.apache.tuscany.core.wire.mock.SimpleTargetImpl; -import org.apache.tuscany.core.wire.mock.MockStaticInvoker; -import org.apache.tuscany.core.wire.mock.MockHandler; -import org.apache.tuscany.core.wire.mock.MockSyncInterceptor; -import org.apache.tuscany.core.wire.impl.InvokerInterceptor; -import org.apache.tuscany.core.wire.impl.MessageChannelImpl; -import org.apache.tuscany.core.message.impl.MessageFactoryImpl; - -import java.lang.reflect.Method; -import java.util.Map; - -public class JDKInvocationHandlerTestCase extends TestCase { - - private Method hello; - - public JDKInvocationHandlerTestCase() { - super(); - } - - public JDKInvocationHandlerTestCase(String arg0) { - super(arg0); - } - - public void setUp() throws Exception { - hello = SimpleTarget.class.getMethod("hello", String.class); - } - - public void testBasicInvoke() throws Throwable { - Map<Method, InvocationConfiguration> configs = new MethodHashMap<InvocationConfiguration>(); - configs.put(hello, getInvocationHandler(hello)); - JDKInvocationHandler handler = new JDKInvocationHandler(new MessageFactoryImpl(), configs); - Assert.assertEquals("foo", handler.invoke(null, hello, new Object[] { "foo" })); - } - - public void testErrorInvoke() throws Throwable { - Map<Method, InvocationConfiguration> configs = new MethodHashMap<InvocationConfiguration>(); - configs.put(hello, getInvocationHandler(hello)); - JDKInvocationHandler handler = new JDKInvocationHandler(new MessageFactoryImpl(), configs); - try { - Assert.assertEquals("foo", handler.invoke(null, hello, new Object[] {})); - fail("Expected " + IllegalArgumentException.class.getName()); - } catch (IllegalArgumentException e) { - // should throw - } - } - - public void testDirectErrorInvoke() throws Throwable { - SourceInvocationConfiguration source = new SourceInvocationConfiguration(hello); - MockStaticInvoker invoker = new MockStaticInvoker(hello, new SimpleTargetImpl()); - source.setTargetInvoker(invoker); - - Map<Method, InvocationConfiguration> configs = new MethodHashMap<InvocationConfiguration>(); - configs.put(hello, source); - JDKInvocationHandler handler = new JDKInvocationHandler(new MessageFactoryImpl(), configs); - try { - Assert.assertEquals("foo", handler.invoke(null, hello, new Object[] {})); - fail("Expected " + IllegalArgumentException.class.getName()); - } catch (IllegalArgumentException e) { - // should throw - } - } - - public void testDirectInvoke() throws Throwable { - SourceInvocationConfiguration source = new SourceInvocationConfiguration(hello); - MockStaticInvoker invoker = new MockStaticInvoker(hello, new SimpleTargetImpl()); - source.setTargetInvoker(invoker); - - Map<Method, InvocationConfiguration> configs = new MethodHashMap<InvocationConfiguration>(); - configs.put(hello, source); - JDKInvocationHandler handler = new JDKInvocationHandler(new MessageFactoryImpl(), configs); - Assert.assertEquals("foo", handler.invoke(null, hello, new Object[] { "foo" })); - } - - private InvocationConfiguration getInvocationHandler(Method m) { - SourceInvocationConfiguration source = new SourceInvocationConfiguration(m); - MockHandler sourceRequestHandler = new MockHandler(); - MockHandler sourceResponseHandler = new MockHandler(); - MockSyncInterceptor sourceInterceptor = new MockSyncInterceptor(); - source.addRequestHandler(sourceRequestHandler); - source.addResponseHandler(sourceResponseHandler); - source.addInterceptor(sourceInterceptor); - - TargetInvocationConfiguration target = new TargetInvocationConfiguration(m); - MockHandler targetRequestHandler = new MockHandler(); - MockHandler targetResponseHandler = new MockHandler(); - MockSyncInterceptor targetInterceptor = new MockSyncInterceptor(); - target.addRequestHandler(targetRequestHandler); - target.addResponseHandler(targetResponseHandler); - target.addInterceptor(targetInterceptor); - target.addInterceptor(new InvokerInterceptor()); - - // connect the source to the target - source.setTargetRequestChannel(new MessageChannelImpl(target.getRequestHandlers())); - source.setTargetResponseChannel(new MessageChannelImpl(target.getResponseHandlers())); - source.build(); - target.build(); - MockStaticInvoker invoker = new MockStaticInvoker(m, new SimpleTargetImpl()); - source.setTargetInvoker(invoker); - return source; - } -} diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKWireFactoryFactoryTestCase.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKWireFactoryFactoryTestCase.java deleted file mode 100644 index 60f8cf837d..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKWireFactoryFactoryTestCase.java +++ /dev/null @@ -1,83 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * Licensed 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.wire.jdk; - -import junit.framework.Assert; -import junit.framework.TestCase; -import org.apache.tuscany.core.context.QualifiedName; -import org.apache.tuscany.core.wire.MethodHashMap; -import org.apache.tuscany.core.wire.WireSourceConfiguration; -import org.apache.tuscany.core.wire.SourceInvocationConfiguration; -import org.apache.tuscany.core.wire.TargetInvocationConfiguration; -import org.apache.tuscany.core.wire.WireTargetConfiguration; -import org.apache.tuscany.core.wire.impl.InvokerInterceptor; -import org.apache.tuscany.core.wire.mock.MockStaticInvoker; -import org.apache.tuscany.core.wire.mock.MockSyncInterceptor; -import org.apache.tuscany.core.wire.mock.SimpleTarget; -import org.apache.tuscany.core.wire.mock.SimpleTargetImpl; -import org.apache.tuscany.core.message.impl.MessageFactoryImpl; - -import java.lang.reflect.Method; -import java.util.Map; - -public class JDKWireFactoryFactoryTestCase extends TestCase { - - private Method hello; - - public JDKWireFactoryFactoryTestCase(String arg0) { - super(arg0); - } - - public void setUp() throws Exception { - hello = SimpleTarget.class.getMethod("hello", String.class); - } - - public void testSourceWireFactory() throws Exception { - SourceInvocationConfiguration source = new SourceInvocationConfiguration(hello); - MockSyncInterceptor sourceInterceptor = new MockSyncInterceptor(); - source.addInterceptor(sourceInterceptor); - source.setTargetInterceptor(new InvokerInterceptor()); - source.setTargetInvoker(new MockStaticInvoker(hello, new SimpleTargetImpl())); - source.build(); - Map<Method, SourceInvocationConfiguration> configs = new MethodHashMap<SourceInvocationConfiguration>(); - configs.put(hello, source); - WireSourceConfiguration config = new WireSourceConfiguration("foo",new QualifiedName("foo"), configs, Thread.currentThread() - .getContextClassLoader(), new MessageFactoryImpl()); - JDKSourceWireFactory factory = new JDKSourceWireFactory(); - factory.setConfiguration(config); - factory.setBusinessInterface(SimpleTarget.class); - factory.initialize(); - SimpleTarget instance = (SimpleTarget) factory.createProxy(); - Assert.assertEquals("foo",instance.hello("foo")); - } - - public void testTargetWireFactory() throws Exception { - TargetInvocationConfiguration source = new TargetInvocationConfiguration(hello); - MockSyncInterceptor sourceInterceptor = new MockSyncInterceptor(); - source.addInterceptor(sourceInterceptor); - source.addInterceptor(new InvokerInterceptor()); - source.setTargetInvoker(new MockStaticInvoker(hello, new SimpleTargetImpl())); - source.build(); - Map<Method, TargetInvocationConfiguration> configs = new MethodHashMap<TargetInvocationConfiguration>(); - configs.put(hello, source); - WireTargetConfiguration config = new WireTargetConfiguration(new QualifiedName("foo"), configs, Thread.currentThread() - .getContextClassLoader(), new MessageFactoryImpl()); - JDKTargetWireFactory factory = new JDKTargetWireFactory(); - factory.setConfiguration(config); - factory.setBusinessInterface(SimpleTarget.class); - factory.initialize(); - SimpleTarget instance = (SimpleTarget) factory.createProxy(); - Assert.assertEquals("foo",instance.hello("foo")); - } -} diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/wire/mock/MockHandler.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/wire/mock/MockHandler.java deleted file mode 100644 index 9def6b5b0e..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/wire/mock/MockHandler.java +++ /dev/null @@ -1,38 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation - * - * Licensed 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.wire.mock; - -import org.apache.tuscany.core.wire.MessageHandler; -import org.apache.tuscany.core.message.Message; - -/** - * - */ -public class MockHandler implements MessageHandler { - - private int count =0; - - public boolean processMessage(Message message) { - //System.out.println("Invoking handler"); - count++; - return true; - } - - public int getCount(){ - return count; - } -} diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/wire/mock/MockScopeContext.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/wire/mock/MockScopeContext.java deleted file mode 100644 index 915885549a..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/wire/mock/MockScopeContext.java +++ /dev/null @@ -1,131 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * Licensed 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.wire.mock; - -import org.apache.tuscany.core.builder.ContextFactory; -import org.apache.tuscany.core.context.ScopeContext; -import org.apache.tuscany.core.context.RuntimeEventListener; -import org.apache.tuscany.core.context.ContextRuntimeException; -import org.apache.tuscany.core.context.AtomicContext; -import org.apache.tuscany.core.context.ScopeRuntimeException; -import org.apache.tuscany.core.context.QualifiedName; -import org.apache.tuscany.core.context.Context; -import org.apache.tuscany.core.context.EventFilter; -import org.apache.tuscany.core.context.event.Event; -import org.apache.tuscany.model.assembly.AtomicComponent; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class MockScopeContext implements ScopeContext { - - Map<String, Object> components; - - public MockScopeContext() { - components = new HashMap<String, Object>(); - components.put("foo", new SimpleTargetImpl()); - components.put("bar", new SimpleTargetImpl()); - } - - public MockScopeContext(Map<String,Object> instances) { - components = instances; - } - - - public void start() { - } - - public void stop() { - } - - public void publish(Event object) { - //To change body of implemented methods use File | Settings | File Templates. - } - - public void addListener(RuntimeEventListener listener) throws ContextRuntimeException { - } - - public void addListener(EventFilter filter, RuntimeEventListener listener) { - //To change body of implemented methods use File | Settings | File Templates. - } - - public void removeListener(RuntimeEventListener listener) throws ContextRuntimeException { - } - - public String getName() { - return "Mock Scope Container"; - } - - public boolean isCacheable() { - return false; - } - - public int[] getEventTypes() { - return null; - } - - public AtomicContext getContext(String name) { - return null; - } - - public Object getInstance(QualifiedName name) throws ScopeRuntimeException { - return components.get(name.getPartName()); - } - - public AtomicContext getContextByKey(String name, Object key) { - return null; - } - - public void setComponent(AtomicComponent component) throws ScopeRuntimeException { - } - - public void removeContext(String name) throws ScopeRuntimeException { - } - - public void removeContextByKey(String name, Object key) throws ScopeRuntimeException { - } - - public AtomicComponent[] getComponents() { - return null; - } - - - public void registerFactories(List<ContextFactory<Context>> configurations) { - } - - public void registerFactory(ContextFactory<Context> configuration) { - } - - public int getLifecycleState(){ - return RUNNING; - } - - - public void setLifecycleState(int state) { - } - - - public void setName(String name) { - } - - - public void onEvent(Event event) { - //To change body of implemented methods use File | Settings | File Templates. - } -} - diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/wire/mock/MockStaticInvoker.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/wire/mock/MockStaticInvoker.java deleted file mode 100644 index 66e8579cb4..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/wire/mock/MockStaticInvoker.java +++ /dev/null @@ -1,86 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation - * - * Licensed 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.wire.mock; - -import org.apache.tuscany.core.wire.Interceptor; -import org.apache.tuscany.core.wire.InvocationRuntimeException; -import org.apache.tuscany.core.wire.TargetInvoker; -import org.apache.tuscany.core.message.Message; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - -/** - * Caches component instances that do not need to be resolved for every wire, e.g. an wire originating from - * a lesser scope intended for a target with a wider scope - * - * @version $Rev: 377006 $ $Date: 2006-02-11 09:41:59 -0800 (Sat, 11 Feb 2006) $ - */ -public class MockStaticInvoker implements TargetInvoker { - - private Object instance; - - private Method operation; - - public MockStaticInvoker(Method operation, Object instance) { - this.operation = operation; - this.instance = instance; - } - - public boolean isCacheable() { - return true; - } - - public Object invokeTarget(Object payload) throws InvocationTargetException { - try { - if (payload != null && !payload.getClass().isArray()) { - return operation.invoke(instance, payload); - } else { - return operation.invoke(instance, (Object[]) payload); - } - } catch (IllegalAccessException e) { - throw new InvocationRuntimeException(e); - } - } - - public Message invoke(Message msg) { - try { - Object resp = invokeTarget(msg.getBody()); - msg.setBody(resp); - } catch (InvocationTargetException e) { - msg.setBody(e.getCause()); - } catch (Throwable e) { - msg.setBody(e); - } - return msg; - } - - public void setNext(Interceptor next) { - throw new IllegalStateException("This interceptor must be the last interceptor in an interceptor chain"); - } - - public Object clone() throws CloneNotSupportedException { - try { - MockStaticInvoker invoker = (MockStaticInvoker) super.clone(); - invoker.instance = this.instance; - invoker.operation = this.operation; - return invoker; - } catch (CloneNotSupportedException e) { - return null; // will not happen - } - } -} diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/wire/mock/MockSyncInterceptor.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/wire/mock/MockSyncInterceptor.java deleted file mode 100644 index a64caed8eb..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/wire/mock/MockSyncInterceptor.java +++ /dev/null @@ -1,45 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * Licensed 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.wire.mock; - -import org.apache.tuscany.core.wire.Interceptor; -import org.apache.tuscany.core.message.Message; - -public class MockSyncInterceptor implements Interceptor { - - private int count; - - private Interceptor next; - - public MockSyncInterceptor() { - } - - public Message invoke(Message msg) { - ++count; - //System.out.println("Invoking interceptor"); - return next.invoke(msg); - } - - public int getCount() { - return count; - } - - public void setNext(Interceptor next) { - this.next=next; - } -} - diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/wire/mock/SimpleSource.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/wire/mock/SimpleSource.java deleted file mode 100644 index 8e8af9ec18..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/wire/mock/SimpleSource.java +++ /dev/null @@ -1,25 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * Licensed 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.wire.mock; - -public interface SimpleSource { - - public void invokeHello() throws Exception; - - public void invokeGoodbye() throws Exception; -} - diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/wire/mock/SimpleSourceImpl.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/wire/mock/SimpleSourceImpl.java deleted file mode 100644 index 900fa9c324..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/wire/mock/SimpleSourceImpl.java +++ /dev/null @@ -1,36 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * Licensed 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.wire.mock; - -public class SimpleSourceImpl implements SimpleSource { - - private SimpleTarget proxy; - - public SimpleSourceImpl(SimpleTarget proxy) { - this.proxy = proxy; - } - - public void invokeHello() throws Exception { - proxy.hello("hello"); - } - - public void invokeGoodbye() throws Exception { - proxy.goodbye("hello"); - } - -} - diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/wire/mock/SimpleTarget.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/wire/mock/SimpleTarget.java deleted file mode 100644 index d63d3a0565..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/wire/mock/SimpleTarget.java +++ /dev/null @@ -1,28 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * Licensed 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.wire.mock; - -public interface SimpleTarget { - - public String hello(String message) throws Exception; - - public String goodbye(String message) throws Exception; - - public String echo(String message) throws Exception; - -} - diff --git a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/wire/mock/SimpleTargetImpl.java b/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/wire/mock/SimpleTargetImpl.java deleted file mode 100644 index 1b6fe93ac8..0000000000 --- a/branches/java-post-M1/sca/core/src/test/java/org/apache/tuscany/core/wire/mock/SimpleTargetImpl.java +++ /dev/null @@ -1,39 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * Licensed 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.wire.mock; - -public class SimpleTargetImpl implements SimpleTarget { - - public SimpleTargetImpl() { - super(); - } - - public String hello(String message) throws Exception { - return message; - } - - public String goodbye(String message) throws Exception { - return message; - } - - public String echo(String message) throws Exception { - return message; - } - - -} - |