summaryrefslogtreecommitdiffstats
path: root/sandbox/ant/tuscany-container-rhino/src/test/java/org/apache/tuscany/container/rhino/e4x/E4XPolicyBuilderTestCase.java
diff options
context:
space:
mode:
Diffstat (limited to 'sandbox/ant/tuscany-container-rhino/src/test/java/org/apache/tuscany/container/rhino/e4x/E4XPolicyBuilderTestCase.java')
-rw-r--r--sandbox/ant/tuscany-container-rhino/src/test/java/org/apache/tuscany/container/rhino/e4x/E4XPolicyBuilderTestCase.java325
1 files changed, 325 insertions, 0 deletions
diff --git a/sandbox/ant/tuscany-container-rhino/src/test/java/org/apache/tuscany/container/rhino/e4x/E4XPolicyBuilderTestCase.java b/sandbox/ant/tuscany-container-rhino/src/test/java/org/apache/tuscany/container/rhino/e4x/E4XPolicyBuilderTestCase.java
new file mode 100644
index 0000000000..09638e7eae
--- /dev/null
+++ b/sandbox/ant/tuscany-container-rhino/src/test/java/org/apache/tuscany/container/rhino/e4x/E4XPolicyBuilderTestCase.java
@@ -0,0 +1,325 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tuscany.container.rhino.e4x;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.wsdl.Input;
+import javax.wsdl.Message;
+import javax.wsdl.Operation;
+import javax.wsdl.Part;
+import javax.wsdl.PortType;
+import javax.xml.namespace.QName;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.common.resource.impl.ResourceLoaderImpl;
+import org.apache.tuscany.container.rhino.assembly.JavaScriptImplementation;
+import org.apache.tuscany.core.wire.Interceptor;
+import org.apache.tuscany.core.wire.TargetInvocationConfiguration;
+import org.apache.tuscany.core.wire.WireTargetConfiguration;
+import org.apache.tuscany.model.assembly.AssemblyContext;
+import org.apache.tuscany.model.assembly.AssemblyInitializationException;
+import org.apache.tuscany.model.assembly.AssemblyVisitor;
+import org.apache.tuscany.model.assembly.AtomicComponent;
+import org.apache.tuscany.model.assembly.AtomicImplementation;
+import org.apache.tuscany.model.assembly.ComponentType;
+import org.apache.tuscany.model.assembly.Composite;
+import org.apache.tuscany.model.assembly.ConfiguredProperty;
+import org.apache.tuscany.model.assembly.ConfiguredReference;
+import org.apache.tuscany.model.assembly.ConfiguredService;
+import org.apache.tuscany.model.assembly.Property;
+import org.apache.tuscany.model.assembly.Reference;
+import org.apache.tuscany.model.assembly.Service;
+import org.apache.tuscany.model.assembly.ServiceContract;
+import org.apache.tuscany.model.types.wsdl.impl.WSDLServiceContractImpl;
+
+import com.ibm.wsdl.InputImpl;
+import com.ibm.wsdl.MessageImpl;
+import com.ibm.wsdl.OperationImpl;
+import com.ibm.wsdl.PartImpl;
+import com.ibm.wsdl.PortTypeImpl;
+
+/**
+ * Tests for the E4XPolicyBuilder
+ */
+public class E4XPolicyBuilderTestCase extends TestCase {
+
+ public E4XPolicyBuilderTestCase() {
+
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ public void testGetElementQName() {
+ E4XPolicyBuilder builder = new E4XPolicyBuilder();
+ QName qn = new QName("foo");
+ JavaScriptImplementation jsImpl = createMockJSImpl("foo", qn);
+ QName qn2 = builder.getElementQName(jsImpl, "foo");
+ assertEquals(qn, qn2);
+ }
+
+ public void testBuild() throws SecurityException, NoSuchMethodException {
+ E4XPolicyBuilder builder = new E4XPolicyBuilder();
+ ConfiguredService service = createMockConfiguredService();
+ WireTargetConfiguration config = createMockWireTargetConfiguration();
+ builder.build(service, config);
+ Map<Method, TargetInvocationConfiguration> configs = config.getInvocationConfigurations();
+ assertNotNull(configs);
+ assertEquals(1, configs.size());
+ TargetInvocationConfiguration tic = configs.values().iterator().next();
+ Interceptor interceptor = tic.getHeadInterceptor();
+ assertTrue(interceptor instanceof E4XInterceptor);
+ }
+
+ private WireTargetConfiguration createMockWireTargetConfiguration() throws SecurityException, NoSuchMethodException {
+ Map<Method, TargetInvocationConfiguration> configs = new HashMap<Method, TargetInvocationConfiguration>();
+ Method foo = Foo.class.getMethod("foo", new Class[0]);
+ TargetInvocationConfiguration config = new TargetInvocationConfiguration(foo);
+ configs.put(foo, config);
+ WireTargetConfiguration wtf = new WireTargetConfiguration(null, configs, null, null);
+ return wtf;
+ }
+
+ interface Foo {
+ public void foo();
+ }
+
+ private ConfiguredService createMockConfiguredService() {
+ ConfiguredService service = new ConfiguredService() {
+
+ public String getName() {
+ return null;
+ }
+
+ public void setName(String name) {
+ }
+
+ public Service getPort() {
+ return null;
+ }
+
+ public void setPort(Service port) {
+ }
+
+ public org.apache.tuscany.model.assembly.Part getPart() {
+ return createPart();
+ }
+
+ public void setPart(org.apache.tuscany.model.assembly.Part part) {
+ }
+
+ public void initialize(AssemblyContext modelContext) throws AssemblyInitializationException {
+ }
+
+ public void freeze() {
+ }
+
+ public boolean accept(AssemblyVisitor visitor) {
+ return false;
+ }
+
+ public void setProxyFactory(Object proxyFactory) {
+ }
+
+ public Object getProxyFactory() {
+ return null;
+ }
+ };
+
+ return service;
+ }
+
+ private org.apache.tuscany.model.assembly.Part createPart() {
+ org.apache.tuscany.model.assembly.Part part = new AtomicComponent() {
+
+ public AtomicImplementation getImplementation() {
+ return createMockJSImpl("foo", new QName("foo"));
+ }
+
+ public void setImplementation(AtomicImplementation value) {
+ }
+
+ public List<ConfiguredProperty> getConfiguredProperties() {
+ return null;
+ }
+
+ public ConfiguredProperty getConfiguredProperty(String name) {
+ return null;
+ }
+
+ public List<ConfiguredReference> getConfiguredReferences() {
+ return null;
+ }
+
+ public ConfiguredReference getConfiguredReference(String name) {
+ return null;
+ }
+
+ public List<ConfiguredService> getConfiguredServices() {
+ return null;
+ }
+
+ public ConfiguredService getConfiguredService(String name) {
+ return null;
+ }
+
+ public String getName() {
+ return null;
+ }
+
+ public void setName(String value) {
+ }
+
+ public Composite getComposite() {
+ return null;
+ }
+
+ public void setComposite(Composite composite) {
+ }
+
+ public List<Object> getExtensibilityElements() {
+ return null;
+ }
+
+ public List<Object> getExtensibilityAttributes() {
+ return null;
+ }
+
+ public void initialize(AssemblyContext modelContext) throws AssemblyInitializationException {
+ }
+
+ public void freeze() {
+ }
+
+ public boolean accept(AssemblyVisitor visitor) {
+ return false;
+ }
+
+ public void setContextFactory(Object contextFactory) {
+ }
+
+ public Object getContextFactory() {
+ return null;
+ }
+ };
+ return part;
+ }
+
+ private JavaScriptImplementation createMockJSImpl(final String name, final QName qn) {
+ JavaScriptImplementation jsImpl = new JavaScriptImplementation();
+
+ jsImpl.setComponentType(new ComponentType() {
+
+ public List<Service> getServices() {
+ return Arrays.asList(new Service[] { createMockService(name, qn) });
+ }
+
+ public Service getService(String name) {
+ return null;
+ }
+
+ public List<Reference> getReferences() {
+ return null;
+ }
+
+ public Reference getReference(String name) {
+ return null;
+ }
+
+ public List<Property> getProperties() {
+ return new ArrayList<Property>();
+ }
+
+ public Property getProperty(String name) {
+ return null;
+ }
+
+ public List<Object> getExtensibilityElements() {
+ return null;
+ }
+
+ public List<Object> getExtensibilityAttributes() {
+ return null;
+ }
+
+ public void initialize(AssemblyContext modelContext) throws AssemblyInitializationException {
+ }
+
+ public void freeze() {
+ }
+
+ public boolean accept(AssemblyVisitor visitor) {
+ return false;
+ }
+ });
+
+ jsImpl.setResourceLoader(new ResourceLoaderImpl(getClass().getClassLoader()));
+
+ return jsImpl;
+ }
+
+ private Service createMockService(final String name, final QName qn) {
+ Service service = new Service() {
+
+ public ServiceContract getServiceContract() {
+ WSDLServiceContractImpl sc = new WSDLServiceContractImpl();
+ PortType pt = new PortTypeImpl();
+ Operation op = new OperationImpl();
+ op.setName(name);
+ Input input = new InputImpl();
+ Message msg = new MessageImpl();
+ Part p = new PartImpl();
+ p.setElementName(qn);
+ msg.addPart(p);
+ input.setMessage(msg);
+ op.setInput(input);
+ pt.addOperation(op);
+ sc.setPortType(pt);
+ return sc;
+ }
+
+ public void setServiceContract(ServiceContract contract) {
+ }
+
+ public String getName() {
+ return null;
+ }
+
+ public void setName(String name) {
+ }
+
+ public void initialize(AssemblyContext modelContext) throws AssemblyInitializationException {
+ }
+
+ public void freeze() {
+ }
+
+ public boolean accept(AssemblyVisitor visitor) {
+ return false;
+ }
+ };
+ return service;
+ }
+
+} \ No newline at end of file