Copied: incubator/tuscany/java/sca/services/containers/container.script/src/test/java/org/apache/tuscany/container/script/ScriptComponentBuilderTestCase.java (from r471107, incubator/tuscany/java/sca/services/containers/container.script/src/test/java/org/apache/tuscany/container/script/helper/ScriptHelperComponentBuilderTestCase.java) URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/containers/container.script/src/test/java/org/apache/tuscany/container/script/ScriptComponentBuilderTestCase.java?view=diff&rev=471211&p1=incubator/tuscany/java/sca/services/containers/container.script/src/test/java/org/apache/tuscany/container/script/helper/ScriptHelperComponentBuilderTestCase.java&r1=471107&p2=incubator/tuscany/java/sca/services/containers/container.script/src/test/java/org/apache/tuscany/container/script/ScriptComponentBuilderTestCase.java&r2=471211 ============================================================================== --- incubator/tuscany/java/sca/services/containers/container.script/src/test/java/org/apache/tuscany/container/script/helper/ScriptHelperComponentBuilderTestCase.java (original) +++ incubator/tuscany/java/sca/services/containers/container.script/src/test/java/org/apache/tuscany/container/script/ScriptComponentBuilderTestCase.java Sat Nov 4 07:06:05 2006 @@ -1,19 +1,26 @@ -package org.apache.tuscany.container.script.helper; +/* + * 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; -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.ScriptHelperComponentBuilder; -import org.apache.tuscany.container.script.helper.ScriptHelperComponentType; -import org.apache.tuscany.container.script.helper.ScriptHelperImplementation; -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; @@ -21,26 +28,28 @@ import org.apache.tuscany.spi.model.Scope; import org.apache.tuscany.spi.model.ServiceContract; import org.apache.tuscany.spi.model.ServiceDefinition; + +import junit.framework.TestCase; +import static org.easymock.EasyMock.createMock; +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.replay; import org.easymock.IAnswer; -public class ScriptHelperComponentBuilderTestCase extends TestCase { +public class ScriptComponentBuilderTestCase extends TestCase { public void testGetImplementationType() { - ScriptHelperComponentBuilder builder = new ScriptHelperComponentBuilder(); - assertEquals(ScriptHelperImplementation.class, builder.getImplementationType()); + ScriptComponentBuilder builder = new ScriptComponentBuilder(); + assertEquals(ScriptImplementation.class, builder.getImplementationType()); } @SuppressWarnings("unchecked") public void testBuild() { - ScriptHelperComponentBuilder builder = new ScriptHelperComponentBuilder(); - ScopeRegistry scopeRegistry = new ScopeRegistryImpl(); - scopeRegistry.registerFactory(Scope.COMPOSITE, new ModuleScopeObjectFactory(scopeRegistry)); - builder.setScopeRegistry(scopeRegistry); + ScriptComponentBuilder builder = new ScriptComponentBuilder(); 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; + return Scope.MODULE; } }); expect(deploymentContext.getModuleScope()).andStubAnswer(new IAnswer() { @@ -49,17 +58,18 @@ } }); replay(deploymentContext); - ComponentDefinition<ScriptHelperImplementation> impl = new ComponentDefinition<ScriptHelperImplementation>(new ScriptHelperImplementation()); - ScriptHelperComponentType componentType = new ScriptHelperComponentType(); - componentType.setLifecycleScope(Scope.COMPOSITE); + ComponentDefinition<ScriptImplementation> impl = + new ComponentDefinition<ScriptImplementation>(new ScriptImplementation()); + ScriptComponentType componentType = new ScriptComponentType(); + componentType.setLifecycleScope(Scope.MODULE); 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); + + PropertyValue<String> pv = new PropertyValue<String>("foo", "", ""); + ObjectFactory<String> pvFactory = (ObjectFactory<String>) createMock(ObjectFactory.class); expect(pvFactory.getInstance()).andStubAnswer(new IAnswer() { public Object answer() throws Throwable { return null; @@ -68,14 +78,14 @@ replay(pvFactory); pv.setValueFactory(pvFactory); impl.add(pv); - + Component component = builder.build(null, impl, deploymentContext); assertNotNull(component); } @SuppressWarnings("unchecked") public void testBuildModuleScope() { - ScriptHelperComponentBuilder builder = new ScriptHelperComponentBuilder(); + ScriptComponentBuilder builder = new ScriptComponentBuilder(); DeploymentContext deploymentContext = createMock(DeploymentContext.class); final ScopeContainer scopeContainer = createMock(ScopeContainer.class); expect(scopeContainer.getScope()).andStubAnswer(new IAnswer() { @@ -89,8 +99,9 @@ } }); replay(deploymentContext); - ComponentDefinition<ScriptHelperImplementation> impl = new ComponentDefinition<ScriptHelperImplementation>(new ScriptHelperImplementation()); - ScriptHelperComponentType componentType = new ScriptHelperComponentType(); + ComponentDefinition<ScriptImplementation> impl = + new ComponentDefinition<ScriptImplementation>(new ScriptImplementation()); + ScriptComponentType componentType = new ScriptComponentType(); ServiceDefinition service = new ServiceDefinition(); ServiceContract serviceContract = new JavaServiceContract(); service.setServiceContract(serviceContract);
Copied: incubator/tuscany/java/sca/services/containers/container.script/src/test/java/org/apache/tuscany/container/script/ScriptComponentTestCase.java (from r471107, incubator/tuscany/java/sca/services/containers/container.script/src/test/java/org/apache/tuscany/container/script/helper/ScriptHelperComponentTestCase.java) URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/containers/container.script/src/test/java/org/apache/tuscany/container/script/ScriptComponentTestCase.java?view=diff&rev=471211&p1=incubator/tuscany/java/sca/services/containers/container.script/src/test/java/org/apache/tuscany/container/script/helper/ScriptHelperComponentTestCase.java&r1=471107&p2=incubator/tuscany/java/sca/services/containers/container.script/src/test/java/org/apache/tuscany/container/script/ScriptComponentTestCase.java&r2=471211 ============================================================================== --- incubator/tuscany/java/sca/services/containers/container.script/src/test/java/org/apache/tuscany/container/script/helper/ScriptHelperComponentTestCase.java (original) +++ incubator/tuscany/java/sca/services/containers/container.script/src/test/java/org/apache/tuscany/container/script/ScriptComponentTestCase.java Sat Nov 4 07:06:05 2006 @@ -1,95 +1,84 @@ -package org.apache.tuscany.container.script.helper; +/* + * 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; -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.lang.reflect.Type; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import junit.framework.TestCase; - -import org.apache.tuscany.container.script.helper.ScriptHelperComponent; -import org.apache.tuscany.container.script.helper.ScriptHelperInstance; -import org.apache.tuscany.container.script.helper.ScriptHelperInstanceFactory; -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 junit.framework.TestCase; +import org.easymock.EasyMock; import org.easymock.IAnswer; -public class ScriptHelperComponentTestCase extends TestCase { - - private ScopeContainer scopeContainer; +public class ScriptComponentTestCase extends TestCase { + + private ScopeContainer container; @SuppressWarnings("unchecked") public void testCreateTargetInvoker() { - ScriptHelperComponent component = new ScriptHelperComponent(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); + ComponentConfiguration config = new ComponentConfiguration(); + config.setName("foo"); + config.setScopeContainer(container); + ScriptComponent component = new ScriptComponent(config); + Operation<Type> operation = new Operation<Type>("hashCode", null, null, null, false, null); + operation.setServiceContract(new Contract<Type>(List.class)); TargetInvoker invoker = component.createTargetInvoker("hashCode", operation, null); - assertNotNull(invoker); } @SuppressWarnings("unchecked") - public void testCreateInstance() throws IOException { - ScriptHelperComponent pc = new ScriptHelperComponent(null,createBSFEasy(), new HashMap(), null, null, scopeContainer, null, null, null); - Object o = pc.createInstance(); - assertNotNull(o); - assertTrue(o instanceof ScriptHelperInstance); - } - - @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; - } - }); - - ScriptHelperComponent pc = new ScriptHelperComponent(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 ScriptHelperInstance); - } - - @SuppressWarnings("unchecked") public void testGetServiceInstance() { - WireService wireService = createMock(WireService.class); - expect(wireService.createProxy(isA(RuntimeWire.class))).andStubAnswer(new IAnswer() { + WireService wireService = EasyMock.createMock(WireService.class); + EasyMock.expect(wireService.createProxy(EasyMock.isA(RuntimeWire.class))).andStubAnswer(new IAnswer() { public Object answer() throws Throwable { return "foo"; } }); - replay(wireService); - ScriptHelperComponent pc = new ScriptHelperComponent(null,null, null, null, null, scopeContainer, wireService, null, null); - InboundWire wire = new InboundWireImpl(); + EasyMock.replay(wireService); + ComponentConfiguration config = new ComponentConfiguration(); + config.setName("foo"); + config.setScopeContainer(container); + config.setWireService(wireService); + ScriptComponent pc = new ScriptComponent(config); + InboundWire wire = EasyMock.createMock(InboundWire.class); + EasyMock.expect(wire.getServiceName()).andReturn("foo"); + EasyMock.replay(wire); pc.addInboundWire(wire); assertEquals("foo", pc.getServiceInstance()); + EasyMock.verify(wireService); } - @SuppressWarnings("unchecked") public void testGetServiceInstanceFail() { - ScriptHelperComponent pc = new ScriptHelperComponent(null,null, null, null, null, scopeContainer, null, null, null); + ComponentConfiguration config = new ComponentConfiguration(); + config.setName("foo"); + config.setScopeContainer(container); + ScriptComponent pc = new ScriptComponent(config); try { pc.getServiceInstance(); fail(); @@ -98,48 +87,54 @@ } } - @SuppressWarnings("unchecked") - public void testGetproperties() { - ScriptHelperComponent pc = new ScriptHelperComponent(null,null, new HashMap(), null, null, scopeContainer, null, null, null); - assertNotNull(pc.getProperties()); - } - - @SuppressWarnings("unchecked") public void testGetServiceInterfaces() { - List services = new ArrayList(); - ScriptHelperComponent pc = new ScriptHelperComponent(null,null,null, services, null, scopeContainer, null, null, null); + List<Class<?>> services = new ArrayList<Class<?>>(); + ComponentConfiguration config = new ComponentConfiguration(); + config.setName("foo"); + config.setScopeContainer(container); + config.setServices(services); + ScriptComponent pc = new ScriptComponent(config); assertEquals(services, pc.getServiceInterfaces()); } - @SuppressWarnings("unchecked") - public void testCreateAsyncTargetInvoker() { - ScriptHelperComponent pc = new ScriptHelperComponent(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; - } - }); + container = EasyMock.createMock(ScopeContainer.class); + EasyMock.expect(container.getScope()).andReturn(Scope.MODULE); + EasyMock.replay(container); } - public ScriptHelperInstanceFactory 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; + private class Contract<T> extends ServiceContract<T> { + + public Contract(Class interfaceClass) { + super(interfaceClass); + } } + +// TODO commented out the following test since it doesn't test refernences. +// TODO have a reference injeciton test in ScriptInstanceFactory that tests an actual invocation +// +// @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; +// } +// }); +// +// ScriptComponent pc = new ScriptComponent(null, createBSFEasy(), new HashMap(), null, null, +// scopeContainer, wireService, null, null); +// OutboundWire wire = EasyMock.createMock(OutboundWire.class); +// EasyMock.expect(wire.getReferenceName()).andReturn("foo").atLeastOnce(); +// EasyMock.replay(wire); +// pc.addOutboundWire(wire); +// Object o = pc.createInstance(); +// assertNotNull(o); +// assertTrue(o instanceof ScriptInstance); +// } +// + + } Copied: incubator/tuscany/java/sca/services/containers/container.script/src/test/java/org/apache/tuscany/container/script/ScriptComponentTypeLoaderTestCase.java (from r471107, incubator/tuscany/java/sca/services/containers/container.script/src/test/java/org/apache/tuscany/container/script/helper/ScriptHelperComponentTypeLoaderTestCase.java) URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/containers/container.script/src/test/java/org/apache/tuscany/container/script/ScriptComponentTypeLoaderTestCase.java?view=diff&rev=471211&p1=incubator/tuscany/java/sca/services/containers/container.script/src/test/java/org/apache/tuscany/container/script/helper/ScriptHelperComponentTypeLoaderTestCase.java&r1=471107&p2=incubator/tuscany/java/sca/services/containers/container.script/src/test/java/org/apache/tuscany/container/script/ScriptComponentTypeLoaderTestCase.java&r2=471211 ============================================================================== --- incubator/tuscany/java/sca/services/containers/container.script/src/test/java/org/apache/tuscany/container/script/helper/ScriptHelperComponentTypeLoaderTestCase.java (original) +++ incubator/tuscany/java/sca/services/containers/container.script/src/test/java/org/apache/tuscany/container/script/ScriptComponentTypeLoaderTestCase.java Sat Nov 4 07:06:05 2006 @@ -16,125 +16,92 @@ * 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; +package org.apache.tuscany.container.script; import java.net.MalformedURLException; import java.net.URL; - import javax.xml.stream.XMLStreamException; -import junit.framework.TestCase; - -import org.apache.tuscany.container.script.helper.ScriptHelperComponentTypeLoader; -import org.apache.tuscany.container.script.helper.ScriptHelperImplementation; -import org.apache.tuscany.container.script.helper.ScriptHelperInstanceFactory; -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 junit.framework.TestCase; +import org.easymock.EasyMock; import org.easymock.IAnswer; -/** - * - */ -public class ScriptHelperComponentTypeLoaderTestCase extends TestCase { +public class ScriptComponentTypeLoaderTestCase extends TestCase { public void testGetSideFileName() { - ScriptHelperComponentTypeLoader loader = new ScriptHelperComponentTypeLoader(); + ScriptComponentTypeLoader loader = new ScriptComponentTypeLoader(); assertEquals("BSFEasyTestCase.componentType", loader.getSideFileName("BSFEasyTestCase.mock")); } public void testGetSideFileNameNoDot() { - ScriptHelperComponentTypeLoader loader = new ScriptHelperComponentTypeLoader(); - assertEquals("BSFEasyTestCase.componentType", loader.getSideFileName("BSFEasyTestCase")); - } - - @SuppressWarnings("unchecked") - public void testLoadFromSideFile() throws MalformedURLException, LoaderException, XMLStreamException { - ScriptHelperComponentTypeLoader loader = new ScriptHelperComponentTypeLoader(); - 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); + ScriptComponentTypeLoader loader = new ScriptComponentTypeLoader(); + assertEquals("BSFEasyTestCase.componentType", loader.getSideFileName("BSFEasyTestCase")); } @SuppressWarnings("unchecked") - public void testLoad() throws LoaderException { - ScriptHelperInstanceFactory bsfEasy = new MockInstanceFactory("org/apache/tuscany/container/script/helper/foo.mock", getClass().getClassLoader()); - ScriptHelperComponentTypeLoader loader = new ScriptHelperComponentTypeLoader(); - 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); - ScriptHelperImplementation implementation = new ScriptHelperImplementation(); - 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 void testLoad() throws MalformedURLException, LoaderException, XMLStreamException { + CompositeComponent parent = EasyMock.createNiceMock(CompositeComponent.class); + DeploymentContext context = EasyMock.createNiceMock(DeploymentContext.class); + LoaderRegistry registry = EasyMock.createMock(LoaderRegistry.class); + registry.load(EasyMock.eq(parent), + EasyMock.isA(ScriptComponentType.class), + EasyMock.isA(URL.class), + EasyMock.isA(Class.class), + EasyMock.eq(context)); + EasyMock.expectLastCall().andStubAnswer(new IAnswer() { public Object answer() throws Throwable { - return Scope.MODULE; + return EasyMock.getCurrentArguments()[1]; } }); - expect(deploymentContext.getModuleScope()).andStubAnswer(new IAnswer() { - public Object answer() throws Throwable { - return scopeContainer; - } - }); - replay(deploymentContext); - loader.load(null, implementation, deploymentContext); + EasyMock.replay(registry); + + ScriptImplementation implementation = new ScriptImplementation(); + implementation.setResourceName("org/apache/tuscany/container/script/helper/foo.componentType"); + implementation.setClassLoader(getClass().getClassLoader()); + ScriptComponentTypeLoader loader = new ScriptComponentTypeLoader(); + loader.setLoaderRegistry(registry); + loader.load(parent, implementation, context); assertNotNull(implementation.getComponentType()); } @SuppressWarnings("unchecked") - public void testLoadMissingSideFile() throws LoaderException { - ScriptHelperInstanceFactory bsfEasy = new MockInstanceFactory("org/apche/tuscany/container/script/helper/foo.mock", getClass().getClassLoader()); - ScriptHelperComponentTypeLoader loader = new ScriptHelperComponentTypeLoader(); - ScriptHelperImplementation implementation = new ScriptHelperImplementation(); - 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 void testLoadMissingSideFile() throws MalformedURLException, LoaderException, XMLStreamException { + CompositeComponent parent = EasyMock.createNiceMock(CompositeComponent.class); + DeploymentContext context = EasyMock.createNiceMock(DeploymentContext.class); + LoaderRegistry registry = EasyMock.createMock(LoaderRegistry.class); + registry.load(EasyMock.eq(parent), + EasyMock.isA(ScriptComponentType.class), + EasyMock.isA(URL.class), + EasyMock.isA(Class.class), + EasyMock.eq(context)); + EasyMock.expectLastCall().andStubAnswer(new IAnswer() { public Object answer() throws Throwable { - return Scope.MODULE; + return EasyMock.getCurrentArguments()[1]; } }); - expect(deploymentContext.getModuleScope()).andStubAnswer(new IAnswer() { - public Object answer() throws Throwable { - return scopeContainer; - } - }); - replay(deploymentContext); + EasyMock.replay(registry); + + ScriptImplementation implementation = new ScriptImplementation(); + implementation.setResourceName("notthere"); + implementation.setClassLoader(getClass().getClassLoader()); + ScriptComponentTypeLoader loader = new ScriptComponentTypeLoader(); + loader.setLoaderRegistry(registry); try { - loader.load(null, implementation, deploymentContext); + loader.load(parent, implementation, context); fail(); - } catch (IllegalArgumentException e) { + } catch (MissingSideFileException e) { + //expected } } public void testGetImplementationClass() { - ScriptHelperComponentTypeLoader loader = new ScriptHelperComponentTypeLoader(); - assertEquals(ScriptHelperImplementation.class, loader.getImplementationClass()); + ScriptComponentTypeLoader loader = new ScriptComponentTypeLoader(); + assertEquals(ScriptImplementation.class, loader.getImplementationClass()); } @Override Copied: incubator/tuscany/java/sca/services/containers/container.script/src/test/java/org/apache/tuscany/container/script/ScriptComponentTypeTestCase.java (from r471107, incubator/tuscany/java/sca/services/containers/container.script/src/test/java/org/apache/tuscany/container/script/helper/ScriptHelperComponentTypeTestCase.java) URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/containers/container.script/src/test/java/org/apache/tuscany/container/script/ScriptComponentTypeTestCase.java?view=diff&rev=471211&p1=incubator/tuscany/java/sca/services/containers/container.script/src/test/java/org/apache/tuscany/container/script/helper/ScriptHelperComponentTypeTestCase.java&r1=471107&p2=incubator/tuscany/java/sca/services/containers/container.script/src/test/java/org/apache/tuscany/container/script/ScriptComponentTypeTestCase.java&r2=471211 ============================================================================== --- incubator/tuscany/java/sca/services/containers/container.script/src/test/java/org/apache/tuscany/container/script/helper/ScriptHelperComponentTypeTestCase.java (original) +++ incubator/tuscany/java/sca/services/containers/container.script/src/test/java/org/apache/tuscany/container/script/ScriptComponentTypeTestCase.java Sat Nov 4 07:06:05 2006 @@ -1,37 +1,34 @@ -package org.apache.tuscany.container.script.helper; +/* + * 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; + +import org.apache.tuscany.spi.model.Scope; import junit.framework.TestCase; -import org.apache.tuscany.container.script.helper.ScriptHelperComponentType; -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 ScriptComponentTypeTestCase extends TestCase { -public class ScriptHelperComponentTypeTestCase extends TestCase { - public void testLifecycleScope() { - ScriptHelperComponentType ct = new ScriptHelperComponentType(); + ScriptComponentType ct = new ScriptComponentType(); 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); - - ScriptHelperComponentType pct = new ScriptHelperComponentType(ct); - - assertEquals(property, pct.getProperties().values().iterator().next()); - assertEquals(reference, pct.getReferences().values().iterator().next()); - assertEquals(service, pct.getServices().values().iterator().next()); - } } Copied: incubator/tuscany/java/sca/services/containers/container.script/src/test/java/org/apache/tuscany/container/script/ScriptImplementationLoaderLoadingTestCase.java (from r471107, incubator/tuscany/java/sca/services/containers/container.script/src/test/java/org/apache/tuscany/container/script/helper/ScriptHelperImplementationLoaderTestCase.java) URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/containers/container.script/src/test/java/org/apache/tuscany/container/script/ScriptImplementationLoaderLoadingTestCase.java?view=diff&rev=471211&p1=incubator/tuscany/java/sca/services/containers/container.script/src/test/java/org/apache/tuscany/container/script/helper/ScriptHelperImplementationLoaderTestCase.java&r1=471107&p2=incubator/tuscany/java/sca/services/containers/container.script/src/test/java/org/apache/tuscany/container/script/ScriptImplementationLoaderLoadingTestCase.java&r2=471211 ============================================================================== --- incubator/tuscany/java/sca/services/containers/container.script/src/test/java/org/apache/tuscany/container/script/helper/ScriptHelperImplementationLoaderTestCase.java (original) +++ incubator/tuscany/java/sca/services/containers/container.script/src/test/java/org/apache/tuscany/container/script/ScriptImplementationLoaderLoadingTestCase.java Sat Nov 4 07:06:05 2006 @@ -16,18 +16,12 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.tuscany.container.script.helper; - -import static org.easymock.classextension.EasyMock.createMock; +package org.apache.tuscany.container.script; 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.ScriptHelperImplementation; -import org.apache.tuscany.container.script.helper.ScriptHelperImplementationLoader; import org.apache.tuscany.spi.component.CompositeComponent; import org.apache.tuscany.spi.deployer.DeploymentContext; import org.apache.tuscany.spi.loader.LoaderException; @@ -35,17 +29,21 @@ import org.apache.tuscany.spi.loader.MissingResourceException; import org.apache.tuscany.spi.model.ModelObject; +import junit.framework.TestCase; +import static org.easymock.classextension.EasyMock.createMock; + /** * */ -public class ScriptHelperImplementationLoaderTestCase extends TestCase { +public class ScriptImplementationLoaderLoadingTestCase extends TestCase { private LoaderRegistry registry; - private ScriptHelperImplementationLoader loader; + private ScriptImplementationLoader loader; public void testLoadSource() throws LoaderException { - String script = loader.loadSource(getClass().getClassLoader(), "org/apache/tuscany/container/script/helper/foo.mock"); + String script = + loader.loadSource(getClass().getClassLoader(), "org/apache/tuscany/container/script/helper/foo.mock"); assertTrue(script.startsWith("hello")); } @@ -66,13 +64,15 @@ protected void setUp() throws Exception { super.setUp(); registry = createMock(LoaderRegistry.class); - loader = new ScriptHelperImplementationLoader(registry){ + loader = new ScriptImplementationLoader(registry) { public QName getXMLType() { return new QName("http://foo", "bar"); } -// @Override - public ScriptHelperImplementation load(CompositeComponent arg0, ModelObject arg1, XMLStreamReader arg2, DeploymentContext arg3) throws XMLStreamException, LoaderException { + + public ScriptImplementation load(CompositeComponent arg0, ModelObject arg1, XMLStreamReader arg2, + DeploymentContext arg3) throws XMLStreamException, LoaderException { return null; - }}; + } + }; } } Copied: incubator/tuscany/java/sca/services/containers/container.script/src/test/java/org/apache/tuscany/container/script/ScriptImplementationTestCase.java (from r471107, incubator/tuscany/java/sca/services/containers/container.script/src/test/java/org/apache/tuscany/container/script/helper/ScriptHelperImplementationTestCase.java) URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/containers/container.script/src/test/java/org/apache/tuscany/container/script/ScriptImplementationTestCase.java?view=diff&rev=471211&p1=incubator/tuscany/java/sca/services/containers/container.script/src/test/java/org/apache/tuscany/container/script/helper/ScriptHelperImplementationTestCase.java&r1=471107&p2=incubator/tuscany/java/sca/services/containers/container.script/src/test/java/org/apache/tuscany/container/script/ScriptImplementationTestCase.java&r2=471211 ============================================================================== --- incubator/tuscany/java/sca/services/containers/container.script/src/test/java/org/apache/tuscany/container/script/helper/ScriptHelperImplementationTestCase.java (original) +++ incubator/tuscany/java/sca/services/containers/container.script/src/test/java/org/apache/tuscany/container/script/ScriptImplementationTestCase.java Sat Nov 4 07:06:05 2006 @@ -1,30 +1,35 @@ -package org.apache.tuscany.container.script.helper; +/* + * 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; import junit.framework.TestCase; -import org.apache.tuscany.container.script.helper.ScriptHelperImplementation; -import org.apache.tuscany.container.script.helper.ScriptHelperInstanceFactory; -import org.apache.tuscany.container.script.helper.mock.MockInstanceFactory; - -public class ScriptHelperImplementationTestCase extends TestCase { - - private ScriptHelperInstanceFactory bsfEasy; - - public void testGetBSFEasy() { - ScriptHelperImplementation impl = new ScriptHelperImplementation(); - impl.setScriptInstanceFactory(bsfEasy); - assertEquals(bsfEasy, impl.getScriptInstanceFactory()); - } +public class ScriptImplementationTestCase extends TestCase { public void testGetResourceName() { - ScriptHelperImplementation impl = new ScriptHelperImplementation(); + ScriptImplementation impl = new ScriptImplementation(); impl.setResourceName("foo"); assertEquals("foo", impl.getResourceName()); } public void setUp() throws Exception { super.setUp(); - bsfEasy = new MockInstanceFactory("BSFEasyTestCase", null); } } Modified: incubator/tuscany/java/sca/services/containers/container.script/src/test/java/org/apache/tuscany/container/script/ScriptInstanceFactoryTestCase.java URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/containers/container.script/src/test/java/org/apache/tuscany/container/script/ScriptInstanceFactoryTestCase.java?view=diff&rev=471211&r1=471210&r2=471211 ============================================================================== --- incubator/tuscany/java/sca/services/containers/container.script/src/test/java/org/apache/tuscany/container/script/ScriptInstanceFactoryTestCase.java (original) +++ incubator/tuscany/java/sca/services/containers/container.script/src/test/java/org/apache/tuscany/container/script/ScriptInstanceFactoryTestCase.java Sat Nov 4 07:06:05 2006 @@ -1,54 +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; import java.lang.reflect.InvocationTargetException; -import java.util.HashMap; +import java.util.Arrays; import java.util.Map; -import junit.framework.TestCase; +import org.apache.tuscany.spi.ObjectCreationException; +import org.apache.tuscany.spi.ObjectFactory; +import junit.framework.TestCase; import org.apache.bsf.BSFManager; import org.apache.tuscany.container.script.mock.MockBSFEngine; -import org.apache.tuscany.spi.ObjectCreationException; public class ScriptInstanceFactoryTestCase extends TestCase { public void testCreateInstance() throws InvocationTargetException { - BSFManager.registerScriptingEngine("mock", MockBSFEngine.class.getName(), new String[] {"mock"}); - ScriptInstanceFactory factory = new ScriptInstanceFactory("foo.mock", "bar", "baz", getClass().getClassLoader()); - Map<String, Object> context = new HashMap<String, Object>(); - context.put("foo", "bar"); - ScriptInstance instance = factory.createInstance(null, context); + BSFManager.registerScriptingEngine("mock", MockBSFEngine.class.getName(), new String[]{"mock"}); + ScriptInstanceFactory factory = + new ScriptInstanceFactory("foo.mock", "bar", "baz", getClass().getClassLoader()); + factory.addContextObjectFactory("foo", new SingletonObjectFactory("bar")); + ScriptInstanceImpl instance = (ScriptInstanceImpl) factory.getInstance(); assertNotNull(instance); assertNotNull(instance.bsfEngine); -// assertNotNull(instance.clazz); } public void testCreateInstanceNoClass() throws InvocationTargetException { - BSFManager.registerScriptingEngine("mock", MockBSFEngine.class.getName(), new String[] {"mock"}); - ScriptInstanceFactory factory = new ScriptInstanceFactory("foo.mock", null, "baz", getClass().getClassLoader()); - Map<String, Object> context = new HashMap<String, Object>(); - context.put("foo", "bar"); - ScriptInstance instance = factory.createInstance(null, context); + BSFManager.registerScriptingEngine("mock", MockBSFEngine.class.getName(), new String[]{"mock"}); + ScriptInstanceFactory factory = + new ScriptInstanceFactory("foo.mock", null, "baz", getClass().getClassLoader()); + factory.addContextObjectFactory("foo", new SingletonObjectFactory("bar")); + ScriptInstanceImpl instance = (ScriptInstanceImpl) factory.getInstance(); assertNotNull(instance); assertNotNull(instance.bsfEngine); } public void testCreateInstanceRuby() throws InvocationTargetException { - BSFManager.registerScriptingEngine("ruby", MockBSFEngine.class.getName(), new String[] {"mock"}); - ScriptInstanceFactory factory = new ScriptInstanceFactory("foo.mock", "bar", "baz", getClass().getClassLoader()); - Map<String, Object> context = new HashMap<String, Object>(); - context.put("foo", "bar"); - ScriptInstance instance = factory.createInstance(null, context); + BSFManager.registerScriptingEngine("ruby", MockBSFEngine.class.getName(), new String[]{"mock"}); + ScriptInstanceFactory factory = + new ScriptInstanceFactory("foo.mock", "bar", "baz", getClass().getClassLoader()); + factory.addContextObjectFactory("foo", new SingletonObjectFactory("bar")); + ScriptInstanceImpl instance = (ScriptInstanceImpl) factory.getInstance(); assertNotNull(instance); assertNotNull(instance.bsfEngine); -// assertNotNull(instance.clazz); } public void testBadCreateInstance() throws InvocationTargetException { - ScriptInstanceFactory factory = new ScriptInstanceFactory("foo", "bar", "baz", getClass().getClassLoader()); - Map<String, Object> context = new HashMap<String, Object>(); + ScriptInstanceFactory factory = + new ScriptInstanceFactory("foo", "bar", "baz", getClass().getClassLoader()); try { - factory.createInstance(null, context); + factory.getInstance(); fail(); } catch (ObjectCreationException e) { // expected @@ -56,14 +73,34 @@ } public void testGetters() throws InvocationTargetException { - ScriptInstanceFactory factory = new ScriptInstanceFactory("foo", "bar", "baz", getClass().getClassLoader()); -// assertEquals("foo", factory.getScriptName()); -// assertEquals("bar", factory.getClassName()); -// assertEquals("baz", factory.getScriptSource()); + ScriptInstanceFactory factory = + new ScriptInstanceFactory("foo", "bar", "baz", getClass().getClassLoader()); assertEquals(getClass().getClassLoader(), factory.getClassLoader()); } + + public void testGetResponseClasses() { + ScriptInstanceFactory factory = + new ScriptInstanceFactory("foo.mock", "bar", "baz", getClass().getClassLoader()); + Map<String, Class> classes = factory.getResponseClasses(Arrays.asList(new Class[]{Runnable.class})); + assertEquals(1, classes.size()); + assertEquals("run", classes.keySet().iterator().next()); + assertEquals(void.class, classes.get("run")); + } + protected void setUp() throws Exception { super.setUp(); + } + + private class SingletonObjectFactory implements ObjectFactory<Object> { + private Object instance; + + public SingletonObjectFactory(Object instance) { + this.instance = instance; + } + + public Object getInstance() throws ObjectCreationException { + return instance; + } } } Copied: incubator/tuscany/java/sca/services/containers/container.script/src/test/java/org/apache/tuscany/container/script/ScriptInstanceImplTestCase.java (from r471107, incubator/tuscany/java/sca/services/containers/container.script/src/test/java/org/apache/tuscany/container/script/ScriptInstanceTestCase.java) URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/containers/container.script/src/test/java/org/apache/tuscany/container/script/ScriptInstanceImplTestCase.java?view=diff&rev=471211&p1=incubator/tuscany/java/sca/services/containers/container.script/src/test/java/org/apache/tuscany/container/script/ScriptInstanceTestCase.java&r1=471107&p2=incubator/tuscany/java/sca/services/containers/container.script/src/test/java/org/apache/tuscany/container/script/ScriptInstanceImplTestCase.java&r2=471211 ============================================================================== --- incubator/tuscany/java/sca/services/containers/container.script/src/test/java/org/apache/tuscany/container/script/ScriptInstanceTestCase.java (original) +++ incubator/tuscany/java/sca/services/containers/container.script/src/test/java/org/apache/tuscany/container/script/ScriptInstanceImplTestCase.java Sat Nov 4 07:06:05 2006 @@ -1,14 +1,30 @@ +/* + * 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; import java.lang.reflect.InvocationTargetException; import junit.framework.TestCase; - import org.apache.tuscany.container.script.mock.MockBSFEngine; -public class ScriptInstanceTestCase extends TestCase { - - private ScriptInstance instance; +public class ScriptInstanceImplTestCase extends TestCase { + private ScriptInstanceImpl instance; public void testInvokeTarget() throws InvocationTargetException { assertEquals("hello:", instance.invokeTarget("hello", null)); @@ -25,6 +41,6 @@ protected void setUp() throws Exception { super.setUp(); - this.instance = new ScriptInstance(new MockBSFEngine(), null); + this.instance = new ScriptInstanceImpl(new MockBSFEngine(), null); } } Copied: incubator/tuscany/java/sca/services/containers/container.script/src/test/java/org/apache/tuscany/container/script/ScriptInvokerTestCase.java (from r471107, incubator/tuscany/java/sca/services/containers/container.script/src/test/java/org/apache/tuscany/container/script/helper/ScriptHelperInvokerTestCase.java) URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/containers/container.script/src/test/java/org/apache/tuscany/container/script/ScriptInvokerTestCase.java?view=diff&rev=471211&p1=incubator/tuscany/java/sca/services/containers/container.script/src/test/java/org/apache/tuscany/container/script/helper/ScriptHelperInvokerTestCase.java&r1=471107&p2=incubator/tuscany/java/sca/services/containers/container.script/src/test/java/org/apache/tuscany/container/script/ScriptInvokerTestCase.java&r2=471211 ============================================================================== --- incubator/tuscany/java/sca/services/containers/container.script/src/test/java/org/apache/tuscany/container/script/helper/ScriptHelperInvokerTestCase.java (original) +++ incubator/tuscany/java/sca/services/containers/container.script/src/test/java/org/apache/tuscany/container/script/ScriptInvokerTestCase.java Sat Nov 4 07:06:05 2006 @@ -1,64 +1,76 @@ -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; +/* + * 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; import java.lang.reflect.InvocationTargetException; import junit.framework.TestCase; - -import org.apache.tuscany.container.script.helper.ScriptHelperComponent; -import org.apache.tuscany.container.script.helper.ScriptHelperInstance; -import org.apache.tuscany.container.script.helper.ScriptHelperInvoker; -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.ScopeContainer; -import org.apache.tuscany.spi.model.Scope; import org.easymock.IAnswer; +import org.easymock.classextension.EasyMock; -public class ScriptHelperInvokerTestCase extends TestCase { - - private ScriptHelperComponent component; +public class ScriptInvokerTestCase extends TestCase { + @SuppressWarnings("unchecked") public void testInvokeTarget() throws InvocationTargetException { - ScriptHelperInvoker invoker = new ScriptHelperInvoker("hello", component); - assertEquals("hello petra", invoker.invokeTarget(null)); - } + ScriptInstance instance = EasyMock.createMock(ScriptInstance.class); + instance.invokeTarget(EasyMock.eq("operation"), (Object[]) EasyMock.notNull()); + EasyMock.expectLastCall().andStubAnswer(new IAnswer() { + public Object answer() throws Throwable { + assertEquals(2, EasyMock.getCurrentArguments().length); + assertEquals("operation", EasyMock.getCurrentArguments()[0]); + return "hello"; + } + }); - public void testInvokeTargetException() throws InvocationTargetException, SecurityException, NoSuchMethodException { - ScriptHelperInvoker badInvoker = new ScriptHelperInvoker("bang", component); - try { - badInvoker.invokeTarget(null); - fail(); - } catch (InvocationTargetException e) { - // expected - } + EasyMock.replay(instance); + ScriptComponent component = EasyMock.createMock(ScriptComponent.class); + EasyMock.expect(component.getTargetInstance()).andReturn(instance); + EasyMock.replay(component); + ScriptTargetInvoker invoker = new ScriptTargetInvoker("operation", component); + assertEquals("hello", invoker.invokeTarget(new Object[]{"petra"})); + EasyMock.verify(instance); + EasyMock.verify(component); } @SuppressWarnings("unchecked") - protected void setUp() throws Exception { - super.setUp(); - - ScopeContainer scopeContainer = createMock(ScopeContainer.class); - expect(scopeContainer.getScope()).andStubAnswer(new IAnswer() { - public Object answer() throws Throwable { - return Scope.MODULE; - } - }); - expect(scopeContainer.getInstance(isA(AtomicComponent.class))).andStubAnswer(new IAnswer() { + public void testInvokeTargetException() throws InvocationTargetException, SecurityException, NoSuchMethodException { + ScriptInstance instance = EasyMock.createMock(ScriptInstance.class); + instance.invokeTarget(EasyMock.eq("operation"), (Object[]) EasyMock.notNull()); + EasyMock.expectLastCall().andStubAnswer(new IAnswer() { public Object answer() throws Throwable { - return new ScriptHelperInstance(){ - public Object invokeTarget(String operationName, Object[] args) throws InvocationTargetException { - if ("bang".equals(operationName)) { - throw new RuntimeException("bang"); - } - return "hello petra"; - }}; + throw new RuntimeException(); } }); - replay(scopeContainer); - this.component = new ScriptHelperComponent(null, null, null, null, null, scopeContainer, null, null, null); + EasyMock.replay(instance); + ScriptComponent component = EasyMock.createMock(ScriptComponent.class); + EasyMock.expect(component.getTargetInstance()).andReturn(instance); + EasyMock.replay(component); + ScriptTargetInvoker invoker = new ScriptTargetInvoker("operation", component); + try { + invoker.invokeTarget(new Object[]{"petra"}); + fail(); + } catch (InvocationTargetException e) { + // expected + } + EasyMock.verify(instance); + EasyMock.verify(component); } + } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
