You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by an...@apache.org on 2006/10/25 14:24:29 UTC

svn commit: r467621 [1/2] - in /incubator/tuscany/sandbox/ant/container.script: ./ src/main/java/org/apache/tuscany/container/script/ src/main/java/org/apache/tuscany/container/script/helper/ src/test/java/org/apache/tuscany/container/script/helper/ sr...

Author: antelder
Date: Wed Oct 25 05:24:28 2006
New Revision: 467621

URL: http://svn.apache.org/viewvc?view=rev&rev=467621
Log:
Remove using the easy container 

Added:
    incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/helper/
    incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/helper/AsyncInvoker.java
    incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/helper/AsyncMonitor.java
    incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/helper/EasyComponent.java
    incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/helper/EasyComponentBuilder.java
    incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/helper/EasyComponentType.java
    incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/helper/EasyComponentTypeLoader.java
    incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/helper/EasyImplementation.java
    incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/helper/EasyImplementationLoader.java
    incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/helper/EasyInstance.java
    incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/helper/EasyInstanceFactory.java
    incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/helper/EasyInvoker.java
    incubator/tuscany/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/
    incubator/tuscany/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/AsyncInvokerTestCase.java
    incubator/tuscany/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/EasyComponentBuilderTestCase.java
    incubator/tuscany/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/EasyComponentTestCase.java
    incubator/tuscany/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/EasyComponentTypeLoaderTestCase.java
    incubator/tuscany/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/EasyComponentTypeTestCase.java
    incubator/tuscany/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/EasyImplementationLoaderTestCase.java
    incubator/tuscany/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/EasyImplementationTestCase.java
    incubator/tuscany/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/EasyInstanceFactoryTestCase.java
    incubator/tuscany/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/EasyInvokerTestCase.java
    incubator/tuscany/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/mock/
    incubator/tuscany/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/mock/AsyncTarget.java
    incubator/tuscany/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/mock/MockInstanceFactory.java
    incubator/tuscany/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/jsr223/
    incubator/tuscany/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/jsr223/JSR223BSFEngineTestCase.java
    incubator/tuscany/sandbox/ant/container.script/src/test/resources/org/apache/tuscany/container/script/helper/
    incubator/tuscany/sandbox/ant/container.script/src/test/resources/org/apache/tuscany/container/script/helper/foo.componentType
    incubator/tuscany/sandbox/ant/container.script/src/test/resources/org/apache/tuscany/container/script/helper/foo.mock
Modified:
    incubator/tuscany/sandbox/ant/container.script/pom.xml
    incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/ScriptImplementationLoader.java
    incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/ScriptInstance.java
    incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/ScriptInstanceFactory.java

Modified: incubator/tuscany/sandbox/ant/container.script/pom.xml
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/ant/container.script/pom.xml?view=diff&rev=467621&r1=467620&r2=467621
==============================================================================
--- incubator/tuscany/sandbox/ant/container.script/pom.xml (original)
+++ incubator/tuscany/sandbox/ant/container.script/pom.xml Wed Oct 25 05:24:28 2006
@@ -33,8 +33,8 @@
     <dependencies>
 
         <dependency>
-            <groupId>org.apache.tuscany.sca.services.containers</groupId>
-            <artifactId>easy-container</artifactId>
+            <groupId>org.apache.tuscany.sca.kernel</groupId>
+            <artifactId>tuscany-spi</artifactId>
             <version>${sca.version}</version>
             <scope>compile</scope>
         </dependency>
@@ -47,6 +47,13 @@
         </dependency>
 
         <dependency>
+            <groupId>bsf</groupId>
+            <artifactId>bsf3</artifactId>
+            <version>3.0-SNAPSHOT</version>
+            <scope>compile</scope>
+        </dependency>
+
+        <dependency>
             <groupId>commons-logging</groupId>
             <artifactId>commons-logging</artifactId>
             <version>1.1</version>
@@ -57,6 +64,13 @@
             <groupId>org.apache.tuscany.sca</groupId>
             <artifactId>test</artifactId>
             <version>${sca.version}</version>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>rhino</groupId>
+            <artifactId>js</artifactId>
+            <version>1.6R2</version>
             <scope>test</scope>
         </dependency>
 

Modified: incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/ScriptImplementationLoader.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/ScriptImplementationLoader.java?view=diff&rev=467621&r1=467620&r2=467621
==============================================================================
--- incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/ScriptImplementationLoader.java (original)
+++ incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/ScriptImplementationLoader.java Wed Oct 25 05:24:28 2006
@@ -24,8 +24,8 @@
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
 
-import org.apache.tuscany.container.easy.EasyImplementation;
-import org.apache.tuscany.container.easy.EasyImplementationLoader;
+import org.apache.tuscany.container.script.helper.EasyImplementation;
+import org.apache.tuscany.container.script.helper.EasyImplementationLoader;
 import org.apache.tuscany.spi.annotation.Autowire;
 import org.apache.tuscany.spi.component.CompositeComponent;
 import org.apache.tuscany.spi.deployer.DeploymentContext;

Modified: incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/ScriptInstance.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/ScriptInstance.java?view=diff&rev=467621&r1=467620&r2=467621
==============================================================================
--- incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/ScriptInstance.java (original)
+++ incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/ScriptInstance.java Wed Oct 25 05:24:28 2006
@@ -21,7 +21,7 @@
 import java.lang.reflect.InvocationTargetException;
 
 import org.apache.bsf.BSFEngine;
-import org.apache.tuscany.container.easy.EasyInstance;
+import org.apache.tuscany.container.script.helper.EasyInstance;
 
 /**
  * An invokable instance of a script

Modified: incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/ScriptInstanceFactory.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/ScriptInstanceFactory.java?view=diff&rev=467621&r1=467620&r2=467621
==============================================================================
--- incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/ScriptInstanceFactory.java (original)
+++ incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/ScriptInstanceFactory.java Wed Oct 25 05:24:28 2006
@@ -24,7 +24,7 @@
 import org.apache.bsf.BSFEngine;
 import org.apache.bsf.BSFException;
 import org.apache.bsf.BSFManager;
-import org.apache.tuscany.container.easy.EasyInstanceFactory;
+import org.apache.tuscany.container.script.helper.EasyInstanceFactory;
 import org.apache.tuscany.spi.ObjectCreationException;
 
 /**

Added: incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/helper/AsyncInvoker.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/helper/AsyncInvoker.java?view=auto&rev=467621
==============================================================================
--- incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/helper/AsyncInvoker.java (added)
+++ incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/helper/AsyncInvoker.java Wed Oct 25 05:24:28 2006
@@ -0,0 +1,210 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.tuscany.container.script.helper;
+
+import java.lang.reflect.InvocationTargetException;
+
+import org.apache.tuscany.spi.component.TargetException;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.services.work.WorkScheduler;
+import org.apache.tuscany.spi.wire.InboundWire;
+import org.apache.tuscany.spi.wire.InvocationRuntimeException;
+import org.apache.tuscany.spi.wire.Message;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+import org.osoa.sca.CompositeContext;
+import org.osoa.sca.CurrentCompositeContext;
+import org.osoa.sca.SCA;
+import org.osoa.sca.ServiceRuntimeException;
+
+/**
+ * Responsible for performing a non-blocking dispatch on a component implementation instance
+ * 
+ * TODO: Pretty much a direct copy of what the groovy container does for async
+ */
+public class AsyncInvoker extends EasyInvoker {
+
+    private static final ContextBinder BINDER = new ContextBinder();
+    private static final Message RESPONSE = new AsyncInvoker.ImmutableMessage();
+
+    private InboundWire wire;
+    private WorkScheduler workScheduler;
+    private AsyncMonitor monitor;
+    private WorkContext workContext;
+    private Object target;
+    private Object messageId;
+
+    /**
+     * Creates a new invoker
+     *
+     * @param operation     the operation the invoker is associated with
+     * @param wire
+     * @param component     the target component
+     * @param workScheduler the work scheduler to run the invocation
+     * @param monitor       the monitor to pass events to
+     * @param workContext
+     */
+    public AsyncInvoker(String operation,
+                              InboundWire wire,
+                              EasyComponent component,
+                              WorkScheduler workScheduler,
+                              AsyncMonitor monitor,
+                              WorkContext workContext) {
+        super(operation, component);
+        this.wire = wire;
+        this.workScheduler = workScheduler;
+        this.monitor = monitor;
+        this.workContext = workContext;
+    }
+
+    // Override invocation methods to defer invocation to work item
+    // Both methods return null to indicate asynchrony; result will
+    // be conveyed by callback
+    @Override
+    public Object invokeTarget(final Object payload) throws InvocationTargetException {
+        final CompositeContext currentContext = CurrentCompositeContext.getContext();
+        // Schedule the invocation of the next interceptor in a new Work instance
+        try {
+            workScheduler.scheduleWork(new Runnable() {
+                private Object currentMessageId = messageId;
+
+                public void run() {
+                    workContext.setCurrentMessageId(null);
+                    workContext.setCurrentCorrelationId(currentMessageId);
+                    CompositeContext oldContext = CurrentCompositeContext.getContext();
+                    try {
+                        BINDER.setContext(currentContext);
+                        // REVIEW response must be null for one-way and non-null for callback
+                        AsyncInvoker.super.invokeTarget(payload);
+                    } catch (Exception e) {
+                        // REVIEW uncomment when it is available
+                        // monitor.executionError(e);
+                        e.printStackTrace();
+                    } finally {
+                        BINDER.setContext(oldContext);
+                    }
+                }
+            });
+        } catch (Exception e) {
+            throw new ServiceRuntimeException(e);
+        }
+        return RESPONSE;
+    }
+
+    public Message invoke(Message msg) throws InvocationRuntimeException {
+        // can't just call overriden invoke because it would bypass async
+        try {
+            messageId = msg.getMessageId();
+            wire.addMapping(messageId, msg.getFromAddress());
+            return (Message) invokeTarget(msg.getBody());
+        } catch (Throwable e) {
+            // FIXME need to log exceptions
+            e.printStackTrace();
+            return null;
+        }
+    }
+
+    public AsyncInvoker clone() {
+        AsyncInvoker invoker = (AsyncInvoker) super.clone();
+        invoker.workScheduler = this.workScheduler;
+        invoker.monitor = this.monitor;
+        return invoker;
+    }
+
+    /**
+     * Resolves the target service instance or returns a cached one
+     */
+    protected Object getInstance() throws TargetException {
+        if (!isCacheable()) {
+            return component.getTargetInstance();
+        } else {
+            if (target == null) {
+                target = component.getTargetInstance();
+            }
+            return target;
+        }
+    }
+
+    protected static class ContextBinder extends SCA {
+        public void setContext(CompositeContext context) {
+            setCompositeContext(context);
+        }
+
+        public void start() {
+            throw new AssertionError();
+        }
+
+        public void stop() {
+            throw new AssertionError();
+        }
+    }
+
+    /**
+     * A dummy message passed back on an invocation
+     */
+    protected static class ImmutableMessage implements Message {
+
+        public Object getBody() {
+            return null;
+        }
+
+        public void setBody(Object body) {
+            throw new UnsupportedOperationException();
+        }
+
+        public void setTargetInvoker(TargetInvoker invoker) {
+            throw new UnsupportedOperationException();
+        }
+
+        public TargetInvoker getTargetInvoker() {
+            return null;
+        }
+
+        public Object getFromAddress() {
+            return null;
+        }
+
+        public void setFromAddress(Object fromAddress) {
+            throw new UnsupportedOperationException();
+        }
+
+        public Object getMessageId() {
+            return null;
+        }
+
+        public void setMessageId(Object messageId) {
+            throw new UnsupportedOperationException();
+        }
+
+        public Object getCorrelationId() {
+            return null;
+        }
+
+        public void setCorrelationId(Object correlationId) {
+            throw new UnsupportedOperationException();
+        }
+
+        public boolean isFault() {
+            return false;
+        }
+
+        public void setBodyWithFault(Object fault) {
+            throw new UnsupportedOperationException();
+        }
+    }
+}

Added: incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/helper/AsyncMonitor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/helper/AsyncMonitor.java?view=auto&rev=467621
==============================================================================
--- incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/helper/AsyncMonitor.java (added)
+++ incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/helper/AsyncMonitor.java Wed Oct 25 05:24:28 2006
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.tuscany.container.script.helper;
+
+/**
+ * A monitor used to log events during non-blocking invocations
+ */
+public interface AsyncMonitor {
+
+    /**
+     * Logs an exception thrown during an invocation
+     */
+    void executionError(Exception e);
+
+}

Added: incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/helper/EasyComponent.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/helper/EasyComponent.java?view=auto&rev=467621
==============================================================================
--- incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/helper/EasyComponent.java (added)
+++ incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/helper/EasyComponent.java Wed Oct 25 05:24:28 2006
@@ -0,0 +1,117 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.tuscany.container.script.helper;
+
+import static org.apache.tuscany.spi.idl.java.JavaIDLUtils.findMethod;
+
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.tuscany.spi.ObjectCreationException;
+import org.apache.tuscany.spi.component.CompositeComponent;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.TargetException;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.extension.AtomicComponentExtension;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.services.work.WorkScheduler;
+import org.apache.tuscany.spi.wire.InboundWire;
+import org.apache.tuscany.spi.wire.OutboundWire;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+import org.apache.tuscany.spi.wire.WireService;
+
+/**
+ * A component implementation for script languages.
+ */
+public class EasyComponent extends AtomicComponentExtension {
+
+    private final List<Class<?>> services;
+
+    private final Map<String, Object> properties;
+
+    protected EasyInstanceFactory instanceFactory;
+
+    public EasyComponent(String name, EasyInstanceFactory instanceFactory, Map<String, Object> properties, List<Class<?>> services, CompositeComponent parent, ScopeContainer scopeContainer,
+            WireService wireService, WorkContext workContext, WorkScheduler workScheduler) {
+
+        super(name, parent, scopeContainer, wireService, workContext, workScheduler, 0);
+
+        this.instanceFactory = instanceFactory;
+        this.services = services;
+        this.scope = scopeContainer.getScope();
+        this.properties = properties;
+    }
+
+    @SuppressWarnings("unchecked")
+    public Object createInstance() throws ObjectCreationException {
+
+        Map<String, Object> context = new HashMap<String, Object>(getProperties());
+
+        for (List<OutboundWire> referenceWires : getOutboundWires().values()) {
+            for (OutboundWire wire : referenceWires) {
+                Object wireProxy = wireService.createProxy(wire);
+                context.put(wire.getReferenceName(), wireProxy);
+            }
+        }
+
+        return instanceFactory.createInstance(services, context);
+    }
+
+    public TargetInvoker createTargetInvoker(String targetName, Operation operation) {
+        Method[] methods = operation.getServiceContract().getInterfaceClass().getMethods();
+        Method method = findMethod(operation, methods);
+        return new EasyInvoker(method.getName(), this);
+    }
+
+    public TargetInvoker createAsyncTargetInvoker(InboundWire wire, Operation operation) {
+        return new AsyncInvoker(operation.getName(), wire, this, workScheduler, null, workContext);
+    }
+
+    // TODO: move all the following up to AtomicComponentExtension?
+
+    public List<Class<?>> getServiceInterfaces() {
+        return services;
+    }
+
+    public Map<String, Object> getProperties() {
+        return properties;
+    }
+
+    public Object getTargetInstance() throws TargetException {
+        return scopeContainer.getInstance(this);
+    }
+
+    public Object getServiceInstance() throws TargetException {
+        return getServiceInstance(null);
+    }
+
+    @SuppressWarnings("unchecked")
+    public Object getServiceInstance(String service) throws TargetException {
+        InboundWire wire = getInboundWire(service);
+        if (wire == null) {
+            TargetException e = new TargetException("ServiceDefinition not found"); // TODO better error message
+            e.setIdentifier(service);
+            throw e;
+        }
+        return wireService.createProxy(wire);
+    }
+
+}

Added: incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/helper/EasyComponentBuilder.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/helper/EasyComponentBuilder.java?view=auto&rev=467621
==============================================================================
--- incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/helper/EasyComponentBuilder.java (added)
+++ incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/helper/EasyComponentBuilder.java Wed Oct 25 05:24:28 2006
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.tuscany.container.script.helper;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.tuscany.spi.builder.BuilderConfigException;
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.component.CompositeComponent;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.extension.ComponentBuilderExtension;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.PropertyValue;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+
+/**
+ * Extension point for creating {@link ScriptComponent}s from an assembly configuration
+ */
+public class EasyComponentBuilder extends ComponentBuilderExtension<EasyImplementation> {
+
+    public EasyComponentBuilder() {
+    }
+
+    protected Class<EasyImplementation> getImplementationType() {
+        return EasyImplementation.class;
+    }
+
+    @SuppressWarnings("unchecked")
+    public Component build(CompositeComponent parent, ComponentDefinition<EasyImplementation> componentDefinition,
+            DeploymentContext deploymentContext) throws BuilderConfigException {
+
+        String name = componentDefinition.getName();
+        EasyImplementation implementation = componentDefinition.getImplementation();
+        EasyComponentType componentType = implementation.getComponentType();
+
+        // get list of services provided by this component
+        Collection<ServiceDefinition> collection = componentType.getServices().values();
+        List<Class<?>> services = new ArrayList<Class<?>>(collection.size());
+        for (ServiceDefinition serviceDefinition : collection) {
+            services.add(serviceDefinition.getServiceContract().getInterfaceClass());
+        }
+
+        // get the properties for the component
+        Map<String, Object> properties = new HashMap<String, Object>();
+        for (PropertyValue propertyValue : componentDefinition.getPropertyValues().values()) {
+            properties.put(propertyValue.getName(), propertyValue.getValueFactory().getInstance());
+        }
+
+        // TODO: have ComponentBuilderExtension pass ScopeContainer in on build method?
+        ScopeContainer scopeContainer;
+        Scope scope = componentType.getLifecycleScope();
+        if (Scope.MODULE == scope) {
+            scopeContainer = deploymentContext.getModuleScope();
+        } else {
+            scopeContainer = scopeRegistry.getScopeContainer(scope);
+        }
+
+        return new EasyComponent(name, implementation.getScriptInstanceFactory(), properties, services, parent, scopeContainer, wireService, workContext, workScheduler);
+    }
+
+}

Added: incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/helper/EasyComponentType.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/helper/EasyComponentType.java?view=auto&rev=467621
==============================================================================
--- incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/helper/EasyComponentType.java (added)
+++ incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/helper/EasyComponentType.java Wed Oct 25 05:24:28 2006
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.tuscany.container.script.helper;
+
+import org.apache.tuscany.spi.model.ComponentType;
+import org.apache.tuscany.spi.model.Property;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+
+/**
+ * A componentType for script components
+ * TODO: need lifecycle methods init/destroy 
+ * TODO: really need a generic componentType that supports scope and lifecycle 
+ */
+public class EasyComponentType extends ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>> {
+
+    private Scope lifecycleScope = Scope.MODULE;
+
+    public EasyComponentType() {
+    }
+
+    @SuppressWarnings("unchecked")
+    public EasyComponentType(ComponentType ct) {
+        // TODO: A bit hacky but this is so the generic .componentType XML side file can be used for now
+        setInitLevel(ct.getInitLevel());
+        for (Object property : ct.getProperties().values()) {
+            add((Property) property);
+        }
+        for (Object reference : ct.getReferences().values()) {
+            add((ReferenceDefinition) reference);
+        }
+        for (Object service : ct.getServices().values()) {
+            add((ServiceDefinition) service);
+        }
+    }
+
+    public Scope getLifecycleScope() {
+        return lifecycleScope;
+    }
+
+    public void setLifecycleScope(Scope lifecycleScope) {
+        this.lifecycleScope = lifecycleScope;
+    }
+
+}

Added: incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/helper/EasyComponentTypeLoader.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/helper/EasyComponentTypeLoader.java?view=auto&rev=467621
==============================================================================
--- incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/helper/EasyComponentTypeLoader.java (added)
+++ incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/helper/EasyComponentTypeLoader.java Wed Oct 25 05:24:28 2006
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.tuscany.container.script.helper;
+
+import java.net.URL;
+
+import org.apache.tuscany.spi.component.CompositeComponent;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.extension.ComponentTypeLoaderExtension;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.model.ComponentType;
+
+/**
+ * ComponentType loader for script components
+ */
+public class EasyComponentTypeLoader extends ComponentTypeLoaderExtension<EasyImplementation> {
+
+    public EasyComponentTypeLoader() {
+    }
+
+    @Override
+    protected Class<EasyImplementation> getImplementationClass() {
+        return EasyImplementation.class;
+    }
+
+    // TODO: must be possible to move all the following up in to ComponentTypeLoaderExtension
+
+    public void load(CompositeComponent parent, EasyImplementation implementation, DeploymentContext deploymentContext) throws LoaderException {
+        String sideFile = getSideFileName(implementation.getResourceName());
+        URL resource = implementation.getScriptInstanceFactory().getClassLoader().getResource(sideFile);
+        EasyComponentType componentType;
+        if (resource == null) {
+            throw new IllegalArgumentException("missing .componentType side file: " + sideFile);
+            // TODO: or else implement introspection
+        } else {
+            componentType = loadFromSidefile(resource, deploymentContext);
+        }
+        implementation.setComponentType(componentType);
+    }
+
+    protected EasyComponentType loadFromSidefile(URL url, DeploymentContext deploymentContext) throws LoaderException {
+        ComponentType ct = loaderRegistry.load(null, null, url, ComponentType.class, deploymentContext);
+        EasyComponentType scriptComponentType = new EasyComponentType(ct);
+        return scriptComponentType;
+    }
+
+    protected String getSideFileName(String resourceName) {
+        int lastDot = resourceName.lastIndexOf('.');
+        if (lastDot != -1) {
+            resourceName = resourceName.substring(0, lastDot);
+        }
+        return resourceName + ".componentType";
+    }
+
+}

Added: incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/helper/EasyImplementation.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/helper/EasyImplementation.java?view=auto&rev=467621
==============================================================================
--- incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/helper/EasyImplementation.java (added)
+++ incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/helper/EasyImplementation.java Wed Oct 25 05:24:28 2006
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.tuscany.container.script.helper;
+
+import org.apache.tuscany.spi.model.AtomicImplementation;
+
+/**
+ * Model object for a script implementation.
+ */
+public class EasyImplementation extends AtomicImplementation<EasyComponentType> {
+
+    private String resourceName;
+    
+    private EasyInstanceFactory scriptInstanceFactory;
+
+    public String getResourceName() {
+        return resourceName;
+    }
+    
+    public void setResourceName(String resourceName) {
+        this.resourceName = resourceName;
+    }
+    
+    public EasyInstanceFactory getScriptInstanceFactory() {
+        return scriptInstanceFactory;
+    }
+
+    public void setScriptInstanceFactory(EasyInstanceFactory scriptInstanceFactory) {
+        this.scriptInstanceFactory = scriptInstanceFactory;
+    }
+}

Added: incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/helper/EasyImplementationLoader.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/helper/EasyImplementationLoader.java?view=auto&rev=467621
==============================================================================
--- incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/helper/EasyImplementationLoader.java (added)
+++ incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/helper/EasyImplementationLoader.java Wed Oct 25 05:24:28 2006
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.tuscany.container.script.helper;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.net.URL;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.spi.annotation.Autowire;
+import org.apache.tuscany.spi.extension.LoaderExtension;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.loader.MissingResourceException;
+import org.osoa.sca.annotations.Constructor;
+
+/**
+ * Loader for handling implementation.script elements.
+ * 
+ * <implementation.script script="path/foo.py" class="myclass">
+ * 
+ */
+public abstract class EasyImplementationLoader extends LoaderExtension<EasyImplementation> {
+
+    @Constructor( { "registry" })
+    public EasyImplementationLoader(@Autowire LoaderRegistry registry) {
+        super(registry);
+    }
+
+    public abstract QName getXMLType();
+
+    protected String loadSource(ClassLoader cl, String resource) throws LoaderException {
+        URL url = cl.getResource(resource);
+        if (url == null) {
+            throw new MissingResourceException(resource);
+        }
+        InputStream is;
+        try {
+            is = url.openStream();
+        } catch (IOException e) {
+            MissingResourceException mre = new MissingResourceException(resource, e);
+            mre.setIdentifier(resource);
+            throw mre;
+        }
+        try {
+            Reader reader = new InputStreamReader(is, "UTF-8");
+            char[] buffer = new char[1024];
+            StringBuilder source = new StringBuilder();
+            int count;
+            while ((count = reader.read(buffer)) > 0) {
+                source.append(buffer, 0, count);
+            }
+            return source.toString();
+        } catch (IOException e) {
+            LoaderException le = new LoaderException(e);
+            le.setIdentifier(resource);
+            throw le;
+        } finally {
+            try {
+                is.close();
+            } catch (IOException e) {
+                // ignore
+            }
+        }
+    }
+}

Added: incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/helper/EasyInstance.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/helper/EasyInstance.java?view=auto&rev=467621
==============================================================================
--- incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/helper/EasyInstance.java (added)
+++ incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/helper/EasyInstance.java Wed Oct 25 05:24:28 2006
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.tuscany.container.script.helper;
+
+import java.lang.reflect.InvocationTargetException;
+
+/**
+ * An invokable instance of a script
+ * 
+ * Basically just a wrapper around a BSF engine with an optional script class object.
+ */
+public interface EasyInstance {
+
+    public Object invokeTarget(String operationName, Object[] args) throws InvocationTargetException;
+}

Added: incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/helper/EasyInstanceFactory.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/helper/EasyInstanceFactory.java?view=auto&rev=467621
==============================================================================
--- incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/helper/EasyInstanceFactory.java (added)
+++ incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/helper/EasyInstanceFactory.java Wed Oct 25 05:24:28 2006
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.tuscany.container.script.helper;
+
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * ScriptInstanceFactory creates ScriptInstances for a script
+ */
+public abstract class EasyInstanceFactory<T extends EasyInstance> {
+
+    protected String resourceName;
+
+    protected ClassLoader classLoader;
+
+    public EasyInstanceFactory(String resourceName, ClassLoader classLoader) {
+        this.resourceName = resourceName;
+        this.classLoader = classLoader;
+    }
+
+    /**
+     * Create a new invokeable instance of the script
+     * @param services 
+     * 
+     * @param context
+     *            objects to add to scope of the script instance
+     * @return a RhinoScriptInstance
+     * TODO: services should be on the constructor not on this method
+     */
+    public abstract T createInstance(List<Class> services, Map<String, Object> context);
+
+    public String getResourceName() {
+        return resourceName;
+    }
+
+    public ClassLoader getClassLoader() {
+        return classLoader;
+    }
+
+    protected Map<String, Class> getResponseClasses(List<Class> services) {
+        Map<String, Class> responseClasses = new HashMap<String, Class>();
+        if (services != null) {
+            for (Class s : services) {
+                for (Method m : s.getMethods()) {
+                    responseClasses.put(m.getName(), m.getReturnType());
+                }
+            }
+        }
+        return responseClasses;
+    }
+
+}

Added: incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/helper/EasyInvoker.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/helper/EasyInvoker.java?view=auto&rev=467621
==============================================================================
--- incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/helper/EasyInvoker.java (added)
+++ incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/helper/EasyInvoker.java Wed Oct 25 05:24:28 2006
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.tuscany.container.script.helper;
+
+import java.lang.reflect.InvocationTargetException;
+
+import org.apache.tuscany.spi.extension.TargetInvokerExtension;
+
+/**
+ * TargetInvoker that calls a function on a ScriptInstance
+ */
+public class EasyInvoker extends TargetInvokerExtension {
+
+    protected EasyComponent component;
+
+    protected String functionName;
+
+    public EasyInvoker(String functionName, EasyComponent component) {
+        this.functionName = functionName;
+        this.component = component;
+    }
+
+    /**
+     * Invoke the function
+     */
+    public Object invokeTarget(final Object payload) throws InvocationTargetException {
+        EasyInstance target = (EasyInstance) component.getTargetInstance();
+        try {
+
+            return target.invokeTarget(functionName, (Object[]) payload);
+
+        } catch (Exception e) {
+            throw new InvocationTargetException(e);
+        }
+    }
+
+}

Added: incubator/tuscany/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/AsyncInvokerTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/AsyncInvokerTestCase.java?view=auto&rev=467621
==============================================================================
--- incubator/tuscany/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/AsyncInvokerTestCase.java (added)
+++ incubator/tuscany/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/AsyncInvokerTestCase.java Wed Oct 25 05:24:28 2006
@@ -0,0 +1,211 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.tuscany.container.script.helper;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.getCurrentArguments;
+import static org.easymock.EasyMock.isA;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+
+import java.lang.reflect.Method;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.container.script.helper.AsyncInvoker;
+import org.apache.tuscany.container.script.helper.AsyncMonitor;
+import org.apache.tuscany.container.script.helper.EasyComponent;
+import org.apache.tuscany.container.script.helper.EasyInstance;
+import org.apache.tuscany.container.script.helper.AsyncInvoker.ContextBinder;
+import org.apache.tuscany.container.script.helper.AsyncInvoker.ImmutableMessage;
+import org.apache.tuscany.container.script.helper.mock.AsyncTarget;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.services.work.WorkScheduler;
+import org.apache.tuscany.spi.wire.InboundWire;
+import org.apache.tuscany.spi.wire.Message;
+import org.apache.tuscany.spi.wire.MessageImpl;
+import org.easymock.IAnswer;
+import org.easymock.classextension.EasyMock;
+
+/**
+ */
+public class AsyncInvokerTestCase extends TestCase {
+    
+    @SuppressWarnings("unchecked")
+    public void testInvoke() throws Exception {
+        EasyInstance instance = createMock(EasyInstance.class);
+        expect(instance.invokeTarget("invoke", null)).andReturn(null).once();
+        replay(instance);
+        EasyComponent component = EasyMock.createMock(EasyComponent.class);
+        expect(component.getTargetInstance()).andReturn(instance);
+        EasyMock.replay(component);
+        AsyncMonitor monitor = createMock(AsyncMonitor.class);
+        replay(monitor);
+
+        WorkScheduler scheduler = createMock(WorkScheduler.class);
+        scheduler.scheduleWork(isA(Runnable.class));
+        expectLastCall().andStubAnswer(new IAnswer() {
+            public Object answer() throws Throwable {
+                Runnable runnable = (Runnable) getCurrentArguments()[0];
+                runnable.run();
+                return null;
+            }
+        });
+        replay(scheduler);
+        WorkContext context = createMock(WorkContext.class);
+        Method method = AsyncTarget.class.getMethod("invoke");
+        method.setAccessible(true);
+        InboundWire wire = createMock(InboundWire.class);
+        AsyncInvoker invoker = new AsyncInvoker("invoke", wire, component, scheduler, monitor, context);
+        Message msg = new MessageImpl();
+        invoker.invoke(msg);
+        verify(instance);
+    }
+    
+    public void testClone() {
+        AsyncInvoker invoker = new AsyncInvoker(null, null, null,null,null,null);
+        assertNotNull(invoker.clone());
+    }
+
+    public void testGetInstance() {
+        EasyComponent component = EasyMock.createMock(EasyComponent.class);
+        expect(component.getTargetInstance()).andReturn("petra");
+        EasyMock.replay(component);
+        AsyncInvoker invoker = new AsyncInvoker(null, null, component,null,null,null);
+        assertEquals("petra", invoker.getInstance());
+    }
+
+    public void testGetInstanceCacheable() {
+        EasyComponent component = EasyMock.createMock(EasyComponent.class);
+        expect(component.getTargetInstance()).andReturn("petra");
+        EasyMock.replay(component);
+        AsyncInvoker invoker = new AsyncInvoker(null, null, component,null,null,null);
+        invoker.setCacheable(true);
+        assertEquals("petra", invoker.getInstance());
+    }
+
+    public void testGetBody() {
+        ImmutableMessage message = new AsyncInvoker.ImmutableMessage();
+        assertNull(message.getBody());
+    }
+
+    public void testSetBody() {
+        ImmutableMessage message = new AsyncInvoker.ImmutableMessage();
+        try {
+            message.setBody(null);
+            fail();
+        } catch (UnsupportedOperationException e) {
+            // expected
+        }
+    }
+
+    public void testGetTargetInvoker() {
+        ImmutableMessage message = new AsyncInvoker.ImmutableMessage();
+        assertNull(message.getTargetInvoker());
+    }
+
+    public void testSetTargetInvoker() {
+        ImmutableMessage message = new AsyncInvoker.ImmutableMessage();
+        try {
+            message.setTargetInvoker(null);
+            fail();
+        } catch (UnsupportedOperationException e) {
+            // expected
+        }
+    }
+
+    public void testGetFromAddress() {
+        ImmutableMessage message = new AsyncInvoker.ImmutableMessage();
+        assertNull(message.getFromAddress());
+    }
+
+    public void testSetFromAddress() {
+        ImmutableMessage message = new AsyncInvoker.ImmutableMessage();
+        try {
+            message.setFromAddress(null);
+            fail();
+        } catch (UnsupportedOperationException e) {
+            // expected
+        }
+    }
+
+    public void testGetMessageId() {
+        ImmutableMessage message = new AsyncInvoker.ImmutableMessage();
+        assertNull(message.getMessageId());
+    }
+
+    public void testSetMessageId() {
+        ImmutableMessage message = new AsyncInvoker.ImmutableMessage();
+        try {
+            message.setMessageId(null);
+            fail();
+        } catch (UnsupportedOperationException e) {
+            // expected
+        }
+    }
+
+    public void testGetCorrelationId() {
+        ImmutableMessage message = new AsyncInvoker.ImmutableMessage();
+        assertNull(message.getCorrelationId());
+    }
+
+    public void testSetCorrelationId() {
+        ImmutableMessage message = new AsyncInvoker.ImmutableMessage();
+        try {
+            message.setCorrelationId(null);
+            fail();
+        } catch (UnsupportedOperationException e) {
+            // expected
+        }
+    }
+
+    public void testIsFault() {
+        ImmutableMessage message = new AsyncInvoker.ImmutableMessage();
+        assertFalse(message.isFault());
+    }
+
+    public void testSetBodyWithFault() {
+        ImmutableMessage message = new AsyncInvoker.ImmutableMessage();
+        try {
+            message.setBodyWithFault(null);
+            fail();
+        } catch (UnsupportedOperationException e) {
+            // expected
+        }
+    }
+
+    public void testContextBinder() {
+        ContextBinder contextBinder = new AsyncInvoker.ContextBinder();
+        contextBinder.setContext(null);
+        try {
+            contextBinder.start();
+            fail();
+        } catch (AssertionError e) {
+            // expected
+        }
+        try {
+            contextBinder.stop();
+            fail();
+        } catch (AssertionError e) {
+            // expected
+        }
+    }
+}

Added: incubator/tuscany/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/EasyComponentBuilderTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/EasyComponentBuilderTestCase.java?view=auto&rev=467621
==============================================================================
--- incubator/tuscany/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/EasyComponentBuilderTestCase.java (added)
+++ incubator/tuscany/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/EasyComponentBuilderTestCase.java Wed Oct 25 05:24:28 2006
@@ -0,0 +1,107 @@
+package org.apache.tuscany.container.script.helper;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import junit.framework.TestCase;
+
+import org.apache.tuscany.container.script.helper.EasyComponentBuilder;
+import org.apache.tuscany.container.script.helper.EasyComponentType;
+import org.apache.tuscany.container.script.helper.EasyImplementation;
+import org.apache.tuscany.core.component.scope.ModuleScopeObjectFactory;
+import org.apache.tuscany.core.component.scope.ScopeRegistryImpl;
+import org.apache.tuscany.spi.ObjectFactory;
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.ScopeRegistry;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.idl.java.JavaServiceContract;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.PropertyValue;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+import org.easymock.IAnswer;
+
+public class EasyComponentBuilderTestCase extends TestCase {
+
+    public void testGetImplementationType() {
+        EasyComponentBuilder builder = new EasyComponentBuilder();
+        assertEquals(EasyImplementation.class, builder.getImplementationType());
+    }
+
+    @SuppressWarnings("unchecked")
+    public void testBuild() {
+        EasyComponentBuilder builder = new EasyComponentBuilder();
+        ScopeRegistry scopeRegistry = new ScopeRegistryImpl();
+        scopeRegistry.registerFactory(Scope.COMPOSITE, new ModuleScopeObjectFactory(scopeRegistry));
+        builder.setScopeRegistry(scopeRegistry);
+        DeploymentContext deploymentContext = createMock(DeploymentContext.class);
+        final ScopeContainer scopeContainer = createMock(ScopeContainer.class);
+        expect(scopeContainer.getScope()).andStubAnswer(new IAnswer() {
+            public Object answer() throws Throwable {
+                return Scope.COMPOSITE;
+            }
+        });
+        expect(deploymentContext.getModuleScope()).andStubAnswer(new IAnswer() {
+            public Object answer() throws Throwable {
+                return scopeContainer;
+            }
+        });
+        replay(deploymentContext);
+        ComponentDefinition<EasyImplementation> impl = new ComponentDefinition<EasyImplementation>(new EasyImplementation());
+        EasyComponentType componentType = new EasyComponentType();
+        componentType.setLifecycleScope(Scope.COMPOSITE);
+        ServiceDefinition service = new ServiceDefinition();
+        ServiceContract serviceContract = new JavaServiceContract();
+        service.setServiceContract(serviceContract);
+        componentType.add(service);
+        impl.getImplementation().setComponentType(componentType);
+        
+        PropertyValue pv = new PropertyValue("foo", "", "");
+        ObjectFactory pvFactory = createMock(ObjectFactory.class);
+        expect(pvFactory.getInstance()).andStubAnswer(new IAnswer() {
+            public Object answer() throws Throwable {
+                return null;
+            }
+        });
+        replay(pvFactory);
+        pv.setValueFactory(pvFactory);
+        impl.add(pv);
+        
+        Component component = builder.build(null, impl, deploymentContext);
+        assertNotNull(component);
+    }
+
+    @SuppressWarnings("unchecked")
+    public void testBuildModuleScope() {
+        EasyComponentBuilder builder = new EasyComponentBuilder();
+        DeploymentContext deploymentContext = createMock(DeploymentContext.class);
+        final ScopeContainer scopeContainer = createMock(ScopeContainer.class);
+        expect(scopeContainer.getScope()).andStubAnswer(new IAnswer() {
+            public Object answer() throws Throwable {
+                return Scope.MODULE;
+            }
+        });
+        expect(deploymentContext.getModuleScope()).andStubAnswer(new IAnswer() {
+            public Object answer() throws Throwable {
+                return scopeContainer;
+            }
+        });
+        replay(deploymentContext);
+        ComponentDefinition<EasyImplementation> impl = new ComponentDefinition<EasyImplementation>(new EasyImplementation());
+        EasyComponentType componentType = new EasyComponentType();
+        ServiceDefinition service = new ServiceDefinition();
+        ServiceContract serviceContract = new JavaServiceContract();
+        service.setServiceContract(serviceContract);
+        componentType.add(service);
+        impl.getImplementation().setComponentType(componentType);
+        Component component = builder.build(null, impl, deploymentContext);
+        assertNotNull(component);
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+    }
+}

Added: incubator/tuscany/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/EasyComponentTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/EasyComponentTestCase.java?view=auto&rev=467621
==============================================================================
--- incubator/tuscany/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/EasyComponentTestCase.java (added)
+++ incubator/tuscany/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/EasyComponentTestCase.java Wed Oct 25 05:24:28 2006
@@ -0,0 +1,145 @@
+package org.apache.tuscany.container.script.helper;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.isA;
+import static org.easymock.EasyMock.replay;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.container.script.helper.EasyComponent;
+import org.apache.tuscany.container.script.helper.EasyInstance;
+import org.apache.tuscany.container.script.helper.EasyInstanceFactory;
+import org.apache.tuscany.container.script.helper.mock.MockInstanceFactory;
+import org.apache.tuscany.core.wire.InboundWireImpl;
+import org.apache.tuscany.core.wire.OutboundWireImpl;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.TargetException;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.wire.InboundWire;
+import org.apache.tuscany.spi.wire.OutboundWire;
+import org.apache.tuscany.spi.wire.RuntimeWire;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+import org.apache.tuscany.spi.wire.WireService;
+import org.easymock.IAnswer;
+
+public class EasyComponentTestCase extends TestCase {
+    
+    private ScopeContainer scopeContainer;
+
+    @SuppressWarnings("unchecked")
+    public void testCreateTargetInvoker() {
+        EasyComponent component = new EasyComponent(null,null, null, null, null, scopeContainer, null, null, null);
+        
+        Operation operation = new Operation("hashCode", null,null,null,false,null);
+        ServiceContract contract = new ServiceContract(List.class){};
+        operation.setServiceContract(contract);
+        TargetInvoker invoker = component.createTargetInvoker("hashCode", operation);
+        
+        assertNotNull(invoker);
+    }
+
+    @SuppressWarnings("unchecked")
+    public void testCreateInstance() throws IOException {
+        EasyComponent pc = new EasyComponent(null,createBSFEasy(), new HashMap(), null, null, scopeContainer, null, null, null);
+        Object o = pc.createInstance();
+        assertNotNull(o);
+        assertTrue(o instanceof EasyInstance);
+    }
+
+    @SuppressWarnings("unchecked")
+    public void testCreateInstanceWithRef() throws IOException {
+        WireService wireService = createMock(WireService.class);
+        expect(wireService.createProxy(isA(RuntimeWire.class))).andStubAnswer(new IAnswer() {
+            public Object answer() throws Throwable {
+                return Scope.MODULE;
+            }
+        });
+       
+        EasyComponent pc = new EasyComponent(null,createBSFEasy(), new HashMap(), null, null, scopeContainer, wireService, null, null);
+        OutboundWire wire = new OutboundWireImpl();
+        wire.setReferenceName("foo");
+        pc.addOutboundWire(wire);
+        Object o = pc.createInstance();
+        assertNotNull(o);
+        assertTrue(o instanceof EasyInstance);
+    }
+
+    @SuppressWarnings("unchecked")
+    public void testGetServiceInstance() {
+        WireService wireService = createMock(WireService.class);
+        expect(wireService.createProxy(isA(RuntimeWire.class))).andStubAnswer(new IAnswer() {
+            public Object answer() throws Throwable {
+                return "foo";
+            }
+        });
+        replay(wireService);
+        EasyComponent pc = new EasyComponent(null,null, null, null, null, scopeContainer, wireService, null, null);
+        InboundWire wire = new InboundWireImpl();
+        pc.addInboundWire(wire);
+        assertEquals("foo", pc.getServiceInstance());
+    }
+
+    @SuppressWarnings("unchecked")
+    public void testGetServiceInstanceFail() {
+        EasyComponent pc = new EasyComponent(null,null, null, null, null, scopeContainer, null, null, null);
+        try {
+            pc.getServiceInstance();
+            fail();
+        } catch (TargetException e) {
+            // expected
+        }
+    }
+
+    @SuppressWarnings("unchecked")
+    public void testGetproperties() {
+        EasyComponent pc = new EasyComponent(null,null, new HashMap(), null, null, scopeContainer, null, null, null);
+        assertNotNull(pc.getProperties());
+    }
+
+    @SuppressWarnings("unchecked")
+    public void testGetServiceInterfaces() {
+        List services = new ArrayList();
+        EasyComponent pc = new EasyComponent(null,null,null, services, null, scopeContainer, null, null, null);
+        assertEquals(services, pc.getServiceInterfaces());
+    }
+
+    @SuppressWarnings("unchecked")
+    public void testCreateAsyncTargetInvoker() {
+        EasyComponent pc = new EasyComponent(null,null,null, new ArrayList<Class<?>>(), null, scopeContainer, null, null, null);
+        assertNotNull(pc.createAsyncTargetInvoker(null, new Operation("foo", null,null,null)));
+    }
+    
+    @Override
+    @SuppressWarnings("unchecked")
+    protected void setUp() throws Exception {
+        super.setUp();
+        this.scopeContainer = createMock(ScopeContainer.class);
+        expect(scopeContainer.getScope()).andStubAnswer(new IAnswer() {
+            public Object answer() throws Throwable {
+                return Scope.MODULE;
+            }
+        });
+    }
+
+    public EasyInstanceFactory createBSFEasy() throws IOException {
+//        URL scriptURL = getClass().getResource("foo.mock");
+//        InputStream is = scriptURL.openStream();
+//        StringBuilder sb = new StringBuilder();
+//        int i = 0;
+//        while ((i = is.read()) != -1) {
+//            sb.append((char) i);
+//        }
+//        is.close();
+//        String script = sb.toString();
+        MockInstanceFactory bsfEasy = new MockInstanceFactory("foo.mock", null);
+        return bsfEasy;
+    }
+}

Added: incubator/tuscany/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/EasyComponentTypeLoaderTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/EasyComponentTypeLoaderTestCase.java?view=auto&rev=467621
==============================================================================
--- incubator/tuscany/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/EasyComponentTypeLoaderTestCase.java (added)
+++ incubator/tuscany/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/EasyComponentTypeLoaderTestCase.java Wed Oct 25 05:24:28 2006
@@ -0,0 +1,144 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.tuscany.container.script.helper;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import javax.xml.stream.XMLStreamException;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.container.script.helper.EasyComponentTypeLoader;
+import org.apache.tuscany.container.script.helper.EasyImplementation;
+import org.apache.tuscany.container.script.helper.EasyInstanceFactory;
+import org.apache.tuscany.container.script.helper.mock.MockInstanceFactory;
+import org.apache.tuscany.core.loader.LoaderRegistryImpl;
+import org.apache.tuscany.spi.component.CompositeComponent;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.model.ComponentType;
+import org.apache.tuscany.spi.model.ModelObject;
+import org.apache.tuscany.spi.model.Scope;
+import org.easymock.IAnswer;
+
+/**
+ * 
+ */
+public class EasyComponentTypeLoaderTestCase extends TestCase {
+
+    public void testGetSideFileName() {
+        EasyComponentTypeLoader loader = new EasyComponentTypeLoader();
+        assertEquals("BSFEasyTestCase.componentType", loader.getSideFileName("BSFEasyTestCase.mock"));
+    }
+
+    public void testGetSideFileNameNoDot() {
+        EasyComponentTypeLoader loader = new EasyComponentTypeLoader();
+      assertEquals("BSFEasyTestCase.componentType", loader.getSideFileName("BSFEasyTestCase"));
+    }
+
+    @SuppressWarnings("unchecked")
+    public void testLoadFromSideFile() throws MalformedURLException, LoaderException, XMLStreamException {
+        EasyComponentTypeLoader loader = new EasyComponentTypeLoader();
+        LoaderRegistry loaderRegistry = new LoaderRegistryImpl() {
+            public <MO extends ModelObject> MO load(CompositeComponent parent, ModelObject mo, URL url, Class<MO> type, DeploymentContext ctx) throws LoaderException {
+                return (MO) new ComponentType();
+            }
+        };
+        loader.setLoaderRegistry(loaderRegistry);
+        loader.loadFromSidefile(null, null);
+    }
+
+    @SuppressWarnings("unchecked")
+    public void testLoad() throws LoaderException {
+        EasyInstanceFactory bsfEasy = new MockInstanceFactory("org/apache/tuscany/container/script/helper/foo.mock", getClass().getClassLoader());
+        EasyComponentTypeLoader loader = new EasyComponentTypeLoader();
+        LoaderRegistry loaderRegistry = new LoaderRegistryImpl() {
+            public <MO extends ModelObject> MO load(CompositeComponent parent,
+                    ModelObject mo,
+                    URL url,
+                    Class<MO> type,
+                    DeploymentContext ctx) throws LoaderException {
+                return (MO) new ComponentType();
+            }
+        };
+        loader.setLoaderRegistry(loaderRegistry);
+        EasyImplementation implementation = new EasyImplementation();
+        implementation.setResourceName("org/apache/tuscany/container/script/helper/foo.mock");
+        implementation.setScriptInstanceFactory(bsfEasy);
+        DeploymentContext deploymentContext = createMock(DeploymentContext.class);
+        final ScopeContainer scopeContainer = createMock(ScopeContainer.class);
+        expect(scopeContainer.getScope()).andStubAnswer(new IAnswer() {
+            public Object answer() throws Throwable {
+                return Scope.MODULE;
+            }
+        });
+        expect(deploymentContext.getModuleScope()).andStubAnswer(new IAnswer() {
+            public Object answer() throws Throwable {
+                return scopeContainer;
+            }
+        });
+        replay(deploymentContext);
+        loader.load(null, implementation, deploymentContext);
+        assertNotNull(implementation.getComponentType());
+    }
+
+    @SuppressWarnings("unchecked")
+    public void testLoadMissingSideFile() throws LoaderException {
+        EasyInstanceFactory bsfEasy = new MockInstanceFactory("org/apche/tuscany/container/script/helper/foo.mock", getClass().getClassLoader());
+        EasyComponentTypeLoader loader = new EasyComponentTypeLoader();
+        EasyImplementation implementation = new EasyImplementation();
+        implementation.setResourceName("org/apache/tuscany/container/script/helper/doesntExist");
+        implementation.setScriptInstanceFactory(bsfEasy);
+        DeploymentContext deploymentContext = createMock(DeploymentContext.class);
+        final ScopeContainer scopeContainer = createMock(ScopeContainer.class);
+        expect(scopeContainer.getScope()).andStubAnswer(new IAnswer() {
+            public Object answer() throws Throwable {
+                return Scope.MODULE;
+            }
+        });
+        expect(deploymentContext.getModuleScope()).andStubAnswer(new IAnswer() {
+            public Object answer() throws Throwable {
+                return scopeContainer;
+            }
+        });
+        replay(deploymentContext);
+        try {
+            loader.load(null, implementation, deploymentContext);
+            fail();
+        } catch (IllegalArgumentException e) {
+        }
+    }
+
+    public void testGetImplementationClass() {
+        EasyComponentTypeLoader loader = new EasyComponentTypeLoader();
+        assertEquals(EasyImplementation.class, loader.getImplementationClass());
+    }
+
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+    }
+}

Added: incubator/tuscany/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/EasyComponentTypeTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/EasyComponentTypeTestCase.java?view=auto&rev=467621
==============================================================================
--- incubator/tuscany/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/EasyComponentTypeTestCase.java (added)
+++ incubator/tuscany/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/EasyComponentTypeTestCase.java Wed Oct 25 05:24:28 2006
@@ -0,0 +1,37 @@
+package org.apache.tuscany.container.script.helper;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.container.script.helper.EasyComponentType;
+import org.apache.tuscany.spi.model.ComponentType;
+import org.apache.tuscany.spi.model.Property;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+
+public class EasyComponentTypeTestCase extends TestCase {
+    
+    public void testLifecycleScope() {
+        EasyComponentType ct = new EasyComponentType();
+        assertEquals(Scope.MODULE, ct.getLifecycleScope());
+        ct.setLifecycleScope(Scope.COMPOSITE);
+        assertEquals(Scope.COMPOSITE, ct.getLifecycleScope());
+    }
+
+    @SuppressWarnings("unchecked")
+    public void testComponentTypeConstructor() {
+        ComponentType ct = new ComponentType();
+        Property property = new Property();
+        ct.add(property);
+        ReferenceDefinition reference = new ReferenceDefinition();
+        ct.add(reference);
+        ServiceDefinition service = new ServiceDefinition();
+        ct.add(service);
+
+        EasyComponentType pct = new EasyComponentType(ct);
+        
+        assertEquals(property, pct.getProperties().values().iterator().next());
+        assertEquals(reference, pct.getReferences().values().iterator().next());
+        assertEquals(service, pct.getServices().values().iterator().next());
+    }
+}

Added: incubator/tuscany/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/EasyImplementationLoaderTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/EasyImplementationLoaderTestCase.java?view=auto&rev=467621
==============================================================================
--- incubator/tuscany/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/EasyImplementationLoaderTestCase.java (added)
+++ incubator/tuscany/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/EasyImplementationLoaderTestCase.java Wed Oct 25 05:24:28 2006
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.tuscany.container.script.helper;
+
+import static org.easymock.classextension.EasyMock.createMock;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.container.script.helper.EasyImplementation;
+import org.apache.tuscany.container.script.helper.EasyImplementationLoader;
+import org.apache.tuscany.spi.component.CompositeComponent;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.loader.MissingResourceException;
+import org.apache.tuscany.spi.model.ModelObject;
+
+/**
+ * 
+ */
+public class EasyImplementationLoaderTestCase extends TestCase {
+
+    private LoaderRegistry registry;
+
+    private EasyImplementationLoader loader;
+
+    public void testLoadSource() throws LoaderException {
+        String script = loader.loadSource(getClass().getClassLoader(), "org/apache/tuscany/container/script/helper/foo.mock");
+        assertTrue(script.startsWith("hello"));
+    }
+
+    public void testLoadSourceMissingResource() throws LoaderException {
+        try {
+            loader.loadSource(getClass().getClassLoader(), "doesnt.exist");
+            fail();
+        } catch (MissingResourceException e) {
+            // expected
+        }
+    }
+
+    public void testGetXMLType() throws LoaderException {
+        assertEquals("http://foo", loader.getXMLType().getNamespaceURI());
+        assertEquals("bar", loader.getXMLType().getLocalPart());
+    }
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        registry = createMock(LoaderRegistry.class);
+        loader = new EasyImplementationLoader(registry){
+            public QName getXMLType() {
+                return new QName("http://foo", "bar");
+            }
+//            @Override
+            public EasyImplementation load(CompositeComponent arg0, ModelObject arg1, XMLStreamReader arg2, DeploymentContext arg3) throws XMLStreamException, LoaderException {
+                return null;
+            }};
+    }
+}

Added: incubator/tuscany/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/EasyImplementationTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/EasyImplementationTestCase.java?view=auto&rev=467621
==============================================================================
--- incubator/tuscany/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/EasyImplementationTestCase.java (added)
+++ incubator/tuscany/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/EasyImplementationTestCase.java Wed Oct 25 05:24:28 2006
@@ -0,0 +1,30 @@
+package org.apache.tuscany.container.script.helper;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.container.script.helper.EasyImplementation;
+import org.apache.tuscany.container.script.helper.EasyInstanceFactory;
+import org.apache.tuscany.container.script.helper.mock.MockInstanceFactory;
+
+public class EasyImplementationTestCase extends TestCase {
+
+    private EasyInstanceFactory bsfEasy;
+
+    public void testGetBSFEasy() {
+        EasyImplementation impl = new EasyImplementation();
+        impl.setScriptInstanceFactory(bsfEasy);
+        assertEquals(bsfEasy, impl.getScriptInstanceFactory());
+    }
+
+    public void testGetResourceName() {
+        EasyImplementation impl = new EasyImplementation();
+        impl.setResourceName("foo");
+        assertEquals("foo", impl.getResourceName());
+    }
+
+    public void setUp() throws Exception {
+        super.setUp();
+        bsfEasy = new MockInstanceFactory("BSFEasyTestCase", null);
+    }
+
+}



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