diff options
Diffstat (limited to 'sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src')
139 files changed, 12009 insertions, 0 deletions
diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/assembly/JavaAssemblyFactory.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/assembly/JavaAssemblyFactory.java new file mode 100644 index 0000000000..90271179d1 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/assembly/JavaAssemblyFactory.java @@ -0,0 +1,30 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.assembly; + +import org.apache.tuscany.model.assembly.AssemblyFactory; + + +/** + * The Factory for the model. + */ +public interface JavaAssemblyFactory extends AssemblyFactory { + /** + * Returns a new JavaImplementation. + */ + JavaImplementation createJavaImplementation(); +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/assembly/JavaImplementation.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/assembly/JavaImplementation.java new file mode 100644 index 0000000000..a87b8ea1bb --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/assembly/JavaImplementation.java @@ -0,0 +1,39 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.assembly; + +import org.apache.tuscany.model.assembly.AtomicImplementation; + + +/** + * Represents a java implementation. + * + * @version $Rev$ $Date$ + */ +public interface JavaImplementation extends AtomicImplementation { + + /** + * Returns the implementation class. + */ + Class<?> getImplementationClass(); + + /** + * Sets the implementation class. + */ + void setImplementationClass(Class<?> value); + +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/assembly/impl/JavaAssemblyFactoryImpl.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/assembly/impl/JavaAssemblyFactoryImpl.java new file mode 100644 index 0000000000..3337c287ac --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/assembly/impl/JavaAssemblyFactoryImpl.java @@ -0,0 +1,45 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.assembly.impl; + +import org.osoa.sca.annotations.Service; + +import org.apache.tuscany.container.java.assembly.JavaAssemblyFactory; +import org.apache.tuscany.container.java.assembly.JavaImplementation; +import org.apache.tuscany.model.assembly.impl.AssemblyFactoryImpl; + +/** + * A factory for the model. + */ +@Service(interfaces = {JavaAssemblyFactory.class}) +public class JavaAssemblyFactoryImpl extends AssemblyFactoryImpl implements JavaAssemblyFactory { + + /** + * Constructor + */ + public JavaAssemblyFactoryImpl() { + super(); + } + + /** + * @see org.apache.tuscany.container.java.assembly.JavaAssemblyFactory#createJavaImplementation() + */ + public JavaImplementation createJavaImplementation() { + return new JavaImplementationImpl(); + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/assembly/impl/JavaImplementationImpl.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/assembly/impl/JavaImplementationImpl.java new file mode 100644 index 0000000000..57a98f4ad6 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/assembly/impl/JavaImplementationImpl.java @@ -0,0 +1,44 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.assembly.impl; + +import org.apache.tuscany.container.java.assembly.JavaImplementation; +import org.apache.tuscany.model.assembly.impl.AtomicImplementationImpl; + +/** + * An implementation of JavaImplementation. + * + * @version $Rev$ $Date$ + */ +public class JavaImplementationImpl extends AtomicImplementationImpl implements JavaImplementation { + private Class<?> implementationClass; + + /** + * Default constructor. + */ + protected JavaImplementationImpl() { + } + + public Class<?> getImplementationClass() { + return implementationClass; + } + + public void setImplementationClass(Class<?> value) { + checkNotFrozen(); + implementationClass = value; + } +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/builder/JavaContextFactoryBuilder.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/builder/JavaContextFactoryBuilder.java new file mode 100644 index 0000000000..de915738f9 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/builder/JavaContextFactoryBuilder.java @@ -0,0 +1,113 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.builder; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.container.java.assembly.JavaImplementation; +import org.apache.tuscany.container.java.config.JavaContextFactory; +import org.apache.tuscany.core.extension.config.extensibility.ComponentNameExtensibilityElement; +import org.apache.tuscany.core.extension.config.extensibility.ContextExtensibilityElement; +import org.apache.tuscany.core.extension.config.extensibility.DestroyInvokerExtensibilityElement; +import org.apache.tuscany.core.extension.config.extensibility.InitInvokerExtensibilityElement; +import org.apache.tuscany.core.extension.config.InjectorExtensibilityElement; +import org.apache.tuscany.core.builder.BuilderConfigException; +import org.apache.tuscany.core.builder.BuilderException; +import org.apache.tuscany.core.builder.ContextFactory; +import org.apache.tuscany.core.config.JavaIntrospectionHelper; +import org.apache.tuscany.core.extension.ContextFactoryBuilderSupport; +import org.apache.tuscany.core.injection.EventInvoker; +import org.apache.tuscany.core.injection.Injector; +import org.apache.tuscany.core.wire.service.WireFactoryService; +import org.apache.tuscany.model.assembly.Scope; + +/** + * Builds context factories for component implementations that map to {@link + * org.apache.tuscany.container.java.assembly.JavaImplementation}. The logical model is then decorated with + * the runtime configuration. + * + * @version $Rev: 368822 $ $Date: 2006-01-13 10:54:38 -0800 (Fri, 13 Jan 2006) $ + * @see org.apache.tuscany.core.builder.ContextFactory + */ +@org.osoa.sca.annotations.Scope("MODULE") +public class JavaContextFactoryBuilder extends ContextFactoryBuilderSupport<JavaImplementation> { + + /** + * Default constructor + */ + public JavaContextFactoryBuilder() { + super(); + } + + /** + * Constructs a new instance + * + * @param wireFactoryService the system service responsible for creating wire factories + */ + public JavaContextFactoryBuilder(WireFactoryService wireFactoryService) { + super(wireFactoryService); + } + + @SuppressWarnings("unchecked") + protected ContextFactory createContextFactory(String name, JavaImplementation javaImpl, Scope scope) { + Class implClass = null; + JavaContextFactory contextFactory; + try { + implClass = javaImpl.getImplementationClass(); + + contextFactory = new JavaContextFactory(name, JavaIntrospectionHelper + .getDefaultConstructor(implClass), scope); + + List<Injector> injectors = new ArrayList<Injector>(); + List<Object> elements = javaImpl.getComponentType().getExtensibilityElements(); + for (Object element : elements) { + if (element instanceof InitInvokerExtensibilityElement) { + InitInvokerExtensibilityElement invokerElement = (InitInvokerExtensibilityElement) element; + EventInvoker<Object> initInvoker = invokerElement.getEventInvoker(); + boolean eagerInit = invokerElement.isEager(); + contextFactory.setEagerInit(eagerInit); + contextFactory.setInitInvoker(initInvoker); + } else if (element instanceof DestroyInvokerExtensibilityElement) { + DestroyInvokerExtensibilityElement invokerElement = (DestroyInvokerExtensibilityElement) element; + EventInvoker<Object> destroyInvoker = invokerElement.getEventInvoker(); + contextFactory.setDestroyInvoker(destroyInvoker); + } else if (element instanceof ComponentNameExtensibilityElement) { + ComponentNameExtensibilityElement nameElement = (ComponentNameExtensibilityElement) element; + injectors.add(nameElement.getEventInvoker(name)); + } else if (element instanceof ContextExtensibilityElement) { + ContextExtensibilityElement contextElement = (ContextExtensibilityElement) element; + injectors.add(contextElement.getInjector(contextFactory)); + }else if (element instanceof InjectorExtensibilityElement){ + InjectorExtensibilityElement injectorElement = (InjectorExtensibilityElement)element; + injectors.add(injectorElement.getInjector(contextFactory)); + } + } + contextFactory.setSetters(injectors); + return contextFactory; + } catch (BuilderException e) { + e.addContextName(name); + throw e; + } catch (NoSuchMethodException e) { + BuilderConfigException ce = new BuilderConfigException("Class does not have a no-arg constructor", e); + ce.setIdentifier(implClass.getName()); + ce.addContextName(name); + throw ce; + } + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/builder/JavaTargetWireBuilder.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/builder/JavaTargetWireBuilder.java new file mode 100644 index 0000000000..cc66fa54f6 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/builder/JavaTargetWireBuilder.java @@ -0,0 +1,38 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package org.apache.tuscany.container.java.builder; + +import org.apache.tuscany.container.java.config.JavaContextFactory; +import org.apache.tuscany.container.java.invocation.ScopedJavaComponentInvoker; +import org.apache.tuscany.core.context.QualifiedName; +import org.apache.tuscany.core.context.ScopeContext; +import org.apache.tuscany.core.extension.WireBuilderSupport; +import org.apache.tuscany.core.wire.TargetInvoker; +import org.osoa.sca.annotations.Scope; + +import java.lang.reflect.Method; + +/** + * Completes a wire to a Java-based target component by adding a scoped java invoker to the source chain + * + * @version $Rev$ $Date$ + */ +@Scope("MODULE") +public class JavaTargetWireBuilder extends WireBuilderSupport<JavaContextFactory> { + + protected TargetInvoker createInvoker(QualifiedName targetName, Method operation, ScopeContext context, boolean downScope) { + boolean cacheable = !downScope; + return new ScopedJavaComponentInvoker(targetName, operation, context,cacheable); + } +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/config/JavaContextFactory.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/config/JavaContextFactory.java new file mode 100644 index 0000000000..ff498d851a --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/config/JavaContextFactory.java @@ -0,0 +1,341 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package org.apache.tuscany.container.java.config; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import commonj.sdo.DataObject; +import org.apache.tuscany.container.java.context.JavaAtomicContext; +import org.apache.tuscany.core.builder.BuilderConfigException; +import org.apache.tuscany.core.builder.ContextCreationException; +import org.apache.tuscany.core.builder.ContextFactory; +import org.apache.tuscany.core.builder.ContextResolver; +import org.apache.tuscany.core.builder.NoAccessorException; +import org.apache.tuscany.core.builder.ObjectFactory; +import org.apache.tuscany.core.builder.impl.ArrayMultiplicityObjectFactory; +import org.apache.tuscany.core.builder.impl.ListMultiplicityObjectFactory; +import org.apache.tuscany.core.builder.impl.ProxyObjectFactory; +import org.apache.tuscany.core.config.JavaIntrospectionHelper; +import org.apache.tuscany.core.context.AtomicContext; +import org.apache.tuscany.core.context.CompositeContext; +import org.apache.tuscany.core.injection.EventInvoker; +import org.apache.tuscany.core.injection.FieldInjector; +import org.apache.tuscany.core.injection.Injector; +import org.apache.tuscany.core.injection.MethodInjector; +import org.apache.tuscany.core.injection.PojoObjectFactory; +import org.apache.tuscany.core.injection.SingletonObjectFactory; +import org.apache.tuscany.core.wire.SourceWireFactory; +import org.apache.tuscany.core.wire.TargetWireFactory; +import org.apache.tuscany.databinding.sdo.SDOObjectFactory; +import org.apache.tuscany.model.assembly.Scope; +import org.osoa.sca.annotations.Property; +import org.osoa.sca.annotations.Reference; + +/** + * A ContextFactory that handles POJO component implementation types + * + * @version $Rev$ $Date$ + */ +public class JavaContextFactory implements ContextFactory<AtomicContext>, ContextResolver { + + // the component name as configured in the hosting module + private String name; + + // the parent context of the component + private CompositeContext parentContext; + + private Map<String, TargetWireFactory> targetProxyFactories = new HashMap<String, TargetWireFactory>(); + + private List<SourceWireFactory> sourceProxyFactories = new ArrayList<SourceWireFactory>(); + + // the implementation type constructor + private Constructor<Object> ctr; + + private Set<Field> fields; + + private Set<Method> methods; + + // injectors for properties, references and other metadata values such as + private List<Injector> setters; + + // an invoker for a method decorated with @Init + private EventInvoker<Object> init; + + // whether the component should be eagerly initialized when its scope starts + private boolean eagerInit; + + // an invoker for a method decorated with @Destroy + private EventInvoker<Object> destroy; + + // the scope of the implementation instance + private Scope scope; + + // whether the component is stateless + private boolean stateless; + + /** + * Creates a new context factory + * + * @param name the SCDL name of the component the context refers to + * @param ctr the implementation type constructor + * @param scope the scope of the component implementation type + */ + public JavaContextFactory(String name, Constructor<Object> ctr, Scope scope) { + assert (name != null) : "Name was null"; + assert (ctr != null) : "Constructor was null"; + this.name = name; + this.ctr = ctr; + this.scope = scope; + stateless = (scope == Scope.INSTANCE); + fields = JavaIntrospectionHelper.getAllFields(ctr.getDeclaringClass()); + methods = JavaIntrospectionHelper.getAllUniqueMethods(ctr.getDeclaringClass()); + } + + public String getName() { + return name; + } + + public Scope getScope() { + return scope; + } + + public AtomicContext createContext() throws ContextCreationException { + PojoObjectFactory<?> objectFactory = new PojoObjectFactory<Object>(ctr, null, setters); + return new JavaAtomicContext(name, objectFactory, eagerInit, init, destroy, stateless); + } + + public void addTargetWireFactory(String serviceName, TargetWireFactory factory) { + targetProxyFactories.put(serviceName, factory); + } + + public TargetWireFactory getTargetWireFactory(String serviceName) { + return targetProxyFactories.get(serviceName); + } + + public Map<String, TargetWireFactory> getTargetWireFactories() { + return targetProxyFactories; + } + + public void addProperty(String propertyName, Object value) { + setters.add(createPropertyInjector(propertyName, value)); + } + + public void addSourceWireFactory(String referenceName, SourceWireFactory factory) { + sourceProxyFactories.add(factory); + setters.add(createReferenceInjector(referenceName, factory, false)); + } + + public void addSourceWireFactories(String referenceName, Class referenceInterface, List<SourceWireFactory> factories, boolean multiplicity) { + sourceProxyFactories.addAll(factories); + setters.add(createReferenceInjector(referenceName, factories, multiplicity)); + } + + public List<SourceWireFactory> getSourceWireFactories() { + return sourceProxyFactories; + } + + public void setSetters(List<Injector> setters) { + this.setters = setters; + } + + public void setEagerInit(boolean val) { + eagerInit = val; + } + + public void setInitInvoker(EventInvoker<Object> invoker) { + init = invoker; + } + + public void setDestroyInvoker(EventInvoker<Object> invoker) { + destroy = invoker; + } + + public void prepare(CompositeContext parent) { + parentContext = parent; + } + + public CompositeContext getCurrentContext() { + return parentContext; + } + + /** + * Creates an <code>Injector</code> for component properties + */ + private Injector createPropertyInjector(String propertyName, Object value) + throws NoAccessorException { + Class type = value.getClass(); + + // There is no efficient way to do this + Method method = null; + Field field = JavaIntrospectionHelper.findClosestMatchingField(propertyName, type, fields); + if (field == null) { + // hack for TUSCANY-322 + for (Field current : fields) { + Property annot = current.getAnnotation(Property.class); + if (annot != null) { + if (propertyName.equals(annot.name())) { + field = current; + break; + } + } + } + method = JavaIntrospectionHelper.findClosestMatchingMethod(propertyName, new Class[]{type}, methods); + if (method == null) { + // hack for TUSCANY-322 + for (Method current : methods) { + Property annot = current.getAnnotation(Property.class); + if (annot != null) { + if (propertyName.equals(annot.name())) { + method = current; + break; + } + } + } + if (method == null) { + throw new NoAccessorException(propertyName); + } + } + } + Injector injector = null; + if (value instanceof DataObject) { + if (field != null) { + injector = new FieldInjector(field, new SDOObjectFactory((DataObject) value)); + } else { + injector = new MethodInjector(method, new SDOObjectFactory((DataObject) value)); + } + } else if (JavaIntrospectionHelper.isImmutable(type)) { + if (field != null) { + injector = new FieldInjector(field, new SingletonObjectFactory<Object>(value)); + } else { + injector = new MethodInjector(method, new SingletonObjectFactory<Object>(value)); + } + } + return injector; + + } + + /** + * Creates proxy factories that represent target(s) of a reference and an <code>Injector</code> + * responsible for injecting them into the reference + */ + private Injector createReferenceInjector(String refName, List<SourceWireFactory> wireFactories, boolean multiplicity) { + Class refClass = wireFactories.get(0).getBusinessInterface(); //reference.getPort().getServiceContract().getInterface(); + // iterate through the targets + List<ObjectFactory> objectFactories = new ArrayList<ObjectFactory>(); + for (SourceWireFactory wireFactory : wireFactories) { + objectFactories.add(new ProxyObjectFactory(wireFactory)); + } + return createInjector(refName, refClass, multiplicity, objectFactories, fields, methods); + + } + + private Injector createReferenceInjector(String refName, SourceWireFactory wireFactory, boolean multiplicity) { + Class refClass = wireFactory.getBusinessInterface();//reference.getPort().getServiceContract().getInterface(); + List<ObjectFactory> objectFactories = new ArrayList<ObjectFactory>(); + objectFactories.add(new ProxyObjectFactory(wireFactory)); + return createInjector(refName, refClass, multiplicity, objectFactories, fields, methods); + + } + + /** + * Creates an <code>Injector</code> for a set of object factories associated with a reference. + */ + private Injector createInjector(String refName, Class refClass, boolean multiplicity, List<ObjectFactory> objectFactories, + Set<Field> fields, Set<Method> methods) throws NoAccessorException, BuilderConfigException { + Field field; + Method method = null; + if (multiplicity) { + // since this is a multiplicity, we cannot match on business interface type, so scan through the fields, + // matching on name and List or Array + field = JavaIntrospectionHelper.findMultiplicityFieldByName(refName, fields); + if (field == null) { + // No fields found. Again, since this is a multiplicity, we cannot match on business interface type, so + // scan through the fields, matching on name and List or Array + method = JavaIntrospectionHelper.findMultiplicityMethodByName(refName, methods); + if (method == null) { + throw new NoAccessorException(refName); + } + } + Injector injector; + // for multiplicities, we need to inject the reference proxy or proxies using an object factory + // which first delegates to create the proxies and then returns them in the appropriate List or array type + if (field != null) { + if (field.getType().isArray()) { + injector = new FieldInjector(field, new ArrayMultiplicityObjectFactory(refClass, objectFactories)); + } else { + injector = new FieldInjector(field, new ListMultiplicityObjectFactory(objectFactories)); + } + } else { + if (method.getParameterTypes()[0].isArray()) { + injector = new MethodInjector(method, new ArrayMultiplicityObjectFactory(refClass, objectFactories)); + } else { + injector = new MethodInjector(method, new ListMultiplicityObjectFactory(objectFactories)); + } + } + return injector; + } else { + field = JavaIntrospectionHelper.findClosestMatchingField(refName, refClass, fields); + if (field == null) { + // hack for TUSCANY-300 + for (Field current : fields) { + Reference annot = current.getAnnotation(Reference.class); + if (annot != null) { + if (refName.equals(annot.name())) { + field = current; + break; + } + } + } + if (field == null) { + method = JavaIntrospectionHelper.findClosestMatchingMethod(refName, new Class[]{refClass}, methods); + if(method == null){ + // Fix for Tuscany-325 + method = JavaIntrospectionHelper.findClosestMatchingMethod("set"+refName.substring(0,1).toUpperCase()+ refName.substring(1), new Class[]{refClass}, methods); + } + if (method == null) { + // hack for TUSCANY-300 + for (Method current : methods) { + Reference annot = current.getAnnotation(Reference.class); + if (annot != null) { + if (refName.equals(annot.name())) { + method = current; + break; + } + } + } + if (method == null) { + throw new NoAccessorException(refName); + } + } + } + } + Injector injector; + if (field != null) { + injector = new FieldInjector(field, objectFactories.get(0)); + } else { + injector = new MethodInjector(method, objectFactories.get(0)); + } + return injector; + } + } + + +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/context/JavaAtomicContext.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/context/JavaAtomicContext.java new file mode 100644 index 0000000000..27581198aa --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/context/JavaAtomicContext.java @@ -0,0 +1,165 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.context; + +import org.apache.tuscany.core.builder.ObjectFactory; +import org.apache.tuscany.core.context.AtomicContext; +import org.apache.tuscany.core.context.ContextInitException; +import org.apache.tuscany.core.context.QualifiedName; +import org.apache.tuscany.core.context.TargetException; +import org.apache.tuscany.core.context.event.InstanceCreated; +import org.apache.tuscany.core.context.impl.AbstractContext; +import org.apache.tuscany.core.injection.EventInvoker; +import org.apache.tuscany.core.injection.ObjectCallbackException; +import org.apache.tuscany.core.injection.ObjectCreationException; + +/** + * Manages Java component implementation instances + * + * @version $Rev$ $Date$ + */ +public class JavaAtomicContext extends AbstractContext implements AtomicContext { + + private boolean eagerInit; + + private EventInvoker<Object> initInvoker; + + private EventInvoker<Object> destroyInvoker; + + private boolean stateless; + + // the cached target instance + private Object cachedTargetInstance; + + // creates a new implementation instance with injected references and properties + private ObjectFactory objectFactory; + + public JavaAtomicContext(String name, ObjectFactory objectFactory, boolean eagerInit, EventInvoker<Object> initInvoker, + EventInvoker<Object> destroyInvoker, boolean stateless) { + super(name); + assert (objectFactory != null) : "Object factory was null"; + if (eagerInit && initInvoker == null) { + ContextInitException e = new ContextInitException("No intialization method found for implementation"); + e.setIdentifier(getName()); + throw e; + } + this.objectFactory = objectFactory; + + this.eagerInit = eagerInit; + this.initInvoker = initInvoker; + this.destroyInvoker = destroyInvoker; + this.stateless = stateless; + } + + public void setName(String name) { + super.setName(name); + } + + protected int type; + + public int getType() { + return type; + } + + public void setType(int type) { + this.type = type; + } + + public void init() throws TargetException { + getInstance(null); + } + + public void destroy() throws TargetException { + if (cachedTargetInstance != null) { + if (destroyInvoker != null) { + try { + destroyInvoker.invokeEvent(cachedTargetInstance); + } catch (ObjectCallbackException e) { + TargetException te = new TargetException(e.getCause()); + te.setIdentifier(getName()); + throw te; + } + } + } + lifecycleState = STARTED; + } + + public synchronized Object getInstance(QualifiedName qName) throws TargetException { + //TODO implement returning of proxy and wire chain for service + if (cachedTargetInstance != null) { + return cachedTargetInstance; // already cached, just return + } + + if (getLifecycleState() == ERROR || getLifecycleState() == CONFIG_ERROR) { + return null; + } + synchronized (this) { + try { + Object instance = objectFactory.getInstance(); + // handle @Init + if (initInvoker != null) { + initInvoker.invokeEvent(instance); + } + publish(new InstanceCreated(this)); + lifecycleState = RUNNING; + if (stateless) { + return instance; + } else { + cachedTargetInstance = instance; // cache the instance + return cachedTargetInstance; + } + } catch (ObjectCreationException e) { + lifecycleState = ERROR; + TargetException te = new TargetException("Error creating component instance", e); + te.setIdentifier(getName()); + throw te; + } + } + + } + + public Object getTargetInstance() throws TargetException { + //TODO refactor when getInstance() returns a proxy + return getInstance(null); + } + + public boolean isEagerInit() { + return eagerInit; + } + + public boolean isDestroyable() { + return (destroyInvoker != null); + } + + public void start() throws ContextInitException { + if (getLifecycleState() != UNINITIALIZED && getLifecycleState() != STOPPED) { + throw new IllegalStateException("Context must be in UNINITIALIZED state [" + getLifecycleState() + "]"); + } + if (objectFactory == null) { + lifecycleState = ERROR; + ContextInitException e = new ContextInitException("Object factory not found"); + e.setIdentifier(getName()); + throw e; + } + lifecycleState = INITIALIZED; + } + + public void stop() { + lifecycleState = STOPPED; + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/invocation/AbstractJavaComponentInvoker.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/invocation/AbstractJavaComponentInvoker.java new file mode 100644 index 0000000000..33fa9238b6 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/invocation/AbstractJavaComponentInvoker.java @@ -0,0 +1,93 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.invocation; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.Set; + +import org.apache.tuscany.core.config.JavaIntrospectionHelper; +import org.apache.tuscany.core.context.TargetException; +import org.apache.tuscany.core.wire.Interceptor; +import org.apache.tuscany.core.wire.InvocationRuntimeException; +import org.apache.tuscany.core.wire.TargetInvoker; +import org.apache.tuscany.core.message.Message; + +/** + * Base class for dispatching to a Java based component implementation. Subclasses implement a strategy for resolving + * implementation instances. + * + * @version $Rev$ $Date$ + */ +public abstract class AbstractJavaComponentInvoker implements TargetInvoker { + + protected Method operation; + + public AbstractJavaComponentInvoker(Method operation) { + assert (operation != null) : "Operation method cannot be null"; + this.operation = operation; + } + + public Object invokeTarget(Object payload) throws InvocationTargetException { + try { + Object instance = getInstance(); + if (!operation.getDeclaringClass().isInstance(instance)) { + Set<Method> methods = JavaIntrospectionHelper.getAllUniqueMethods(instance.getClass()); + Method newOperation = JavaIntrospectionHelper.findClosestMatchingMethod(operation.getName(), operation + .getParameterTypes(), methods); + if (newOperation != null) + operation = newOperation; + } + if (payload != null && !payload.getClass().isArray()) { + return operation.invoke(instance, payload); + } else { + return operation.invoke(instance, (Object[]) payload); + } + } catch (IllegalAccessException e) { + throw new InvocationRuntimeException(e); + } + } + + public Message invoke(Message msg) { + try { + Object resp = invokeTarget(msg.getBody()); + msg.setBody(resp); + } catch (InvocationTargetException e) { + msg.setBody(e.getCause()); + } catch (Throwable e) { + msg.setBody(e); + } + return msg; + } + + protected abstract Object getInstance() throws TargetException; + + public void setNext(Interceptor next) { + throw new IllegalStateException("This interceptor must be the last interceptor in an interceptor chain"); + } + + @Override + public Object clone() throws CloneNotSupportedException { + try { + AbstractJavaComponentInvoker clone = (AbstractJavaComponentInvoker) super.clone(); + clone.operation = this.operation; + return clone; + } catch (CloneNotSupportedException e) { + return null; // will not happen + } + } +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/invocation/ScopedJavaComponentInvoker.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/invocation/ScopedJavaComponentInvoker.java new file mode 100644 index 0000000000..85d72b4b0d --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/invocation/ScopedJavaComponentInvoker.java @@ -0,0 +1,89 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.invocation; + +import org.apache.tuscany.core.context.QualifiedName; +import org.apache.tuscany.core.context.ScopeContext; +import org.apache.tuscany.core.context.TargetException; + +import java.lang.reflect.Method; + +/** + * Uses a scope container to resolve an implementation instance based on the current thread context + * + * @version $Rev$ $Date$ + */ +public class ScopedJavaComponentInvoker extends AbstractJavaComponentInvoker { + + private ScopeContext container; + + private QualifiedName name; + + private Object target; + + public boolean cacheable; + + + /** + * Creates a new invoker + * + * @param serviceName the name of the component/service pair to invoke + * @param operation the operation the invoker is associated with + * @param scopeContext the scope context the component is resolved in + * @param cacheable Sets whether the target service instance may be cached by the invoker. This is a possible optimization + * when a wire is configured for a "down-scope" reference, i.e. a reference from a source of a shorter + * lifetime to a source of greater lifetime. + */ + public ScopedJavaComponentInvoker(QualifiedName serviceName, Method operation, ScopeContext scopeContext, boolean cacheable) { + super(operation); + assert (serviceName != null) : "No service name specified"; + assert (scopeContext != null) : "No scope scopeContext specified"; + name = serviceName; + this.container = scopeContext; + this.cacheable = cacheable; + } + + /** + * Returns whether the target is cacheable. + */ + public boolean isCacheable() { + return cacheable; + } + + /** + * Resolves the target service instance or returns a cached one + */ + protected Object getInstance() throws TargetException { + if (!cacheable) { + return container.getInstance(name); + } else { + if (target == null) { + target = container.getInstance(name); + } + return target; + } + } + + public Object clone() throws CloneNotSupportedException { + ScopedJavaComponentInvoker invoker = (ScopedJavaComponentInvoker) super.clone(); + invoker.target = null; + invoker.cacheable = this.cacheable; + invoker.container = this.container; + invoker.name = this.name; + return invoker; + } +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/invocation/StaticJavaComponentTargetInvoker.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/invocation/StaticJavaComponentTargetInvoker.java new file mode 100644 index 0000000000..dd757137cf --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/invocation/StaticJavaComponentTargetInvoker.java @@ -0,0 +1,50 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.invocation; + +import java.lang.reflect.Method; + +/** + * Caches component instances that do not need to be resolved for every wire, e.g. an wire originating from + * a lesser scope intended for a target with a wider scope + * + * @version $Rev$ $Date$ + */ +public class StaticJavaComponentTargetInvoker extends AbstractJavaComponentInvoker { + + private Object instance; + + public StaticJavaComponentTargetInvoker(Method operation, Object instance) { + super(operation); + assert (instance != null) : "Instance cannot be null"; + this.instance = instance; + } + + protected Object getInstance() { + return instance; + } + + public boolean isCacheable() { + return true; + } + + public Object clone() throws CloneNotSupportedException { + StaticJavaComponentTargetInvoker invoker = (StaticJavaComponentTargetInvoker) super.clone(); + invoker.instance = null; + return invoker; + } +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/loader/JavaImplementationLoader.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/loader/JavaImplementationLoader.java new file mode 100644 index 0000000000..db3dd07c98 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/loader/JavaImplementationLoader.java @@ -0,0 +1,165 @@ +/** + * + * Copyright 2005 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.loader; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import javax.xml.namespace.QName; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.common.resource.ResourceLoader; +import org.apache.tuscany.container.java.assembly.JavaAssemblyFactory; +import org.apache.tuscany.container.java.assembly.JavaImplementation; +import org.apache.tuscany.core.config.ComponentTypeIntrospector; +import org.apache.tuscany.core.config.ConfigurationLoadException; +import org.apache.tuscany.core.config.InvalidRootElementException; +import org.apache.tuscany.core.config.JavaIntrospectionHelper; +import org.apache.tuscany.core.config.SidefileLoadException; +import org.apache.tuscany.core.config.processor.ProcessorUtils; +import org.apache.tuscany.core.loader.LoaderContext; +import org.apache.tuscany.core.loader.StAXElementLoader; +import org.apache.tuscany.core.loader.StAXLoaderRegistry; +import org.apache.tuscany.core.loader.assembly.AssemblyConstants; +import org.apache.tuscany.core.system.annotation.Autowire; +import org.apache.tuscany.model.assembly.ComponentType; +import org.osoa.sca.annotations.Destroy; +import org.osoa.sca.annotations.Init; +import org.osoa.sca.annotations.Scope; + +/** + * @version $Rev$ $Date$ + */ +@Scope("MODULE") +public class JavaImplementationLoader implements StAXElementLoader<JavaImplementation> { + public static final QName IMPLEMENTATION_JAVA = new QName("http://www.osoa.org/xmlns/sca/0.9", "implementation.java"); + + private StAXLoaderRegistry registry; + private XMLInputFactory xmlFactory; + + private JavaAssemblyFactory factory; + private ComponentTypeIntrospector introspector; + + public JavaImplementationLoader() { + // todo make this a reference to a system service + xmlFactory = XMLInputFactory.newInstance(); + } + + @Autowire + public void setRegistry(StAXLoaderRegistry registry) { + this.registry = registry; + } + + @Autowire + public void setFactory(JavaAssemblyFactory factory) { + this.factory = factory; + //FIXME JFM HACK + introspector = ProcessorUtils.createCoreIntrospector(factory); + } + + @Init(eager = true) + public void start() { + registry.registerLoader(IMPLEMENTATION_JAVA, this); + } + + @Destroy + public void stop() { + registry.unregisterLoader(IMPLEMENTATION_JAVA, this); + } + + public JavaImplementation load(XMLStreamReader reader, LoaderContext loaderContext) throws XMLStreamException, ConfigurationLoadException { + JavaImplementation javaImpl = factory.createJavaImplementation(); + String typeName = reader.getAttributeValue(null, "class"); + Class<?> implementationClass = getImplementationClass(loaderContext.getResourceLoader(), typeName); + javaImpl.setImplementationClass(implementationClass); + javaImpl.setComponentType(loadComponentType(loaderContext, implementationClass)); + return javaImpl; + } + + protected Class<?> getImplementationClass(ResourceLoader resourceLoader, String typeName) throws ConfigurationLoadException { + ClassLoader oldCL = Thread.currentThread().getContextClassLoader(); + try { + // set TCCL in case the application code needs it + Thread.currentThread().setContextClassLoader(resourceLoader.getClassLoader()); + return resourceLoader.loadClass(typeName); + } catch (ClassNotFoundException e) { + throw new ConfigurationLoadException(e.getMessage(), e); + } finally { + Thread.currentThread().setContextClassLoader(oldCL); + } + } + + protected ComponentType loadComponentType(LoaderContext loaderContext, Class<?> implClass) throws ConfigurationLoadException, XMLStreamException { + String baseName = JavaIntrospectionHelper.getBaseName(implClass); + URL sidefile = implClass.getResource(baseName + ".componentType"); + if (sidefile == null) { + return loadComponentTypeByIntrospection(implClass); + } else { + return loadComponentTypeFromSidefile(sidefile, loaderContext); + } + } + + protected ComponentType loadComponentTypeByIntrospection(Class<?> implClass) throws ConfigurationLoadException { + return introspector.introspect(implClass); + } + + protected ComponentType loadComponentTypeFromSidefile(URL sidefile, LoaderContext loaderContext) throws SidefileLoadException { + try { + XMLStreamReader reader; + InputStream is; + is = sidefile.openStream(); + try { + reader = xmlFactory.createXMLStreamReader(is); + try { + reader.nextTag(); + if (!AssemblyConstants.COMPONENT_TYPE.equals(reader.getName())) { + InvalidRootElementException e = new InvalidRootElementException(AssemblyConstants.COMPONENT_TYPE, reader.getName()); + e.setResourceURI(sidefile.toString()); + throw e; + } + return (ComponentType) registry.load(reader, loaderContext); + } finally { + try { + reader.close(); + } catch (XMLStreamException e) { + // ignore + } + } + } finally { + try { + is.close(); + } catch (IOException e) { + // ignore + } + } + } catch (IOException e) { + SidefileLoadException sfe = new SidefileLoadException(e.getMessage()); + sfe.setResourceURI(sidefile.toString()); + throw sfe; + } catch (XMLStreamException e) { + SidefileLoadException sfe = new SidefileLoadException(e.getMessage()); + sfe.setResourceURI(sidefile.toString()); + throw sfe; + } catch (ConfigurationLoadException e) { + SidefileLoadException sfe = new SidefileLoadException(e.getMessage()); + sfe.setResourceURI(sidefile.toString()); + throw sfe; + } + } +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/main/resources/META-INF/LICENSE.txt b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/main/resources/META-INF/LICENSE.txt new file mode 100644 index 0000000000..25d78feeac --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/main/resources/META-INF/LICENSE.txt @@ -0,0 +1,1277 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + 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. + + +APACHE TUSCANY SUBCOMPONENTS: + +The Apache Tuscany distribution includes a number of subcomponents with +separate copyright notices and license terms. Your use of the source +code for the these subcomponents is subject to the terms and +conditions of the following licenses. + +=============================================================================== + +For the Eclipse Modeling Framework component and the Celtix binding: + +Eclipse Public License - v 1.0 + +THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE +PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF +THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT. + +1. DEFINITIONS + +"Contribution" means: + +a) in the case of the initial Contributor, the initial code and +documentation distributed under this Agreement, and +b) in the case of each subsequent Contributor: + +i) changes to the Program, and + +ii) additions to the Program; + +where such changes and/or additions to the Program originate from and +are distributed by that particular Contributor. A Contribution +'originates' from a Contributor if it was added to the Program by such +Contributor itself or anyone acting on such Contributor's behalf. +Contributions do not include additions to the Program which: (i) are +separate modules of software distributed in conjunction with the +Program under their own license agreement, and (ii) are not derivative +works of the Program. + +"Contributor" means any person or entity that distributes the Program. + +"Licensed Patents " mean patent claims licensable by a Contributor +which are necessarily infringed by the use or sale of its Contribution +alone or when combined with the Program. + +"Program" means the Contributions distributed in accordance with this +Agreement. + +"Recipient" means anyone who receives the Program under this +Agreement, including all Contributors. + +2. GRANT OF RIGHTS + +a) Subject to the terms of this Agreement, each Contributor hereby +grants Recipient a non-exclusive, worldwide, royalty-free copyright +license to reproduce, prepare derivative works of, publicly display, +publicly perform, distribute and sublicense the Contribution of such +Contributor, if any, and such derivative works, in source code and +object code form. + +b) Subject to the terms of this Agreement, each Contributor hereby +grants Recipient a non-exclusive, worldwide, royalty-free patent +license under Licensed Patents to make, use, sell, offer to sell, +import and otherwise transfer the Contribution of such Contributor, if +any, in source code and object code form. This patent license shall +apply to the combination of the Contribution and the Program if, at +the time the Contribution is added by the Contributor, such addition +of the Contribution causes such combination to be covered by the +Licensed Patents. The patent license shall not apply to any other +combinations which include the Contribution. No hardware per se is +licensed hereunder. + +c) Recipient understands that although each Contributor grants the +licenses to its Contributions set forth herein, no assurances are +provided by any Contributor that the Program does not infringe the +patent or other intellectual property rights of any other entity. Each +Contributor disclaims any liability to Recipient for claims brought by +any other entity based on infringement of intellectual property rights +or otherwise. As a condition to exercising the rights and licenses +granted hereunder, each Recipient hereby assumes sole responsibility +to secure any other intellectual property rights needed, if any. For +example, if a third party patent license is required to allow +Recipient to distribute the Program, it is Recipient's responsibility +to acquire that license before distributing the Program. + +d) Each Contributor represents that to its knowledge it has sufficient +copyright rights in its Contribution, if any, to grant the copyright +license set forth in this Agreement. + +3. REQUIREMENTS + +A Contributor may choose to distribute the Program in object code form +under its own license agreement, provided that: + +a) it complies with the terms and conditions of this Agreement; and + +b) its license agreement: + +i) effectively disclaims on behalf of all Contributors all warranties +and conditions, express and implied, including warranties or +conditions of title and non-infringement, and implied warranties or +conditions of merchantability and fitness for a particular purpose; + +ii) effectively excludes on behalf of all Contributors all liability +for damages, including direct, indirect, special, incidental and +consequential damages, such as lost profits; + +iii) states that any provisions which differ from this Agreement are +offered by that Contributor alone and not by any other party; and + +iv) states that source code for the Program is available from such +Contributor, and informs licensees how to obtain it in a reasonable +manner on or through a medium customarily used for software exchange. + +When the Program is made available in source code form: + +a) it must be made available under this Agreement; and + +b) a copy of this Agreement must be included with each copy of the +Program. + +Contributors may not remove or alter any copyright notices contained +within the Program. + +Each Contributor must identify itself as the originator of its +Contribution, if any, in a manner that reasonably allows subsequent +Recipients to identify the originator of the Contribution. + +4. COMMERCIAL DISTRIBUTION + +Commercial distributors of software may accept certain +responsibilities with respect to end users, business partners and the +like. While this license is intended to facilitate the commercial use +of the Program, the Contributor who includes the Program in a +commercial product offering should do so in a manner which does not +create potential liability for other Contributors. Therefore, if a +Contributor includes the Program in a commercial product offering, +such Contributor ("Commercial Contributor") hereby agrees to defend +and indemnify every other Contributor ("Indemnified Contributor") +against any losses, damages and costs (collectively "Losses") arising +from claims, lawsuits and other legal actions brought by a third party +against the Indemnified Contributor to the extent caused by the acts +or omissions of such Commercial Contributor in connection with its +distribution of the Program in a commercial product offering. The +obligations in this section do not apply to any claims or Losses +relating to any actual or alleged intellectual property infringement. +In order to qualify, an Indemnified Contributor must: a) promptly +notify the Commercial Contributor in writing of such claim, and b) +allow the Commercial Contributor to control, and cooperate with the +Commercial Contributor in, the defense and any related settlement +negotiations. The Indemnified Contributor may participate in any such +claim at its own expense. + +For example, a Contributor might include the Program in a commercial +product offering, Product X. That Contributor is then a Commercial +Contributor. If that Commercial Contributor then makes performance +claims, or offers warranties related to Product X, those performance +claims and warranties are such Commercial Contributor's responsibility +alone. Under this section, the Commercial Contributor would have to +defend claims against the other Contributors related to those +performance claims and warranties, and if a court requires any other +Contributor to pay any damages as a result, the Commercial Contributor +must pay those damages. + +5. NO WARRANTY + +EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS +PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY +WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY +OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely +responsible for determining the appropriateness of using and +distributing the Program and assumes all risks associated with its +exercise of rights under this Agreement , including but not limited to +the risks and costs of program errors, compliance with applicable +laws, damage to or loss of data, programs or equipment, and +unavailability or interruption of operations. + +6. DISCLAIMER OF LIABILITY + +EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR +ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING +WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR +DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED +HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + +7. GENERAL + +If any provision of this Agreement is invalid or unenforceable under +applicable law, it shall not affect the validity or enforceability of +the remainder of the terms of this Agreement, and without further +action by the parties hereto, such provision shall be reformed to the +minimum extent necessary to make such provision valid and enforceable. + +If Recipient institutes patent litigation against any entity +(including a cross-claim or counterclaim in a lawsuit) alleging that +the Program itself (excluding combinations of the Program with other +software or hardware) infringes such Recipient's patent(s), then such +Recipient's rights granted under Section 2(b) shall terminate as of +the date such litigation is filed. + +All Recipient's rights under this Agreement shall terminate if it +fails to comply with any of the material terms or conditions of this +Agreement and does not cure such failure in a reasonable period of +time after becoming aware of such noncompliance. If all Recipient's +rights under this Agreement terminate, Recipient agrees to cease use +and distribution of the Program as soon as reasonably practicable. +However, Recipient's obligations under this Agreement and any licenses +granted by Recipient relating to the Program shall continue and +survive. + +Everyone is permitted to copy and distribute copies of this Agreement, +but in order to avoid inconsistency the Agreement is copyrighted and +may only be modified in the following manner. The Agreement Steward +reserves the right to publish new versions (including revisions) of +this Agreement from time to time. No one other than the Agreement +Steward has the right to modify this Agreement. The Eclipse Foundation +is the initial Agreement Steward. The Eclipse Foundation may assign +the responsibility to serve as the Agreement Steward to a suitable +separate entity. Each new version of the Agreement will be given a +distinguishing version number. The Program (including Contributions) +may always be distributed subject to the version of the Agreement +under which it was received. In addition, after a new version of the +Agreement is published, Contributor may elect to distribute the +Program (including its Contributions) under the new version. Except as +expressly stated in Sections 2(a) and 2(b) above, Recipient receives +no rights or licenses to the intellectual property of any Contributor +under this Agreement, whether expressly, by implication, estoppel or +otherwise. All rights in the Program not expressly granted under this +Agreement are reserved. + +This Agreement is governed by the laws of the State of New York and +the intellectual property laws of the United States of America. No +party to this Agreement will bring a legal action under this Agreement +more than one year after the cause of action arose. Each party waives +its rights to a jury trial in any resulting litigation. + +=============================================================================== + +For the Rhino JavaScript container component: + +Mozilla Public License 1.1 (MPL 1.1) + +1. Definitions. + + 1.0.1. "Commercial Use" means distribution or otherwise making the +Covered Code available to a third party. + + 1.1. "Contributor" means each entity that creates or contributes to +the creation of Modifications. + + 1.2. "Contributor Version" means the combination of the Original Code, +prior Modifications used by a Contributor, and the Modifications made by that +particular Contributor. + + 1.3. "Covered Code" means the Original Code or Modifications or the +combination of the Original Code and Modifications, in each case including +portions thereof. + + 1.4. "Electronic Distribution Mechanism" means a mechanism generally +accepted in the software development community for the electronic transfer of +data. + + 1.5. "Executable" means Covered Code in any form other than Source +Code. + + 1.6. "Initial Developer" means the individual or entity identified as +the Initial Developer in the Source Code notice required by Exhibit A. + + 1.7. "Larger Work" means a work which combines Covered Code or +portions thereof with code not governed by the terms of this License. + + 1.8. "License" means this document. + + 1.8.1. "Licensable" means having the right to grant, to the maximum +extent possible, whether at the time of the initial grant or subsequently +acquired, any and all of the rights conveyed herein. + + 1.9. "Modifications" means any addition to or deletion from the +substance or structure of either the Original Code or any previous +Modifications. When Covered Code is released as a series of files, a +Modification is: + A. Any addition to or deletion from the contents of a file +containing Original Code or previous Modifications. + + B. Any new file that contains any part of the Original Code or +previous Modifications. + + 1.10. "Original Code" means Source Code of computer software code +which is described in the Source Code notice required by Exhibit A as Original +Code, and which, at the time of its release under this License is not already +Covered Code governed by this License. + + 1.10.1. "Patent Claims" means any patent claim(s), now owned or +hereafter acquired, including without limitation, method, process, and +apparatus claims, in any patent Licensable by grantor. + + 1.11. "Source Code" means the preferred form of the Covered Code for +making modifications to it, including all modules it contains, plus any +associated interface definition files, scripts used to control compilation and +installation of an Executable, or source code differential comparisons against +either the Original Code or another well known, available Covered Code of the +Contributor's choice. The Source Code can be in a compressed or archival form, +provided the appropriate decompression or de-archiving software is widely +available for no charge. + + 1.12. "You" (or "Your") means an individual or a legal entity +exercising rights under, and complying with all of the terms of, this License +or a future version of this License issued under Section 6.1. For legal +entities, "You" includes any entity which controls, is controlled by, or is +under common control with You. For purposes of this definition, "control" +means (a) the power, direct or indirect, to cause the direction or management +of such entity, whether by contract or otherwise, or (b) ownership of more +than fifty percent (50%) of the outstanding shares or beneficial ownership of +such entity. + +2. Source Code License. + + 2.1. The Initial Developer Grant. + The Initial Developer hereby grants You a world-wide, royalty-free, +non-exclusive license, subject to third party intellectual property claims: + (a) under intellectual property rights (other than patent or +trademark) Licensable by Initial Developer to use, reproduce, modify, display, +perform, sublicense and distribute the Original Code (or portions thereof) +with or without Modifications, and/or as part of a Larger Work; and + + (b) under Patents Claims infringed by the making, using or selling +of Original Code, to make, have made, use, practice, sell, and offer for sale, +and/or otherwise dispose of the Original Code (or portions thereof). + (c) the licenses granted in this Section 2.1(a) and +(b) are effective on the date Initial Developer first distributes Original +Code under the terms of this License. + + (d) Notwithstanding Section 2.1(b) above, no patent license is +granted: 1) for code that You delete from the Original Code; 2) separate from +the Original Code; or 3) for infringements caused by: i) the modification of +the Original Code or ii) the combination of the Original Code with other +software or devices. + + 2.2. Contributor Grant. + Subject to third party intellectual property claims, each Contributor +hereby grants You a world-wide, royalty-free, non-exclusive license + + (a) under intellectual property rights (other than patent or +trademark) Licensable by Contributor, to use, reproduce, modify, display, +perform, sublicense and distribute the Modifications created by such +Contributor (or portions thereof) either on an unmodified basis, with other +Modifications, as Covered Code and/or as part of a Larger Work; and + + (b) under Patent Claims infringed by the making, using, or selling +of Modifications made by that Contributor either alone and/or in combination +with its Contributor Version (or portions of such combination), to make, use, +sell, offer for sale, have made, and/or otherwise dispose of: 1) Modifications +made by that Contributor (or portions thereof); and 2) the combination of +Modifications made by that Contributor with its Contributor Version (or +portions of such combination). + + (c) the licenses granted in Sections 2.2(a) and 2.2(b) are +effective on the date Contributor first makes Commercial Use of the Covered +Code. + + (d) Notwithstanding Section 2.2(b) above, no patent license is +granted: 1) for any code that Contributor has deleted from the Contributor +Version; 2) separate from the Contributor Version; 3) for infringements +caused by: i) third party modifications of Contributor Version or ii) the +combination of Modifications made by that Contributor with other software +(except as part of the Contributor Version) or other devices; or 4) under +Patent Claims infringed by Covered Code in the absence of Modifications made +by that Contributor. + + +3. Distribution Obligations. + + 3.1. Application of License. + The Modifications which You create or to which You contribute are +governed by the terms of this License, including without limitation Section +2.2. The Source Code version of Covered Code may be distributed only under the +terms of this License or a future version of this License released under +Section 6.1, and You must include a copy of this License with every copy of +the Source Code You distribute. You may not offer or impose any terms on any +Source Code version that alters or restricts the applicable version of this +License or the recipients' rights hereunder. However, You may include an +additional document offering the additional rights described in Section 3.5. + + 3.2. Availability of Source Code. + Any Modification which You create or to which You contribute must be +made available in Source Code form under the terms of this License either on +the same media as an Executable version or via an accepted Electronic +Distribution Mechanism to anyone to whom you made an Executable version +available; and if made available via Electronic Distribution Mechanism, must +remain available for at least twelve (12) months after the date it initially +became available, or at least six (6) months after a subsequent version of +that particular Modification has been made available to such recipients. You +are responsible for ensuring that the Source Code version remains available +even if the Electronic Distribution Mechanism is maintained by a third party. + + 3.3. Description of Modifications. + You must cause all Covered Code to which You contribute to contain a +file documenting the changes You made to create that Covered Code and the date +of any change. You must include a prominent statement that the Modification is +derived, directly or indirectly, from Original Code provided by the Initial +Developer and including the name of the Initial Developer in (a) the Source +Code, and (b) in any notice in an Executable version or related documentation +in which You describe the origin or ownership of the Covered Code. + + 3.4. Intellectual Property Matters + (a) Third Party Claims. + If Contributor has knowledge that a license under a third party's +intellectual property rights is required to exercise the rights granted by +such Contributor under Sections 2.1 or 2.2, Contributor must include a text +file with the Source Code distribution titled "LEGAL" which describes the +claim and the party making the claim in sufficient detail that a recipient +will know whom to contact. If Contributor obtains such knowledge after the +Modification is made available as described in Section 3.2, Contributor shall +promptly modify the LEGAL file in all copies Contributor makes available +thereafter and shall take other steps (such as notifying appropriate mailing +lists or newsgroups) reasonably calculated to inform those who received the +Covered Code that new knowledge has been obtained. + + (b) Contributor APIs. + If Contributor's Modifications include an application programming +interface and Contributor has knowledge of patent licenses which are +reasonably necessary to implement that API, Contributor must also include this +information in the LEGAL file. + + (c) Representations. + Contributor represents that, except as disclosed pursuant to +Section 3.4(a) above, Contributor believes that Contributor's Modifications +are Contributor's original creation(s) and/or Contributor has sufficient +rights to grant the rights conveyed by this License. + + + 3.5. Required Notices. + You must duplicate the notice in Exhibit A in each file of the Source +Code. If it is not possible to put such notice in a particular Source Code +file due to its structure, then You must include such notice in a location +(such as a relevant directory) where a user would be likely to look for such a +notice. If You created one or more Modification(s) You may add your name as a +Contributor to the notice described in Exhibit A. You must also duplicate +this License in any documentation for the Source Code where You describe +recipients' rights or ownership rights relating to Covered Code. You may +choose to offer, and to charge a fee for, warranty, support, indemnity or +liability obligations to one or more recipients of Covered Code. However, You +may do so only on Your own behalf, and not on behalf of the Initial Developer +or any Contributor. You must make it absolutely clear than any such warranty, +support, indemnity or liability obligation is offered by You alone, and You +hereby agree to indemnify the Initial Developer and every Contributor for any +liability incurred by the Initial Developer or such Contributor as a result of +warranty, support, indemnity or liability terms You offer. + + 3.6. Distribution of Executable Versions. + You may distribute Covered Code in Executable form only if the +requirements of Section 3.1-3.5 have been met for that Covered Code, and if +You include a notice stating that the Source Code version of the Covered Code +is available under the terms of this License, including a description of how +and where You have fulfilled the obligations of Section 3.2. The notice must +be conspicuously included in any notice in an Executable version, related +documentation or collateral in which You describe recipients' rights relating +to the Covered Code. You may distribute the Executable version of Covered Code +or ownership rights under a license of Your choice, which may contain terms +different from this License, provided that You are in compliance with the +terms of this License and that the license for the Executable version does not +attempt to limit or alter the recipient's rights in the Source Code version +from the rights set forth in this License. If You distribute the Executable +version under a different license You must make it absolutely clear that any +terms which differ from this License are offered by You alone, not by the +Initial Developer or any Contributor. You hereby agree to indemnify the +Initial Developer and every Contributor for any liability incurred by the +Initial Developer or such Contributor as a result of any such terms You offer. + + 3.7. Larger Works. + You may create a Larger Work by combining Covered Code with other code +not governed by the terms of this License and distribute the Larger Work as a +single product. In such a case, You must make sure the requirements of this +License are fulfilled for the Covered Code. + +4. Inability to Comply Due to Statute or Regulation. + + If it is impossible for You to comply with any of the terms of this +License with respect to some or all of the Covered Code due to statute, +judicial order, or regulation then You must: (a) comply with the terms of this +License to the maximum extent possible; and (b) describe the limitations and +the code they affect. Such description must be included in the LEGAL file +described in Section 3.4 and must be included with all distributions of the +Source Code. Except to the extent prohibited by statute or regulation, such +description must be sufficiently detailed for a recipient of ordinary skill to +be able to understand it. + +5. Application of this License. + + This License applies to code to which the Initial Developer has attached +the notice in Exhibit A and to related Covered Code. + +6. Versions of the License. + + 6.1. New Versions. + Netscape Communications Corporation ("Netscape") may publish revised +and/or new versions of the License from time to time. Each version will be +given a distinguishing version number. + + 6.2. Effect of New Versions. + Once Covered Code has been published under a particular version of the +License, You may always continue to use it under the terms of that version. +You may also choose to use such Covered Code under the terms of any subsequent +version of the License published by Netscape. No one other than Netscape has +the right to modify the terms applicable to Covered Code created under this +License. + + 6.3. Derivative Works. + If You create or use a modified version of this License (which you may +only do in order to apply it to code which is not already Covered Code +governed by this License), You must (a) rename Your license so that the +phrases "Mozilla", "MOZILLAPL", "MOZPL", "Netscape", "MPL", "NPL" or +any confusingly similar phrase do not appear in your license (except to note +that your license differs from this License) and (b) otherwise make it clear +that Your version of the license contains terms which differ from the Mozilla +Public License and Netscape Public License. (Filling in the name of the +Initial Developer, Original Code or Contributor in the notice described in +Exhibit A shall not of themselves be deemed to be modifications of this +License.) + +7. DISCLAIMER OF WARRANTY. + + COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, +WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT +LIMITATION, WARRANTIES THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, +FIT FOR A PARTICULAR PURPOSE OR NON-INFRINGING. THE ENTIRE RISK AS TO THE +QUALITY AND PERFORMANCE OF THE COVERED CODE IS WITH YOU. SHOULD ANY COVERED +CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT THE INITIAL DEVELOPER OR ANY +OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY SERVICING, REPAIR OR +CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS +LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER THIS +DISCLAIMER. + +8. TERMINATION. + + 8.1. This License and the rights granted hereunder will terminate +automatically if You fail to comply with terms herein and fail to cure such +breach within 30 days of becoming aware of the breach. All sublicenses to the +Covered Code which are properly granted shall survive any termination of this +License. Provisions which, by their nature, must remain in effect beyond the +termination of this License shall survive. + + 8.2. If You initiate litigation by asserting a patent infringement +claim (excluding declatory judgment actions) against Initial Developer or a +Contributor (the Initial Developer or Contributor against whom You file such +action is referred to as "Participant") alleging that: + + (a) such Participant's Contributor Version directly or indirectly +infringes any patent, then any and all rights granted by such Participant to +You under Sections 2.1 and/or 2.2 of this License shall, upon 60 days notice +from Participant terminate prospectively, unless if within 60 days after +receipt of notice You either: (i) agree in writing to pay Participant a +mutually agreeable reasonable royalty for Your past and future use of +Modifications made by such Participant, or (ii) withdraw Your litigation claim +with respect to the Contributor Version against such Participant. If within +60 days of notice, a reasonable royalty and payment arrangement are not +mutually agreed upon in writing by the parties or the litigation claim is not +withdrawn, the rights granted by Participant to You under Sections 2.1 and/or +2.2 automatically terminate at the expiration of the 60 day notice period +specified above. + + (b) any software, hardware, or device, other than such Participant's +Contributor Version, directly or indirectly infringes any patent, then any +rights granted to You by such Participant under Sections 2.1(b) and 2.2(b) are +revoked effective as of the date You first made, used, sold, distributed, or +had made, Modifications made by that Participant. + + 8.3. If You assert a patent infringement claim against Participant +alleging that such Participant's Contributor Version directly or indirectly +infringes any patent where such claim is resolved (such as by license or +settlement) prior to the initiation of patent infringement litigation, then +the reasonable value of the licenses granted by such Participant under +Sections 2.1 or 2.2 shall be taken into account in determining the amount or +value of any payment or license. + + 8.4. In the event of termination under Sections 8.1 or 8.2 above, all +end user license agreements (excluding distributors and resellers) which have +been validly granted by You or any distributor hereunder prior to termination +shall survive termination. + +9. LIMITATION OF LIABILITY. + + UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, WHETHER TORT +(INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL YOU, THE INITIAL +DEVELOPER, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF COVERED CODE, OR ANY +SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO ANY PERSON FOR ANY INDIRECT, +SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, +WITHOUT LIMITATION, DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER +FAILURE OR MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, +EVEN IF SUCH PARTY SHALL HAVE BEEN INFORMED OF THE POSSIBILITY OF SUCH +DAMAGES. THIS LIMITATION OF LIABILITY SHALL NOT APPLY TO LIABILITY FOR DEATH +OR PERSONAL INJURY RESULTING FROM SUCH PARTY'S NEGLIGENCE TO THE EXTENT +APPLICABLE LAW PROHIBITS SUCH LIMITATION. SOME JURISDICTIONS DO NOT ALLOW THE +EXCLUSION OR LIMITATION OF INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO THIS +EXCLUSION AND LIMITATION MAY NOT APPLY TO YOU. + +10. U.S. GOVERNMENT END USERS. + + The Covered Code is a "commercial item," as that term is defined in 48 +C.F.R. 2.101 (Oct. 1995), consisting of "commercial computer software" and +"commercial computer software documentation," as such terms are used in 48 +C.F.R. 12.212 (Sept. 1995). Consistent with 48 C.F.R. 12.212 and 48 C.F.R. +227.7202-1 through 227.7202-4 (June 1995), all U.S. Government End Users +acquire Covered Code with only those rights set forth herein. + +11. MISCELLANEOUS. + + This License represents the complete agreement concerning subject matter +hereof. If any provision of this License is held to be unenforceable, such +provision shall be reformed only to the extent necessary to make it +enforceable. This License shall be governed by California law provisions +(except to the extent applicable law, if any, provides otherwise), excluding +its conflict-of-law provisions. With respect to disputes in which at least one +party is a citizen of, or an entity chartered or registered to do business in +the United States of America, any litigation relating to this License shall be +subject to the jurisdiction of the Federal Courts of the Northern District of +California, with venue lying in Santa Clara County, California, with the +losing party responsible for costs, including without limitation, court costs +and reasonable attorneys' fees and expenses. The application of the United +Nations Convention on Contracts for the International Sale of Goods is +expressly excluded. Any law or regulation which provides that the language of +a contract shall be construed against the drafter shall not apply to this +License. + +12. RESPONSIBILITY FOR CLAIMS. + + As between Initial Developer and the Contributors, each party is +responsible for claims and damages arising, directly or indirectly, out of its +utilization of rights under this License and You agree to work with Initial +Developer and Contributors to distribute such responsibility on an equitable +basis. Nothing herein is intended or shall be deemed to constitute any +admission of liability. + +13. MULTIPLE-LICENSED CODE. + + Initial Developer may designate portions of the Covered Code as +Multiple-Licensed. Multiple-Licensed means that the Initial Developer permits +you to utilize portions of the Covered Code under Your choice of the MPL or +the alternative licenses, if any, specified by the Initial Developer in the +file described in Exhibit A. + + +EXHIBIT A -Mozilla Public License. + + ``The contents of this file are subject to the Mozilla Public License +Version 1.1 (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.mozilla.org/MPL/ + + Software distributed under the License is distributed on an "AS IS" +basis, WITHOUT WARRANTY OF + ANY KIND, either express or implied. See the License for the specific +language governing rights and + limitations under the License. + + The Original Code is ______________________________________. + + The Initial Developer of the Original Code is ________________________. +Portions created by + ______________________ are Copyright (C) ______ +_______________________. All Rights + Reserved. + + Contributor(s): ______________________________________. + + Alternatively, the contents of this file may be used under the terms of +the _____ license (the [___] License), in which case the provisions of +[______] License are applicable instead of those above. If you wish to allow +use of your version of this file only under the terms of the [____] License +and not to allow others to use your version of this file under the MPL, +indicate your decision by deleting the provisions above and replace them +with the notice and other provisions required by the [___] License. If you do +not delete the provisions above, a recipient may use your version of this file +under either the MPL or the [___] License." + + [NOTE: The text of this Exhibit A may differ slightly from the text of +the notices in the Source Code files of the Original Code. You should use the +text of this Exhibit A rather than the text found in the Original Code Source +Code for Your Modifications.] + + +=============================================================================== + +For the JAX-WS Reference Implementation component: + +COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0 + + + 1. Definitions. + + 1.1. "Contributor" means each individual or entity that + creates or contributes to the creation of Modifications. + + 1.2. "Contributor Version" means the combination of the + Original Software, prior Modifications used by a + Contributor (if any), and the Modifications made by that + particular Contributor. + + 1.3. "Covered Software" means (a) the Original Software, or + (b) Modifications, or (c) the combination of files + containing Original Software with files containing + Modifications, in each case including portions thereof. + + 1.4. "Executable" means the Covered Software in any form + other than Source Code. + + 1.5. "Initial Developer" means the individual or entity + that first makes Original Software available under this + License. + + 1.6. "Larger Work" means a work which combines Covered + Software or portions thereof with code not governed by the + terms of this License. + + 1.7. "License" means this document. + + 1.8. "Licensable" means having the right to grant, to the + maximum extent possible, whether at the time of the initial + grant or subsequently acquired, any and all of the rights + conveyed herein. + + 1.9. "Modifications" means the Source Code and Executable + form of any of the following: + + A. Any file that results from an addition to, + deletion from or modification of the contents of a + file containing Original Software or previous + Modifications; + + B. Any new file that contains any part of the + Original Software or previous Modification; or + + C. Any new file that is contributed or otherwise made + available under the terms of this License. + + 1.10. "Original Software" means the Source Code and + Executable form of computer software code that is + originally released under this License. + + 1.11. "Patent Claims" means any patent claim(s), now owned + or hereafter acquired, including without limitation, + method, process, and apparatus claims, in any patent + Licensable by grantor. + + 1.12. "Source Code" means (a) the common form of computer + software code in which modifications are made and (b) + associated documentation included in or with such code. + + 1.13. "You" (or "Your") means an individual or a legal + entity exercising rights under, and complying with all of + the terms of, this License. For legal entities, "You" + includes any entity which controls, is controlled by, or is + under common control with You. For purposes of this + definition, "control" means (a) the power, direct or + indirect, to cause the direction or management of such + entity, whether by contract or otherwise, or (b) ownership + of more than fifty percent (50%) of the outstanding shares + or beneficial ownership of such entity. + + 2. License Grants. + + 2.1. The Initial Developer Grant. + + Conditioned upon Your compliance with Section 3.1 below and + subject to third party intellectual property claims, the + Initial Developer hereby grants You a world-wide, + royalty-free, non-exclusive license: + + (a) under intellectual property rights (other than + patent or trademark) Licensable by Initial Developer, + to use, reproduce, modify, display, perform, + sublicense and distribute the Original Software (or + portions thereof), with or without Modifications, + and/or as part of a Larger Work; and + + (b) under Patent Claims infringed by the making, + using or selling of Original Software, to make, have + made, use, practice, sell, and offer for sale, and/or + otherwise dispose of the Original Software (or + portions thereof). + + (c) The licenses granted in Sections 2.1(a) and (b) + are effective on the date Initial Developer first + distributes or otherwise makes the Original Software + available to a third party under the terms of this + License. + + (d) Notwithstanding Section 2.1(b) above, no patent + license is granted: (1) for code that You delete from + the Original Software, or (2) for infringements + caused by: (i) the modification of the Original + Software, or (ii) the combination of the Original + Software with other software or devices. + + 2.2. Contributor Grant. + + Conditioned upon Your compliance with Section 3.1 below and + subject to third party intellectual property claims, each + Contributor hereby grants You a world-wide, royalty-free, + non-exclusive license: + + (a) under intellectual property rights (other than + patent or trademark) Licensable by Contributor to + use, reproduce, modify, display, perform, sublicense + and distribute the Modifications created by such + Contributor (or portions thereof), either on an + unmodified basis, with other Modifications, as + Covered Software and/or as part of a Larger Work; and + + + (b) under Patent Claims infringed by the making, + using, or selling of Modifications made by that + Contributor either alone and/or in combination with + its Contributor Version (or portions of such + combination), to make, use, sell, offer for sale, + have made, and/or otherwise dispose of: (1) + Modifications made by that Contributor (or portions + thereof); and (2) the combination of Modifications + made by that Contributor with its Contributor Version + (or portions of such combination). + + (c) The licenses granted in Sections 2.2(a) and + 2.2(b) are effective on the date Contributor first + distributes or otherwise makes the Modifications + available to a third party. + + (d) Notwithstanding Section 2.2(b) above, no patent + license is granted: (1) for any code that Contributor + has deleted from the Contributor Version; (2) for + infringements caused by: (i) third party + modifications of Contributor Version, or (ii) the + combination of Modifications made by that Contributor + with other software (except as part of the + Contributor Version) or other devices; or (3) under + Patent Claims infringed by Covered Software in the + absence of Modifications made by that Contributor. + + 3. Distribution Obligations. + + 3.1. Availability of Source Code. + + Any Covered Software that You distribute or otherwise make + available in Executable form must also be made available in + Source Code form and that Source Code form must be + distributed only under the terms of this License. You must + include a copy of this License with every copy of the + Source Code form of the Covered Software You distribute or + otherwise make available. You must inform recipients of any + such Covered Software in Executable form as to how they can + obtain such Covered Software in Source Code form in a + reasonable manner on or through a medium customarily used + for software exchange. + + 3.2. Modifications. + + The Modifications that You create or to which You + contribute are governed by the terms of this License. You + represent that You believe Your Modifications are Your + original creation(s) and/or You have sufficient rights to + grant the rights conveyed by this License. + + 3.3. Required Notices. + + You must include a notice in each of Your Modifications + that identifies You as the Contributor of the Modification. + You may not remove or alter any copyright, patent or + trademark notices contained within the Covered Software, or + any notices of licensing or any descriptive text giving + attribution to any Contributor or the Initial Developer. + + 3.4. Application of Additional Terms. + + You may not offer or impose any terms on any Covered + Software in Source Code form that alters or restricts the + applicable version of this License or the recipients' + rights hereunder. You may choose to offer, and to charge a + fee for, warranty, support, indemnity or liability + obligations to one or more recipients of Covered Software. + However, you may do so only on Your own behalf, and not on + behalf of the Initial Developer or any Contributor. You + must make it absolutely clear that any such warranty, + support, indemnity or liability obligation is offered by + You alone, and You hereby agree to indemnify the Initial + Developer and every Contributor for any liability incurred + by the Initial Developer or such Contributor as a result of + warranty, support, indemnity or liability terms You offer. + + + 3.5. Distribution of Executable Versions. + + You may distribute the Executable form of the Covered + Software under the terms of this License or under the terms + of a license of Your choice, which may contain terms + different from this License, provided that You are in + compliance with the terms of this License and that the + license for the Executable form does not attempt to limit + or alter the recipient's rights in the Source Code form + from the rights set forth in this License. If You + distribute the Covered Software in Executable form under a + different license, You must make it absolutely clear that + any terms which differ from this License are offered by You + alone, not by the Initial Developer or Contributor. You + hereby agree to indemnify the Initial Developer and every + Contributor for any liability incurred by the Initial + Developer or such Contributor as a result of any such terms + You offer. + + 3.6. Larger Works. + + You may create a Larger Work by combining Covered Software + with other code not governed by the terms of this License + and distribute the Larger Work as a single product. In such + a case, You must make sure the requirements of this License + are fulfilled for the Covered Software. + + 4. Versions of the License. + + 4.1. New Versions. + + Sun Microsystems, Inc. is the initial license steward and + may publish revised and/or new versions of this License + from time to time. Each version will be given a + distinguishing version number. Except as provided in + Section 4.3, no one other than the license steward has the + right to modify this License. + + 4.2. Effect of New Versions. + + You may always continue to use, distribute or otherwise + make the Covered Software available under the terms of the + version of the License under which You originally received + the Covered Software. If the Initial Developer includes a + notice in the Original Software prohibiting it from being + distributed or otherwise made available under any + subsequent version of the License, You must distribute and + make the Covered Software available under the terms of the + version of the License under which You originally received + the Covered Software. Otherwise, You may also choose to + use, distribute or otherwise make the Covered Software + available under the terms of any subsequent version of the + License published by the license steward. + + 4.3. Modified Versions. + + When You are an Initial Developer and You want to create a + new license for Your Original Software, You may create and + use a modified version of this License if You: (a) rename + the license and remove any references to the name of the + license steward (except to note that the license differs + from this License); and (b) otherwise make it clear that + the license contains terms which differ from this License. + + + 5. DISCLAIMER OF WARRANTY. + + COVERED SOFTWARE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" + BASIS, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, + INCLUDING, WITHOUT LIMITATION, WARRANTIES THAT THE COVERED + SOFTWARE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR + PURPOSE OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND + PERFORMANCE OF THE COVERED SOFTWARE IS WITH YOU. SHOULD ANY + COVERED SOFTWARE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT THE + INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF + ANY NECESSARY SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF + WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. NO USE OF + ANY COVERED SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER THIS + DISCLAIMER. + + 6. TERMINATION. + + 6.1. This License and the rights granted hereunder will + terminate automatically if You fail to comply with terms + herein and fail to cure such breach within 30 days of + becoming aware of the breach. Provisions which, by their + nature, must remain in effect beyond the termination of + this License shall survive. + + 6.2. If You assert a patent infringement claim (excluding + declaratory judgment actions) against Initial Developer or + a Contributor (the Initial Developer or Contributor against + whom You assert such claim is referred to as "Participant") + alleging that the Participant Software (meaning the + Contributor Version where the Participant is a Contributor + or the Original Software where the Participant is the + Initial Developer) directly or indirectly infringes any + patent, then any and all rights granted directly or + indirectly to You by such Participant, the Initial + Developer (if the Initial Developer is not the Participant) + and all Contributors under Sections 2.1 and/or 2.2 of this + License shall, upon 60 days notice from Participant + terminate prospectively and automatically at the expiration + of such 60 day notice period, unless if within such 60 day + period You withdraw Your claim with respect to the + Participant Software against such Participant either + unilaterally or pursuant to a written agreement with + Participant. + + 6.3. In the event of termination under Sections 6.1 or 6.2 + above, all end user licenses that have been validly granted + by You or any distributor hereunder prior to termination + (excluding licenses granted to You by any distributor) + shall survive termination. + + 7. LIMITATION OF LIABILITY. + + UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, WHETHER TORT + (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL YOU, THE + INITIAL DEVELOPER, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF + COVERED SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE + LIABLE TO ANY PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR + CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT + LIMITATION, DAMAGES FOR LOST PROFITS, LOSS OF GOODWILL, WORK + STOPPAGE, COMPUTER FAILURE OR MALFUNCTION, OR ANY AND ALL OTHER + COMMERCIAL DAMAGES OR LOSSES, EVEN IF SUCH PARTY SHALL HAVE BEEN + INFORMED OF THE POSSIBILITY OF SUCH DAMAGES. THIS LIMITATION OF + LIABILITY SHALL NOT APPLY TO LIABILITY FOR DEATH OR PERSONAL + INJURY RESULTING FROM SUCH PARTY'S NEGLIGENCE TO THE EXTENT + APPLICABLE LAW PROHIBITS SUCH LIMITATION. SOME JURISDICTIONS DO + NOT ALLOW THE EXCLUSION OR LIMITATION OF INCIDENTAL OR + CONSEQUENTIAL DAMAGES, SO THIS EXCLUSION AND LIMITATION MAY NOT + APPLY TO YOU. + + 8. U.S. GOVERNMENT END USERS. + + The Covered Software is a "commercial item," as that term is + defined in 48 C.F.R. 2.101 (Oct. 1995), consisting of "commercial + computer software" (as that term is defined at 48 C.F.R. + 252.227-7014(a)(1)) and "commercial computer software + documentation" as such terms are used in 48 C.F.R. 12.212 (Sept. + 1995). Consistent with 48 C.F.R. 12.212 and 48 C.F.R. 227.7202-1 + through 227.7202-4 (June 1995), all U.S. Government End Users + acquire Covered Software with only those rights set forth herein. + This U.S. Government Rights clause is in lieu of, and supersedes, + any other FAR, DFAR, or other clause or provision that addresses + Government rights in computer software under this License. + + 9. MISCELLANEOUS. + + This License represents the complete agreement concerning subject + matter hereof. If any provision of this License is held to be + unenforceable, such provision shall be reformed only to the + extent necessary to make it enforceable. This License shall be + governed by the law of the jurisdiction specified in a notice + contained within the Original Software (except to the extent + applicable law, if any, provides otherwise), excluding such + jurisdiction's conflict-of-law provisions. Any litigation + relating to this License shall be subject to the jurisdiction of + the courts located in the jurisdiction and venue specified in a + notice contained within the Original Software, with the losing + party responsible for costs, including, without limitation, court + costs and reasonable attorneys' fees and expenses. The + application of the United Nations Convention on Contracts for the + International Sale of Goods is expressly excluded. Any law or + regulation which provides that the language of a contract shall + be construed against the drafter shall not apply to this License. + You agree that You alone are responsible for compliance with the + United States export administration regulations (and the export + control laws and regulation of any other countries) when You use, + distribute or otherwise make available any Covered Software. + + 10. RESPONSIBILITY FOR CLAIMS. + + As between Initial Developer and the Contributors, each party is + responsible for claims and damages arising, directly or + indirectly, out of its utilization of rights under this License + and You agree to work with Initial Developer and Contributors to + distribute such responsibility on an equitable basis. Nothing + herein is intended or shall be deemed to constitute any admission + of liability. + diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/main/resources/META-INF/NOTICE b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/main/resources/META-INF/NOTICE new file mode 100644 index 0000000000..d48810c0ec --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/main/resources/META-INF/NOTICE @@ -0,0 +1,18 @@ +========================================================================= +== NOTICE file corresponding to the section 4 d of == +== the Apache License, Version 2.0, == +== in this case for the Apache Tuscany distribution. == +========================================================================= + +This product includes software developed by the Apache Software Foundation +(http://www.apache.org/). + +This product also includes software developed by: +- the Eclipse Modeling Framework project (http://www.eclipse.org/emf/) +- the Celtix project (http://celtix.objectweb.org/) +- the Mozilla Rhino project (http://www.mozilla.org/rhino/) +- the GlassFish JAX-WS project (https://jax-ws.dev.java.net/) + +Please read the LICENSE.txt file present in the root directory of this +distribution. + diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/main/resources/META-INF/README.txt b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/main/resources/META-INF/README.txt new file mode 100644 index 0000000000..9b26d1690a --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/main/resources/META-INF/README.txt @@ -0,0 +1,35 @@ +Apache Tuscany M1 build (May, 2006) +=================================== + +http://incubator.apache.org/tuscany/ + +Tuscany is an effort undergoing incubation at the Apache Software Foundation +(ASF), sponsored by the Web Services PMC. + +Incubation is required of all newly accepted projects until a further review +indicates that the infrastructure, communications, and decision making process +have stabilized in a manner consistent with other successful ASF projects. + +While incubation status is not necessarily a reflection of the completeness or +stability of the code, it does indicate that the project has yet to be fully +endorsed by the ASF. + + +Support +------- + +Any problem with this release can be reported to the Tuscany mailing list +or in the JIRA issue tracker. + +Mailing list subscription: + tuscany-dev-subscribe@ws.apache.org + +Jira: + http://issues.apache.org/jira/browse/Tuscany + + +Thank you for using Tuscany! + + +The Tuscany Team. + diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/main/resources/org/apache/tuscany/container/java/Messages.properties b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/main/resources/org/apache/tuscany/container/java/Messages.properties new file mode 100644 index 0000000000..4581e44bff --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/main/resources/org/apache/tuscany/container/java/Messages.properties @@ -0,0 +1,25 @@ +# Copyright (c) 2005 The Apache Software Foundation or its licensors, as applicable. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ==================================================================== +# To code developer: +# Do NOT change the properties between this line and the +# "%%% END OF TRANSLATED PROPERTIES %%%" line. +# Make a new property name, append to the end of the file and change +# the code to use the new property. +# ==================================================================== + +# ===================================================================== +# %%% END OF TRANSLATED PROPERTIES %%% +# ===================================================================== +# NLS_MESSAGEFORMAT_ALL diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/main/resources/system.fragment b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/main/resources/system.fragment new file mode 100644 index 0000000000..6aab9b8510 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/main/resources/system.fragment @@ -0,0 +1,41 @@ +<?xml version="1.0" encoding="ASCII"?>
+<!--
+ Copyright (c) 2005 The Apache Software Foundation or its licensors, as applicable.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ -->
+<moduleFragment xmlns="http://www.osoa.org/xmlns/sca/0.9" xmlns:v="http://www.osoa.org/xmlns/sca/values/0.9"
+ xmlns:tuscany="http://org.apache.tuscany/xmlns/system/0.9"
+ name="org.apache.tuscany.container.java">
+
+ <component name="org.apache.tuscany.container.java.builder.JavaContextFactoryBuilder">
+ <tuscany:implementation.system class="org.apache.tuscany.container.java.builder.JavaContextFactoryBuilder"/>
+ </component>
+ <component name="org.apache.tuscany.core.config.ComponentTypeIntrospector">
+ <tuscany:implementation.system class="org.apache.tuscany.core.config.impl.Java5ComponentTypeIntrospector"/>
+ </component>
+
+
+ <component name="org.apache.tuscany.container.java.builder.JavaTargetWireBuilder">
+ <tuscany:implementation.system class="org.apache.tuscany.container.java.builder.JavaTargetWireBuilder"/>
+ </component>
+
+ <component name="org.apache.tuscany.container.java.assembly.JavaAssemblyFactory">
+ <tuscany:implementation.system class="org.apache.tuscany.container.java.assembly.impl.JavaAssemblyFactoryImpl"/>
+ </component>
+
+ <component name="org.apache.tuscany.container.java.loader.JavaImplementationLoader">
+ <tuscany:implementation.system class="org.apache.tuscany.container.java.loader.JavaImplementationLoader"/>
+ </component>
+
+</moduleFragment>
diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/main/test/sca.module b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/main/test/sca.module new file mode 100644 index 0000000000..1c1ddafb53 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/main/test/sca.module @@ -0,0 +1,75 @@ +<?xml version="1.0" encoding="ASCII"?>
+<!--
+ Copyright (c) 2005 The Apache Software Foundation or its licensors, as applicable.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ -->
+<module xmlns="http://www.osoa.org/xmlns/sca/0.9" xmlns:v="http://www.osoa.org/xmlns/sca/values/0.9"
+
+ name="sample.myvaluemodule">
+ <!--
+ <entryPoint name="MyValueService">
+ <interface.java interface="services.myvalue.MyValueService"/>
+ <binding.ws port="http://webservice.myvalue#wsdl.endpoint(MyValueService/MyValueWebService)"/>
+ <reference>MyValueServiceComponent</reference>
+ </entryPoint>
+
+ <component name="MyValueServiceComponent">
+ <implementation.java class="services.myvalue.MyValueServiceImpl"/>
+ <properties>
+ <v:currency>EURO</v:currency>
+ </properties>
+ <references>
+ <v:customerService>CustomerServiceComponent</v:customerService>
+ <v:stockQuoteService>StockQuoteMediatorComponent</v:stockQuoteService>
+ </references>
+ </component>
+
+ <component name="StockQuoteMediatorComponent">
+ <implementation.java class="services.mediator.StockQuoteMediatorImpl"/>
+ <references>
+ <v:stockQuoteService>StockQuoteService</v:stockQuoteService>
+ </references>
+ </component>
+
+ <component name="CustomerServiceComponent">
+ <implementation.java class="services.customer.CustomerServiceImpl"/>
+ </component>
+
+ <component name="StockQuoteService">
+ <implementation.java class="services.stockquote.StockQuoteServiceImpl"/>
+ </component>
+ -->
+ <component name="TestService">
+ <implementation.java class="test.org.apache.tuscany.container.java.components.ModuleScopeComponentImpl"/>
+ <properties>
+ <v:foo>MyFoo</v:foo>
+ <v:mInt>1</v:mInt>
+ </properties>
+ <references>
+ <v:mGenericComponent>TestService2</v:mGenericComponent>
+ </references>
+ </component>
+ <component name="TestService2">
+ <implementation.java class="test.org.apache.tuscany.container.java.components.ModuleScopeComponentImpl"/>
+ </component>
+
+ <!--
+ <externalService name="StockQuoteService">
+ <interface.java interface="services.stockquote.StockQuoteService"/>
+ <binding.ws port="http://webservice.stockquote#wsdl.endpoint(StockQuoteService/StockQuoteWebService)"/>
+ </externalService>
+ -->
+
+</module>
+
\ No newline at end of file diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/mock/HelloWorldImpl.componentType b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/mock/HelloWorldImpl.componentType new file mode 100644 index 0000000000..784d8bf728 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/mock/HelloWorldImpl.componentType @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="ASCII"?>
+<!--
+ Copyright (c) 2005 The Apache Software Foundation or its licensors, as applicable.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ -->
+<componentType xmlns="http://www.osoa.org/xmlns/sca/0.9" + xmlns:xsd="http://www.w3.org/2001/XMLSchema">
+ <service name="HelloWorldService">
+ <interface.java interface="org.apache.tuscany.container.java.assembly.mock.HelloWorldService" remoteable="true"/>
+ </service>
+ <property name="text" type="xsd:string"/>
+</componentType>
\ No newline at end of file diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/mock/HelloWorldImpl.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/mock/HelloWorldImpl.java new file mode 100644 index 0000000000..74f4c658ce --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/mock/HelloWorldImpl.java @@ -0,0 +1,36 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.assembly.mock; + +/** + * @version $Rev$ $Date$ + */ +public class HelloWorldImpl implements HelloWorldService { + + private String text; + + private int count; + + public String hello(String name) { + ++count; + return "Hello " + name; + } + + public int count() { + return count; + } +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/mock/HelloWorldService.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/mock/HelloWorldService.java new file mode 100644 index 0000000000..a7d0fe7788 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/mock/HelloWorldService.java @@ -0,0 +1,27 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.assembly.mock; + +/** + * @version $Rev$ $Date$ + */ +public interface HelloWorldService { + String hello(String name); + + public int count(); + +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/mock/HelloWorldWithFieldProperties.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/mock/HelloWorldWithFieldProperties.java new file mode 100644 index 0000000000..0801c56f44 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/mock/HelloWorldWithFieldProperties.java @@ -0,0 +1,40 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.assembly.mock; + +import org.osoa.sca.annotations.Property; + +/** + * @version $Rev$ $Date$ + */ +public class HelloWorldWithFieldProperties { + @Property + protected String text; + + @Property(required = true) + public Integer text2; + + @Property(name = "foo") + public int text3; + + @Property(name = "not exposed") + protected int field4; + + public String hello(String name) { + return "Hello " + name; + } +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/mock/NakedHelloWorld.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/mock/NakedHelloWorld.java new file mode 100644 index 0000000000..2f1ae5d17b --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/mock/NakedHelloWorld.java @@ -0,0 +1,26 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.assembly.mock; + +/** + * @version $Rev$ $Date$ + */ +public class NakedHelloWorld { + public String hello(String name) { + return "Hello " + name; + } +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/mock/NakedHelloWorldWithInterface.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/mock/NakedHelloWorldWithInterface.java new file mode 100644 index 0000000000..9d5fe5e969 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/mock/NakedHelloWorldWithInterface.java @@ -0,0 +1,28 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.assembly.mock; + +import java.io.Serializable; + +/** + * @version $Rev$ $Date$ + */ +public class NakedHelloWorldWithInterface implements Serializable { + public String hello(String name) { + return "Hello " + name; + } +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/account/AccountReport.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/account/AccountReport.java new file mode 100644 index 0000000000..1770c2b011 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/account/AccountReport.java @@ -0,0 +1,32 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.assembly.tests.bigbank.account.services.account; + +import java.util.List; + +/** + * @model + */ + +public interface AccountReport { + + /** + * @model type="services.account.AccountSummary" + */ + + List getAccountSummaries(); +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/account/AccountService.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/account/AccountService.java new file mode 100644 index 0000000000..1bb938655f --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/account/AccountService.java @@ -0,0 +1,25 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.assembly.tests.bigbank.account.services.account; + +import org.osoa.sca.annotations.Remotable; + +@Remotable +public interface AccountService { + + public AccountReport getAccountReport(String customerID); +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/account/AccountService.wsdl b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/account/AccountService.wsdl new file mode 100644 index 0000000000..022258f2c5 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/account/AccountService.wsdl @@ -0,0 +1,78 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright (c) 2005 The Apache Software Foundation or its licensors, as applicable.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ -->
+<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
+ xmlns:tns="http://www.bigbank.com/AccountService/"
+ xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ targetNamespace="http://www.bigbank.com/AccountService/"
+
+ name="AccountService">
+
+ <wsdl:types>
+ <xsd:schema targetNamespace="http://www.bigbank.com/AccountService/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
+
+ <xsd:element name="customerID" type="xsd:string"/>
+ <xsd:element name="getAccountReportResponse" type="tns:AccountReport"/>
+
+ <xsd:complexType name="AccountReport">
+ <xsd:sequence>
+ <xsd:element name="accountSummary" type="tns:AccountSummary" maxOccurs="unbounded"/>
+ </xsd:sequence>
+ </xsd:complexType>
+ <xsd:complexType name="AccountSummary">
+ <xsd:sequence>
+ <xsd:element name="accountNumber" type="xsd:string"/>
+ <xsd:element name="accountType" type="xsd:string"/>
+ <xsd:element name="balance" type="xsd:float"/>
+ </xsd:sequence>
+ </xsd:complexType>
+
+ </xsd:schema>
+ </wsdl:types>
+ <wsdl:message name="getAccountReportRequest">
+ <wsdl:part element="tns:customerID" name="getAccountReportRequest"/>
+ </wsdl:message>
+ <wsdl:message name="getAccountReportResponse">
+ <wsdl:part element="tns:getAccountReportResponse" name="getAccountReportResponse"/>
+ </wsdl:message>
+ <wsdl:portType name="AccountService">
+ <wsdl:operation name="getAccountReport">
+ <wsdl:input message="tns:getAccountReportRequest"/>
+ <wsdl:output message="tns:getAccountReportResponse"/>
+ </wsdl:operation>
+ </wsdl:portType>
+ <wsdl:binding name="AccountServiceSOAP" type="tns:AccountService">
+ <soap:binding style="document"
+ transport="http://schemas.xmlsoap.org/soap/http"/>
+ <wsdl:operation name="getAccountReport">
+ <soap:operation
+ soapAction="http://www.bigbank.com/AccountService/getAccountReport"/>
+ <wsdl:input>
+ <soap:body use="literal"/>
+ </wsdl:input>
+ <wsdl:output>
+ <soap:body use="literal"/>
+ </wsdl:output>
+ </wsdl:operation>
+ </wsdl:binding>
+ <wsdl:service name="AccountService">
+ <wsdl:port binding="tns:AccountServiceSOAP"
+ name="AccountServiceSOAP">
+ <soap:address location="http://localhost:8080/tuscany-container-java/services/AccountService"/>
+ </wsdl:port>
+ </wsdl:service>
+</wsdl:definitions>
diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/account/AccountServiceImpl.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/account/AccountServiceImpl.java new file mode 100644 index 0000000000..9a5ddb0005 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/account/AccountServiceImpl.java @@ -0,0 +1,42 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.assembly.tests.bigbank.account.services.account; + +import org.osoa.sca.annotations.Property; +import org.osoa.sca.annotations.Reference; + +import org.apache.tuscany.container.java.assembly.tests.bigbank.account.services.accountdata.AccountDataService; +import org.apache.tuscany.container.java.assembly.tests.bigbank.account.services.stockquote.StockQuoteService; + +public class AccountServiceImpl implements AccountService { + + @Property + public String currency = "USD"; + + @Reference + public AccountDataService accountDataService; + @Reference + public StockQuoteService stockQuoteService; + + public AccountServiceImpl() { + } + + public AccountReport getAccountReport(String customerID) { + return null; + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/account/AccountSummary.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/account/AccountSummary.java new file mode 100644 index 0000000000..2b11e23425 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/account/AccountSummary.java @@ -0,0 +1,46 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.assembly.tests.bigbank.account.services.account; + +/** + * @model + */ + +public interface AccountSummary { + + /** + * @model + */ + String getAccountNumber(); + + void setAccountNumber(String accountNumber); + + /** + * @model + */ + String getAccountType(); + + void setAccountType(String accountType); + + /** + * @model + */ + float getBalance(); + + void setBalance(float balance); +} + diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/accountdata/AccountDataService.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/accountdata/AccountDataService.java new file mode 100644 index 0000000000..56f24ea4ac --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/accountdata/AccountDataService.java @@ -0,0 +1,26 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.assembly.tests.bigbank.account.services.accountdata; + +public interface AccountDataService { + + CheckingAccount getCheckingAccount(String customerID); + + SavingsAccount getSavingsAccount(String customerID); + + StockAccount getStockAccount(String customerID); +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/accountdata/AccountDataServiceImpl.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/accountdata/AccountDataServiceImpl.java new file mode 100644 index 0000000000..a7a40f954d --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/accountdata/AccountDataServiceImpl.java @@ -0,0 +1,48 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.assembly.tests.bigbank.account.services.accountdata; + +public class AccountDataServiceImpl implements AccountDataService { + + public CheckingAccount getCheckingAccount(String customerID) { + + CheckingAccount checkingAccount = new CheckingAccount(); + checkingAccount.setAccountNumber(customerID + "_" + "CHA12345"); + checkingAccount.setBalance(1500.0f); + + return checkingAccount; + } + + public SavingsAccount getSavingsAccount(String customerID) { + + SavingsAccount savingsAccount = new SavingsAccount(); + savingsAccount.setAccountNumber(customerID + "_" + "SAA12345"); + savingsAccount.setBalance(1500.0f); + + return savingsAccount; + } + + public StockAccount getStockAccount(String customerID) { + + StockAccount stockAccount = new StockAccount(); + stockAccount.setAccountNumber(customerID + "_" + "STA12345"); + stockAccount.setSymbol("IBM"); + stockAccount.setQuantity(100); + + return stockAccount; + } +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/accountdata/CheckingAccount.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/accountdata/CheckingAccount.java new file mode 100644 index 0000000000..ff84e9968a --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/accountdata/CheckingAccount.java @@ -0,0 +1,39 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.assembly.tests.bigbank.account.services.accountdata; + +public class CheckingAccount { + + private String accountNumber; + private float balance; + + public String getAccountNumber() { + return accountNumber; + } + + public void setAccountNumber(String accountNumber) { + this.accountNumber = accountNumber; + } + + public float getBalance() { + return balance; + } + + public void setBalance(float balance) { + this.balance = balance; + } +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/accountdata/SavingsAccount.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/accountdata/SavingsAccount.java new file mode 100644 index 0000000000..b39d9051de --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/accountdata/SavingsAccount.java @@ -0,0 +1,39 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.assembly.tests.bigbank.account.services.accountdata; + +public class SavingsAccount { + + private String accountNumber; + private float balance; + + public String getAccountNumber() { + return accountNumber; + } + + public void setAccountNumber(String accountNumber) { + this.accountNumber = accountNumber; + } + + public float getBalance() { + return balance; + } + + public void setBalance(float balance) { + this.balance = balance; + } +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/accountdata/StockAccount.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/accountdata/StockAccount.java new file mode 100644 index 0000000000..bce0821b25 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/accountdata/StockAccount.java @@ -0,0 +1,48 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.assembly.tests.bigbank.account.services.accountdata; + +public class StockAccount { + + private String accountNumber; + private String symbol; + private int quantity; + + public String getAccountNumber() { + return accountNumber; + } + + public void setAccountNumber(String accountNumber) { + this.accountNumber = accountNumber; + } + + public int getQuantity() { + return quantity; + } + + public void setQuantity(int quantity) { + this.quantity = quantity; + } + + public String getSymbol() { + return symbol; + } + + public void setSymbol(String symbol) { + this.symbol = symbol; + } +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/stockquote/StockQuoteService.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/stockquote/StockQuoteService.java new file mode 100644 index 0000000000..78ece12b41 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/stockquote/StockQuoteService.java @@ -0,0 +1,24 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.assembly.tests.bigbank.account.services.stockquote; + +public interface StockQuoteService { + + public float getQuote(String symbol); +} + +
\ No newline at end of file diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/stockquote/StockQuoteServiceImpl.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/stockquote/StockQuoteServiceImpl.java new file mode 100644 index 0000000000..fa180d0ceb --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/stockquote/StockQuoteServiceImpl.java @@ -0,0 +1,28 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.assembly.tests.bigbank.account.services.stockquote; + +/* Dummy'd up StockQuoteService, override webservice for now */ + +public class StockQuoteServiceImpl implements StockQuoteService { + + public float getQuote(String symbol) { + // Just hardcode for now + return 83.00f; + } + +}
\ No newline at end of file diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/stockquote/StockQuoteWebService.wsdl b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/stockquote/StockQuoteWebService.wsdl new file mode 100644 index 0000000000..6af61ef80e --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/stockquote/StockQuoteWebService.wsdl @@ -0,0 +1,98 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright (c) 2005 The Apache Software Foundation or its licensors, as applicable.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ -->
+<wsdl:definitions targetNamespace="http://webservice.stockquote" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://webservice.stockquote" xmlns:intf="http://webservice.stockquote" xmlns:tns1="http://stockquote" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="stockquote">
+ <!--WSDL created by Apache Axis version: 1.2.1
+Built on Jun 14, 2005 (09:15:57 EDT)-->
+ <wsdl:types>
+ <schema elementFormDefault="qualified" targetNamespace="http://stockquote" xmlns="http://www.w3.org/2001/XMLSchema">
+ <complexType name="GetQuoteRequest">
+ <sequence>
+ <element name="symbol" nillable="true" type="xsd:string"/>
+ </sequence>
+ </complexType>
+ <complexType name="GetQuoteResponse">
+ <sequence>
+ <element name="price" type="xsd:float"/>
+ </sequence>
+ </complexType>
+ </schema>
+ <schema elementFormDefault="qualified" targetNamespace="http://webservice.stockquote" xmlns="http://www.w3.org/2001/XMLSchema">
+ <import namespace="http://stockquote"/>
+ <element name="request" type="tns1:GetQuoteRequest"/>
+ <element name="getQuoteReturn" type="tns1:GetQuoteResponse"/>
+ </schema>
+ </wsdl:types>
+
+ <wsdl:message name="getQuoteResponse">
+
+ <wsdl:part element="impl:getQuoteReturn" name="getQuoteReturn"/>
+
+ </wsdl:message>
+
+ <wsdl:message name="getQuoteRequest">
+
+ <wsdl:part element="impl:request" name="request"/>
+
+ </wsdl:message>
+
+ <wsdl:portType name="StockQuoteWebService">
+
+ <wsdl:operation name="getQuote" parameterOrder="request">
+
+ <wsdl:input message="impl:getQuoteRequest" name="getQuoteRequest"/>
+
+ <wsdl:output message="impl:getQuoteResponse" name="getQuoteResponse"/>
+
+ </wsdl:operation>
+
+ </wsdl:portType>
+
+ <wsdl:binding name="StockQuoteWebServiceSoapBinding" type="impl:StockQuoteWebService">
+
+ <wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
+
+ <wsdl:operation name="getQuote">
+
+ <wsdlsoap:operation soapAction=""/>
+
+ <wsdl:input name="getQuoteRequest">
+
+ <wsdlsoap:body use="literal"/>
+
+ </wsdl:input>
+
+ <wsdl:output name="getQuoteResponse">
+
+ <wsdlsoap:body use="literal"/>
+
+ </wsdl:output>
+
+ </wsdl:operation>
+
+ </wsdl:binding>
+
+ <wsdl:service name="StockQuoteWebServiceService">
+
+ <wsdl:port binding="impl:StockQuoteWebServiceSoapBinding" name="StockQuoteWebService">
+
+ <wsdlsoap:address location="http://localhost:8123/StockQuoteWebService/services/StockQuoteWebService"/>
+
+ </wsdl:port>
+
+ </wsdl:service>
+
+</wsdl:definitions>
diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/builder/JavaContextFactoryBuilderTestCase.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/builder/JavaContextFactoryBuilderTestCase.java new file mode 100644 index 0000000000..fcfd320e0e --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/builder/JavaContextFactoryBuilderTestCase.java @@ -0,0 +1,112 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.builder; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.apache.tuscany.container.java.invocation.mock.MockSyncInterceptor; +import org.apache.tuscany.container.java.mock.MockFactory; +import org.apache.tuscany.container.java.mock.components.GenericComponent; +import org.apache.tuscany.container.java.mock.components.ModuleScopeComponent; +import org.apache.tuscany.core.builder.ContextFactory; +import org.apache.tuscany.core.builder.system.PolicyBuilderRegistry; +import org.apache.tuscany.core.builder.system.DefaultPolicyBuilderRegistry; +import org.apache.tuscany.core.builder.impl.DefaultWireBuilder; +import org.apache.tuscany.core.context.impl.EventContextImpl; +import org.apache.tuscany.core.context.scope.DefaultScopeStrategy; +import org.apache.tuscany.core.context.scope.ModuleScopeContext; +import org.apache.tuscany.core.context.ScopeStrategy; +import org.apache.tuscany.core.context.EventContext; +import org.apache.tuscany.core.context.ScopeContext; +import org.apache.tuscany.core.context.Context; +import org.apache.tuscany.core.context.event.ModuleStart; +import org.apache.tuscany.core.wire.WireConfiguration; +import org.apache.tuscany.core.wire.jdk.JDKWireFactoryFactory; +import org.apache.tuscany.core.wire.SourceWireFactory; +import org.apache.tuscany.core.wire.service.WireFactoryService; +import org.apache.tuscany.core.wire.service.DefaultWireFactoryService; +import org.apache.tuscany.core.message.impl.MessageFactoryImpl; +import org.apache.tuscany.model.assembly.Component; +import org.apache.tuscany.model.assembly.Module; + +public class JavaContextFactoryBuilderTestCase extends TestCase { + + public JavaContextFactoryBuilderTestCase() { + } + + public void testBuilder() throws Exception { + MockSyncInterceptor mockInterceptor = new MockSyncInterceptor(); + MockInterceptorBuilder interceptorBuilder = new MockInterceptorBuilder(mockInterceptor, true); + PolicyBuilderRegistry policyRegistry = new DefaultPolicyBuilderRegistry(); + policyRegistry.registerSourceBuilder(interceptorBuilder); + WireFactoryService wireService = new DefaultWireFactoryService(new MessageFactoryImpl(), new JDKWireFactoryFactory(), policyRegistry); + JavaContextFactoryBuilder builder = new JavaContextFactoryBuilder(wireService); + + JavaTargetWireBuilder javaWireBuilder = new JavaTargetWireBuilder(); + ScopeStrategy strategy = new DefaultScopeStrategy(); + DefaultWireBuilder wireBuilder = new DefaultWireBuilder(); + wireBuilder.addWireBuilder(javaWireBuilder); + Module module = MockFactory.createModule(); + EventContext eCtx = new EventContextImpl(); + ScopeContext scopeContext = new ModuleScopeContext(eCtx); + scopeContext.start(); + scopeContext.onEvent(new ModuleStart(this)); + List<Component> components = module.getComponents(); + Map<String, Component> compMap = new HashMap<String, Component>(components.size()); + + for (Component component : components) { + compMap.put(component.getName(), component); + builder.build(component); + ContextFactory contextFactory = (ContextFactory) component.getContextFactory(); + Assert.assertNotNull(contextFactory); + } + for (Component component : components) { + ContextFactory<Context> source = (ContextFactory<Context>) component.getContextFactory(); + Assert.assertNotNull(source); + for (SourceWireFactory pFactory : source.getSourceWireFactories()) { + WireConfiguration pConfig = pFactory.getConfiguration(); + Component target = compMap.get(pConfig.getTargetName().getPartName()); + + if (target != null) { + ContextFactory targetConfig = (ContextFactory) target.getContextFactory(); + boolean downScope = strategy.downScopeReference(source.getScope(), targetConfig.getScope()); + wireBuilder.connect(pFactory, targetConfig.getTargetWireFactory(pFactory.getConfiguration().getTargetName() + .getPortName()), targetConfig.getClass(), downScope, scopeContext); + } + pFactory.initialize(); + } + scopeContext.registerFactory(source); + } + for (Component component : components) { + ContextFactory config = (ContextFactory) component.getContextFactory(); + Context context = config.createContext(); + if ("source".equals(component.getName())) { + ModuleScopeComponent source = (ModuleScopeComponent) context.getInstance(null); + Assert.assertNotNull(source); + GenericComponent gComp = source.getGenericComponent(); + gComp.getString(); + } + } + } + + +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/builder/JavaTargetWireBuilderTestCase.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/builder/JavaTargetWireBuilderTestCase.java new file mode 100644 index 0000000000..5a0ee8e14c --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/builder/JavaTargetWireBuilderTestCase.java @@ -0,0 +1,132 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.builder; + +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.Map; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.apache.tuscany.container.java.config.JavaContextFactory; +import org.apache.tuscany.container.java.invocation.mock.MockHandler; +import org.apache.tuscany.container.java.invocation.mock.MockSyncInterceptor; +import org.apache.tuscany.container.java.invocation.mock.SimpleTarget; +import org.apache.tuscany.container.java.invocation.mock.SimpleTargetImpl; +import org.apache.tuscany.container.java.mock.MockScopeContext; +import org.apache.tuscany.core.builder.impl.DefaultWireBuilder; +import org.apache.tuscany.core.context.QualifiedName; +import org.apache.tuscany.core.wire.MethodHashMap; +import org.apache.tuscany.core.wire.impl.InvokerInterceptor; +import org.apache.tuscany.core.wire.jdk.JDKWireFactoryFactory; +import org.apache.tuscany.core.wire.WireSourceConfiguration; +import org.apache.tuscany.core.wire.WireTargetConfiguration; +import org.apache.tuscany.core.wire.SourceInvocationConfiguration; +import org.apache.tuscany.core.wire.TargetInvocationConfiguration; +import org.apache.tuscany.core.wire.TargetWireFactory; +import org.apache.tuscany.core.wire.SourceWireFactory; +import org.apache.tuscany.core.message.Message; +import org.apache.tuscany.core.message.MessageFactory; +import org.apache.tuscany.core.message.impl.MessageFactoryImpl; + +public class JavaTargetWireBuilderTestCase extends TestCase { + + private Method hello; + + public JavaTargetWireBuilderTestCase() { + } + + public JavaTargetWireBuilderTestCase(String arg0) { + super(arg0); + } + + public void setUp() throws Exception { + hello = SimpleTarget.class.getMethod("hello", String.class); + } + + + /** + * Tests basic wiring of a source to a target, including handlers and interceptors + */ + public void testInvocation() throws Exception { + MessageFactory msgFactory = new MessageFactoryImpl(); + + SourceInvocationConfiguration source = new SourceInvocationConfiguration(hello); + MockHandler sourceRequestHandler = new MockHandler(); + MockHandler sourceResponseHandler = new MockHandler(); + MockSyncInterceptor sourceInterceptor = new MockSyncInterceptor(); + source.addRequestHandler(sourceRequestHandler); + source.addResponseHandler(sourceResponseHandler); + source.addInterceptor(sourceInterceptor); + + SourceWireFactory sourceFactory = new JDKWireFactoryFactory().createSourceWireFactory(); + Map<Method, SourceInvocationConfiguration> sourceInvocationConfigs = new MethodHashMap<SourceInvocationConfiguration>(); + sourceInvocationConfigs.put(hello, source); + WireSourceConfiguration sourceConfig = new WireSourceConfiguration("foo",new QualifiedName("target/SimpleTarget"), + sourceInvocationConfigs, Thread.currentThread().getContextClassLoader(), msgFactory); + sourceFactory.setConfiguration(sourceConfig); + sourceFactory.setBusinessInterface(SimpleTarget.class); + + TargetInvocationConfiguration target = new TargetInvocationConfiguration(hello); + MockHandler targetRequestHandler = new MockHandler(); + MockHandler targetResponseHandler = new MockHandler(); + MockSyncInterceptor targetInterceptor = new MockSyncInterceptor(); + target.addRequestHandler(targetRequestHandler); + target.addResponseHandler(targetResponseHandler); + target.addInterceptor(targetInterceptor); + target.addInterceptor(new InvokerInterceptor()); + + TargetWireFactory targetFactory = new JDKWireFactoryFactory().createTargetWireFactory(); + Map<Method, TargetInvocationConfiguration> targetInvocationConfigs = new MethodHashMap<TargetInvocationConfiguration>(); + targetInvocationConfigs.put(hello, target); + WireTargetConfiguration targetConfig = new WireTargetConfiguration(new QualifiedName("target/SimpleTarget"), + targetInvocationConfigs, Thread.currentThread().getContextClassLoader(), msgFactory); + targetFactory.setConfiguration(targetConfig); + targetFactory.setBusinessInterface(SimpleTarget.class); + + // bootstrap a scope container with the target in it + Map<String,Object> instances = new HashMap<String,Object>(); + SimpleTarget simpleTarget = new SimpleTargetImpl(); + instances.put("target",simpleTarget); + MockScopeContext scopeCtx = new MockScopeContext(instances); + + // connect the source to the target + DefaultWireBuilder builder = new DefaultWireBuilder(); + builder.addWireBuilder(new JavaTargetWireBuilder()); + + builder.connect(sourceFactory, targetFactory, JavaContextFactory.class, true, scopeCtx); + source.build(); + target.build(); + Assert.assertNotNull(source.getTargetInvoker()); + + Message msg = msgFactory.createMessage(); + msg.setBody("foo"); + msg.setTargetInvoker(source.getTargetInvoker()); + Message response = source.getHeadInterceptor().invoke(msg); + Assert.assertEquals("foo", response.getBody()); + Assert.assertEquals(1, sourceRequestHandler.getCount()); + Assert.assertEquals(1, sourceResponseHandler.getCount()); + Assert.assertEquals(1, sourceInterceptor.getCount()); + Assert.assertEquals(1, targetRequestHandler.getCount()); + Assert.assertEquals(1, targetResponseHandler.getCount()); + Assert.assertEquals(1, targetInterceptor.getCount()); + } + + +} + diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/builder/MockHandlerBuilder.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/builder/MockHandlerBuilder.java new file mode 100644 index 0000000000..bd1c13c4ac --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/builder/MockHandlerBuilder.java @@ -0,0 +1,120 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package org.apache.tuscany.container.java.builder; + +import org.apache.tuscany.core.builder.BuilderException; +import org.apache.tuscany.core.builder.SourcePolicyBuilder; +import org.apache.tuscany.core.builder.TargetPolicyBuilder; +import org.apache.tuscany.core.wire.InvocationConfiguration; +import org.apache.tuscany.core.wire.MessageHandler; +import org.apache.tuscany.core.wire.SourceInvocationConfiguration; +import org.apache.tuscany.core.wire.SourceWireFactory; +import org.apache.tuscany.core.wire.TargetInvocationConfiguration; +import org.apache.tuscany.core.wire.TargetWireFactory; +import org.apache.tuscany.core.wire.WireSourceConfiguration; +import org.apache.tuscany.core.wire.WireTargetConfiguration; +import org.apache.tuscany.model.assembly.AssemblyObject; +import org.apache.tuscany.model.assembly.ConfiguredReference; +import org.apache.tuscany.model.assembly.ConfiguredService; + +import java.util.List; + +/** + * Adds a handler to a source or target proxy configuration + * + * @version $Rev$ $Date$ + */ +public class MockHandlerBuilder implements SourcePolicyBuilder, TargetPolicyBuilder { + + + private MessageHandler handler; + + private boolean source; + + private boolean request; + + /** + * Creates the builder. + * + * @param handler the handler to add to the source or target proxy configuration + * @param source true if the handler should be added on the source side; false if the handler should be added to the target + * side + * @param request true if the handler is a request handler; false if the handler is a response handler + */ + public MockHandlerBuilder(MessageHandler handler, boolean source, boolean request) { + this.handler = handler; + this.source = source; + this.request = request; + } + + public void build(AssemblyObject modelObject) throws BuilderException { + if (source) { + if (!(modelObject instanceof ConfiguredReference)) { + return; + } else { + ConfiguredReference cref = (ConfiguredReference) modelObject; + // /xcv WireFactory pFactory = (WireFactory) cref.getProxyFactory(); + for (ConfiguredService configuredService : cref.getTargetConfiguredServices()) { + SourceWireFactory pFactory = (SourceWireFactory) configuredService.getProxyFactory(); + for (InvocationConfiguration config : pFactory.getConfiguration().getInvocationConfigurations().values()) { + if (request) { + config.addRequestHandler(handler); + } else { + config.addResponseHandler(handler); + } + } + } + } + } else { + if (!(modelObject instanceof ConfiguredService)) { + return; + } else { + ConfiguredService cservice = (ConfiguredService) modelObject; + TargetWireFactory pFactory = (TargetWireFactory) cservice.getProxyFactory(); + for (InvocationConfiguration config : pFactory.getConfiguration().getInvocationConfigurations().values()) { + if (request) { + config.addRequestHandler(handler); + } else { + config.addResponseHandler(handler); + } + } + } + + } + } + + public void build(ConfiguredReference reference, List<WireSourceConfiguration> configurations) throws BuilderException { + for (WireSourceConfiguration wireSourceConfiguration : configurations) { + for (SourceInvocationConfiguration configuration : wireSourceConfiguration.getInvocationConfigurations().values()) { + if (request) { + configuration.addRequestHandler(handler); + } else { + configuration.addResponseHandler(handler); + } + + } + + } + } + + public void build(ConfiguredService service, WireTargetConfiguration configuration) throws BuilderException { + for (TargetInvocationConfiguration config : configuration.getInvocationConfigurations().values()) { + if (request) { + config.addRequestHandler(handler); + } else { + config.addResponseHandler(handler); + } + } + } +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/builder/MockInterceptorBuilder.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/builder/MockInterceptorBuilder.java new file mode 100644 index 0000000000..d3ad8a53b5 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/builder/MockInterceptorBuilder.java @@ -0,0 +1,66 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package org.apache.tuscany.container.java.builder; + +import org.apache.tuscany.core.builder.BuilderException; +import org.apache.tuscany.core.builder.SourcePolicyBuilder; +import org.apache.tuscany.core.builder.TargetPolicyBuilder; +import org.apache.tuscany.core.wire.Interceptor; +import org.apache.tuscany.core.wire.SourceInvocationConfiguration; +import org.apache.tuscany.core.wire.SourceWireFactory; +import org.apache.tuscany.core.wire.TargetInvocationConfiguration; +import org.apache.tuscany.core.wire.TargetWireFactory; +import org.apache.tuscany.core.wire.WireFactory; +import org.apache.tuscany.core.wire.WireSourceConfiguration; +import org.apache.tuscany.core.wire.WireTargetConfiguration; +import org.apache.tuscany.model.assembly.AssemblyObject; +import org.apache.tuscany.model.assembly.ConfiguredReference; +import org.apache.tuscany.model.assembly.ConfiguredService; + +import java.util.List; + +/** + * Adds an interceptor to a source or target proxy configuration + * + * @version $Rev$ $Date$ + */ +public class MockInterceptorBuilder implements SourcePolicyBuilder, TargetPolicyBuilder { + + private Interceptor interceptor; + + /** + * Creates the builder + * + * @param interceptor the interceptor ot add + * @param source true if the interceptor should be added to the source side; false if the interceptor should be added to + * the target side + */ + public MockInterceptorBuilder(Interceptor interceptor, boolean source) { + this.interceptor = interceptor; + } + + public void build(ConfiguredReference reference, List<WireSourceConfiguration> configurations) throws BuilderException { + for (WireSourceConfiguration wireSourceConfiguration : configurations) { + for (SourceInvocationConfiguration configuration : wireSourceConfiguration.getInvocationConfigurations().values()) { + configuration.addInterceptor(interceptor); + } + } + } + + public void build(ConfiguredService service, WireTargetConfiguration configuration) throws BuilderException { + for (TargetInvocationConfiguration config : configuration.getInvocationConfigurations().values()) { + config.addInterceptor(interceptor); + } + } +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/context/DifferentInterfaceWireTestCase.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/context/DifferentInterfaceWireTestCase.java new file mode 100644 index 0000000000..ed91b9cb9b --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/context/DifferentInterfaceWireTestCase.java @@ -0,0 +1,81 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package org.apache.tuscany.container.java.context; + +import java.util.ArrayList; +import java.util.List; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.apache.tuscany.container.java.builder.JavaContextFactoryBuilder; +import org.apache.tuscany.container.java.builder.JavaTargetWireBuilder; +import org.apache.tuscany.container.java.mock.MockConfigContext; +import org.apache.tuscany.container.java.mock.MockFactory; +import org.apache.tuscany.container.java.mock.components.OtherTarget; +import org.apache.tuscany.container.java.mock.components.Source; +import org.apache.tuscany.container.java.mock.components.Target; +import org.apache.tuscany.core.builder.ContextFactoryBuilder; +import org.apache.tuscany.core.builder.WireBuilder; +import org.apache.tuscany.core.builder.system.DefaultPolicyBuilderRegistry; +import org.apache.tuscany.core.context.CompositeContext; +import org.apache.tuscany.core.context.AtomicContext; +import org.apache.tuscany.core.context.event.ModuleStart; +import org.apache.tuscany.core.context.impl.CompositeContextImpl; +import org.apache.tuscany.core.wire.jdk.JDKWireFactoryFactory; +import org.apache.tuscany.core.wire.service.WireFactoryService; +import org.apache.tuscany.core.wire.service.DefaultWireFactoryService; +import org.apache.tuscany.core.message.impl.MessageFactoryImpl; +import org.apache.tuscany.model.assembly.Scope; + +/** + * Tests wires that have different interfaces on the source and target side + * + * @version $Rev$ $Date$ + */ +public class DifferentInterfaceWireTestCase extends TestCase { + + public void testMultiplicity() throws Exception { + + CompositeContext context = createContext(); + context.start(); + context.registerModelObject(MockFactory.createModuleWithWiredComponentsOfDifferentInterface(Scope.MODULE, Scope.MODULE)); + context.publish(new ModuleStart(this)); + Source source = (Source) ((AtomicContext) context.getContext("source")).getTargetInstance(); + Assert.assertNotNull(source); + OtherTarget target = (OtherTarget) ((AtomicContext)context.getContext("target")).getTargetInstance(); + Assert.assertNotNull(target); + // test setter injection + List<Target> targets = source.getTargets(); + Assert.assertEquals(1, targets.size()); + + // test field injection + targets = source.getTargetsThroughField(); + Assert.assertEquals(1, targets.size()); + targets.get(0).setString("foo"); + Assert.assertEquals("foo",target.getString()); + } + + private CompositeContext createContext() { + CompositeContextImpl context = new CompositeContextImpl(); + context.setName("system.context"); + List<ContextFactoryBuilder>builders = MockFactory.createSystemBuilders(); + WireFactoryService wireService = new DefaultWireFactoryService(new MessageFactoryImpl(), new JDKWireFactoryFactory(), new DefaultPolicyBuilderRegistry()); + builders.add(new JavaContextFactoryBuilder(wireService)); + List<WireBuilder> wireBuilders = new ArrayList<WireBuilder>(); + wireBuilders.add(new JavaTargetWireBuilder()); + context.setConfigurationContext(new MockConfigContext(builders,wireBuilders)); + return context; + } +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/context/JavaAtomicContextLifecycleTestCase.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/context/JavaAtomicContextLifecycleTestCase.java new file mode 100644 index 0000000000..c257a1f892 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/context/JavaAtomicContextLifecycleTestCase.java @@ -0,0 +1,59 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.context; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.apache.tuscany.container.java.mock.MockFactory; +import org.apache.tuscany.container.java.mock.components.ModuleScopeInitOnlyComponent; +import org.apache.tuscany.container.java.mock.components.ModuleScopeInitDestroyComponent; +import org.apache.tuscany.core.context.CompositeContext; +import org.apache.tuscany.core.context.impl.CompositeContextImpl; +import org.apache.tuscany.model.assembly.Scope; + +/** + * Tests init and destroy lifecycle callbacks are handled properly + * + * @version $Rev$ $Date$ + */ +public class JavaAtomicContextLifecycleTestCase extends TestCase { + + public void testComponentNameSet() throws Exception { + CompositeContext mc = new CompositeContextImpl(); + mc.setName("mc"); + JavaAtomicContext context = MockFactory.createPojoContext("TestServiceInit", + ModuleScopeInitOnlyComponent.class, Scope.MODULE, mc); + context.start(); + ModuleScopeInitOnlyComponent instance = (ModuleScopeInitOnlyComponent) context.getInstance(null); + Assert.assertNotNull(instance); + Assert.assertEquals("TestServiceInit", instance.getName()); + context.stop(); + } + + public void testModuleContextSet() throws Exception { + CompositeContext mc = new CompositeContextImpl(); + mc.setName("mc"); + JavaAtomicContext context = MockFactory.createPojoContext("TestServiceInit", + ModuleScopeInitOnlyComponent.class, Scope.MODULE, mc); + context.start(); + ModuleScopeInitOnlyComponent instance = (ModuleScopeInitOnlyComponent) context.getInstance(null); + Assert.assertNotNull(instance); + Assert.assertEquals(mc, instance.getModuleContext()); + context.stop(); + } +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/context/JavaAtomicContextMetadataInjectionTestCase.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/context/JavaAtomicContextMetadataInjectionTestCase.java new file mode 100644 index 0000000000..a79a04f5ab --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/context/JavaAtomicContextMetadataInjectionTestCase.java @@ -0,0 +1,58 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.context; + +import junit.framework.TestCase; +import junit.framework.Assert; +import org.apache.tuscany.core.context.CompositeContext; +import org.apache.tuscany.core.context.impl.CompositeContextImpl; +import org.apache.tuscany.container.java.mock.MockFactory; +import org.apache.tuscany.container.java.mock.components.ModuleScopeInitOnlyComponent; +import org.apache.tuscany.container.java.mock.components.ModuleScopeInitDestroyComponent; +import org.apache.tuscany.model.assembly.Scope; + +/** + * Tests SCA metadata such as <code>@ComponentName</code> and <code>@Context</code> are handled properly + * + * @version $Rev: 394173 $ $Date: 2006-04-14 11:54:59 -0700 (Fri, 14 Apr 2006) $ + */ +public class JavaAtomicContextMetadataInjectionTestCase extends TestCase { + + public void testComponentNameSet() throws Exception { + CompositeContext mc = new CompositeContextImpl(); + mc.setName("mc"); + JavaAtomicContext context = MockFactory.createPojoContext("TestServiceInit", + ModuleScopeInitOnlyComponent.class, Scope.MODULE, mc); + context.start(); + ModuleScopeInitOnlyComponent instance = (ModuleScopeInitOnlyComponent) context.getInstance(null); + Assert.assertNotNull(instance); + Assert.assertEquals("TestServiceInit", instance.getName()); + context.stop(); + } + + public void testModuleContextSet() throws Exception { + CompositeContext mc = new CompositeContextImpl(); + mc.setName("mc"); + JavaAtomicContext context = MockFactory.createPojoContext("TestServiceInit", + ModuleScopeInitOnlyComponent.class, Scope.MODULE, mc); + context.start(); + ModuleScopeInitOnlyComponent instance = (ModuleScopeInitOnlyComponent) context.getInstance(null); + Assert.assertNotNull(instance); + Assert.assertEquals(mc, instance.getModuleContext()); + context.stop(); + } +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/context/JavaAtomicContextNegativeMetadataTestCase.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/context/JavaAtomicContextNegativeMetadataTestCase.java new file mode 100644 index 0000000000..0a4527f405 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/context/JavaAtomicContextNegativeMetadataTestCase.java @@ -0,0 +1,73 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.context; + +import junit.framework.TestCase; + +import org.apache.tuscany.container.java.mock.MockFactory; +import org.apache.tuscany.container.java.mock.components.BadContextPojo; +import org.apache.tuscany.container.java.mock.components.BadNamePojo; +import org.apache.tuscany.core.context.CompositeContext; +import org.apache.tuscany.core.context.impl.CompositeContextImpl; +import org.apache.tuscany.model.assembly.Scope; + +/** + * Performs rudimentary negative testing by using malformed metadata on a POJO + * + * @version $Rev $Date + */ +public class JavaAtomicContextNegativeMetadataTestCase extends TestCase { + + /** + * Tests that a pojo with <code>@ComponentName</code> specified on a non-String type generates an error. + * <p/> + * <strong>NB:</strong> the test assumes an error with a message containing + * "@ComponentName" is generated + */ + public void testBadNameType() throws Exception { + CompositeContext mc = new CompositeContextImpl(); + mc.setName("mc"); + try { + MockFactory.createPojoContext("BadNamePojo", BadNamePojo.class, Scope.MODULE, mc); + } catch (NoSuchMethodException e) { + if (e.getMessage().indexOf("@ComponentName") < 0) { + throw e; + } + } + + } + + /** + * Tests that a pojo with <code>@Context</code> specified on a non-ModuleContext type generates an error. + * <p/> + * <strong>NB:</strong> the test assumes an error with a message containing + * "@Context" is generated + */ + public void testContextType() throws Exception { + CompositeContext mc = new CompositeContextImpl(); + mc.setName("mc"); + try { + MockFactory.createPojoContext("BadContextPojo", BadContextPojo.class, Scope.MODULE, mc); + } catch (NoSuchMethodException e) { + if (e.getMessage().indexOf("@Context") < 0) { + throw e; + } + } + + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/context/JavaAtomicContextScopeTestCase.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/context/JavaAtomicContextScopeTestCase.java new file mode 100644 index 0000000000..96bff0cf2e --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/context/JavaAtomicContextScopeTestCase.java @@ -0,0 +1,95 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.context; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.apache.tuscany.container.java.assembly.JavaAssemblyFactory; +import org.apache.tuscany.container.java.assembly.impl.JavaAssemblyFactoryImpl; +import org.apache.tuscany.container.java.mock.components.GenericComponent; +import org.apache.tuscany.container.java.mock.components.ModuleScopeComponentImpl; +import org.apache.tuscany.container.java.mock.components.RequestScopeComponentImpl; +import org.apache.tuscany.container.java.mock.components.SessionScopeComponentImpl; +import org.apache.tuscany.container.java.mock.components.StatelessComponentImpl; +import org.apache.tuscany.core.config.JavaIntrospectionHelper; +import org.apache.tuscany.core.context.CompositeContext; +import org.apache.tuscany.core.context.impl.CompositeContextImpl; +import org.apache.tuscany.core.injection.PojoObjectFactory; + +/** + * Tests {@link JavaAtomicContext} to ensure it handles component scopes properly + * + * @version $Rev$ $Date$ + */ +public class JavaAtomicContextScopeTestCase extends TestCase { + + JavaAssemblyFactory factory = new JavaAssemblyFactoryImpl(); + + public void testGetModuleInstance() throws Exception { + CompositeContext mc = new CompositeContextImpl(); + mc.setName("mc"); + JavaAtomicContext c = new JavaAtomicContext("foo", new PojoObjectFactory<ModuleScopeComponentImpl>(JavaIntrospectionHelper + .getDefaultConstructor(ModuleScopeComponentImpl.class), null, null), false, null, null, false); + GenericComponent service = (GenericComponent) c.getInstance(null); + Assert.assertNotNull(service); + service.setString("foo"); + GenericComponent service2 = (GenericComponent) c.getInstance(null); + Assert.assertNotNull(service2); + Assert.assertSame(service, service2); + } + + public void testGetSessionInstance() throws Exception { + CompositeContext mc = new CompositeContextImpl(); + mc.setName("mc"); + JavaAtomicContext c = new JavaAtomicContext("foo", new PojoObjectFactory<SessionScopeComponentImpl>(JavaIntrospectionHelper + .getDefaultConstructor(SessionScopeComponentImpl.class), null, null), false, null, null, false); + GenericComponent service = (GenericComponent) c.getInstance(null); + Assert.assertNotNull(service); + service.setString("foo"); + GenericComponent service2 = (GenericComponent) c.getInstance(null); + Assert.assertNotNull(service2); + Assert.assertSame(service, service2); + } + + public void testGetRequestInstance() throws Exception { + CompositeContext mc = new CompositeContextImpl(); + mc.setName("mc"); + JavaAtomicContext c = new JavaAtomicContext("foo", new PojoObjectFactory<RequestScopeComponentImpl>(JavaIntrospectionHelper + .getDefaultConstructor(RequestScopeComponentImpl.class), null, null), false, null, null, false); + GenericComponent service = (GenericComponent) c.getInstance(null); + Assert.assertNotNull(service); + service.setString("foo"); + GenericComponent service2 = (GenericComponent) c.getInstance(null); + Assert.assertNotNull(service2); + Assert.assertSame(service, service2); + } + + public void testGetStatelessInstance() throws Exception { + CompositeContext mc = new CompositeContextImpl(); + mc.setName("fooContext"); + JavaAtomicContext c = new JavaAtomicContext("foo", new PojoObjectFactory<StatelessComponentImpl>(JavaIntrospectionHelper + .getDefaultConstructor(StatelessComponentImpl.class), null, null), false, null, null, true); + GenericComponent service = (GenericComponent) c.getInstance(null); + Assert.assertNotNull(service); + service.setString("foo"); + GenericComponent service2 = (GenericComponent) c.getInstance(null); + Assert.assertNotNull(service2); + Assert.assertTrue(!"foo".equals(service2.getString())); + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/context/MultiplicityTestCase.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/context/MultiplicityTestCase.java new file mode 100644 index 0000000000..a22a8dfce2 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/context/MultiplicityTestCase.java @@ -0,0 +1,77 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package org.apache.tuscany.container.java.context; + +import java.util.ArrayList; +import java.util.List; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.apache.tuscany.container.java.builder.JavaContextFactoryBuilder; +import org.apache.tuscany.container.java.builder.JavaTargetWireBuilder; +import org.apache.tuscany.container.java.mock.MockConfigContext; +import org.apache.tuscany.container.java.mock.MockFactory; +import org.apache.tuscany.container.java.mock.components.Source; +import org.apache.tuscany.container.java.mock.components.Target; +import org.apache.tuscany.core.builder.ContextFactoryBuilder; +import org.apache.tuscany.core.builder.WireBuilder; +import org.apache.tuscany.core.builder.system.DefaultPolicyBuilderRegistry; +import org.apache.tuscany.core.context.CompositeContext; +import org.apache.tuscany.core.context.AtomicContext; +import org.apache.tuscany.core.context.event.ModuleStart; +import org.apache.tuscany.core.context.impl.CompositeContextImpl; +import org.apache.tuscany.core.wire.jdk.JDKWireFactoryFactory; +import org.apache.tuscany.core.wire.service.WireFactoryService; +import org.apache.tuscany.core.wire.service.DefaultWireFactoryService; +import org.apache.tuscany.core.message.impl.MessageFactoryImpl; +import org.apache.tuscany.model.assembly.Scope; + +/** + * Tests wires that are configured with a multiplicity + * + * @version $Rev$ $Date$ + */ +public class MultiplicityTestCase extends TestCase { + + public void testMultiplicity() throws Exception { + CompositeContext context = createContext(); + context.start(); + context.registerModelObject(MockFactory.createModuleWithWiredComponents(Scope.MODULE, Scope.MODULE)); + context.publish(new ModuleStart(this)); + Source source = (Source) ((AtomicContext) context.getContext("source")).getTargetInstance(); + Assert.assertNotNull(source); + Target target = (Target) ((AtomicContext)context.getContext("target")).getTargetInstance(); + Assert.assertNotNull(target); + // test setter injection + List<Target> targets = source.getTargets(); + Assert.assertEquals(1, targets.size()); + + // test field injection + targets = source.getTargetsThroughField(); + Assert.assertEquals(1, targets.size()); + } + + private CompositeContext createContext() { + CompositeContextImpl context = new CompositeContextImpl(); + context.setName("system.context"); + List<ContextFactoryBuilder>builders = MockFactory.createSystemBuilders(); + WireFactoryService wireService = new DefaultWireFactoryService(new MessageFactoryImpl(), new JDKWireFactoryFactory(), new DefaultPolicyBuilderRegistry()); + builders.add(new JavaContextFactoryBuilder(wireService)); + List<WireBuilder> wireBuilders = new ArrayList<WireBuilder>(); + wireBuilders.add(new JavaTargetWireBuilder()); + context.setConfigurationContext(new MockConfigContext(builders,wireBuilders)); + return context; + } +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/GreetingProvider.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/GreetingProvider.java new file mode 100644 index 0000000000..58180674b3 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/GreetingProvider.java @@ -0,0 +1,24 @@ +/** + * + * Copyright 2005 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.integration; + +/** + * @version $Rev$ $Date$ + */ +public interface GreetingProvider { + String getGreeting(String name, String locale); +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/GreetingProviderImpl.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/GreetingProviderImpl.java new file mode 100644 index 0000000000..fef068c22e --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/GreetingProviderImpl.java @@ -0,0 +1,42 @@ +/** + * + * Copyright 2005 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.integration; + +import org.osoa.sca.annotations.Property; +import org.osoa.sca.annotations.Service; + +/** + * @version $Rev$ $Date$ + */ +@Service(GreetingProvider.class) +public class GreetingProviderImpl implements GreetingProvider { + + public String greeting; + + @Property + public void setGreeting(String greeting) { + this.greeting = greeting; + } + + public String getGreeting(String name, String locale) { + if ("fr".equals(locale)) { + return "Bonjour " + name; + } else { + return greeting + name; + } + } +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/HelloWorldImpl.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/HelloWorldImpl.java new file mode 100644 index 0000000000..9ff58f2d8d --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/HelloWorldImpl.java @@ -0,0 +1,29 @@ +/** + * + * Copyright 2005 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.integration; + +import org.osoa.sca.annotations.Service; + +/** + * @version $Rev$ $Date$ + */ +@Service(HelloWorldService.class) +public class HelloWorldImpl implements HelloWorldService { + public String getGreetings(String name) { + return "Hello " + name; + } +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/HelloWorldMCImpl.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/HelloWorldMCImpl.java new file mode 100644 index 0000000000..aa5069c232 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/HelloWorldMCImpl.java @@ -0,0 +1,61 @@ +/** + * + * Copyright 2005 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.integration; + +import org.osoa.sca.annotations.Property; +import org.osoa.sca.annotations.Reference; +import org.osoa.sca.annotations.Service; +import org.apache.tuscany.core.sdo.helper.SDOHelper; +import commonj.sdo.helper.TypeHelper; +import commonj.sdo.helper.DataFactory; + +/** + * @version $Rev$ $Date$ + */ +@Service(HelloWorldService.class) +public class HelloWorldMCImpl implements HelloWorldService { + + @Property + public String locale; + + public String getBar() { + return bar; + } + + @Property(name= "bar", required=true) + public void setXBar(String bar) { + this.bar = bar; + } + + public String bar; + + @Reference(name="greetingProvider") + public void setGreetingProvider(GreetingProvider greetingProvider) { + this.greetingProvider2 = greetingProvider; + } + + public GreetingProvider greetingProvider2; + + @Reference(required=false) + public GreetingProvider foo; + + public String getGreetings(String name) { + return greetingProvider2.getGreeting(name, locale); + } + + +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/HelloWorldMCTestCase.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/HelloWorldMCTestCase.java new file mode 100644 index 0000000000..5a73abd45a --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/HelloWorldMCTestCase.java @@ -0,0 +1,59 @@ +/** + * + * Copyright 2005 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.integration; + +import java.net.URL; +import java.net.URLClassLoader; + +import junit.framework.TestCase; +import org.apache.tuscany.core.client.TuscanyRuntime; +import org.osoa.sca.CurrentModuleContext; +import org.osoa.sca.ModuleContext; + +/** + * @version $Rev$ $Date$ + */ +public class HelloWorldMCTestCase extends TestCase { + private ClassLoader oldCL; + + public void testHelloWorld() throws Exception { + TuscanyRuntime tuscany = new TuscanyRuntime("test", "foo"); + tuscany.start(); + ModuleContext moduleContext = CurrentModuleContext.getContext(); + assertNotNull(moduleContext); + assertEquals("foo", moduleContext.getURI()); + HelloWorldService helloworldService = (HelloWorldService) moduleContext.locateService("HelloWorld"); + assertNotNull(helloworldService); + + String value = helloworldService .getGreetings("World"); + assertEquals("Hello World", value); + tuscany.stop(); + } + + protected void setUp() throws Exception { + super.setUp(); + URL url = getClass().getResource("/helloworldmc/"); + ClassLoader cl = new URLClassLoader(new URL[]{url}, getClass().getClassLoader()); + oldCL = Thread.currentThread().getContextClassLoader(); + Thread.currentThread().setContextClassLoader(cl); + } + + protected void tearDown() throws Exception { + Thread.currentThread().setContextClassLoader(oldCL); + super.tearDown(); + } +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/HelloWorldService.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/HelloWorldService.java new file mode 100644 index 0000000000..3abb99d7e0 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/HelloWorldService.java @@ -0,0 +1,24 @@ +/** + * + * Copyright 2005 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.integration; + +/** + * @version $Rev$ $Date$ + */ +public interface HelloWorldService { + public String getGreetings(String name); +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/HelloWorldTestCase.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/HelloWorldTestCase.java new file mode 100644 index 0000000000..c714b416e4 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/HelloWorldTestCase.java @@ -0,0 +1,61 @@ +/** + * + * Copyright 2005 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.integration; + +import java.net.URL; +import java.net.URLClassLoader; + +import junit.framework.TestCase; +import org.osoa.sca.CurrentModuleContext; +import org.osoa.sca.ModuleContext; + +import org.apache.tuscany.core.client.TuscanyRuntime; + +/** + * @version $Rev$ $Date$ + */ +public class HelloWorldTestCase extends TestCase { + private ClassLoader oldCL; + + public void testHelloWorld() throws Exception { + TuscanyRuntime tuscany = new TuscanyRuntime("test", null); + tuscany.start(); + ModuleContext moduleContext = CurrentModuleContext.getContext(); + assertNotNull(moduleContext); + + HelloWorldService helloworldService = (HelloWorldService) moduleContext.locateService("HelloWorld"); + assertNotNull(helloworldService); + + String value = helloworldService .getGreetings("World"); + assertEquals("Hello World", value); + + tuscany.stop(); + } + + protected void setUp() throws Exception { + super.setUp(); + URL url = getClass().getResource("/helloworld/"); + ClassLoader cl = new URLClassLoader(new URL[]{url}, getClass().getClassLoader()); + oldCL = Thread.currentThread().getContextClassLoader(); + Thread.currentThread().setContextClassLoader(cl); + } + + protected void tearDown() throws Exception { + Thread.currentThread().setContextClassLoader(oldCL); + super.tearDown(); + } +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/JavaBuilderContextIntegrationTestCase.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/JavaBuilderContextIntegrationTestCase.java new file mode 100644 index 0000000000..f7cc2ed149 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/JavaBuilderContextIntegrationTestCase.java @@ -0,0 +1,189 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package org.apache.tuscany.container.java.integration; + +import junit.framework.Assert; +import junit.framework.TestCase; +import org.apache.tuscany.common.monitor.impl.NullMonitorFactory; +import org.apache.tuscany.container.java.builder.JavaContextFactoryBuilder; +import org.apache.tuscany.container.java.builder.JavaTargetWireBuilder; +import org.apache.tuscany.container.java.builder.MockHandlerBuilder; +import org.apache.tuscany.container.java.builder.MockInterceptorBuilder; +import org.apache.tuscany.container.java.invocation.mock.MockHandler; +import org.apache.tuscany.container.java.invocation.mock.MockSyncInterceptor; +import org.apache.tuscany.container.java.mock.MockFactory; +import org.apache.tuscany.container.java.mock.components.GenericComponent; +import org.apache.tuscany.core.builder.ContextFactoryBuilderRegistry; +import org.apache.tuscany.core.builder.impl.DefaultWireBuilder; +import org.apache.tuscany.core.builder.system.DefaultPolicyBuilderRegistry; +import org.apache.tuscany.core.builder.system.PolicyBuilderRegistry; +import org.apache.tuscany.core.client.BootstrapHelper; +import org.apache.tuscany.core.context.CompositeContext; +import org.apache.tuscany.core.context.event.ModuleStart; +import org.apache.tuscany.core.context.event.ModuleStop; +import org.apache.tuscany.core.message.impl.MessageFactoryImpl; +import org.apache.tuscany.core.runtime.RuntimeContext; +import org.apache.tuscany.core.runtime.RuntimeContextImpl; +import org.apache.tuscany.core.wire.jdk.JDKWireFactoryFactory; +import org.apache.tuscany.core.wire.service.DefaultWireFactoryService; +import org.apache.tuscany.core.wire.service.WireFactoryService; + +/** + * Verifies that the composite context implementation and java component builders construct references properly + * + * @version $Rev$ $Date$ + */ +public class JavaBuilderContextIntegrationTestCase extends TestCase { + private ContextFactoryBuilderRegistry builderRegistry; + private DefaultWireBuilder defaultWireBuilder; + private NullMonitorFactory monitorFactory; + + public JavaBuilderContextIntegrationTestCase(String arg0) { + super(arg0); + } + + protected void setUp() throws Exception { + super.setUp(); + monitorFactory = new NullMonitorFactory(); + builderRegistry = BootstrapHelper.bootstrapContextFactoryBuilders(monitorFactory); + defaultWireBuilder = new DefaultWireBuilder(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public void testRefWithSourceInterceptor() throws Exception { + MockSyncInterceptor mockInterceptor = new MockSyncInterceptor(); + MockInterceptorBuilder interceptorBuilder = new MockInterceptorBuilder(mockInterceptor, true); + PolicyBuilderRegistry policyRegistry = new DefaultPolicyBuilderRegistry(); + policyRegistry.registerSourceBuilder(interceptorBuilder); + WireFactoryService wireFactory = new DefaultWireFactoryService(new MessageFactoryImpl(), new JDKWireFactoryFactory(), policyRegistry); + JavaContextFactoryBuilder javaBuilder = new JavaContextFactoryBuilder(wireFactory); + + builderRegistry.register(javaBuilder); + + RuntimeContext runtime = new RuntimeContextImpl(monitorFactory, builderRegistry, defaultWireBuilder); + runtime.addBuilder(new JavaTargetWireBuilder()); + runtime.start(); + runtime.getRootContext().registerModelObject( + MockFactory.createCompositeComponent("test.module")); + CompositeContext child = (CompositeContext) runtime.getRootContext().getContext("test.module"); + child.registerModelObject(MockFactory.createModule()); + child.publish(new ModuleStart(this)); + GenericComponent source = (GenericComponent) child.getContext("source").getInstance(null); + Assert.assertNotNull(source); + source.getGenericComponent().getString(); + Assert.assertEquals(1, mockInterceptor.getCount()); + source.getGenericComponent().getString(); + Assert.assertEquals(2, mockInterceptor.getCount()); + child.publish(new ModuleStop(this)); + runtime.stop(); + } + + public void testRefWithSourceInterceptorHandler() throws Exception { + MockSyncInterceptor mockInterceptor = new MockSyncInterceptor(); + MockInterceptorBuilder interceptorBuilder = new MockInterceptorBuilder(mockInterceptor, true); + MockHandler mockHandler = new MockHandler(); + MockHandlerBuilder handlerBuilder = new MockHandlerBuilder(mockHandler, true, true); + PolicyBuilderRegistry policyRegistry = new DefaultPolicyBuilderRegistry(); + policyRegistry.registerSourceBuilder(interceptorBuilder); + policyRegistry.registerSourceBuilder(handlerBuilder); + WireFactoryService wireFactory = new DefaultWireFactoryService(new MessageFactoryImpl(), new JDKWireFactoryFactory(), policyRegistry); + JavaContextFactoryBuilder javaBuilder = new JavaContextFactoryBuilder(wireFactory); + + builderRegistry.register(javaBuilder); + RuntimeContext runtime = new RuntimeContextImpl(monitorFactory, builderRegistry, defaultWireBuilder); + runtime.addBuilder(new JavaTargetWireBuilder()); + runtime.start(); + runtime.getRootContext().registerModelObject( + MockFactory.createCompositeComponent("test.module")); + CompositeContext child = (CompositeContext) runtime.getRootContext().getContext("test.module"); + child.registerModelObject(MockFactory.createModule()); + child.publish(new ModuleStart(this)); + GenericComponent source = (GenericComponent) child.getContext("source").getInstance(null); + Assert.assertNotNull(source); + source.getGenericComponent().getString(); + Assert.assertEquals(1, mockInterceptor.getCount()); + Assert.assertEquals(1, mockHandler.getCount()); + source.getGenericComponent().getString(); + Assert.assertEquals(2, mockInterceptor.getCount()); + Assert.assertEquals(2, mockHandler.getCount()); + child.publish(new ModuleStop(this)); + runtime.stop(); + } + + public void testRefWithTargetInterceptorHandler() throws Exception { + MockSyncInterceptor mockInterceptor = new MockSyncInterceptor(); + MockInterceptorBuilder interceptorBuilder = new MockInterceptorBuilder(mockInterceptor, false); + MockHandler mockHandler = new MockHandler(); + MockHandlerBuilder handlerBuilder = new MockHandlerBuilder(mockHandler, false, true); + PolicyBuilderRegistry policyRegistry = new DefaultPolicyBuilderRegistry(); + policyRegistry.registerSourceBuilder(interceptorBuilder); + policyRegistry.registerSourceBuilder(handlerBuilder); + WireFactoryService wireFactory = new DefaultWireFactoryService(new MessageFactoryImpl(), new JDKWireFactoryFactory(), policyRegistry); + JavaContextFactoryBuilder javaBuilder = new JavaContextFactoryBuilder(wireFactory); + + builderRegistry.register(javaBuilder); + + RuntimeContext runtime = new RuntimeContextImpl(monitorFactory, builderRegistry, defaultWireBuilder); + runtime.addBuilder(new JavaTargetWireBuilder()); + runtime.start(); + runtime.getRootContext().registerModelObject( + MockFactory.createCompositeComponent("test.module")); + CompositeContext child = (CompositeContext) runtime.getRootContext().getContext("test.module"); + child.registerModelObject(MockFactory.createModule()); + child.publish(new ModuleStart(this)); + GenericComponent source = (GenericComponent) child.getContext("source").getInstance(null); + Assert.assertNotNull(source); + source.getGenericComponent().getString(); + Assert.assertEquals(1, mockInterceptor.getCount()); + Assert.assertEquals(1, mockHandler.getCount()); + source.getGenericComponent().getString(); + Assert.assertEquals(2, mockInterceptor.getCount()); + Assert.assertEquals(2, mockHandler.getCount()); + child.publish(new ModuleStop(this)); + runtime.stop(); + } + + public void testRefWithTargetInterceptor() throws Exception { + MockSyncInterceptor mockInterceptor = new MockSyncInterceptor(); + MockInterceptorBuilder interceptorBuilder = new MockInterceptorBuilder(mockInterceptor, false); + PolicyBuilderRegistry policyRegistry = new DefaultPolicyBuilderRegistry(); + policyRegistry.registerSourceBuilder(interceptorBuilder); + WireFactoryService wireFactory = new DefaultWireFactoryService(new MessageFactoryImpl(), new JDKWireFactoryFactory(), policyRegistry); + JavaContextFactoryBuilder javaBuilder = new JavaContextFactoryBuilder(wireFactory); + + builderRegistry.register(javaBuilder); + + RuntimeContext runtime = new RuntimeContextImpl(monitorFactory, builderRegistry, defaultWireBuilder); + runtime.addBuilder(new JavaTargetWireBuilder()); + + runtime.start(); + runtime.getRootContext().registerModelObject( + MockFactory.createCompositeComponent("test.module")); + CompositeContext child = (CompositeContext) runtime.getRootContext().getContext("test.module"); + child.registerModelObject(MockFactory.createModule()); + child.publish(new ModuleStart(this)); + GenericComponent source = (GenericComponent) child.getContext("source").getInstance(null); + Assert.assertNotNull(source); + source.getGenericComponent().getString(); + Assert.assertEquals(1, mockInterceptor.getCount()); + source.getGenericComponent().getString(); + Assert.assertEquals(2, mockInterceptor.getCount()); + child.publish(new ModuleStop(this)); + runtime.stop(); + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/JavaIntegrationTestCase.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/JavaIntegrationTestCase.java new file mode 100644 index 0000000000..a5ec39480f --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/JavaIntegrationTestCase.java @@ -0,0 +1,68 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.integration; + +import junit.framework.TestCase; + +import org.apache.tuscany.common.monitor.MonitorFactory; +import org.apache.tuscany.common.monitor.impl.NullMonitorFactory; +import org.apache.tuscany.container.java.assembly.JavaAssemblyFactory; +import org.apache.tuscany.container.java.assembly.impl.JavaAssemblyFactoryImpl; +import org.apache.tuscany.core.builder.ContextFactoryBuilderRegistry; +import org.apache.tuscany.core.builder.impl.DefaultWireBuilder; +import org.apache.tuscany.core.client.BootstrapHelper; +import org.apache.tuscany.core.runtime.RuntimeContext; +import org.apache.tuscany.core.runtime.RuntimeContextImpl; +import org.apache.tuscany.model.assembly.Module; +import org.apache.tuscany.model.assembly.ModuleComponent; + +/** + * Integration test that verifies container.java can be used to host components. + * + * @version $Rev$ $Date$ + */ +public class JavaIntegrationTestCase extends TestCase { + private JavaAssemblyFactory factory; + private RuntimeContext runtime; + + public void testModuleWithOneComponent() throws Exception { + Module module = factory.createModule(); + ModuleComponent moduleComponent = factory.createModuleComponent(); + moduleComponent.setImplementation(module); + +// runtime.registerModelObject(moduleComponent); + } + + protected void setUp() throws Exception { + super.setUp(); + + // Create a factory for model objects + factory = new JavaAssemblyFactoryImpl(); + + // Create and bootstrap an empty Tuscany runtime + MonitorFactory monitorFactory = new NullMonitorFactory(); + ContextFactoryBuilderRegistry builderRegistry = BootstrapHelper.bootstrapContextFactoryBuilders(monitorFactory); + DefaultWireBuilder wireBuilder = new DefaultWireBuilder(); + runtime = new RuntimeContextImpl(monitorFactory, builderRegistry, wireBuilder); + runtime.start(); + } + + protected void tearDown() throws Exception { + runtime.stop(); + super.tearDown(); + } +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/JavaRuntimeBootstrapTestCase.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/JavaRuntimeBootstrapTestCase.java new file mode 100644 index 0000000000..6a9fca90c9 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/JavaRuntimeBootstrapTestCase.java @@ -0,0 +1,53 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package org.apache.tuscany.container.java.integration; + +import org.apache.tuscany.container.java.mock.MockFactory; +import org.apache.tuscany.container.java.mock.components.GenericComponent; +import org.apache.tuscany.core.context.CompositeContext; +import org.apache.tuscany.core.context.Context; +import org.apache.tuscany.core.context.event.ModuleStart; +import org.apache.tuscany.core.runtime.RuntimeContext; + +import junit.framework.Assert; +import junit.framework.TestCase; + +/** + * Ensures basic runtime with Java support boots properly + * + * @version $Rev$ $Date$ + */ +public class JavaRuntimeBootstrapTestCase extends TestCase { + + /** + * Tests the runtime can be bootstrapped with Java builders and two module-scoped Java-based components can be wired + */ + public void testRuntimeBoot() throws Exception{ + RuntimeContext runtime = MockFactory.createJavaRuntime(); + Context ctx = runtime.getSystemContext().getContext(MockFactory.SYSTEM_CHILD); + Assert.assertNotNull(ctx); + runtime.getRootContext().registerModelObject(MockFactory.createCompositeComponent("test")); + CompositeContext testCtx = (CompositeContext) runtime.getRootContext().getContext("test"); + Assert.assertNotNull(testCtx); + testCtx.registerModelObject(MockFactory.createModule()); + testCtx.publish(new ModuleStart(this)); + GenericComponent source = (GenericComponent)testCtx.getContext("source").getInstance(null); + Assert.assertNotNull(source); + GenericComponent target = (GenericComponent)testCtx.getContext("target").getInstance(null); + Assert.assertNotNull(target); + source.getGenericComponent().getString(); + } + +} + diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/StartStopTestCase.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/StartStopTestCase.java new file mode 100644 index 0000000000..8b7ed342c4 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/StartStopTestCase.java @@ -0,0 +1,68 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.integration; + +import java.net.URL; +import java.net.URLClassLoader; + +import junit.framework.TestCase; +import org.apache.tuscany.core.client.TuscanyRuntime; +import org.osoa.sca.ModuleContext; +import org.osoa.sca.CurrentModuleContext; + +/** + * @version $Rev$ $Date$ + */ +public class StartStopTestCase extends TestCase { + private ClassLoader oldCL; + + public void testHelloWorld() throws Exception { + TuscanyRuntime tuscany = new TuscanyRuntime("test", null); + tuscany.start(); + ModuleContext moduleContext = CurrentModuleContext.getContext(); + assertNotNull(moduleContext); + + HelloWorldService helloworldService = (HelloWorldService) moduleContext.locateService("HelloWorld"); + assertNotNull(helloworldService); + + String value = helloworldService .getGreetings("World"); + assertEquals("Hello World", value); + tuscany.stop(); + tuscany = new TuscanyRuntime("test", null); + tuscany.start(); + moduleContext = CurrentModuleContext.getContext(); + assertNotNull(moduleContext); + helloworldService = (HelloWorldService) moduleContext.locateService("HelloWorld"); + assertNotNull(helloworldService); + value = helloworldService .getGreetings("World"); + assertEquals("Hello World", value); + tuscany.stop(); + } + + protected void setUp() throws Exception { + super.setUp(); + URL url = getClass().getResource("/helloworldmc/"); + ClassLoader cl = new URLClassLoader(new URL[]{url}, getClass().getClassLoader()); + oldCL = Thread.currentThread().getContextClassLoader(); + Thread.currentThread().setContextClassLoader(cl); + } + + protected void tearDown() throws Exception { + Thread.currentThread().setContextClassLoader(oldCL); + super.tearDown(); + } +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/binding/EPtoExternalServiceTestCase.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/binding/EPtoExternalServiceTestCase.java new file mode 100644 index 0000000000..17424669bc --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/binding/EPtoExternalServiceTestCase.java @@ -0,0 +1,99 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.integration.binding; + +import junit.framework.Assert; +import junit.framework.TestCase; +import org.apache.tuscany.container.java.assembly.mock.HelloWorldService; +import org.apache.tuscany.container.java.builder.MockInterceptorBuilder; +import org.apache.tuscany.container.java.invocation.mock.MockSyncInterceptor; +import org.apache.tuscany.container.java.mock.MockFactory; +import org.apache.tuscany.core.builder.system.PolicyBuilderRegistry; +import org.apache.tuscany.core.context.CompositeContext; +import org.apache.tuscany.core.context.EntryPointContext; +import org.apache.tuscany.core.context.event.ModuleStart; +import org.apache.tuscany.core.context.event.ModuleStop; +import org.apache.tuscany.core.context.event.RequestEnd; +import org.apache.tuscany.core.context.event.RequestStart; +import org.apache.tuscany.core.runtime.RuntimeContext; + +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; + +/** + * @version $$Rev$$ $$Date$$ + */ +public class EPtoExternalServiceTestCase extends TestCase { + private Method hello; + + /** + * Tests wiring of an entry point directly to an external service + */ + public void testEPtoESInvocation() throws Throwable { + RuntimeContext runtime = MockFactory.registerFooBinding(MockFactory.createJavaRuntime()); + PolicyBuilderRegistry registry = (PolicyBuilderRegistry) ((CompositeContext) runtime.getSystemContext().getContext(MockFactory.SYSTEM_CHILD)) + .getContext(MockFactory.POLICY_BUILDER_REGISTRY).getInstance(null); + MockSyncInterceptor mockInterceptor = new MockSyncInterceptor(); + MockInterceptorBuilder interceptorBuilder = new MockInterceptorBuilder(mockInterceptor, false); + registry.registerTargetBuilder(interceptorBuilder); + runtime.getRootContext().registerModelObject(MockFactory.createCompositeComponent("test.module")); + CompositeContext child = (CompositeContext) runtime.getRootContext().getContext("test.module"); + child.registerModelObject(MockFactory.createModuleWithEntryPointToExternalService()); + child.publish(new ModuleStart(this)); + Object id = new Object(); + child.publish(new RequestStart(this, id)); + EntryPointContext ctx = (EntryPointContext) child.getContext("source"); + Assert.assertNotNull(ctx); + InvocationHandler handler = (InvocationHandler) ctx.getHandler(); + Assert.assertEquals(0, mockInterceptor.getCount()); + Object response = handler.invoke(null, hello, new Object[]{"foo"}); + Assert.assertEquals("foo", response); + Assert.assertEquals(1, mockInterceptor.getCount()); + + ctx = (EntryPointContext) child.getContext("source"); + Assert.assertNotNull(ctx); + handler = (InvocationHandler) ctx.getHandler(); + response = handler.invoke(null, hello, new Object[]{"foo"}); + Assert.assertEquals("foo", response); + child.publish(new RequestEnd(this, id)); + + // second request + Object id2 = new Object(); + child.publish(new RequestStart(this, id2)); + ctx = (EntryPointContext) child.getContext("source"); + Assert.assertNotNull(ctx); + handler = (InvocationHandler) ctx.getHandler(); + Assert.assertEquals(2, mockInterceptor.getCount()); + response = handler.invoke(null, hello, new Object[]{"foo"}); + Assert.assertEquals("foo", response); + Assert.assertEquals(3, mockInterceptor.getCount()); + child.publish(new RequestEnd(this, id2)); + + child.publish(new ModuleStop(this)); + runtime.stop(); + + } + + protected void setUp() throws Exception { + super.setUp(); + hello = HelloWorldService.class.getMethod("hello", String.class); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/binding/EntryPointToJavaTestCase.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/binding/EntryPointToJavaTestCase.java new file mode 100644 index 0000000000..f8ba1e2192 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/binding/EntryPointToJavaTestCase.java @@ -0,0 +1,261 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package org.apache.tuscany.container.java.integration.binding; + +import junit.framework.Assert; +import junit.framework.TestCase; +import org.apache.tuscany.container.java.assembly.mock.HelloWorldService; +import org.apache.tuscany.container.java.builder.MockInterceptorBuilder; +import org.apache.tuscany.container.java.invocation.mock.MockSyncInterceptor; +import org.apache.tuscany.container.java.mock.MockFactory; +import org.apache.tuscany.core.builder.system.PolicyBuilderRegistry; +import org.apache.tuscany.core.context.CompositeContext; +import org.apache.tuscany.core.context.EntryPointContext; +import org.apache.tuscany.core.context.event.HttpSessionBound; +import org.apache.tuscany.core.context.event.HttpSessionEnd; +import org.apache.tuscany.core.context.event.ModuleStart; +import org.apache.tuscany.core.context.event.ModuleStop; +import org.apache.tuscany.core.context.event.RequestEnd; +import org.apache.tuscany.core.context.event.RequestStart; +import org.apache.tuscany.core.runtime.RuntimeContext; +import org.apache.tuscany.model.assembly.Scope; + +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; + +/** + * Tests basic entry point functionality with Java components + * + * @version $Rev$ $Date$ + */ +public class EntryPointToJavaTestCase extends TestCase { + + private Method hello; + + public void setUp() throws Exception { + hello = HelloWorldService.class.getMethod("hello", String.class); + } + + /** + * Tests creation and wire of an entry point wired to a module-scoped service offered by a Java component + */ + public void testEPtoJavaModuleScopeInvoke() throws Throwable { + RuntimeContext runtime = MockFactory.registerFooBinding(MockFactory.createJavaRuntime()); + PolicyBuilderRegistry registry = (PolicyBuilderRegistry) ((CompositeContext) runtime.getSystemContext().getContext(MockFactory.SYSTEM_CHILD)) + .getContext(MockFactory.POLICY_BUILDER_REGISTRY).getInstance(null); + + MockSyncInterceptor mockInterceptor = new MockSyncInterceptor(); + MockInterceptorBuilder interceptorBuilder = new MockInterceptorBuilder(mockInterceptor, false); + registry.registerTargetBuilder(interceptorBuilder); + runtime.getRootContext().registerModelObject(MockFactory.createCompositeComponent("test.module")); + CompositeContext child = (CompositeContext) runtime.getRootContext().getContext("test.module"); + child.registerModelObject(MockFactory.createModuleWithEntryPoint(Scope.MODULE)); + child.publish(new ModuleStart(this)); + Object id = new Object(); + child.publish(new RequestStart(this, id)); + EntryPointContext ctx = (EntryPointContext) child.getContext("source"); + Assert.assertNotNull(ctx); + InvocationHandler handler = (InvocationHandler) ctx.getHandler(); + Assert.assertEquals(0, mockInterceptor.getCount()); + Object response = handler.invoke(null, hello, new Object[]{"foo"}); + Assert.assertEquals("Hello foo", response); + Assert.assertEquals(1, mockInterceptor.getCount()); + Object id2 = new Object(); + child.publish(new RequestStart(this, id2)); + + // second request + Object id3 = new Object(); + child.publish(new RequestStart(this, id3)); + ctx = (EntryPointContext) child.getContext("source"); + Assert.assertNotNull(ctx); + handler = (InvocationHandler) ctx.getHandler(); + Assert.assertEquals(1, mockInterceptor.getCount()); + response = handler.invoke(null, hello, new Object[]{"foo"}); + Assert.assertEquals("Hello foo", response); + Assert.assertEquals(2, mockInterceptor.getCount()); + HelloWorldService service1 = (HelloWorldService) child.getContext("target").getInstance(null); + Assert.assertEquals(2, service1.count()); + child.publish(new RequestEnd(this, id3)); + + child.publish(new ModuleStop(this)); + runtime.stop(); + } + + /** + * Tests creation and wire of an entry point wired to a session-scoped service offered by a Java component + */ + public void testEPtoJavaSessionScopeInvoke() throws Throwable { + RuntimeContext runtime = MockFactory.registerFooBinding(MockFactory.createJavaRuntime()); + PolicyBuilderRegistry registry = (PolicyBuilderRegistry) ((CompositeContext) runtime.getSystemContext().getContext(MockFactory.SYSTEM_CHILD)) + .getContext(MockFactory.POLICY_BUILDER_REGISTRY).getInstance(null); + MockSyncInterceptor mockInterceptor = new MockSyncInterceptor(); + MockInterceptorBuilder interceptorBuilder = new MockInterceptorBuilder(mockInterceptor, false); + registry.registerTargetBuilder(interceptorBuilder); + runtime.getRootContext().registerModelObject(MockFactory.createCompositeComponent("test.module")); + CompositeContext child = (CompositeContext) runtime.getRootContext().getContext("test.module"); + child.registerModelObject(MockFactory.createModuleWithEntryPoint(Scope.SESSION)); + child.publish(new ModuleStart(this)); + + // first session + Object session = new Object(); + Object id = new Object(); + child.publish(new RequestStart(this, id)); + child.publish(new HttpSessionBound(this, session)); + + EntryPointContext ctx = (EntryPointContext) child.getContext("source"); + Assert.assertNotNull(ctx); + InvocationHandler handler = (InvocationHandler) ctx.getHandler(); + Assert.assertEquals(0, mockInterceptor.getCount()); + Object response = handler.invoke(null, hello, new Object[]{"foo"}); + Assert.assertEquals("Hello foo", response); + Assert.assertEquals(1, mockInterceptor.getCount()); + child.publish(new RequestEnd(this, id)); + + Object id2 = new Object(); + child.publish(new RequestStart(this, id2)); + child.publish(new HttpSessionBound(this, session)); + EntryPointContext ctx2 = (EntryPointContext) child.getContext("source"); + Assert.assertNotNull(ctx2); + response = handler.invoke(null, hello, new Object[]{"foo"}); + Assert.assertEquals("Hello foo", response); + Assert.assertEquals(2, mockInterceptor.getCount()); + HelloWorldService service1 = (HelloWorldService) child.getContext("target").getInstance(null); + Assert.assertEquals(2, service1.count()); + child.publish(new RequestEnd(this, id2)); + child.publish(new HttpSessionEnd(this, session)); + + // second session + Object session2 = new Object(); + child.publish(new RequestStart(this, new Object())); + child.publish(new HttpSessionBound(this, session2)); + + ctx = (EntryPointContext) child.getContext("source"); + Assert.assertNotNull(ctx); + Assert.assertEquals(2, mockInterceptor.getCount()); + response = handler.invoke(null, hello, new Object[]{"foo"}); + Assert.assertEquals("Hello foo", response); + Assert.assertEquals(3, mockInterceptor.getCount()); + child.publish(new HttpSessionBound(this, session2)); + + Object id3 = new Object(); + child.publish(new RequestStart(this, id3)); + child.publish(new HttpSessionBound(this, session2)); + ctx2 = (EntryPointContext) child.getContext("source"); + Assert.assertNotNull(ctx2); + response = handler.invoke(null, hello, new Object[]{"foo"}); + Assert.assertEquals("Hello foo", response); + Assert.assertEquals(4, mockInterceptor.getCount()); + HelloWorldService service2 = (HelloWorldService) child.getContext("target").getInstance(null); + Assert.assertEquals(2, service2.count()); + Assert.assertEquals(2, service1.count()); //ensure sessions not crossed + child.publish(new RequestEnd(this, session2)); + child.publish(new HttpSessionBound(this, session2)); + + child.publish(new ModuleStop(this)); + runtime.stop(); + } + + + /** + * Tests creation and wire of an entry point wired to a module-scoped service offered by a Java component + */ + public void testEPtoJavaStatelessInvoke() throws Throwable { + RuntimeContext runtime = MockFactory.registerFooBinding(MockFactory.createJavaRuntime()); + PolicyBuilderRegistry registry = (PolicyBuilderRegistry) ((CompositeContext) runtime.getSystemContext().getContext(MockFactory.SYSTEM_CHILD)) + .getContext(MockFactory.POLICY_BUILDER_REGISTRY).getInstance(null); + MockSyncInterceptor mockInterceptor = new MockSyncInterceptor(); + MockInterceptorBuilder interceptorBuilder = new MockInterceptorBuilder(mockInterceptor, false); + registry.registerTargetBuilder(interceptorBuilder); + runtime.getRootContext().registerModelObject(MockFactory.createCompositeComponent("test.module")); + CompositeContext child = (CompositeContext) runtime.getRootContext().getContext("test.module"); + child.registerModelObject(MockFactory.createModuleWithEntryPoint(Scope.INSTANCE)); + child.publish(new ModuleStart(this)); + Object id = new Object(); + child.publish(new RequestStart(this, id)); + EntryPointContext ctx = (EntryPointContext) child.getContext("source"); + Assert.assertNotNull(ctx); + InvocationHandler handler = (InvocationHandler) ctx.getHandler(); + Assert.assertEquals(0, mockInterceptor.getCount()); + Object response = handler.invoke(null, hello, new Object[]{"foo"}); + Assert.assertEquals("Hello foo", response); + Assert.assertEquals(1, mockInterceptor.getCount()); + child.publish(new RequestEnd(this, id)); + + // second request + Object id2 = new Object(); + child.publish(new RequestStart(this, id2)); + ctx = (EntryPointContext) child.getContext("source"); + Assert.assertNotNull(ctx); + handler = (InvocationHandler) ctx.getHandler(); + Assert.assertEquals(1, mockInterceptor.getCount()); + response = handler.invoke(null, hello, new Object[]{"foo"}); + Assert.assertEquals("Hello foo", response); + Assert.assertEquals(2, mockInterceptor.getCount()); + HelloWorldService service1 = (HelloWorldService) child.getContext("target").getInstance(null); + Assert.assertEquals(0, service1.count()); + child.publish(new RequestEnd(this, id)); + + child.publish(new ModuleStop(this)); + runtime.stop(); + } + + public void testEPtoJavaRequestInvoke() throws Throwable { + RuntimeContext runtime = MockFactory.registerFooBinding(MockFactory.createJavaRuntime()); + PolicyBuilderRegistry registry = (PolicyBuilderRegistry) ((CompositeContext) runtime.getSystemContext().getContext(MockFactory.SYSTEM_CHILD)) + .getContext(MockFactory.POLICY_BUILDER_REGISTRY).getInstance(null); + MockSyncInterceptor mockInterceptor = new MockSyncInterceptor(); + MockInterceptorBuilder interceptorBuilder = new MockInterceptorBuilder(mockInterceptor, false); + registry.registerTargetBuilder(interceptorBuilder); + runtime.getRootContext().registerModelObject(MockFactory.createCompositeComponent("test.module")); + CompositeContext child = (CompositeContext) runtime.getRootContext().getContext("test.module"); + child.registerModelObject(MockFactory.createModuleWithEntryPoint(Scope.REQUEST)); + child.publish(new ModuleStart(this)); + Object id = new Object(); + child.publish(new RequestStart(this, id)); + EntryPointContext ctx = (EntryPointContext) child.getContext("source"); + Assert.assertNotNull(ctx); + InvocationHandler handler = (InvocationHandler) ctx.getHandler(); + Assert.assertEquals(0, mockInterceptor.getCount()); + Object response = handler.invoke(null, hello, new Object[]{"foo"}); + Assert.assertEquals("Hello foo", response); + Assert.assertEquals(1, mockInterceptor.getCount()); + + ctx = (EntryPointContext) child.getContext("source"); + Assert.assertNotNull(ctx); + handler = (InvocationHandler) ctx.getHandler(); + response = handler.invoke(null, hello, new Object[]{"foo"}); + HelloWorldService service1 = (HelloWorldService) child.getContext("target").getInstance(null); + Assert.assertEquals(2, service1.count()); + + child.publish(new RequestEnd(this, id)); + + // second request + Object id2 = new Object(); + child.publish(new RequestStart(this, id2)); + ctx = (EntryPointContext) child.getContext("source"); + Assert.assertNotNull(ctx); + handler = (InvocationHandler) ctx.getHandler(); + Assert.assertEquals(2, mockInterceptor.getCount()); + response = handler.invoke(null, hello, new Object[]{"foo"}); + Assert.assertEquals("Hello foo", response); + Assert.assertEquals(3, mockInterceptor.getCount()); + HelloWorldService service2 = (HelloWorldService) child.getContext("target").getInstance(null); + Assert.assertEquals(1, service2.count()); + child.publish(new RequestEnd(this, id2)); + + child.publish(new ModuleStop(this)); + runtime.stop(); + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/binding/ExternalServiceProxyInvokeTestCase.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/binding/ExternalServiceProxyInvokeTestCase.java new file mode 100644 index 0000000000..7357f973f7 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/binding/ExternalServiceProxyInvokeTestCase.java @@ -0,0 +1,73 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.integration.binding; + +import junit.framework.Assert; +import junit.framework.TestCase; +import org.apache.tuscany.container.java.assembly.mock.HelloWorldService; +import org.apache.tuscany.container.java.builder.MockInterceptorBuilder; +import org.apache.tuscany.container.java.invocation.mock.MockSyncInterceptor; +import org.apache.tuscany.container.java.mock.MockFactory; +import org.apache.tuscany.core.builder.system.PolicyBuilderRegistry; +import org.apache.tuscany.core.context.CompositeContext; +import org.apache.tuscany.core.context.event.ModuleStart; +import org.apache.tuscany.core.context.event.ModuleStop; +import org.apache.tuscany.core.context.event.RequestEnd; +import org.apache.tuscany.core.context.event.RequestStart; +import org.apache.tuscany.core.runtime.RuntimeContext; + +/** + * @version $$Rev$$ $$Date$$ + */ +public class ExternalServiceProxyInvokeTestCase extends TestCase { + + /** + * Tests that an external service can be invoked by locating a proxy to it as opposed to invoking it over a wire from another + * source such as an entry point or external service. + * + * @throws Throwable + */ + public void testProxyInvocation() throws Throwable { + RuntimeContext runtime = MockFactory.registerFooBinding(MockFactory.createJavaRuntime()); + PolicyBuilderRegistry registry = (PolicyBuilderRegistry) ((CompositeContext) runtime.getSystemContext().getContext(MockFactory.SYSTEM_CHILD)) + .getContext(MockFactory.POLICY_BUILDER_REGISTRY).getInstance(null); + MockSyncInterceptor mockInterceptor = new MockSyncInterceptor(); + MockInterceptorBuilder interceptorBuilder = new MockInterceptorBuilder(mockInterceptor, false); + registry.registerTargetBuilder(interceptorBuilder); + runtime.getRootContext().registerModelObject(MockFactory.createCompositeComponent("test.module")); + CompositeContext child = (CompositeContext) runtime.getRootContext().getContext("test.module"); + child.registerModelObject(MockFactory.createModuleWithEntryPointToExternalService()); + child.publish(new ModuleStart(this)); + Object id = new Object(); + child.publish(new RequestStart(this, id)); + HelloWorldService service1 = (HelloWorldService) child.getContext("target").getInstance(null); + Assert.assertEquals("foo", service1.hello("foo")); + + child.publish(new RequestEnd(this, id)); + child.publish(new ModuleStop(this)); + runtime.stop(); + + } + + protected void setUp() throws Exception { + super.setUp(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/binding/JavaToExternalServiceTestCase.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/binding/JavaToExternalServiceTestCase.java new file mode 100644 index 0000000000..90acb1c591 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/binding/JavaToExternalServiceTestCase.java @@ -0,0 +1,61 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package org.apache.tuscany.container.java.integration.binding; + +import junit.framework.Assert; +import junit.framework.TestCase; +import org.apache.tuscany.container.java.assembly.mock.HelloWorldService; +import org.apache.tuscany.container.java.builder.MockInterceptorBuilder; +import org.apache.tuscany.container.java.invocation.mock.MockSyncInterceptor; +import org.apache.tuscany.container.java.mock.MockFactory; +import org.apache.tuscany.core.builder.system.PolicyBuilderRegistry; +import org.apache.tuscany.core.context.CompositeContext; +import org.apache.tuscany.core.context.event.ModuleStart; +import org.apache.tuscany.core.context.event.ModuleStop; +import org.apache.tuscany.core.runtime.RuntimeContext; + +/** + * Tests basic Java to external service interaction + * + * @version $Rev$ $Date$ + */ +public class JavaToExternalServiceTestCase extends TestCase { + + /** + * Tests an wire of an external service configured with the {@link org.apache.tuscany.container.java.mock.binding.foo.FooBinding} + * from a Java component + * + * @throws Exception + */ + public void testJavaToESInvoke() throws Exception { + RuntimeContext runtime = MockFactory.registerFooBinding(MockFactory.createJavaRuntime()); + PolicyBuilderRegistry registry = (PolicyBuilderRegistry) ((CompositeContext) runtime.getSystemContext().getContext( + MockFactory.SYSTEM_CHILD)).getContext(MockFactory.POLICY_BUILDER_REGISTRY).getInstance(null); + MockSyncInterceptor mockInterceptor = new MockSyncInterceptor(); + MockInterceptorBuilder interceptorBuilder = new MockInterceptorBuilder(mockInterceptor, false); + registry.registerTargetBuilder(interceptorBuilder); + runtime.getRootContext().registerModelObject(MockFactory.createCompositeComponent("test.module")); + CompositeContext child = (CompositeContext) runtime.getRootContext().getContext("test.module"); + child.registerModelObject(MockFactory.createModuleWithExternalService()); + child.publish(new ModuleStart(this)); + HelloWorldService source = (HelloWorldService) child.getContext("source").getInstance(null); + Assert.assertNotNull(source); + Assert.assertEquals(0, mockInterceptor.getCount()); + Assert.assertEquals("foo", source.hello("foo")); + Assert.assertEquals(1, mockInterceptor.getCount()); + child.publish(new ModuleStop(this)); + runtime.stop(); + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/context/ScopeReferenceTestCase.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/context/ScopeReferenceTestCase.java new file mode 100644 index 0000000000..89320f60e5 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/context/ScopeReferenceTestCase.java @@ -0,0 +1,741 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package org.apache.tuscany.container.java.integration.context; + +import org.apache.tuscany.container.java.mock.MockFactory; +import org.apache.tuscany.container.java.mock.components.GenericComponent; +import org.apache.tuscany.core.context.CompositeContext; +import org.apache.tuscany.core.context.Context; +import org.apache.tuscany.core.context.event.ModuleStart; +import org.apache.tuscany.core.context.event.RequestStart; +import org.apache.tuscany.core.context.event.HttpSessionBound; +import org.apache.tuscany.core.context.event.RequestEnd; +import org.apache.tuscany.core.runtime.RuntimeContext; +import org.apache.tuscany.model.assembly.Scope; + +import junit.framework.Assert; +import junit.framework.TestCase; + +/** + * Tests scoping is properly handled for service references + * + * @version $Rev$ $Date$ + */ +public class ScopeReferenceTestCase extends TestCase { + + /** + * Tests a module-to-module scoped wire is setup properly by the runtime + */ + public void testModuleToModule() throws Exception{ + RuntimeContext runtime = MockFactory.createJavaRuntime(); + Context ctx = runtime.getSystemContext().getContext("tuscany.system.child"); + Assert.assertNotNull(ctx); + runtime.getRootContext().registerModelObject(MockFactory.createCompositeComponent("test")); + CompositeContext testCtx = (CompositeContext) runtime.getRootContext().getContext("test"); + Assert.assertNotNull(testCtx); + testCtx.registerModelObject(MockFactory.createModule()); + testCtx.publish(new ModuleStart(this)); + GenericComponent source = (GenericComponent)testCtx.getContext("source").getInstance(null); + Assert.assertNotNull(source); + GenericComponent target = (GenericComponent)testCtx.getContext("target").getInstance(null); + Assert.assertNotNull(target); + source.getGenericComponent().getString(); + } + + /** + * Tests a module-to-session scoped wire is setup properly by the runtime + */ + public void testModuleToSession() throws Exception{ + RuntimeContext runtime = MockFactory.createJavaRuntime(); + Context ctx = runtime.getSystemContext().getContext("tuscany.system.child"); + Assert.assertNotNull(ctx); + runtime.getRootContext().registerModelObject(MockFactory.createCompositeComponent("test")); + CompositeContext testCtx = (CompositeContext) runtime.getRootContext().getContext("test"); + Assert.assertNotNull(testCtx); + testCtx.registerModelObject(MockFactory.createModule(Scope.MODULE,Scope.SESSION)); + testCtx.publish(new ModuleStart(this)); + + // first session + Object session = new Object(); + Object id = new Object(); + testCtx.publish(new RequestStart(this,id)); + testCtx.publish(new HttpSessionBound(this,session)); + GenericComponent source = (GenericComponent)testCtx.getContext("source").getInstance(null); + Assert.assertNotNull(source); + GenericComponent target = (GenericComponent)testCtx.getContext("target").getInstance(null); + Assert.assertNotNull(target); + source.getGenericComponent().setString("foo"); + Assert.assertEquals("foo",target.getString()); + testCtx.publish(new RequestEnd(this,id)); + + //second session + Object session2 = new Object(); + Object id2 = new Object(); + testCtx.publish(new RequestStart(this,id2)); + testCtx.publish(new HttpSessionBound(this,session2)); + GenericComponent target2 = (GenericComponent)testCtx.getContext("target").getInstance(null); + Assert.assertNotNull(target2); + Assert.assertTrue(!"foo".equals(target2.getString())); + + Assert.assertTrue(!"foo".equals(source.getGenericComponent().getString())); + source.getGenericComponent().setString("bar"); + Assert.assertEquals("bar",target2.getString()); + Assert.assertEquals("bar",source.getGenericComponent().getString()); + //testCtx.fireEvent(EventContext.SESSION_NOTIFY,session); + + } + + /** + * Tests a module-to-request scoped wire is setup properly by the runtime + */ + public void testModuleToRequest() throws Exception{ + RuntimeContext runtime = MockFactory.createJavaRuntime(); + Context ctx = runtime.getSystemContext().getContext("tuscany.system.child"); + Assert.assertNotNull(ctx); + runtime.getRootContext().registerModelObject(MockFactory.createCompositeComponent("test")); + CompositeContext testCtx = (CompositeContext) runtime.getRootContext().getContext("test"); + Assert.assertNotNull(testCtx); + testCtx.registerModelObject(MockFactory.createModule(Scope.MODULE,Scope.REQUEST)); + testCtx.publish(new ModuleStart(this)); + + // first request + Object id = new Object(); + testCtx.publish(new RequestStart(this,id)); + GenericComponent source = (GenericComponent)testCtx.getContext("source").getInstance(null); + Assert.assertNotNull(source); + GenericComponent target = (GenericComponent)testCtx.getContext("target").getInstance(null); + Assert.assertNotNull(target); + source.getGenericComponent().setString("foo"); + Assert.assertEquals("foo",target.getString()); + testCtx.publish(new RequestEnd(this,id)); + + //second request + Object id2 = new Object(); + testCtx.publish(new RequestStart(this,id2)); + GenericComponent target2 = (GenericComponent)testCtx.getContext("target").getInstance(null); + Assert.assertNotNull(target2); + Assert.assertTrue(!"foo".equals(target2.getString())); + + Assert.assertTrue(!"foo".equals(source.getGenericComponent().getString())); + source.getGenericComponent().setString("bar"); + Assert.assertEquals("bar",target2.getString()); + Assert.assertEquals("bar",source.getGenericComponent().getString()); + + } + + /** + * Tests a module-to-stateless scoped wire is setup properly by the runtime + */ + public void testModuleToStateless() throws Exception{ + RuntimeContext runtime = MockFactory.createJavaRuntime(); + Context ctx = runtime.getSystemContext().getContext("tuscany.system.child"); + Assert.assertNotNull(ctx); + runtime.getRootContext().registerModelObject(MockFactory.createCompositeComponent("test")); + CompositeContext testCtx = (CompositeContext) runtime.getRootContext().getContext("test"); + Assert.assertNotNull(testCtx); + testCtx.registerModelObject(MockFactory.createModule(Scope.MODULE,Scope.INSTANCE)); + testCtx.publish(new ModuleStart(this)); + + // first request + Object id = new Object(); + testCtx.publish(new RequestStart(this,id)); + GenericComponent source = (GenericComponent)testCtx.getContext("source").getInstance(null); + Assert.assertNotNull(source); + GenericComponent target = (GenericComponent)testCtx.getContext("target").getInstance(null); + Assert.assertNotNull(target); + source.getGenericComponent().setString("foo"); + Assert.assertTrue(!"foo".equals(target.getString())); + testCtx.publish(new RequestEnd(this,id)); + + //second request + Object id2 = new Object(); + testCtx.publish(new RequestStart(this,id2)); + GenericComponent target2 = (GenericComponent)testCtx.getContext("target").getInstance(null); + Assert.assertNotNull(target2); + Assert.assertTrue(!"foo".equals(target2.getString())); + + Assert.assertTrue(!"foo".equals(source.getGenericComponent().getString())); + source.getGenericComponent().setString("bar"); + Assert.assertTrue(!"bar".equals(target2.getString())); + } + + /** + * Tests a session-to-session scoped wire is setup properly by the runtime + */ + public void testSessionToSession() throws Exception{ + RuntimeContext runtime = MockFactory.createJavaRuntime(); + Context ctx = runtime.getSystemContext().getContext("tuscany.system.child"); + Assert.assertNotNull(ctx); + runtime.getRootContext().registerModelObject(MockFactory.createCompositeComponent("test")); + CompositeContext testCtx = (CompositeContext) runtime.getRootContext().getContext("test"); + Assert.assertNotNull(testCtx); + testCtx.registerModelObject(MockFactory.createModule(Scope.SESSION,Scope.SESSION)); + testCtx.publish(new ModuleStart(this)); + + // first session + Object session = new Object(); + Object id = new Object(); + testCtx.publish(new RequestStart(this,id)); + testCtx.publish(new HttpSessionBound(this,session)); + GenericComponent source = (GenericComponent)testCtx.getContext("source").getInstance(null); + Assert.assertNotNull(source); + GenericComponent target = (GenericComponent)testCtx.getContext("target").getInstance(null); + Assert.assertNotNull(target); + source.getGenericComponent().setString("foo"); + source.getGenericComponent().setString("foo"); + Assert.assertEquals("foo",target.getString()); + testCtx.publish(new RequestEnd(this,id)); + + //second session + Object session2 = new Object(); + Object id2 = new Object(); + testCtx.publish(new RequestStart(this,id2)); + testCtx.publish(new HttpSessionBound(this,session2)); + GenericComponent source2 = (GenericComponent)testCtx.getContext("source").getInstance(null); + Assert.assertNotNull(source2); + GenericComponent target2 = (GenericComponent)testCtx.getContext("target").getInstance(null); + + Assert.assertNotNull(target2); + Assert.assertEquals(null,target2.getString()); + Assert.assertEquals(null,source2.getGenericComponent().getString()); + source2.getGenericComponent().setString("baz"); + Assert.assertEquals("baz",source2.getGenericComponent().getString()); + Assert.assertEquals("baz",target2.getString()); + + testCtx.publish(new RequestEnd(this,id2)); + + } + + + /** + * Tests a session-to-module scoped wire is setup properly by the runtime + */ + public void testSessionToModule() throws Exception{ + RuntimeContext runtime = MockFactory.createJavaRuntime(); + Context ctx = runtime.getSystemContext().getContext("tuscany.system.child"); + Assert.assertNotNull(ctx); + runtime.getRootContext().registerModelObject(MockFactory.createCompositeComponent("test")); + CompositeContext testCtx = (CompositeContext) runtime.getRootContext().getContext("test"); + Assert.assertNotNull(testCtx); + testCtx.registerModelObject(MockFactory.createModule(Scope.SESSION,Scope.MODULE)); + testCtx.publish(new ModuleStart(this)); + + // first session + Object session = new Object(); + Object id = new Object(); + testCtx.publish(new RequestStart(this,id)); + testCtx.publish(new HttpSessionBound(this,session)); + GenericComponent source = (GenericComponent)testCtx.getContext("source").getInstance(null); + Assert.assertNotNull(source); + GenericComponent target = (GenericComponent)testCtx.getContext("target").getInstance(null); + Assert.assertNotNull(target); + source.getGenericComponent().setString("foo"); + source.getGenericComponent().setString("foo"); + Assert.assertEquals("foo",target.getString()); + testCtx.publish(new RequestEnd(this,id)); + + //second session + Object session2 = new Object(); + Object id2 = new Object(); + testCtx.publish(new RequestStart(this,id2)); + testCtx.publish(new HttpSessionBound(this,session2)); + GenericComponent source2 = (GenericComponent)testCtx.getContext("source").getInstance(null); + Assert.assertNotNull(source2); + GenericComponent target2 = (GenericComponent)testCtx.getContext("target").getInstance(null); + + Assert.assertNotNull(target2); + Assert.assertEquals("foo",target2.getString()); + Assert.assertEquals("foo",source2.getGenericComponent().getString()); + source2.getGenericComponent().setString("baz"); + Assert.assertEquals("baz",source2.getGenericComponent().getString()); + Assert.assertEquals("baz",target2.getString()); + Assert.assertEquals("baz",target.getString()); + + testCtx.publish(new RequestEnd(this,session2)); + + } + + /** + * Tests a session-to-request scoped wire is setup properly by the runtime + */ + public void testSessionToRequest() throws Exception{ + RuntimeContext runtime = MockFactory.createJavaRuntime(); + Context ctx = runtime.getSystemContext().getContext("tuscany.system.child"); + Assert.assertNotNull(ctx); + runtime.getRootContext().registerModelObject(MockFactory.createCompositeComponent("test")); + CompositeContext testCtx = (CompositeContext) runtime.getRootContext().getContext("test"); + Assert.assertNotNull(testCtx); + testCtx.registerModelObject(MockFactory.createModule(Scope.SESSION,Scope.REQUEST)); + testCtx.publish(new ModuleStart(this)); + + // first session + Object session = new Object(); + Object id = new Object(); + testCtx.publish(new RequestStart(this,id)); + testCtx.publish(new HttpSessionBound(this,session)); + GenericComponent source = (GenericComponent)testCtx.getContext("source").getInstance(null); + Assert.assertNotNull(source); + GenericComponent target = (GenericComponent)testCtx.getContext("target").getInstance(null); + Assert.assertNotNull(target); + source.getGenericComponent().setString("foo"); + Assert.assertEquals("foo",target.getString()); + testCtx.publish(new RequestEnd(this,session)); + + //second session + Object session2 = new Object(); + Object id2 = new Object(); + testCtx.publish(new RequestStart(this,id2)); + testCtx.publish(new HttpSessionBound(this,session2)); + GenericComponent source2 = (GenericComponent)testCtx.getContext("source").getInstance(null); + Assert.assertNotNull(source); + GenericComponent target2 = (GenericComponent)testCtx.getContext("target").getInstance(null); + + Assert.assertNotNull(target2); + Assert.assertEquals(null,target2.getString()); + source2.getGenericComponent().setString("baz"); + Assert.assertEquals("baz",target2.getString()); + Assert.assertEquals("baz",source2.getGenericComponent().getString()); + + Assert.assertEquals("foo",target.getString()); + testCtx.publish(new RequestEnd(this,session)); + + } + + + /** + * Tests a session-to-stateless scoped wire is setup properly by the runtime + */ + public void testSessionToStateless() throws Exception{ + RuntimeContext runtime = MockFactory.createJavaRuntime(); + Context ctx = runtime.getSystemContext().getContext("tuscany.system.child"); + Assert.assertNotNull(ctx); + runtime.getRootContext().registerModelObject(MockFactory.createCompositeComponent("test")); + CompositeContext testCtx = (CompositeContext) runtime.getRootContext().getContext("test"); + Assert.assertNotNull(testCtx); + testCtx.registerModelObject(MockFactory.createModule(Scope.SESSION,Scope.INSTANCE)); + testCtx.publish(new ModuleStart(this)); + + // first session + Object session = new Object(); + Object id = new Object(); + testCtx.publish(new RequestStart(this,id)); + testCtx.publish(new HttpSessionBound(this,session)); + GenericComponent source = (GenericComponent)testCtx.getContext("source").getInstance(null); + Assert.assertNotNull(source); + GenericComponent target = (GenericComponent)testCtx.getContext("target").getInstance(null); + Assert.assertNotNull(target); + source.getGenericComponent().setString("foo"); + Assert.assertEquals(null,target.getString()); + testCtx.publish(new RequestEnd(this,session)); + + //second session + Object session2 = new Object(); + Object id2 = new Object(); + testCtx.publish(new RequestStart(this,id2)); + testCtx.publish(new HttpSessionBound(this,session2)); + GenericComponent source2 = (GenericComponent)testCtx.getContext("source").getInstance(null); + Assert.assertNotNull(source); + GenericComponent target2 = (GenericComponent)testCtx.getContext("target").getInstance(null); + + Assert.assertNotNull(target2); + Assert.assertEquals(null,target2.getString()); + source2.getGenericComponent().setString("baz"); + Assert.assertEquals(null,target2.getString()); //Note assumes no pooling + Assert.assertEquals(null,source2.getGenericComponent().getString()); + + Assert.assertEquals(null,target.getString()); //Note assumes no pooling + testCtx.publish(new RequestEnd(this,session)); + + } + + /** + * Tests a request-to-request scoped wire is setup properly by the runtime + */ + public void testRequestToRequest() throws Exception{ + RuntimeContext runtime = MockFactory.createJavaRuntime(); + Context ctx = runtime.getSystemContext().getContext("tuscany.system.child"); + Assert.assertNotNull(ctx); + runtime.getRootContext().registerModelObject(MockFactory.createCompositeComponent("test")); + CompositeContext testCtx = (CompositeContext) runtime.getRootContext().getContext("test"); + Assert.assertNotNull(testCtx); + testCtx.registerModelObject(MockFactory.createModule(Scope.REQUEST,Scope.REQUEST)); + testCtx.publish(new ModuleStart(this)); + + // first request + Object id = new Object(); + testCtx.publish(new RequestStart(this,id)); + GenericComponent source = (GenericComponent)testCtx.getContext("source").getInstance(null); + Assert.assertNotNull(source); + GenericComponent target = (GenericComponent)testCtx.getContext("target").getInstance(null); + Assert.assertNotNull(target); + source.getGenericComponent().setString("foo"); + Assert.assertEquals("foo",target.getString()); + testCtx.publish(new RequestEnd(this,new Object())); + + //second request + Object id2 = new Object(); + testCtx.publish(new RequestStart(this,id2)); + GenericComponent source2 = (GenericComponent)testCtx.getContext("source").getInstance(null); + Assert.assertNotNull(source2); + GenericComponent target2 = (GenericComponent)testCtx.getContext("target").getInstance(null); + + Assert.assertNotNull(target2); + Assert.assertEquals(null,target2.getString()); + Assert.assertEquals(null,source2.getGenericComponent().getString()); + source2.getGenericComponent().setString("baz"); + Assert.assertEquals("baz",source2.getGenericComponent().getString()); + Assert.assertEquals("baz",target2.getString()); + + testCtx.publish(new RequestEnd(this,new Object())); + } + + /** + * Tests a request-to-module scoped wire is setup properly by the runtime + */ + public void testRequestToModule() throws Exception{ + RuntimeContext runtime = MockFactory.createJavaRuntime(); + Context ctx = runtime.getSystemContext().getContext("tuscany.system.child"); + Assert.assertNotNull(ctx); + runtime.getRootContext().registerModelObject(MockFactory.createCompositeComponent("test")); + CompositeContext testCtx = (CompositeContext) runtime.getRootContext().getContext("test"); + Assert.assertNotNull(testCtx); + testCtx.registerModelObject(MockFactory.createModule(Scope.REQUEST,Scope.MODULE)); + testCtx.publish(new ModuleStart(this)); + + // first request + Object id = new Object(); + testCtx.publish(new RequestStart(this,id)); + GenericComponent source = (GenericComponent)testCtx.getContext("source").getInstance(null); + Assert.assertNotNull(source); + GenericComponent target = (GenericComponent)testCtx.getContext("target").getInstance(null); + Assert.assertNotNull(target); + source.getGenericComponent().setString("foo"); + Assert.assertEquals("foo",target.getString()); + testCtx.publish(new RequestEnd(this,new Object())); + + //second request + Object id2 = new Object(); + testCtx.publish(new RequestStart(this,id2)); + GenericComponent source2 = (GenericComponent)testCtx.getContext("source").getInstance(null); + Assert.assertNotNull(source2); + GenericComponent target2 = (GenericComponent)testCtx.getContext("target").getInstance(null); + + Assert.assertNotNull(target2); + Assert.assertEquals("foo",target2.getString()); + Assert.assertEquals("foo",source2.getGenericComponent().getString()); + source2.getGenericComponent().setString("baz"); + Assert.assertEquals("baz",source2.getGenericComponent().getString()); + Assert.assertEquals("baz",target2.getString()); + Assert.assertEquals("baz",target.getString()); + + testCtx.publish(new RequestEnd(this,new Object())); + } + + /** + * Tests a request-to-session scoped wire is setup properly by the runtime + */ + public void testRequestToSession() throws Exception{ + RuntimeContext runtime = MockFactory.createJavaRuntime(); + Context ctx = runtime.getSystemContext().getContext("tuscany.system.child"); + Assert.assertNotNull(ctx); + runtime.getRootContext().registerModelObject(MockFactory.createCompositeComponent("test")); + CompositeContext testCtx = (CompositeContext) runtime.getRootContext().getContext("test"); + Assert.assertNotNull(testCtx); + testCtx.registerModelObject(MockFactory.createModule(Scope.REQUEST,Scope.SESSION)); + testCtx.publish(new ModuleStart(this)); + + // first session + Object session = new Object(); + Object id = new Object(); + testCtx.publish(new RequestStart(this,id)); + testCtx.publish(new HttpSessionBound(this,session)); + GenericComponent source = (GenericComponent)testCtx.getContext("source").getInstance(null); + Assert.assertNotNull(source); + GenericComponent target = (GenericComponent)testCtx.getContext("target").getInstance(null); + Assert.assertNotNull(target); + source.getGenericComponent().setString("foo"); + Assert.assertEquals("foo",target.getString()); + testCtx.publish(new RequestEnd(this,new Object())); + + //second request for session + Object id2 = new Object(); + testCtx.publish(new RequestStart(this,id2)); + testCtx.publish(new HttpSessionBound(this,session)); + GenericComponent targetR2 = (GenericComponent)testCtx.getContext("target").getInstance(null); + Assert.assertEquals("foo",targetR2.getString()); + GenericComponent sourceR2 = (GenericComponent)testCtx.getContext("source").getInstance(null); + Assert.assertNotNull(sourceR2); + Assert.assertEquals("foo",sourceR2.getGenericComponent().getString()); + + testCtx.publish(new RequestEnd(this,new Object())); + + //second session + Object session2 = new Object(); + Object id3 = new Object(); + testCtx.publish(new RequestStart(this,id3)); + testCtx.publish(new HttpSessionBound(this,session2)); + GenericComponent source2 = (GenericComponent)testCtx.getContext("source").getInstance(null); + Assert.assertNotNull(source2); + GenericComponent target2 = (GenericComponent)testCtx.getContext("target").getInstance(null); + + Assert.assertNotNull(target2); + Assert.assertEquals(null,target2.getString()); + Assert.assertEquals(null,source2.getGenericComponent().getString()); + source2.getGenericComponent().setString("baz"); + Assert.assertEquals("baz",source2.getGenericComponent().getString()); + Assert.assertEquals("baz",target2.getString()); + + testCtx.publish(new RequestEnd(this,session2)); + Object id4 = new Object(); + testCtx.publish(new RequestStart(this,id4)); + testCtx.publish(new HttpSessionBound(this,session)); + testCtx.publish(new RequestEnd(this,session)); + + } + + + /** + * Tests a request-to-stateless scoped wire is setup properly by the runtime + */ + public void testRequestToStateless() throws Exception{ + RuntimeContext runtime = MockFactory.createJavaRuntime(); + Context ctx = runtime.getSystemContext().getContext("tuscany.system.child"); + Assert.assertNotNull(ctx); + runtime.getRootContext().registerModelObject(MockFactory.createCompositeComponent("test")); + CompositeContext testCtx = (CompositeContext) runtime.getRootContext().getContext("test"); + Assert.assertNotNull(testCtx); + testCtx.registerModelObject(MockFactory.createModule(Scope.REQUEST,Scope.INSTANCE)); + testCtx.publish(new ModuleStart(this)); + + // first request + Object id = new Object(); + testCtx.publish(new RequestStart(this,id)); + GenericComponent source = (GenericComponent)testCtx.getContext("source").getInstance(null); + Assert.assertNotNull(source); + GenericComponent target = (GenericComponent)testCtx.getContext("target").getInstance(null); + Assert.assertNotNull(target); + source.getGenericComponent().setString("foo"); + Assert.assertEquals(null,target.getString()); + testCtx.publish(new RequestEnd(this,new Object())); + + //second request + Object id2 = new Object(); + testCtx.publish(new RequestStart(this,id2)); + GenericComponent source2 = (GenericComponent)testCtx.getContext("source").getInstance(null); + Assert.assertNotNull(source2); + GenericComponent target2 = (GenericComponent)testCtx.getContext("target").getInstance(null); + + Assert.assertNotNull(target2); + Assert.assertEquals(null,target2.getString()); + Assert.assertEquals(null,source2.getGenericComponent().getString()); + source2.getGenericComponent().setString("baz"); + Assert.assertEquals(null,source2.getGenericComponent().getString()); + Assert.assertEquals(null,target2.getString()); + + testCtx.publish(new RequestEnd(this,new Object())); + } + + + /** + * Tests a stateless-to-stateless scoped wire is setup properly by the runtime + */ + public void testStatelessToStateless() throws Exception{ + RuntimeContext runtime = MockFactory.createJavaRuntime(); + Context ctx = runtime.getSystemContext().getContext("tuscany.system.child"); + Assert.assertNotNull(ctx); + runtime.getRootContext().registerModelObject(MockFactory.createCompositeComponent("test")); + CompositeContext testCtx = (CompositeContext) runtime.getRootContext().getContext("test"); + Assert.assertNotNull(testCtx); + testCtx.registerModelObject(MockFactory.createModule(Scope.INSTANCE,Scope.INSTANCE)); + testCtx.publish(new ModuleStart(this)); + + // first request + Object id = new Object(); + testCtx.publish(new RequestStart(this,id)); + GenericComponent source = (GenericComponent)testCtx.getContext("source").getInstance(null); + Assert.assertNotNull(source); + GenericComponent target = (GenericComponent)testCtx.getContext("target").getInstance(null); + Assert.assertNotNull(target); + source.getGenericComponent().setString("foo"); + Assert.assertEquals(null,target.getString()); + testCtx.publish(new RequestEnd(this,new Object())); + + //second request + Object id2 = new Object(); + testCtx.publish(new RequestStart(this,id2)); + GenericComponent source2 = (GenericComponent)testCtx.getContext("source").getInstance(null); + Assert.assertNotNull(source2); + GenericComponent target2 = (GenericComponent)testCtx.getContext("target").getInstance(null); + + Assert.assertNotNull(target2); + Assert.assertEquals(null,target2.getString()); + Assert.assertEquals(null,source2.getGenericComponent().getString()); + source2.getGenericComponent().setString("baz"); + Assert.assertEquals(null,source2.getGenericComponent().getString()); + Assert.assertEquals(null,target2.getString()); + + testCtx.publish(new RequestEnd(this,new Object())); + } + + /** + * Tests a stateless-to-request scoped wire is setup properly by the runtime + */ + public void testStatelessToRequest() throws Exception{ + RuntimeContext runtime = MockFactory.createJavaRuntime(); + Context ctx = runtime.getSystemContext().getContext("tuscany.system.child"); + Assert.assertNotNull(ctx); + runtime.getRootContext().registerModelObject(MockFactory.createCompositeComponent("test")); + CompositeContext testCtx = (CompositeContext) runtime.getRootContext().getContext("test"); + Assert.assertNotNull(testCtx); + testCtx.registerModelObject(MockFactory.createModule(Scope.INSTANCE,Scope.REQUEST)); + testCtx.publish(new ModuleStart(this)); + + // first request + Object id = new Object(); + testCtx.publish(new RequestStart(this,id)); + GenericComponent source = (GenericComponent)testCtx.getContext("source").getInstance(null); + Assert.assertNotNull(source); + GenericComponent target = (GenericComponent)testCtx.getContext("target").getInstance(null); + Assert.assertNotNull(target); + source.getGenericComponent().setString("foo"); + Assert.assertEquals("foo",target.getString()); + testCtx.publish(new RequestEnd(this,new Object())); + + GenericComponent targetR1 = (GenericComponent)testCtx.getContext("target").getInstance(null); + Assert.assertNotNull(targetR1); + Assert.assertEquals("foo",target.getString()); + + //second request + Object id2 = new Object(); + testCtx.publish(new RequestStart(this,id2)); + GenericComponent source2 = (GenericComponent)testCtx.getContext("source").getInstance(null); + Assert.assertNotNull(source2); + GenericComponent target2 = (GenericComponent)testCtx.getContext("target").getInstance(null); + + Assert.assertNotNull(target2); + Assert.assertEquals(null,target2.getString()); + Assert.assertEquals(null,source2.getGenericComponent().getString()); + source2.getGenericComponent().setString("baz"); + Assert.assertEquals("baz",source2.getGenericComponent().getString()); + Assert.assertEquals("baz",target2.getString()); + + testCtx.publish(new RequestEnd(this,new Object())); + } + + /** + * Tests a stateless-to-session scoped wire is setup properly by the runtime + */ + public void testStatelessToSession() throws Exception{ + RuntimeContext runtime = MockFactory.createJavaRuntime(); + Context ctx = runtime.getSystemContext().getContext("tuscany.system.child"); + Assert.assertNotNull(ctx); + runtime.getRootContext().registerModelObject(MockFactory.createCompositeComponent("test")); + CompositeContext testCtx = (CompositeContext) runtime.getRootContext().getContext("test"); + Assert.assertNotNull(testCtx); + testCtx.registerModelObject(MockFactory.createModule(Scope.INSTANCE,Scope.SESSION)); + testCtx.publish(new ModuleStart(this)); + + // first session + Object session = new Object(); + Object id = new Object(); + testCtx.publish(new RequestStart(this,id)); + testCtx.publish(new HttpSessionBound(this,session)); + GenericComponent source = (GenericComponent)testCtx.getContext("source").getInstance(null); + Assert.assertNotNull(source); + GenericComponent target = (GenericComponent)testCtx.getContext("target").getInstance(null); + Assert.assertNotNull(target); + source.getGenericComponent().setString("foo"); + Assert.assertEquals("foo",target.getString()); + testCtx.publish(new RequestEnd(this,new Object())); + + //second request for session + Object id2 = new Object(); + testCtx.publish(new RequestStart(this,id2)); + testCtx.publish(new HttpSessionBound(this,session)); + GenericComponent targetR2 = (GenericComponent)testCtx.getContext("target").getInstance(null); + Assert.assertEquals("foo",targetR2.getString()); + GenericComponent sourceR2 = (GenericComponent)testCtx.getContext("source").getInstance(null); + Assert.assertNotNull(sourceR2); + Assert.assertEquals("foo",sourceR2.getGenericComponent().getString()); + + testCtx.publish(new RequestEnd(this,new Object())); + + //second session + Object session2 = new Object(); + Object id3 = new Object(); + testCtx.publish(new RequestStart(this,id3)); + testCtx.publish(new HttpSessionBound(this,session2)); + GenericComponent source2 = (GenericComponent)testCtx.getContext("source").getInstance(null); + Assert.assertNotNull(source2); + GenericComponent target2 = (GenericComponent)testCtx.getContext("target").getInstance(null); + + Assert.assertNotNull(target2); + Assert.assertEquals(null,target2.getString()); + Assert.assertEquals(null,source2.getGenericComponent().getString()); + source2.getGenericComponent().setString("baz"); + Assert.assertEquals("baz",source2.getGenericComponent().getString()); + Assert.assertEquals("baz",target2.getString()); + + testCtx.publish(new RequestEnd(this,session2)); + Object id4 = new Object(); + testCtx.publish(new RequestStart(this,id4)); + testCtx.publish(new HttpSessionBound(this,session)); + testCtx.publish(new RequestEnd(this,session)); + + } + + + /** + * Tests a stateless-to-module scoped wire is setup properly by the runtime + */ + public void testStatelessToModule() throws Exception{ + RuntimeContext runtime = MockFactory.createJavaRuntime(); + Context ctx = runtime.getSystemContext().getContext("tuscany.system.child"); + Assert.assertNotNull(ctx); + runtime.getRootContext().registerModelObject(MockFactory.createCompositeComponent("test")); + CompositeContext testCtx = (CompositeContext) runtime.getRootContext().getContext("test"); + Assert.assertNotNull(testCtx); + testCtx.registerModelObject(MockFactory.createModule(Scope.INSTANCE,Scope.MODULE)); + testCtx.publish(new ModuleStart(this)); + + Object id = new Object(); + testCtx.publish(new RequestStart(this,id)); + GenericComponent source = (GenericComponent)testCtx.getContext("source").getInstance(null); + Assert.assertNotNull(source); + GenericComponent target = (GenericComponent)testCtx.getContext("target").getInstance(null); + Assert.assertNotNull(target); + source.getGenericComponent().setString("foo"); + Assert.assertEquals("foo",target.getString()); + testCtx.publish(new RequestEnd(this,new Object())); + + //second session + Object id2 = new Object(); + testCtx.publish(new RequestStart(this,id2)); + GenericComponent source2 = (GenericComponent)testCtx.getContext("source").getInstance(null); + Assert.assertNotNull(source2); + GenericComponent target2 = (GenericComponent)testCtx.getContext("target").getInstance(null); + + Assert.assertNotNull(target2); + Assert.assertEquals("foo",target2.getString()); + Assert.assertEquals("foo",source2.getGenericComponent().getString()); + source2.getGenericComponent().setString("baz"); + Assert.assertEquals("baz",source2.getGenericComponent().getString()); + Assert.assertEquals("baz",target2.getString()); + + testCtx.publish(new RequestEnd(this,new Object())); + + } + +} + diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/invocation/MediationTestCase.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/invocation/MediationTestCase.java new file mode 100644 index 0000000000..e560af6fd3 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/invocation/MediationTestCase.java @@ -0,0 +1,53 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package org.apache.tuscany.container.java.invocation; + +import java.lang.reflect.Method; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.apache.tuscany.container.java.invocation.mock.SimpleTargetImpl; +import org.apache.tuscany.core.message.Message; +import org.apache.tuscany.core.message.MessageFactory; +import org.apache.tuscany.core.message.impl.MessageFactoryImpl; + +/** + * Tests invoking on a different interface from the one actually implemented by the target + * + * @version $Rev$ $Date$ + */ +public class MediationTestCase extends TestCase { + + private Method hello; + + private MessageFactory msgFactory = new MessageFactoryImpl(); + + public void setUp() throws Exception { + hello = Hello.class.getMethod("hello", String.class); + } + + public void testMediation() throws Exception { + StaticJavaComponentTargetInvoker invoker = new StaticJavaComponentTargetInvoker(hello, new SimpleTargetImpl()); + Message msg = msgFactory.createMessage(); + msg.setBody("foo"); + Assert.assertEquals("foo", invoker.invoke(msg).getBody()); + } + + public interface Hello { + + public String hello(String message) throws Exception; + + } +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/invocation/ScopedPojoInvokerTestCase.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/invocation/ScopedPojoInvokerTestCase.java new file mode 100644 index 0000000000..f4337fe3cb --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/invocation/ScopedPojoInvokerTestCase.java @@ -0,0 +1,53 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.invocation; + +import java.lang.reflect.Method; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.apache.tuscany.container.java.invocation.mock.SimpleTarget; +import org.apache.tuscany.container.java.mock.MockScopeContext; +import org.apache.tuscany.core.context.QualifiedName; +import org.apache.tuscany.core.context.ScopeContext; + +public class ScopedPojoInvokerTestCase extends TestCase { + + private Method echoMethod; + + public ScopedPojoInvokerTestCase() { + super(); + } + + public ScopedPojoInvokerTestCase(String arg0) { + super(arg0); + } + + public void setUp() throws Exception { + echoMethod = SimpleTarget.class.getDeclaredMethod("echo", String.class); + Assert.assertNotNull(echoMethod); + } + + public void testScopedInvoke() throws Exception { + ScopeContext container = new MockScopeContext(); + ScopedJavaComponentInvoker invoker = new ScopedJavaComponentInvoker(new QualifiedName("foo"), echoMethod, container,false); + Object ret = invoker.invokeTarget("foo"); + Assert.assertEquals("foo", ret); + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/invocation/StaticPojoInvokerTestCase.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/invocation/StaticPojoInvokerTestCase.java new file mode 100644 index 0000000000..31e7e3c64e --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/invocation/StaticPojoInvokerTestCase.java @@ -0,0 +1,154 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.invocation; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import static java.lang.Integer.*; + +import junit.framework.Assert; +import junit.framework.TestCase; + +public class StaticPojoInvokerTestCase extends TestCase { + + private Method echoMethod; + private Method arrayMethod; + private Method nullParamMethod; + private Method primitiveMethod; + private Method checkedMethod; + private Method runtimeMethod; + + public StaticPojoInvokerTestCase() { + + } + + public StaticPojoInvokerTestCase(String arg0) { + super(arg0); + } + + public void setUp() throws Exception { + echoMethod = TestBean.class.getDeclaredMethod("echo", String.class); + arrayMethod = TestBean.class.getDeclaredMethod("arrayEcho", String[].class); + nullParamMethod = TestBean.class.getDeclaredMethod("nullParam", (Class[]) null); + primitiveMethod = TestBean.class.getDeclaredMethod("primitiveEcho", TYPE); + checkedMethod = TestBean.class.getDeclaredMethod("checkedException", (Class[]) null); + runtimeMethod = TestBean.class.getDeclaredMethod("runtimeException", (Class[]) null); + Assert.assertNotNull(echoMethod); + Assert.assertNotNull(checkedMethod); + Assert.assertNotNull(runtimeMethod); + } + + public void testObjectInvoke() throws Throwable { + TestBean bean = new TestBean(); + StaticJavaComponentTargetInvoker invoker = new StaticJavaComponentTargetInvoker(echoMethod, bean); + Object ret = invoker.invokeTarget("foo"); + Assert.assertEquals("foo", ret); + } + + public void testArrayInvoke() throws Throwable { + TestBean bean = new TestBean(); + StaticJavaComponentTargetInvoker invoker = new StaticJavaComponentTargetInvoker(arrayMethod, bean); + String[] args = new String[]{"foo", "bar"}; + Object ret = invoker.invokeTarget(new Object[]{args}); + String[] retA = (String[]) ret; + Assert.assertNotNull(retA); + Assert.assertEquals(2, retA.length); + Assert.assertEquals("foo", retA[0]); + Assert.assertEquals("bar", retA[1]); + } + + public void testNullInvoke() throws Throwable { + TestBean bean = new TestBean(); + StaticJavaComponentTargetInvoker invoker = new StaticJavaComponentTargetInvoker(nullParamMethod, bean); + Object ret = invoker.invokeTarget(null); + String retS = (String) ret; + Assert.assertEquals("foo", retS); + } + + public void testPrimitiveInvoke() throws Throwable { + TestBean bean = new TestBean(); + StaticJavaComponentTargetInvoker invoker = new StaticJavaComponentTargetInvoker(primitiveMethod, bean); + Object ret = invoker.invokeTarget(new Integer[]{1}); + Integer retI = (Integer) ret; + Assert.assertEquals(1, retI.intValue()); + } + + public void testInvokeCheckedException() throws Throwable { + TestBean bean = new TestBean(); + StaticJavaComponentTargetInvoker invoker = new StaticJavaComponentTargetInvoker(checkedMethod, bean); + try { + invoker.invokeTarget(null); + } catch (InvocationTargetException e) { + if (e.getCause() != null && TestException.class.equals(e.getCause().getClass())) { + return; + } + } catch (Throwable e) { + } + fail(TestException.class.getName() + " should have been thrown"); + } + + public void testInvokeRuntimeException() throws Throwable { + TestBean bean = new TestBean(); + StaticJavaComponentTargetInvoker invoker = new StaticJavaComponentTargetInvoker(runtimeMethod, bean); + try { + invoker.invokeTarget(null); + } catch (InvocationTargetException e) { + if (e.getCause() != null && e.getCause() instanceof TestRuntimeException) { + return; + } + } + fail(TestException.class.getName() + " should have been thrown"); + } + + private class TestBean { + + public String echo(String msg) throws Exception { + Assert.assertEquals("foo", msg); + return msg; + } + + public String[] arrayEcho(String[] msg) throws Exception { + Assert.assertNotNull(msg); + Assert.assertEquals(2, msg.length); + Assert.assertEquals("foo", msg[0]); + Assert.assertEquals("bar", msg[1]); + return msg; + } + + public String nullParam() throws Exception { + return "foo"; + } + + public int primitiveEcho(int i) throws Exception { + return i; + } + + public void checkedException() throws TestException { + throw new TestException(); + } + + public void runtimeException() throws TestRuntimeException { + throw new TestRuntimeException(); + } + } + + public class TestException extends Exception { + } + + public class TestRuntimeException extends RuntimeException { + } +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/invocation/mock/MockHandler.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/invocation/mock/MockHandler.java new file mode 100644 index 0000000000..cda09e8540 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/invocation/mock/MockHandler.java @@ -0,0 +1,38 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.invocation.mock; + +import org.apache.tuscany.core.wire.MessageHandler; +import org.apache.tuscany.core.message.Message; + +/** + * + */ +public class MockHandler implements MessageHandler { + + private int count =0; + + public boolean processMessage(Message message) { + //System.out.println("Invoking handler"); + count++; + return true; + } + + public int getCount(){ + return count; + } +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/invocation/mock/MockSyncInterceptor.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/invocation/mock/MockSyncInterceptor.java new file mode 100644 index 0000000000..24b22a641a --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/invocation/mock/MockSyncInterceptor.java @@ -0,0 +1,45 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.invocation.mock; + +import org.apache.tuscany.core.wire.Interceptor; +import org.apache.tuscany.core.message.Message; + +public class MockSyncInterceptor implements Interceptor { + + private int count; + + private Interceptor next; + + public MockSyncInterceptor() { + } + + public Message invoke(Message msg) { + ++count; + //System.out.println("Invoking interceptor"); + return next.invoke(msg); + } + + public int getCount() { + return count; + } + + public void setNext(Interceptor next) { + this.next=next; + } +} + diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/invocation/mock/SimpleSource.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/invocation/mock/SimpleSource.java new file mode 100644 index 0000000000..213caab7e9 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/invocation/mock/SimpleSource.java @@ -0,0 +1,25 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.invocation.mock; + +public interface SimpleSource { + + public void invokeHello() throws Exception; + + public void invokeGoodbye() throws Exception; +} + diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/invocation/mock/SimpleSourceImpl.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/invocation/mock/SimpleSourceImpl.java new file mode 100644 index 0000000000..2e7bd75f11 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/invocation/mock/SimpleSourceImpl.java @@ -0,0 +1,36 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.invocation.mock; + +public class SimpleSourceImpl implements SimpleSource { + + private SimpleTarget proxy; + + public SimpleSourceImpl(SimpleTarget proxy) { + this.proxy = proxy; + } + + public void invokeHello() throws Exception { + proxy.hello("hello"); + } + + public void invokeGoodbye() throws Exception { + proxy.goodbye("hello"); + } + +} + diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/invocation/mock/SimpleTarget.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/invocation/mock/SimpleTarget.java new file mode 100644 index 0000000000..cbd3037529 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/invocation/mock/SimpleTarget.java @@ -0,0 +1,28 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.invocation.mock; + +public interface SimpleTarget { + + public String hello(String message) throws Exception; + + public String goodbye(String message) throws Exception; + + public String echo(String message) throws Exception; + +} + diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/invocation/mock/SimpleTargetImpl.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/invocation/mock/SimpleTargetImpl.java new file mode 100644 index 0000000000..18abf6108a --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/invocation/mock/SimpleTargetImpl.java @@ -0,0 +1,39 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.invocation.mock; + +public class SimpleTargetImpl implements SimpleTarget { + + public SimpleTargetImpl() { + super(); + } + + public String hello(String message) throws Exception { + return message; + } + + public String goodbye(String message) throws Exception { + return message; + } + + public String echo(String message) throws Exception { + return message; + } + + +} + diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/loader/JavaImplementationLoaderTestCase.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/loader/JavaImplementationLoaderTestCase.java new file mode 100644 index 0000000000..85e79d8780 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/loader/JavaImplementationLoaderTestCase.java @@ -0,0 +1,134 @@ +/** + * + * Copyright 2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.loader; + +import java.net.URL; +import java.util.List; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.namespace.QName; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.apache.tuscany.container.java.assembly.JavaAssemblyFactory; +import org.apache.tuscany.container.java.assembly.impl.JavaAssemblyFactoryImpl; +import org.apache.tuscany.container.java.assembly.mock.HelloWorldImpl; +import org.apache.tuscany.container.java.assembly.mock.HelloWorldWithFieldProperties; +import org.apache.tuscany.container.java.assembly.mock.NakedHelloWorld; +import org.apache.tuscany.core.config.ConfigurationLoadException; +import org.apache.tuscany.core.loader.StAXElementLoader; +import org.apache.tuscany.core.loader.StAXLoaderRegistry; +import org.apache.tuscany.core.loader.LoaderContext; +import org.apache.tuscany.core.loader.assembly.AssemblyConstants; +import org.apache.tuscany.model.assembly.AssemblyContext; +import org.apache.tuscany.model.assembly.AssemblyObject; +import org.apache.tuscany.model.assembly.ComponentType; +import org.apache.tuscany.model.assembly.Property; +import org.apache.tuscany.model.assembly.Service; + +/** + * @version $Rev$ $Date$ + */ +public class JavaImplementationLoaderTestCase extends TestCase { + private JavaImplementationLoader loader; + private ComponentType mockType; + + public void testNakedHelloWorld() throws ConfigurationLoadException { + ComponentType type = loader.loadComponentTypeByIntrospection(NakedHelloWorld.class); + Assert.assertNotNull(type); + Assert.assertEquals(1,type.getProperties().size()); + Assert.assertTrue(type.getReferences().isEmpty()); + List<Service> services = type.getServices(); + Assert.assertEquals(1, services.size()); + Assert.assertEquals("NakedHelloWorld", services.get(0).getName()); + } + + public void testHelloWorldWithSidefile() throws XMLStreamException, ConfigurationLoadException { + StAXLoaderRegistry mockRegistry = new MockRegistry(mockType); + loader.setRegistry(mockRegistry); + URL sidefile = HelloWorldImpl.class.getResource("HelloWorldImpl.componentType"); + ComponentType type = loader.loadComponentTypeFromSidefile(sidefile, null); + assertSame(mockType, type); + } + + public void testHelloWorldWithFieldProperties() throws ConfigurationLoadException { + ComponentType type = loader.loadComponentTypeByIntrospection(HelloWorldWithFieldProperties.class); + type.initialize(null); + Assert.assertNotNull(type); + List<Property> props = type.getProperties(); + Assert.assertEquals(5, props.size()); + + Property prop = type.getProperty("text"); + Assert.assertNotNull(prop); + Assert.assertEquals("text", prop.getName()); + Assert.assertEquals(false, prop.isRequired()); + Assert.assertEquals(String.class, prop.getType()); + + prop = type.getProperty("text2"); + Assert.assertNotNull(prop); + Assert.assertEquals("text2", prop.getName()); + Assert.assertEquals(true, prop.isRequired()); + Assert.assertEquals(Integer.class, prop.getType()); + + prop = type.getProperty("foo"); + Assert.assertNotNull(prop); + Assert.assertEquals("foo", prop.getName()); + Assert.assertEquals(false, prop.isRequired()); + Assert.assertEquals(Integer.TYPE, prop.getType()); + } + + protected void setUp() throws Exception { + super.setUp(); + JavaAssemblyFactory factory = new JavaAssemblyFactoryImpl(); + mockType = factory.createComponentType(); + + loader = new JavaImplementationLoader(); + loader.setFactory(factory); + } + + private static class MockRegistry implements StAXLoaderRegistry { + private final ComponentType mockType; + + public MockRegistry(ComponentType mockType) { + this.mockType = mockType; + } + + public AssemblyObject load(XMLStreamReader reader, LoaderContext loaderContext) throws XMLStreamException, ConfigurationLoadException { + assertEquals(AssemblyConstants.COMPONENT_TYPE, reader.getName()); + return mockType; + } + + public <T extends AssemblyObject> void registerLoader(QName element, StAXElementLoader<T> loader) { + throw new UnsupportedOperationException(); + } + + public <T extends AssemblyObject> void unregisterLoader(QName element, StAXElementLoader<T> loader) { + throw new UnsupportedOperationException(); + } + + @Deprecated + public AssemblyContext getContext() { + throw new UnsupportedOperationException(); + } + + @Deprecated + public void setContext(AssemblyContext context) { + throw new UnsupportedOperationException(); + } + } +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/MockConfigContext.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/MockConfigContext.java new file mode 100644 index 0000000000..9cb1998d68 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/MockConfigContext.java @@ -0,0 +1,64 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package org.apache.tuscany.container.java.mock; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.core.builder.BuilderConfigException; +import org.apache.tuscany.core.builder.ContextFactoryBuilder; +import org.apache.tuscany.core.builder.WireBuilder; +import org.apache.tuscany.core.builder.impl.AssemblyVisitorImpl; +import org.apache.tuscany.core.builder.impl.DefaultWireBuilder; +import org.apache.tuscany.core.context.ConfigurationContext; +import org.apache.tuscany.core.context.ScopeContext; +import org.apache.tuscany.core.wire.TargetWireFactory; +import org.apache.tuscany.core.wire.SourceWireFactory; +import org.apache.tuscany.model.assembly.AssemblyObject; + +/** + * A mock configuration context + * + * @version $Rev: 368822 $ $Date: 2006-01-13 10:54:38 -0800 (Fri, 13 Jan 2006) $ + */ +public class MockConfigContext implements ConfigurationContext { + + private List<ContextFactoryBuilder> builders; + + private DefaultWireBuilder wireBuilder = new DefaultWireBuilder(); + + public MockConfigContext(List<ContextFactoryBuilder> builders, List<WireBuilder> wireBuilders) { + this.builders = (builders == null) ? new ArrayList(1) : builders; + if (wireBuilders != null){ + for (WireBuilder builder : wireBuilders) { + wireBuilder.addWireBuilder(builder); + } + } + } + + public void build(AssemblyObject model) throws BuilderConfigException { + AssemblyVisitorImpl visitor = new AssemblyVisitorImpl(builders); + visitor.start(model); + } + + public void connect(SourceWireFactory sourceFactory, TargetWireFactory targetFactory, Class targetType, boolean downScope, + ScopeContext targetScopeContext) throws BuilderConfigException { + wireBuilder.connect(sourceFactory, targetFactory, targetType, downScope, targetScopeContext); + } + + public void completeTargetChain(TargetWireFactory targetFactory, Class targetType, ScopeContext targetScopeContext) throws BuilderConfigException { + wireBuilder.completeTargetChain(targetFactory, targetType, targetScopeContext); + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/MockContextFactory.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/MockContextFactory.java new file mode 100644 index 0000000000..4e00e4c236 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/MockContextFactory.java @@ -0,0 +1,92 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.mock; + +import org.apache.tuscany.container.java.assembly.JavaAssemblyFactory; +import org.apache.tuscany.container.java.assembly.impl.JavaAssemblyFactoryImpl; +import org.apache.tuscany.container.java.config.JavaContextFactory; +import org.apache.tuscany.container.java.scopes.OrderedDependentPojo; +import org.apache.tuscany.core.builder.ContextFactory; +import org.apache.tuscany.core.builder.ObjectFactory; +import org.apache.tuscany.core.config.JavaIntrospectionHelper; +import org.apache.tuscany.core.context.Context; +import org.apache.tuscany.core.context.ScopeContext; +import org.apache.tuscany.core.injection.Injector; +import org.apache.tuscany.core.injection.MethodInjector; +import org.apache.tuscany.core.injection.ObjectCreationException; +import org.apache.tuscany.core.injection.EventInvoker; +import org.apache.tuscany.core.injection.MethodEventInvoker; +import org.apache.tuscany.model.assembly.AssemblyContext; +import org.apache.tuscany.model.assembly.Scope; +import org.apache.tuscany.model.assembly.impl.AssemblyContextImpl; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.List; + +/** + * @version $$Rev$$ $$Date$$ + */ +public class MockContextFactory { + + private MockContextFactory(){} + + /** + * Wires together a source and target + * @throws NoSuchMethodException + */ + public static List<ContextFactory<Context>> createWiredContexts(Scope scope, ScopeContext context) throws NoSuchMethodException{ + + Constructor constructor = JavaIntrospectionHelper.getDefaultConstructor(OrderedDependentPojo.class); + Method getPojo = OrderedDependentPojo.class.getMethod("setPojo",OrderedDependentPojo.class); + Method init = OrderedDependentPojo.class.getMethod("init",(Class[])null); + EventInvoker<Object> initInvoker = new MethodEventInvoker<Object>(init); + Method destroy = OrderedDependentPojo.class.getMethod("destroy",(Class[])null); + EventInvoker<Object> destroyInvoker = new MethodEventInvoker<Object>(destroy); + + JavaContextFactory source = new JavaContextFactory("source",constructor,scope); + source.setInitInvoker(initInvoker); + source.setDestroyInvoker(destroyInvoker); + JavaContextFactory target = new JavaContextFactory("target",constructor,scope); + target.setInitInvoker(initInvoker); + target.setDestroyInvoker(destroyInvoker); + List<Injector> injectors = new ArrayList<Injector>(); + injectors.add(new MethodInjector(getPojo, new MockTargetFactory("target",context))); + source.setSetters(injectors); + List<ContextFactory<Context>> list = new ArrayList<ContextFactory<Context>>(); + list.add((ContextFactory)source); + list.add((ContextFactory)target); + return list; + } + + private static class MockTargetFactory implements ObjectFactory{ + + private String name; + private ScopeContext context; + + public MockTargetFactory (String name, ScopeContext context){ + this.name = name; + this.context = context; + } + + public Object getInstance() throws ObjectCreationException { + return context.getContext(name).getInstance(null); + } + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/MockFactory.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/MockFactory.java new file mode 100644 index 0000000000..3b45352865 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/MockFactory.java @@ -0,0 +1,819 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.mock; + +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +import junit.framework.Assert; +import org.apache.tuscany.common.monitor.MonitorFactory; +import org.apache.tuscany.common.monitor.impl.NullMonitorFactory; +import org.apache.tuscany.container.java.assembly.JavaAssemblyFactory; +import org.apache.tuscany.container.java.assembly.JavaImplementation; +import org.apache.tuscany.container.java.assembly.impl.JavaAssemblyFactoryImpl; +import org.apache.tuscany.container.java.assembly.mock.HelloWorldImpl; +import org.apache.tuscany.container.java.assembly.mock.HelloWorldService; +import org.apache.tuscany.container.java.builder.JavaContextFactoryBuilder; +import org.apache.tuscany.container.java.builder.JavaTargetWireBuilder; +import org.apache.tuscany.container.java.context.JavaAtomicContext; +import org.apache.tuscany.container.java.mock.binding.foo.FooBinding; +import org.apache.tuscany.container.java.mock.binding.foo.FooBindingBuilder; +import org.apache.tuscany.container.java.mock.binding.foo.FooBindingWireBuilder; +import org.apache.tuscany.container.java.mock.components.GenericComponent; +import org.apache.tuscany.container.java.mock.components.HelloWorldClient; +import org.apache.tuscany.container.java.mock.components.ModuleScopeComponent; +import org.apache.tuscany.container.java.mock.components.ModuleScopeComponentImpl; +import org.apache.tuscany.container.java.mock.components.OtherTarget; +import org.apache.tuscany.container.java.mock.components.OtherTargetImpl; +import org.apache.tuscany.container.java.mock.components.Source; +import org.apache.tuscany.container.java.mock.components.SourceImpl; +import org.apache.tuscany.container.java.mock.components.Target; +import org.apache.tuscany.container.java.mock.components.TargetImpl; +import org.apache.tuscany.core.builder.BuilderException; +import org.apache.tuscany.core.builder.ContextFactory; +import org.apache.tuscany.core.builder.ContextFactoryBuilder; +import org.apache.tuscany.core.builder.ContextFactoryBuilderRegistry; +import org.apache.tuscany.core.builder.WireBuilder; +import org.apache.tuscany.core.builder.impl.DefaultWireBuilder; +import org.apache.tuscany.core.builder.system.DefaultPolicyBuilderRegistry; +import org.apache.tuscany.core.builder.system.PolicyBuilderRegistry; +import org.apache.tuscany.core.client.BootstrapHelper; +import org.apache.tuscany.core.config.ComponentTypeIntrospector; +import org.apache.tuscany.core.config.ConfigurationException; +import org.apache.tuscany.core.config.ConfigurationLoadException; +import org.apache.tuscany.core.config.JavaIntrospectionHelper; +import org.apache.tuscany.core.config.processor.ProcessorUtils; +import org.apache.tuscany.core.context.CompositeContext; +import org.apache.tuscany.core.context.Context; +import org.apache.tuscany.core.context.SystemCompositeContext; +import org.apache.tuscany.core.context.event.ModuleStart; +import org.apache.tuscany.core.context.impl.CompositeContextImpl; +import org.apache.tuscany.core.injection.EventInvoker; +import org.apache.tuscany.core.injection.FieldInjector; +import org.apache.tuscany.core.injection.Injector; +import org.apache.tuscany.core.injection.MethodEventInvoker; +import org.apache.tuscany.core.injection.MethodInjector; +import org.apache.tuscany.core.injection.PojoObjectFactory; +import org.apache.tuscany.core.injection.SingletonObjectFactory; +import org.apache.tuscany.core.message.MessageFactory; +import org.apache.tuscany.core.message.impl.MessageFactoryImpl; +import org.apache.tuscany.core.runtime.RuntimeContext; +import org.apache.tuscany.core.runtime.RuntimeContextImpl; +import org.apache.tuscany.core.system.assembly.SystemAssemblyFactory; +import org.apache.tuscany.core.system.assembly.SystemBinding; +import org.apache.tuscany.core.system.assembly.impl.SystemAssemblyFactoryImpl; +import org.apache.tuscany.core.system.builder.SystemContextFactoryBuilder; +import org.apache.tuscany.core.system.builder.SystemEntryPointBuilder; +import org.apache.tuscany.core.system.builder.SystemExternalServiceBuilder; +import org.apache.tuscany.core.system.context.SystemCompositeContextImpl; +import org.apache.tuscany.core.wire.WireFactoryFactory; +import org.apache.tuscany.core.wire.jdk.JDKWireFactoryFactory; +import org.apache.tuscany.core.wire.service.DefaultWireFactoryService; +import org.apache.tuscany.model.assembly.AssemblyContext; +import org.apache.tuscany.model.assembly.AtomicComponent; +import org.apache.tuscany.model.assembly.Component; +import org.apache.tuscany.model.assembly.ComponentType; +import org.apache.tuscany.model.assembly.ConfiguredReference; +import org.apache.tuscany.model.assembly.ConfiguredService; +import org.apache.tuscany.model.assembly.EntryPoint; +import org.apache.tuscany.model.assembly.ExternalService; +import org.apache.tuscany.model.assembly.Module; +import org.apache.tuscany.model.assembly.Multiplicity; +import org.apache.tuscany.model.assembly.Reference; +import org.apache.tuscany.model.assembly.Scope; +import org.apache.tuscany.model.assembly.Service; +import org.apache.tuscany.model.assembly.impl.AssemblyContextImpl; +import org.apache.tuscany.model.types.java.JavaServiceContract; +import org.osoa.sca.annotations.ComponentName; +import org.osoa.sca.annotations.Destroy; +import org.osoa.sca.annotations.Init; + +/** + * Generates test components, modules, and runtime artifacts + * + * @version $Rev$ $Date$ + */ +public class MockFactory { + + public static final String JAVA_BUILDER = "java.runtime.builder"; + public static final String MESSAGE_FACTORY = "java.runtime.messageFactory"; + public static final String PROXY_FACTORY_FACTORY = "java.runtime.wireFactoryFactory"; + public static final String WIRE_FACTORY_SERVICE = "java.runtime.wireFactoryservice"; + public static final String JAVA_WIRE_BUILDER = "java.wire.builder"; + public static final String FOO_BUILDER = "foo.binding.builder"; + public static final String FOO_WIRE_BUILDER = "foo.binding.wire.builder"; + public static final String POLICY_BUILDER_REGISTRY = "foo.binding.policy.registry"; + public static final String SYSTEM_CHILD = "tuscany.system.child"; + + private static JavaAssemblyFactory factory = new JavaAssemblyFactoryImpl(); + private static SystemAssemblyFactory systemFactory = new SystemAssemblyFactoryImpl(); + private static AssemblyContext assemblyContext = new AssemblyContextImpl(null, null); + private static ComponentTypeIntrospector introspector; + private static ComponentType systemComponentType; + private static ComponentType compositeComponentType; + + public static ComponentType getComponentType() throws ConfigurationLoadException { + if (systemComponentType == null) { + systemComponentType = getIntrospector().introspect(SystemCompositeContextImpl.class); + } + return systemComponentType; + } + + public static ComponentType getCompositeComponentType() throws ConfigurationLoadException { + if (compositeComponentType == null) { + compositeComponentType = getIntrospector().introspect(CompositeContextImpl.class); + } + return compositeComponentType; + } + + public static ComponentTypeIntrospector getIntrospector() { + if (introspector == null) { + introspector = ProcessorUtils.createCoreIntrospector(systemFactory); + } + return introspector; + } + + /** + * Creates an initialized simple component + * + * @param name the component name + * @param type the implementation type + * @param scope the component scope + */ + public static AtomicComponent createComponent(String name, Class type, Scope scope) throws ConfigurationLoadException { + AtomicComponent sc = factory.createSimpleComponent(); + JavaImplementation impl = factory.createJavaImplementation(); + impl.setComponentType(getIntrospector().introspect(type)); + impl.setImplementationClass(type); + sc.setImplementation(impl); + Service s = factory.createService(); + JavaServiceContract ji = factory.createJavaServiceContract(); + ji.setInterface(type); + s.setServiceContract(ji); + ji.setScope(scope); + impl.getComponentType().getServices().add(s); + sc.setName(name); + sc.setImplementation(impl); + return sc; + } + + public static AtomicComponent createNonIntrospectedComponent(String name, Class service, Class type, Scope scope) throws ConfigurationLoadException { + AtomicComponent sc = factory.createSimpleComponent(); + JavaImplementation impl = factory.createJavaImplementation(); + impl.setComponentType(factory.createComponentType()); + impl.setImplementationClass(type); + sc.setImplementation(impl); + Service s = factory.createService(); + JavaServiceContract ji = factory.createJavaServiceContract(); + ji.setInterface(service); + s.setServiceContract(ji); + ji.setScope(scope); + impl.getComponentType().getServices().add(s); + sc.setName(name); + sc.setImplementation(impl); + return sc; + } + + + /** + * Creates an composite component with the given name + */ + public static Component createCompositeComponent(String name) throws ConfigurationLoadException { + Component sc = systemFactory.createModuleComponent(); + Module impl = systemFactory.createModule(); + impl.setName(name); + //impl.setImplementationClass(CompositeContextImpl.class); + sc.setImplementation(impl); + Service s = systemFactory.createService(); + JavaServiceContract ji = systemFactory.createJavaServiceContract(); + s.setServiceContract(ji); + ji.setScope(Scope.AGGREGATE); + //impl.setComponentType(systemFactory.createComponentType()); + impl.setImplementationClass(CompositeContextImpl.class); + impl.setComponentType(getCompositeComponentType()); + impl.getComponentType().getServices().add(s); + sc.setName(name); + sc.setImplementation(impl); + + return sc; + } + + /** + * Creates a system composite component with the given name + */ + public static Component createSystemCompositeComponent(String name) throws ConfigurationLoadException { + Component sc = systemFactory.createModuleComponent(); + Module impl = systemFactory.createSystemModule(); + impl.setName(name); + //impl.setImplementationClass(SystemCompositeContextImpl.class); + sc.setImplementation(impl); + Service s = systemFactory.createService(); + JavaServiceContract ji = systemFactory.createJavaServiceContract(); + s.setServiceContract(ji); + ji.setScope(Scope.AGGREGATE); + impl.setComponentType(getComponentType()); + //impl.setComponentType(systemFactory.createComponentType()); + impl.getComponentType().getServices().add(s); + sc.setName(name); + sc.setImplementation(impl); + return sc; + } + + /** + * Creates an external service configured with the 'Foo' test binding + */ + public static ExternalService createFooBindingExternalService(String name, Class interfaz) { + ExternalService es = factory.createExternalService(); + es.setName(name); + Service s = factory.createService(); + JavaServiceContract ji = factory.createJavaServiceContract(); + ji.setScope(Scope.MODULE); + ji.setInterface(interfaz); + s.setServiceContract(ji); + ConfiguredService configuredService = factory.createConfiguredService(); + es.setConfiguredService(configuredService); + + FooBinding binding = new FooBinding(); + es.getBindings().add(binding); + return es; + } + + /** + * Creates an entry point with the given name configured with the given interface and the {@link + * FooBinding} + */ + public static EntryPoint createFooBindingEntryPoint(String name, Class interfaz) { + EntryPoint ep = factory.createEntryPoint(); + ep.setName(name); + Service s = factory.createService(); + JavaServiceContract ji = factory.createJavaServiceContract(); + ji.setScope(Scope.MODULE); + ji.setInterface(interfaz); + s.setServiceContract(ji); + ConfiguredService configuredService = factory.createConfiguredService(); + configuredService.setPort(s); + ep.setConfiguredService(configuredService); + FooBinding binding = new FooBinding(); + ep.getBindings().add(binding); + return ep; + } + + /** + * Creates an external service configured with a {@link SystemBinding} + */ + public static ExternalService createESSystemBinding(String name, String refName) { + ExternalService es = systemFactory.createExternalService(); + es.setName(name); + ConfiguredService configuredService = systemFactory.createConfiguredService(); + es.setConfiguredService(configuredService); + SystemBinding binding = systemFactory.createSystemBinding(); + binding.setTargetName(refName); + es.getBindings().add(binding); + es.initialize(null); + return es; + } + + /** + * Creates a module with a Java-based "target" module-scoped component wired to a module-scoped "source" + */ + public static Module createModule() throws ConfigurationLoadException { + return createModule(Scope.MODULE, Scope.MODULE); + } + + /** + * Creates a module with a Java-based "target" component wired to a "source" + */ + public static Module createModule(Scope sourceScope, Scope targetScope) throws ConfigurationLoadException { + Component sourceComponent = createNonIntrospectedComponent("source", ModuleScopeComponent.class, ModuleScopeComponentImpl.class, sourceScope); + Component targetComponent = createNonIntrospectedComponent("target", ModuleScopeComponent.class, ModuleScopeComponentImpl.class, targetScope); + + Service targetService = factory.createService(); + JavaServiceContract targetContract = factory.createJavaServiceContract(); + targetContract.setInterface(GenericComponent.class); + targetService.setServiceContract(targetContract); + targetService.setName("GenericComponent"); + targetContract.setScope(targetScope); + ConfiguredService cTargetService = factory.createConfiguredService(); + cTargetService.setPort(targetService); + cTargetService.initialize(assemblyContext); + targetComponent.getConfiguredServices().add(cTargetService); + targetComponent.initialize(assemblyContext); + + Reference ref = factory.createReference(); + ref.setName("setGenericComponent"); + JavaServiceContract inter = factory.createJavaServiceContract(); + inter.setInterface(GenericComponent.class); + ref.setServiceContract(inter); + sourceComponent.getImplementation().getComponentType().getReferences().add(ref); + + ConfiguredReference cref = factory.createConfiguredReference("setGenericComponent", "target"); + cref.initialize(assemblyContext); + sourceComponent.getConfiguredReferences().add(cref); + sourceComponent.initialize(assemblyContext); + + Module module = factory.createModule(); + module.setName("test.module"); + module.getComponents().add(sourceComponent); + module.getComponents().add(targetComponent); + module.initialize(assemblyContext); + return module; + } + + /** + * Creates a module with a Java-based source component wired to a "target" external service configured + * with the {@link FooBinding} + */ + public static Module createModuleWithExternalService() throws ConfigurationLoadException { + Component sourceComponent = createComponent("source", HelloWorldClient.class, Scope.MODULE); + ExternalService targetES = createFooBindingExternalService("target", HelloWorldService.class); + + Service targetService = factory.createService(); + JavaServiceContract targetContract = factory.createJavaServiceContract(); + targetContract.setInterface(HelloWorldService.class); + targetService.setServiceContract(targetContract); + targetService.setName("HelloWorld"); + ConfiguredService cTargetService = factory.createConfiguredService(); + cTargetService.setPort(targetService); + targetES.setConfiguredService(cTargetService); + targetES.initialize(assemblyContext); + + Reference ref = factory.createReference(); + ref.setName("setHelloWorldService"); + JavaServiceContract inter = factory.createJavaServiceContract(); + inter.setInterface(HelloWorldService.class); + ref.setServiceContract(inter); + sourceComponent.getImplementation().getComponentType().getReferences().add(ref); + + ConfiguredReference cref = factory.createConfiguredReference(ref.getName(), "target"); + cref.initialize(assemblyContext); + sourceComponent.getConfiguredReferences().add(cref); + sourceComponent.initialize(assemblyContext); + + Module module = factory.createModule(); + module.setName("test.module"); + module.getComponents().add(sourceComponent); + module.getExternalServices().add(targetES); + module.initialize(assemblyContext); + return module; + } + + /** + * Creates a module with an entry point named "source" configured with the {@link FooBinding} wired to a + * service offered by a Java-based component named "target" + * + * @param scope the scope of the target service + */ + public static Module createModuleWithEntryPoint(Scope scope) throws ConfigurationLoadException { + Component targetComponent = createComponent("target", HelloWorldImpl.class, scope); + + Service targetService = factory.createService(); + JavaServiceContract targetContract = factory.createJavaServiceContract(); + targetContract.setInterface(HelloWorldService.class); + targetService.setServiceContract(targetContract); + targetService.setName("HelloWorldService"); + ConfiguredService cTargetService = factory.createConfiguredService(); + cTargetService.setPort(targetService); + targetComponent.getConfiguredServices().add(cTargetService); + targetComponent.initialize(assemblyContext); + + Reference ref = factory.createReference(); + ConfiguredReference cref = factory.createConfiguredReference(); + ref.setName("setHelloWorldService"); + JavaServiceContract inter = factory.createJavaServiceContract(); + inter.setInterface(HelloWorldService.class); + ref.setServiceContract(inter); + cref.setPort(ref); + cref.getTargetConfiguredServices().add(cTargetService); + cref.initialize(assemblyContext); + + EntryPoint sourceEP = createFooBindingEntryPoint("source", HelloWorldService.class); + sourceEP.setConfiguredReference(cref); + sourceEP.getConfiguredService().getPort().setName("HelloWorldService"); + sourceEP.initialize(assemblyContext); + + Module module = factory.createModule(); + module.setName("test.module"); + module.getEntryPoints().add(sourceEP); + module.getComponents().add(targetComponent); + module.setImplementationClass(CompositeContextImpl.class); + module.setComponentType(getCompositeComponentType()); + module.initialize(assemblyContext); + return module; + } + + /** + * Creates a module with an entry point wired to a "target" external service configured with the {@link + * FooBinding} + */ + public static Module createModuleWithEntryPointToExternalService() { + //Component sourceComponent = createComponent("source", HelloWorldClient.class, Scope.MODULE); + + EntryPoint sourceEP = createFooBindingEntryPoint("source", HelloWorldService.class); + sourceEP.getConfiguredService().getPort().setName("HelloWorldService"); + sourceEP.initialize(assemblyContext); + + + ExternalService targetES = createFooBindingExternalService("target", HelloWorldService.class); + + Service targetService = factory.createService(); + JavaServiceContract targetContract = factory.createJavaServiceContract(); + targetContract.setInterface(HelloWorldService.class); + targetService.setServiceContract(targetContract); + targetService.setName("HelloWorld"); + ConfiguredService cTargetService = factory.createConfiguredService(); + cTargetService.setPort(targetService); + targetES.setConfiguredService(cTargetService); + targetES.initialize(assemblyContext); + + Reference ref = factory.createReference(); + ref.setName("setHelloWorldService"); + JavaServiceContract inter = factory.createJavaServiceContract(); + inter.setInterface(HelloWorldService.class); + ref.setServiceContract(inter); + + + ConfiguredReference cref = factory.createConfiguredReference(ref.getName(), "target"); + cref.setPort(ref); + cref.initialize(assemblyContext); + sourceEP.setConfiguredReference(cref); + sourceEP.initialize(assemblyContext); + + Module module = factory.createModule(); + module.setName("test.module"); + module.getEntryPoints().add(sourceEP); + module.getExternalServices().add(targetES); + module.initialize(assemblyContext); + return module; + } + + + /** + * Creates a test system module with source and target components wired together. + * + * @see org.apache.tuscany.core.mock.component.Source + * @see org.apache.tuscany.core.mock.component.Target + */ + + public static Module createModuleWithWiredComponents(Scope sourceScope, Scope targetScope) { + + // create the target component + AtomicComponent target = factory.createSimpleComponent(); + target.setName("target"); + JavaImplementation targetImpl = factory.createJavaImplementation(); + targetImpl.setComponentType(factory.createComponentType()); + targetImpl.setImplementationClass(TargetImpl.class); + target.setImplementation(targetImpl); + Service targetService = factory.createService(); + JavaServiceContract targetContract = factory.createJavaServiceContract(); + targetContract.setInterface(Target.class); + targetService.setServiceContract(targetContract); + targetService.setName("Target"); + targetImpl.getComponentType().getServices().add(targetService); + targetContract.setScope(targetScope); + ConfiguredService cTargetService = factory.createConfiguredService(); + cTargetService.setPort(targetService); + cTargetService.initialize(assemblyContext); + target.getConfiguredServices().add(cTargetService); + target.initialize(assemblyContext); + + // create the source component + AtomicComponent source = factory.createSimpleComponent(); + ComponentType componentType = factory.createComponentType(); + source.setName("source"); + JavaImplementation impl = factory.createJavaImplementation(); + impl.setComponentType(componentType); + impl.setImplementationClass(SourceImpl.class); + source.setImplementation(impl); + Service s = systemFactory.createService(); + JavaServiceContract contract = systemFactory.createJavaServiceContract(); + contract.setInterface(Source.class); + s.setServiceContract(contract); + contract.setScope(sourceScope); + impl.getComponentType().getServices().add(s); + source.setImplementation(impl); + + // wire source to target + JavaServiceContract refContract = systemFactory.createJavaServiceContract(); + refContract.setInterface(Target.class); + Reference reference = systemFactory.createReference(); + reference.setName("setTarget"); + reference.setServiceContract(refContract); + componentType.getReferences().add(reference); + ConfiguredReference cReference = systemFactory.createConfiguredReference(reference.getName(), "target"); + cReference.initialize(assemblyContext); + source.getConfiguredReferences().add(cReference); + + // wire multiplicity using a setter + JavaServiceContract refContract2 = systemFactory.createJavaServiceContract(); + refContract2.setInterface(Target.class); + Reference reference2 = systemFactory.createReference(); + reference2.setName("setTargets"); + reference2.setServiceContract(refContract2); + reference2.setMultiplicity(Multiplicity.ONE_N); + componentType.getReferences().add(reference2); + ConfiguredReference cReference2 = systemFactory.createConfiguredReference(reference2.getName(), "target"); + cReference2.initialize(assemblyContext); + source.getConfiguredReferences().add(cReference2); + + // wire multiplicity using a field + JavaServiceContract refContract3 = systemFactory.createJavaServiceContract(); + refContract3.setInterface(Target.class); + Reference reference3 = systemFactory.createReference(); + reference3.setName("targetsThroughField"); + reference3.setServiceContract(refContract3); + reference3.setMultiplicity(Multiplicity.ONE_N); + componentType.getReferences().add(reference3); + ConfiguredReference cReference3 = systemFactory.createConfiguredReference(reference3.getName(), "target"); + cReference3.initialize(assemblyContext); + source.getConfiguredReferences().add(cReference3); + + // wire multiplicity using a array + JavaServiceContract refContract4 = systemFactory.createJavaServiceContract(); + refContract4.setInterface(Target.class); + Reference reference4 = systemFactory.createReference(); + reference4.setName("setArrayOfTargets"); + reference4.setServiceContract(refContract4); + reference4.setMultiplicity(Multiplicity.ONE_N); + componentType.getReferences().add(reference4); + ConfiguredReference cReference4 = systemFactory.createConfiguredReference(reference4.getName(), "target"); + cReference4.initialize(assemblyContext); + source.getConfiguredReferences().add(cReference4); + + source.initialize(assemblyContext); + + Module module = systemFactory.createModule(); + module.setName("system.module"); + + module.getComponents().add(source); + module.getComponents().add(target); + module.initialize(assemblyContext); + return module; + } + + + /** + * Creates a test system module with source and target components wired together. + * + * @see org.apache.tuscany.core.mock.component.Source + * @see org.apache.tuscany.core.mock.component.Target + */ + + public static Module createModuleWithWiredComponentsOfDifferentInterface(Scope sourceScope, Scope targetScope) { + + // create the target component + AtomicComponent target = factory.createSimpleComponent(); + target.setName("target"); + JavaImplementation targetImpl = factory.createJavaImplementation(); + targetImpl.setComponentType(factory.createComponentType()); + targetImpl.setImplementationClass(OtherTargetImpl.class); + target.setImplementation(targetImpl); + Service targetService = factory.createService(); + JavaServiceContract targetContract = factory.createJavaServiceContract(); + targetContract.setInterface(OtherTarget.class); + targetService.setServiceContract(targetContract); + targetService.setName("Target"); + targetImpl.getComponentType().getServices().add(targetService); + targetContract.setScope(targetScope); + ConfiguredService cTargetService = factory.createConfiguredService(); + cTargetService.setPort(targetService); + cTargetService.initialize(assemblyContext); + target.getConfiguredServices().add(cTargetService); + target.initialize(assemblyContext); + + // create the source component + AtomicComponent source = factory.createSimpleComponent(); + ComponentType componentType = factory.createComponentType(); + source.setName("source"); + JavaImplementation impl = factory.createJavaImplementation(); + impl.setComponentType(componentType); + impl.setImplementationClass(SourceImpl.class); + source.setImplementation(impl); + Service s = systemFactory.createService(); + JavaServiceContract contract = systemFactory.createJavaServiceContract(); + contract.setInterface(Source.class); + s.setServiceContract(contract); + contract.setScope(sourceScope); + impl.getComponentType().getServices().add(s); + source.setImplementation(impl); + + // wire source to target + JavaServiceContract refContract = systemFactory.createJavaServiceContract(); + refContract.setInterface(Target.class); + Reference reference = systemFactory.createReference(); + reference.setName("setTarget"); + reference.setServiceContract(refContract); + componentType.getReferences().add(reference); + ConfiguredReference cReference = systemFactory.createConfiguredReference(reference.getName(), "target"); + cReference.initialize(assemblyContext); + source.getConfiguredReferences().add(cReference); + + // wire multiplicity using a setter + JavaServiceContract refContract2 = systemFactory.createJavaServiceContract(); + refContract2.setInterface(Target.class); + Reference reference2 = systemFactory.createReference(); + reference2.setName("setTargets"); + reference2.setServiceContract(refContract2); + reference2.setMultiplicity(Multiplicity.ONE_N); + componentType.getReferences().add(reference2); + ConfiguredReference cReference2 = systemFactory.createConfiguredReference(reference2.getName(), "target"); + cReference2.initialize(assemblyContext); + source.getConfiguredReferences().add(cReference2); + + // wire multiplicity using a field + JavaServiceContract refContract3 = systemFactory.createJavaServiceContract(); + refContract3.setInterface(Target.class); + Reference reference3 = systemFactory.createReference(); + reference3.setName("targetsThroughField"); + reference3.setServiceContract(refContract3); + reference3.setMultiplicity(Multiplicity.ONE_N); + componentType.getReferences().add(reference3); + ConfiguredReference cReference3 = systemFactory.createConfiguredReference(reference3.getName(), "target"); + cReference3.initialize(assemblyContext); + source.getConfiguredReferences().add(cReference3); + + // wire multiplicity using a array + JavaServiceContract refContract4 = systemFactory.createJavaServiceContract(); + refContract4.setInterface(Target.class); + Reference reference4 = systemFactory.createReference(); + reference4.setName("setArrayOfTargets"); + reference4.setServiceContract(refContract4); + reference4.setMultiplicity(Multiplicity.ONE_N); + componentType.getReferences().add(reference4); + ConfiguredReference cReference4 = systemFactory.createConfiguredReference(reference4.getName(), "target"); + cReference4.initialize(assemblyContext); + source.getConfiguredReferences().add(cReference4); + + source.initialize(assemblyContext); + + Module module = systemFactory.createModule(); + module.setName("system.module"); + + module.getComponents().add(source); + module.getComponents().add(target); + module.initialize(assemblyContext); + return module; + } + + + /** + * Returns a collection of bootstrap configuration builders + */ + public static List<ContextFactoryBuilder> createSystemBuilders() { + List<ContextFactoryBuilder> builders = new ArrayList<ContextFactoryBuilder>(); + builders.add((new SystemContextFactoryBuilder(null))); + builders.add(new SystemEntryPointBuilder()); + builders.add(new SystemExternalServiceBuilder()); + return builders; + } + + /** + * Creates an composite context faxtory + * + * @param name the name of the component + * @throws BuilderException + * @see ContextFactory + */ + public static ContextFactory<Context> createCompositeConfiguration(String name + ) throws BuilderException, ConfigurationLoadException { + + Component sc = createCompositeComponent(name); + SystemContextFactoryBuilder builder = new SystemContextFactoryBuilder(null); + builder.build(sc); + return (ContextFactory<Context>) sc.getContextFactory(); + } + + /** + * Creates a Java POJO component context + * + * @param name the name of the context + * @param implType the POJO class + * @param scope the component scope + * @param moduleComponentContext the containing composite context + * @throws NoSuchMethodException if the POJO does not have a default noi-args constructor + */ + public static JavaAtomicContext createPojoContext(String name, Class implType, Scope scope, + CompositeContext moduleComponentContext) throws NoSuchMethodException, ConfigurationLoadException { + AtomicComponent component = createComponent(name, implType, scope); + + Set<Field> fields = JavaIntrospectionHelper.getAllFields(implType); + Set<Method> methods = JavaIntrospectionHelper.getAllUniqueMethods(implType); + List<Injector> injectors = new ArrayList<Injector>(); + + EventInvoker initInvoker = null; + boolean eagerInit = false; + EventInvoker destroyInvoker = null; + for (Field field : fields) { + ComponentName compName = field.getAnnotation(ComponentName.class); + if (compName != null) { + Injector injector = new FieldInjector(field, new SingletonObjectFactory(name)); + injectors.add(injector); + } + org.osoa.sca.annotations.Context context = field.getAnnotation(org.osoa.sca.annotations.Context.class); + if (context != null) { + Injector injector = new FieldInjector(field, new SingletonObjectFactory(moduleComponentContext)); + injectors.add(injector); + } + } + for (Method method : methods) { + // FIXME Java5 + Init init = method.getAnnotation(Init.class); + if (init != null && initInvoker == null) { + initInvoker = new MethodEventInvoker(method); + eagerInit = init.eager(); + continue; + } + Destroy destroy = method.getAnnotation(Destroy.class); + if (destroy != null && destroyInvoker == null) { + destroyInvoker = new MethodEventInvoker(method); + continue; + } + ComponentName compName = method.getAnnotation(ComponentName.class); + if (compName != null) { + Injector injector = new MethodInjector(method, new SingletonObjectFactory(name)); + injectors.add(injector); + } + org.osoa.sca.annotations.Context context = method.getAnnotation(org.osoa.sca.annotations.Context.class); + if (context != null) { + Injector injector = new MethodInjector(method, new SingletonObjectFactory(moduleComponentContext)); + injectors.add(injector); + } + } + boolean stateless = (scope == Scope.INSTANCE); + return new JavaAtomicContext("foo", new PojoObjectFactory(JavaIntrospectionHelper + .getDefaultConstructor(implType), null, injectors), eagerInit, initInvoker, destroyInvoker, stateless); + } + + /** + * Creates a default {@link RuntimeContext} configured with support for Java component implementations + * + * @throws ConfigurationException + */ + public static RuntimeContext createJavaRuntime() throws ConfigurationException { + MonitorFactory monitorFactory = new NullMonitorFactory(); + ContextFactoryBuilderRegistry builderRegistry = BootstrapHelper.bootstrapContextFactoryBuilders(monitorFactory); + DefaultWireBuilder wireBuilder = new DefaultWireBuilder(); + RuntimeContext runtime = new RuntimeContextImpl(monitorFactory, builderRegistry, wireBuilder); + runtime.start(); + runtime.getSystemContext().registerModelObject(createSystemCompositeComponent(SYSTEM_CHILD)); + SystemCompositeContext ctx = (SystemCompositeContext) runtime.getSystemContext().getContext(SYSTEM_CHILD); + Component comp = systemFactory.createSystemComponent(POLICY_BUILDER_REGISTRY, PolicyBuilderRegistry.class, DefaultPolicyBuilderRegistry.class, Scope.MODULE); + comp.getImplementation().setComponentType(getIntrospector().introspect(DefaultPolicyBuilderRegistry.class)); + ctx.registerModelObject(comp); + comp = systemFactory.createSystemComponent(MESSAGE_FACTORY, MessageFactory.class, MessageFactoryImpl.class, Scope.MODULE); + comp.getImplementation().setComponentType(getIntrospector().introspect(MessageFactoryImpl.class)); + ctx.registerModelObject(comp); + comp = systemFactory.createSystemComponent(PROXY_FACTORY_FACTORY, WireFactoryFactory.class, JDKWireFactoryFactory.class, Scope.MODULE); + comp.getImplementation().setComponentType(getIntrospector().introspect(JDKWireFactoryFactory.class)); + ctx.registerModelObject(comp); + comp = systemFactory.createSystemComponent(WIRE_FACTORY_SERVICE, org.apache.tuscany.core.wire.service.WireFactoryService.class, DefaultWireFactoryService.class, Scope.MODULE); + comp.getImplementation().setComponentType(getIntrospector().introspect(DefaultWireFactoryService.class)); + ctx.registerModelObject(comp); + comp = systemFactory.createSystemComponent(JAVA_BUILDER, ContextFactoryBuilder.class, JavaContextFactoryBuilder.class, Scope.MODULE); + comp.getImplementation().setComponentType(getIntrospector().introspect(JavaContextFactoryBuilder.class)); + ctx.registerModelObject(comp); + comp = systemFactory.createSystemComponent(JAVA_WIRE_BUILDER, WireBuilder.class, JavaTargetWireBuilder.class, Scope.MODULE); + comp.getImplementation().setComponentType(getIntrospector().introspect(JavaTargetWireBuilder.class)); + ctx.registerModelObject(comp); + ctx.publish(new ModuleStart(new Object())); + return runtime; + } + + /** + * Registers the {@link FooBinding} builders with a given runtime + * + * @throws ConfigurationException + */ + public static RuntimeContext registerFooBinding(RuntimeContext runtime) throws ConfigurationException { + CompositeContext child = (CompositeContext) runtime.getSystemContext().getContext(MockFactory.SYSTEM_CHILD); + child.getContext(MockFactory.JAVA_BUILDER).getInstance(null); + Component comp = systemFactory.createSystemComponent(FOO_BUILDER, ContextFactoryBuilder.class, FooBindingBuilder.class, Scope.MODULE); + comp.getImplementation().setComponentType(getIntrospector().introspect(FooBindingBuilder.class)); + child.registerModelObject(comp); + comp = systemFactory.createSystemComponent(FOO_WIRE_BUILDER, WireBuilder.class, FooBindingWireBuilder.class, Scope.MODULE); + comp.getImplementation().setComponentType(getIntrospector().introspect(FooBindingWireBuilder.class)); + child.registerModelObject(comp); + // since the child context is already started, we need to manually retrieve the components to init them + Assert.assertNotNull(child.getContext(FOO_BUILDER).getInstance(null)); + Assert.assertNotNull(child.getContext(FOO_WIRE_BUILDER).getInstance(null)); + return runtime; + } + + +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/MockScopeContext.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/MockScopeContext.java new file mode 100644 index 0000000000..fe128f19a7 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/MockScopeContext.java @@ -0,0 +1,131 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.mock; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.tuscany.container.java.invocation.mock.SimpleTargetImpl; +import org.apache.tuscany.core.builder.ContextFactory; +import org.apache.tuscany.core.context.AtomicContext; +import org.apache.tuscany.core.context.Context; +import org.apache.tuscany.core.context.ContextRuntimeException; +import org.apache.tuscany.core.context.EventFilter; +import org.apache.tuscany.core.context.QualifiedName; +import org.apache.tuscany.core.context.RuntimeEventListener; +import org.apache.tuscany.core.context.ScopeContext; +import org.apache.tuscany.core.context.ScopeRuntimeException; +import org.apache.tuscany.core.context.event.Event; +import org.apache.tuscany.model.assembly.AtomicComponent; + +public class MockScopeContext implements ScopeContext { + + Map<String, Object> components; + + public MockScopeContext() { + components = new HashMap<String, Object>(); + components.put("foo", new SimpleTargetImpl()); + components.put("bar", new SimpleTargetImpl()); + } + + public MockScopeContext(Map<String,Object> instances) { + components = instances; + } + + + public void start() { + } + + public void stop() { + } + + public void publish(Event object) { + //To change body of implemented methods use File | Settings | File Templates. + } + + public void addListener(RuntimeEventListener listener) throws ContextRuntimeException { + } + + public void addListener(EventFilter filter, RuntimeEventListener listener) { + //To change body of implemented methods use File | Settings | File Templates. + } + + public void removeListener(RuntimeEventListener listener) throws ContextRuntimeException { + } + + public String getName() { + return "Mock Scope Container"; + } + + public boolean isCacheable() { + return false; + } + + public int[] getEventTypes() { + return null; + } + + public AtomicContext getContext(String name) { + return null; + } + + public Object getInstance(QualifiedName name) throws ScopeRuntimeException { + return components.get(name.getPartName()); + } + + public AtomicContext getContextByKey(String name, Object key) { + return null; + } + + public void setComponent(AtomicComponent component) throws ScopeRuntimeException { + } + + public void removeContext(String name) throws ScopeRuntimeException { + } + + public void removeContextByKey(String name, Object key) throws ScopeRuntimeException { + } + + public AtomicComponent[] getComponents() { + return null; + } + + public void registerFactories(List<ContextFactory<Context>> configurations) { + } + + public void registerFactory(ContextFactory<Context> configuration) { + } + + public int getLifecycleState(){ + return RUNNING; + } + + + public void setLifecycleState(int state) { + } + + + public void setName(String name) { + } + + + public void onEvent(Event event) { + //To change body of implemented methods use File | Settings | File Templates. + } +} + diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/binding/foo/FooBinding.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/binding/foo/FooBinding.java new file mode 100644 index 0000000000..49c59bc718 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/binding/foo/FooBinding.java @@ -0,0 +1,58 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package org.apache.tuscany.container.java.mock.binding.foo; + +import org.apache.tuscany.model.assembly.AssemblyContext; +import org.apache.tuscany.model.assembly.AssemblyVisitor; +import org.apache.tuscany.model.assembly.Binding; + +/** + * Represents a mock binding that echoes back a single parameter + * + * @version $Rev$ $Date$ + */ +public class FooBinding implements Binding { + + public FooBinding() { + } + + public String getURI() { + return null; + } + + public void setURI(String value) { + } + + public void initialize(AssemblyContext modelContext) { + } + + public void freeze() { + } + + public boolean accept(AssemblyVisitor visitor) { + return true; + } + + private Object contextFactory; + + public void setContextFactory(Object factory) { + contextFactory = factory; + } + + public Object getContextFactory() { + System.out.println("retting"); + return contextFactory; + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/binding/foo/FooBindingBuilder.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/binding/foo/FooBindingBuilder.java new file mode 100644 index 0000000000..558a8ce2cf --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/binding/foo/FooBindingBuilder.java @@ -0,0 +1,114 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package org.apache.tuscany.container.java.mock.binding.foo; + +import org.apache.tuscany.core.builder.BuilderException; +import org.apache.tuscany.core.builder.ContextFactoryBuilder; +import org.apache.tuscany.core.builder.ContextFactoryBuilderRegistry; +import org.apache.tuscany.core.builder.ObjectFactory; +import org.apache.tuscany.core.extension.EntryPointContextFactory; +import org.apache.tuscany.core.injection.ObjectCreationException; +import org.apache.tuscany.core.message.MessageFactory; +import org.apache.tuscany.core.system.annotation.Autowire; +import org.apache.tuscany.core.wire.SourceWireFactory; +import org.apache.tuscany.core.wire.TargetWireFactory; +import org.apache.tuscany.core.wire.service.WireFactoryService; +import org.apache.tuscany.model.assembly.AssemblyObject; +import org.apache.tuscany.model.assembly.ConfiguredService; +import org.apache.tuscany.model.assembly.EntryPoint; +import org.apache.tuscany.model.assembly.ExternalService; +import org.apache.tuscany.model.assembly.Service; +import org.osoa.sca.annotations.Init; +import org.osoa.sca.annotations.Scope; + +/** + * Creates a <code>ContextFactoryBuilder</code> for an entry point or external service configured with the {@link FooBinding} + * + * @version $Rev$ $Date$ + */ +@Scope("MODULE") +public class FooBindingBuilder implements ContextFactoryBuilder { + private ContextFactoryBuilderRegistry builderRegistry; + + private MessageFactory messageFactory; + + private WireFactoryService wireFactoryService; + + public FooBindingBuilder(WireFactoryService wireFactoryService) { + this.wireFactoryService = wireFactoryService; + } + + public FooBindingBuilder() { + } + + @Init(eager = true) + public void init() { + builderRegistry.register(this); + } + + @Autowire + public void setBuilderRegistry(ContextFactoryBuilderRegistry builderRegistry) { + this.builderRegistry = builderRegistry; + } + + @Autowire + public void setWireFactoryService(WireFactoryService wireFactoryService) { + this.wireFactoryService = wireFactoryService; + } + + + /** + * Sets the factory used to construct wire messages + * + * @param msgFactory + */ + @Autowire + public void setMessageFactory(MessageFactory msgFactory) { + this.messageFactory = msgFactory; + } + + public void build(AssemblyObject object) throws BuilderException { + if (object instanceof EntryPoint) { + EntryPoint ep = (EntryPoint) object; + if (ep.getBindings().size() < 1 || !(ep.getBindings().get(0) instanceof FooBinding)) { + return; + } + EntryPointContextFactory contextFactory = new FooEntryPointContextFactory(ep.getName(), messageFactory); + ConfiguredService configuredService = ep.getConfiguredService(); + Service service = configuredService.getPort(); + SourceWireFactory wireFactory = wireFactoryService.createSourceFactory(ep.getConfiguredReference()).get(0); + contextFactory.addSourceWireFactory(service.getName(), wireFactory); + ep.setContextFactory(contextFactory); + } else if (object instanceof ExternalService) { + ExternalService es = (ExternalService) object; + if (es.getBindings().size() < 1 || !(es.getBindings().get(0) instanceof FooBinding)) { + return; + } + FooExternalServiceContextFactory contextFactory = new FooExternalServiceContextFactory(es.getName(), + new FooClientFactory()); + ConfiguredService configuredService = es.getConfiguredService(); + Service service = configuredService.getPort(); + TargetWireFactory wireFactory = wireFactoryService.createTargetFactory(configuredService); + contextFactory.addTargetWireFactory(service.getName(), wireFactory); + es.setContextFactory(contextFactory); + } + } + + private static class FooClientFactory implements ObjectFactory { + + public Object getInstance() throws ObjectCreationException { + return new FooClient(); + } + } +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/binding/foo/FooBindingWireBuilder.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/binding/foo/FooBindingWireBuilder.java new file mode 100644 index 0000000000..e2592024f8 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/binding/foo/FooBindingWireBuilder.java @@ -0,0 +1,76 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.mock.binding.foo; + +import org.apache.tuscany.core.builder.BuilderConfigException; +import org.apache.tuscany.core.builder.WireBuilder; +import org.apache.tuscany.core.context.ScopeContext; +import org.apache.tuscany.core.runtime.RuntimeContext; +import org.apache.tuscany.core.system.annotation.Autowire; +import org.apache.tuscany.core.wire.SourceInvocationConfiguration; +import org.apache.tuscany.core.wire.SourceWireFactory; +import org.apache.tuscany.core.wire.TargetInvocationConfiguration; +import org.apache.tuscany.core.wire.TargetInvoker; +import org.apache.tuscany.core.wire.TargetWireFactory; +import org.osoa.sca.annotations.Init; + +public class FooBindingWireBuilder implements WireBuilder { + + public FooBindingWireBuilder() { + super(); + } + + private RuntimeContext runtimeContext; + + @Autowire + public void setRuntimeContext(RuntimeContext context) { + runtimeContext = context; + } + + @Init(eager = true) + public void init() { + runtimeContext.addBuilder(this); + } + + + public void connect(SourceWireFactory sourceFactory, TargetWireFactory targetFactory, Class targetType, boolean downScope, + ScopeContext targetScopeContext) throws BuilderConfigException { + if (!FooExternalServiceContextFactory.class.isAssignableFrom(targetType)) { + return; + } + for (SourceInvocationConfiguration sourceInvocationConfig : sourceFactory.getConfiguration().getInvocationConfigurations() + .values()) { + FooExternalServiceTargetInvoker invoker = new FooExternalServiceTargetInvoker(sourceFactory.getConfiguration().getTargetName() + .getPartName()); + sourceInvocationConfig.setTargetInvoker(invoker); + } + + } + + public void completeTargetChain(TargetWireFactory targetFactory, Class targetType, ScopeContext targetScopeContext) + throws BuilderConfigException { + if (FooExternalServiceContextFactory.class.isAssignableFrom(targetType)) { + for (TargetInvocationConfiguration targetInvocationConfig : targetFactory.getConfiguration().getInvocationConfigurations() + .values()) { + TargetInvoker invoker = new FooExternalServiceTargetInvoker(targetFactory.getConfiguration().getTargetName().getQualifiedName()); + targetInvocationConfig.setTargetInvoker(invoker); + } + + } + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/binding/foo/FooClient.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/binding/foo/FooClient.java new file mode 100644 index 0000000000..9f67eb7786 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/binding/foo/FooClient.java @@ -0,0 +1,37 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package org.apache.tuscany.container.java.mock.binding.foo; + +import java.lang.reflect.Array; + +import org.apache.tuscany.core.context.TargetException; + +/** + * A mock client for a transport binding + * + * @version $Rev$ $Date$ + */ +public class FooClient { + + public FooClient() { + } + + public Object invoke(Object msg) { + if (msg!=null && msg.getClass().isArray() && Array.getLength(msg) == 1){ + return Array.get(msg,0); + }else{ + throw new TargetException("This binding only understands operations with a single parameter"); + } + } +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/binding/foo/FooEntryPointContextFactory.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/binding/foo/FooEntryPointContextFactory.java new file mode 100644 index 0000000000..69d81f66be --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/binding/foo/FooEntryPointContextFactory.java @@ -0,0 +1,31 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package org.apache.tuscany.container.java.mock.binding.foo; + +import org.apache.tuscany.core.extension.EntryPointContextFactory; +import org.apache.tuscany.core.message.MessageFactory; + +/** + * + * + * @version $Rev$ $Date$ + */ +public class FooEntryPointContextFactory extends EntryPointContextFactory { + + public FooEntryPointContextFactory(String name, MessageFactory msgFactory) { + super(name, msgFactory); + } + +} + diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/binding/foo/FooExternalServiceContextFactory.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/binding/foo/FooExternalServiceContextFactory.java new file mode 100644 index 0000000000..c7f67e2ff2 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/binding/foo/FooExternalServiceContextFactory.java @@ -0,0 +1,32 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package org.apache.tuscany.container.java.mock.binding.foo; + +import org.apache.tuscany.core.builder.ObjectFactory; +import org.apache.tuscany.core.extension.ExternalServiceContextFactory; + +/** + * Creates instances of {@link org.apache.tuscany.core.context.ExternalServiceContext} configured with the appropriate + * wire chains and bindings. This implementation serves as a marker for + * {@link org.apache.tuscany.container.java.mock.binding.foo.FooBindingWireBuilder} + * + * @version $Rev$ $Date$ + */ +public class FooExternalServiceContextFactory extends ExternalServiceContextFactory { + + public FooExternalServiceContextFactory(String name, ObjectFactory objectFactory) { + super(name, objectFactory); + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/binding/foo/FooExternalServiceTargetInvoker.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/binding/foo/FooExternalServiceTargetInvoker.java new file mode 100644 index 0000000000..ecc9655a10 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/binding/foo/FooExternalServiceTargetInvoker.java @@ -0,0 +1,78 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package org.apache.tuscany.container.java.mock.binding.foo; + +import org.apache.tuscany.core.context.ExternalServiceContext; +import org.apache.tuscany.core.message.Message; +import org.apache.tuscany.core.wire.Interceptor; +import org.apache.tuscany.core.wire.TargetInvoker; + +import java.lang.reflect.InvocationTargetException; + +/** + * Responsible for invoking a mock transport binding client configured for an external service over a wire + * + * @version $Rev$ $Date$ + */ +public class FooExternalServiceTargetInvoker implements TargetInvoker { + + private String name; + private ExternalServiceContext context; + + public FooExternalServiceTargetInvoker(String esName) { + assert (esName != null) : "No external service name specified"; + name = esName; // name is not used; it is included for illustration + } + + public Object invokeTarget(Object payload) throws InvocationTargetException { + FooClient client = new FooClient(); + if (payload != null) { + return client.invoke(payload); + } else { + return client.invoke(null); + } + } + + public boolean isCacheable() { + return false; + } + + public Message invoke(Message msg) { + try { + Object resp = invokeTarget(msg.getBody()); + msg.setBody(resp); + } catch (InvocationTargetException e) { + msg.setBody(e.getCause()); + } catch (Throwable e) { + msg.setBody(e); + } + return msg; + } + + public void setNext(Interceptor next) { + throw new UnsupportedOperationException(); + } + + public Object clone() throws CloneNotSupportedException { + try { + FooExternalServiceTargetInvoker invoker = (FooExternalServiceTargetInvoker) super.clone(); + invoker.context = this.context; + invoker.name = this.name; + return invoker; + } catch (CloneNotSupportedException e) { + return null; // will not happen + } + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/AbstractGenericComponent.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/AbstractGenericComponent.java new file mode 100644 index 0000000000..0c9d8172f8 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/AbstractGenericComponent.java @@ -0,0 +1,296 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.mock.components; + +import java.util.List; +import java.util.Map; + +import org.osoa.sca.ModuleContext; +import org.osoa.sca.annotations.ComponentName; +import org.osoa.sca.annotations.Context; +import org.osoa.sca.annotations.Property; + +/** + * Base test component implementation + * + * @version $Rev$ $Date$ + */ +public class AbstractGenericComponent implements GenericComponent { + + @ComponentName + private String name; + + public String getName() { + return name; + } + + @Context + private ModuleContext context; + + public ModuleContext getModuleContext() { + return context; + } + + //---------------------------------- + // Collections + //---------------------------------- + + Map testMap; + + public Map getTestMap() { + return testMap; + } + + public void setTestMap(Map testMap) { + this.testMap = testMap; + } + + List testList; + + public List getTestList() { + return testList; + } + + public void setTestList(List testList) { + this.testList = testList; + } + + //---------------------------------- + // Arrays + //---------------------------------- + + private int[] arrayInt; + + public int[] getArrayInt() { + return arrayInt; + } + + public void setArrayInt(int[] arrayInt) { + this.arrayInt = arrayInt; + } + + private float[] arrayFloat; + + public float[] getArrayFloat() { + return arrayFloat; + } + + public void setArrayFloat(float[] pArrayFloat) { + arrayFloat = pArrayFloat; + } + + private double[] arrayDouble; + + public double[] getArrayDouble() { + return arrayDouble; + } + + public void setArrayDouble(double[] pArrayDouble) { + arrayDouble = pArrayDouble; + } + + private long[] arrayLong; + + public long[] getArrayLong() { + return arrayLong; + } + + public void setArrayLong(long[] arrayLong) { + this.arrayLong = arrayLong; + } + + private short[] arrayShort; + + public short[] getArrayShort() { + return arrayShort; + } + + public void setArrayShort(short[] arrayShort) { + this.arrayShort = arrayShort; + } + + private boolean[] arrayBoolean; + + public boolean[] getArrayBoolean() { + return arrayBoolean; + } + + public void setArrayBoolean(boolean[] arrayBoolean) { + this.arrayBoolean = arrayBoolean; + } + + private String[] arrayString; + + public String[] getArrayString() { + return arrayString; + } + + public void setArrayString(String[] arrayString) { + this.arrayString = arrayString; + } + + //---------------------------------- + // Primitives + //---------------------------------- + + private boolean mBoolean; + + public boolean getBoolean() { + return mBoolean; + } + + public void setBoolean(boolean pBoolean) { + mBoolean = pBoolean; + } + + private short mShort; + + public short getShort() { + return mShort; + } + + public void setShort(short pShort) { + mShort = pShort; + } + + private int mInt; + + public int getInt() { + return mInt; + } + + public void setInt(int pInt) { + mInt = pInt; + } + + private long mLong; + + public long getLong() { + return mLong; + } + + public void setLong(long pLong) { + mLong = pLong; + } + + private double mDouble; + + public double getDouble() { + return mDouble; + } + + public void setDouble(double pDouble) { + mDouble = pDouble; + } + + private float mFloat; + + public float getFloat() { + return mFloat; + } + + public void setFloat(float pFloat) { + mFloat = pFloat; + } + + private char mChar; + + public char getChar() { + return mChar; + } + + public void setChar(char pChar) { + mChar = pChar; + } + + //---------------------------------- + // Object types + //---------------------------------- + + private String mString; + + public String getString() { + return mString; + } + + public void setString(String pString) { + mString = pString; + } + + private Short mOShort; + + public Short getOShort() { + return mOShort; + } + + public void setOShort(Short pOShort) { + mOShort = pOShort; + } + + private Integer mOInteger; + + public Integer getOInteger() { + return mOInteger; + } + + public void setOInteger(Integer pOInteger) { + mOInteger = pOInteger; + } + + private Long mOLong; + + public Long getOLong() { + return mOLong; + } + + public void setOLong(Long pOLong) { + mOLong = pOLong; + } + + private Float mOFloat; + + public Float getOFloat() { + return mOFloat; + } + + public void setOFloat(Float pOFloat) { + mOFloat = pOFloat; + } + + private Double mODouble; + + public Double getODouble() { + return mODouble; + } + + public void setODouble(Double pODouble) { + mODouble = pODouble; + } + + @Property(name = "genericComponent") + private GenericComponent mGenericComponent; + + public GenericComponent getGenericComponent() { + return mGenericComponent; + } + + public void setGenericComponent(GenericComponent pGenericComponent) { + mGenericComponent = pGenericComponent; + } + + +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/BadContextPojo.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/BadContextPojo.java new file mode 100644 index 0000000000..7840b57dea --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/BadContextPojo.java @@ -0,0 +1,26 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.mock.components; + +import org.osoa.sca.annotations.Context; + +public class BadContextPojo { + + @Context + String moduleContext; + +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/BadNamePojo.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/BadNamePojo.java new file mode 100644 index 0000000000..d9753fa9f0 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/BadNamePojo.java @@ -0,0 +1,24 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.mock.components; + +import org.osoa.sca.annotations.ComponentName; + +public class BadNamePojo { + @ComponentName + private int name; +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/DataObject.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/DataObject.java new file mode 100644 index 0000000000..695cc2a5a1 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/DataObject.java @@ -0,0 +1,38 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.mock.components; + +import java.io.Serializable; + +/** + * A complex type for testing + * + * @version $Rev$ $Date$ + */ +public class DataObject implements Serializable { + + private String stringValue; + + public String getStringValue() { + return stringValue; + } + + public void setStringValue(String stringValue) { + this.stringValue = stringValue; + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/GenericComponent.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/GenericComponent.java new file mode 100644 index 0000000000..44f1c02bfd --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/GenericComponent.java @@ -0,0 +1,142 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.mock.components; + +import java.util.List; +import java.util.Map; + +import org.osoa.sca.ModuleContext; + +/** + * Generic test component + * + * @version $Rev$ $Date$ + */ +public interface GenericComponent { + + public String getName(); + + public ModuleContext getModuleContext(); + + // ---------------------------------- + // Collections + // ---------------------------------- + + public Map getTestMap(); + + public void setTestMap(Map pTestMap); + + public List getTestList(); + + public void setTestList(List pTestList); + + // ---------------------------------- + // Arrays + // ---------------------------------- + + public int[] getArrayInt(); + + public void setArrayInt(int[] pArrayInt); + + public float[] getArrayFloat(); + + public void setArrayFloat(float[] pArrayFloat); + + public double[] getArrayDouble(); + + public void setArrayDouble(double[] pArrayDouble); + + public long[] getArrayLong(); + + public void setArrayLong(long[] pArrayLong); + + public short[] getArrayShort(); + + public void setArrayShort(short[] pArrayShort); + + public boolean[] getArrayBoolean(); + + public void setArrayBoolean(boolean[] pArrayBoolean); + + public String[] getArrayString(); + + public void setArrayString(String[] pArrayString); + + // ---------------------------------- + // Primitives + // ---------------------------------- + + public boolean getBoolean(); + + public void setBoolean(boolean pBoolean); + + public short getShort(); + + public void setShort(short pShort); + + public int getInt(); + + public void setInt(int pInt); + + public long getLong(); + + public void setLong(long pLong); + + public double getDouble(); + + public void setDouble(double pDouble); + + public float getFloat(); + + public void setFloat(float pFloat); + + public char getChar(); + + public void setChar(char pChar); + + // ---------------------------------- + // Object types + // ---------------------------------- + + public String getString(); + + public void setString(String pString); + + public Short getOShort(); + + public void setOShort(Short pOShort); + + public Integer getOInteger(); + + public void setOInteger(Integer pOInteger); + + public Long getOLong(); + + public void setOLong(Long pOLong); + + public Float getOFloat(); + + public void setOFloat(Float pOFloat); + + public Double getODouble(); + + public void setODouble(Double pODouble); + + public GenericComponent getGenericComponent(); + + public void setGenericComponent(GenericComponent pGenericComponent); +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/HelloWorldClient.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/HelloWorldClient.java new file mode 100644 index 0000000000..1e7ca9f36b --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/HelloWorldClient.java @@ -0,0 +1,46 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package org.apache.tuscany.container.java.mock.components; + +import org.apache.tuscany.container.java.assembly.mock.HelloWorldService; + +/** + * + * + * @version $Rev$ $Date$ + */ +public class HelloWorldClient implements HelloWorldService{ + + private int count; + + public HelloWorldClient() { + } + + private HelloWorldService service; + + public void setHelloWorldService(HelloWorldService service){ + this.service = service; + } + + public String hello(String name) { + ++count; + return service.hello(name); + } + + public int count() { + return count; + } + +} + diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/LocalComponentImpl.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/LocalComponentImpl.java new file mode 100644 index 0000000000..4b57c7f301 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/LocalComponentImpl.java @@ -0,0 +1,97 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.mock.components; + +import org.osoa.sca.ModuleContext; +import org.osoa.sca.annotations.ComponentName; +import org.osoa.sca.annotations.Context; +import org.osoa.sca.annotations.Property; +import org.osoa.sca.annotations.Reference; + +/** + * A test local service + * + * @version $Rev$ $Date$ + */ + +public class LocalComponentImpl { + + @ComponentName + protected String name; + + public String getName() { + return name; + } + + @Context + protected ModuleContext moduleCtx; + + public ModuleContext getModuleContext() { + return moduleCtx; + } + + @Property(name = "fieldSetter", required = true) + private String mfieldSetter; + + public String getfieldSetter() { + return mfieldSetter; + } + + public void setfieldSetter(String pfieldSetter) throws Exception { + throw new Exception("Set method instead of field"); + } + + private String mMethodSetter; + boolean mSetByMethod; + + public String getMethodSetter() throws Exception { + if (mSetByMethod) { + return mMethodSetter; + } + throw new Exception("Property method setter failed"); + + } + + @Property(required = true) + public void setMethodSetter(String pMethodSetter) { + mSetByMethod = true; + mMethodSetter = pMethodSetter; + } + + @Reference(name = "requiredDataObject", required = true) + private DataObject mRequiredDataObject; + + public DataObject getRequiredDataObject() { + return mRequiredDataObject; + } + + public void setRequiredDataObject(DataObject pRequiredDataObject) { + mRequiredDataObject = pRequiredDataObject; + } + + @Reference(name = "optionalDataObject") + private DataObject mOptionalDataObject; + + public DataObject getOptionalDataObject() { + return mOptionalDataObject; + } + + public void setOptionalDataObject(DataObject pOptionalDataObject) { + mOptionalDataObject = pOptionalDataObject; + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/ModuleScopeComponent.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/ModuleScopeComponent.java new file mode 100644 index 0000000000..04cbb01de6 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/ModuleScopeComponent.java @@ -0,0 +1,31 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.mock.components; + +import org.osoa.sca.annotations.Scope; + +/** + * @version $Rev$ $Date$ + */ +@Scope("MODULE") +public interface ModuleScopeComponent extends GenericComponent { + public GenericComponent getGenericComponent(); + + public String getString(); + //public boolean isInit(); +} + diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/ModuleScopeComponentImpl.componentType b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/ModuleScopeComponentImpl.componentType new file mode 100644 index 0000000000..ca4c633e59 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/ModuleScopeComponentImpl.componentType @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="ASCII"?>
+<!--
+ Copyright (c) 2005 The Apache Software Foundation or its licensors, as applicable.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ -->
+<!-- remove this once ImplementationImpl is fixed not to requrie this -->
+<componentType xmlns="http://www.osoa.org/xmlns/sca/0.9">
+
+ <service name="ModuleScopeComponent" scope="module">
+ <interface.java interface="janus.test.component.ModuleScopeComponent"/>
+ </service> + <!-- Not supported, not in the spec
+ <property.java name="mInt" class="java.lang.Integer" default="default"/>
+ <property.java name="foo" class="java.lang.String" default="default"/> + -->
+ <reference name="mGenericComponent" multiplicity="0..1">
+ <interface.java interface="test.org.apache.tuscany.container.java.components.AbstractGenericComponent"/>
+ </reference>
+
+</componentType>
+
diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/ModuleScopeComponentImpl.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/ModuleScopeComponentImpl.java new file mode 100644 index 0000000000..7981208b9e --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/ModuleScopeComponentImpl.java @@ -0,0 +1,38 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.mock.components; + +import org.osoa.sca.annotations.Scope; + + +/** + * @version $Rev$ $Date$ + */ +@Scope("MODULE") +public class ModuleScopeComponentImpl extends AbstractGenericComponent implements + ModuleScopeComponent { + + private String foo; + + public void setFoo(String foo) { + this.foo = foo; + } + + public String getFoo() { + return foo; + } +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/ModuleScopeDestroyOnlyComponent.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/ModuleScopeDestroyOnlyComponent.java new file mode 100644 index 0000000000..76218c2d6c --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/ModuleScopeDestroyOnlyComponent.java @@ -0,0 +1,34 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.mock.components; + +import org.osoa.sca.annotations.Destroy; + +public class ModuleScopeDestroyOnlyComponent extends ModuleScopeComponentImpl { + + boolean destroyed = false; + + public boolean isDestroyed() { + return destroyed; + } + + @Destroy + public void destroy() { + destroyed = true; + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/ModuleScopeEagerInitComponent.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/ModuleScopeEagerInitComponent.java new file mode 100644 index 0000000000..56a0421f24 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/ModuleScopeEagerInitComponent.java @@ -0,0 +1,39 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.mock.components; + +import org.osoa.sca.annotations.Init; + +public class ModuleScopeEagerInitComponent extends ModuleScopeComponentImpl { + + boolean initialized = false; + + public boolean isInitialized() { + return initialized; + } + + // this value tests to ensure introspection can find the init() method even + // if a field is named the same. Ultimately, this should be in the + // introspection tests + private boolean init; + + @Init(eager = true) + public void init() { + initialized = true; + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/ModuleScopeEagerInitDestroyComponent.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/ModuleScopeEagerInitDestroyComponent.java new file mode 100644 index 0000000000..dae156737a --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/ModuleScopeEagerInitDestroyComponent.java @@ -0,0 +1,33 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.mock.components; + +import org.osoa.sca.annotations.Destroy; + +public class ModuleScopeEagerInitDestroyComponent extends ModuleScopeEagerInitComponent { + + boolean destroyed = false; + + public boolean isDestroyed() { + return destroyed; + } + + @Destroy + public void destroy() { + destroyed = true; + } +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/ModuleScopeInitDestroyComponent.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/ModuleScopeInitDestroyComponent.java new file mode 100644 index 0000000000..695157612b --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/ModuleScopeInitDestroyComponent.java @@ -0,0 +1,37 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.mock.components; + +import org.osoa.sca.annotations.Destroy; + +public class ModuleScopeInitDestroyComponent extends ModuleScopeInitOnlyComponent { + + boolean destroyed = false; + + public boolean isDestroyed() { + return destroyed; + } + + @Destroy + public void destroy() { + if (destroyed){ + throw new AssertionError("Destroy called more than once"); + } + destroyed = true; + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/ModuleScopeInitOnlyComponent.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/ModuleScopeInitOnlyComponent.java new file mode 100644 index 0000000000..4945309852 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/ModuleScopeInitOnlyComponent.java @@ -0,0 +1,41 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.mock.components; + +import org.osoa.sca.annotations.Init; + +public class ModuleScopeInitOnlyComponent extends ModuleScopeComponentImpl { + + boolean initialized = false; + + public boolean isInitialized() { + return initialized; + } + + // this value tests to ensure introspection can find the init() method even + // if a field is named the same. Ultimately, this should be in the introspection tests + private boolean init; + + @Init + public void init() { + if (initialized){ + throw new AssertionError("Init called more than once"); + } + initialized = true; + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/OtherTarget.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/OtherTarget.java new file mode 100644 index 0000000000..2edc8246db --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/OtherTarget.java @@ -0,0 +1,27 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package org.apache.tuscany.container.java.mock.components; + +/** + * Implementations are used in wiring tests + * + * @version $Rev$ $Date$ + */ +public interface OtherTarget { + + public String getString(); + + public void setString(String val); +} + diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/OtherTargetImpl.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/OtherTargetImpl.java new file mode 100644 index 0000000000..08d4d9f720 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/OtherTargetImpl.java @@ -0,0 +1,35 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package org.apache.tuscany.container.java.mock.components; + +/** + * A target used for testing wires with a different source and target interface + * + * @version $Rev$ $Date$ + */ +public class OtherTargetImpl implements OtherTarget{ + + private String theString; + + public String getString() { + return theString; + } + + public void setString(String val) { + theString = val; + } + + +} + diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/RemotableService.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/RemotableService.java new file mode 100644 index 0000000000..645fd7f47c --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/RemotableService.java @@ -0,0 +1,40 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.mock.components; + +import org.osoa.sca.annotations.Remotable; + +/** + * Used for testing basic remoting operations + * + * @version $Rev$ $Date$ + */ + +@Remotable +public interface RemotableService { + + public void syncOneWay(String msg); + + public String syncTwoWay(String msg); + + public DataObject syncTwoWayCustomType(DataObject val); + + public String getString(); + + public void setString(String string); + +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/RemotableServiceImpl.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/RemotableServiceImpl.java new file mode 100644 index 0000000000..34a4273323 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/RemotableServiceImpl.java @@ -0,0 +1,61 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.mock.components; + +import junit.framework.Assert; +import org.osoa.sca.annotations.Property; + + +/** + * @version $Rev$ $Date$ + */ +public class RemotableServiceImpl implements RemotableService { + + // ---------------------------------- + // Properties + // ---------------------------------- + + @Property(name = "string", required = true) + private String mString; + + public String getString() { + return mString; + } + + public void setString(String string) { + mString = string; + } + + // ---------------------------------- + // Methods + // ---------------------------------- + + public void syncOneWay(String msg) { + Assert.assertEquals("hello", msg); + } + + public String syncTwoWay(String msg) { + return "response"; + } + + public DataObject syncTwoWayCustomType(DataObject val) { + Assert.assertEquals("hello", val.getStringValue()); + DataObject dto = new DataObject(); + dto.setStringValue("return"); + return dto; + } +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/RequestScopeComponent.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/RequestScopeComponent.java new file mode 100644 index 0000000000..ac7931bd2c --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/RequestScopeComponent.java @@ -0,0 +1,28 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.mock.components; + +import org.osoa.sca.annotations.Scope; + +/** + * @version $Rev$ $Date$ + */ +@Scope("REQUEST") +public interface RequestScopeComponent extends GenericComponent { + +} + diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/RequestScopeComponentImpl.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/RequestScopeComponentImpl.java new file mode 100644 index 0000000000..5b20519d90 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/RequestScopeComponentImpl.java @@ -0,0 +1,25 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.mock.components; + +/** + * @version $Rev$ $Date$ + */ +public class RequestScopeComponentImpl extends AbstractGenericComponent implements + RequestScopeComponent { + +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/RequestScopeDestroyOnlyComponent.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/RequestScopeDestroyOnlyComponent.java new file mode 100644 index 0000000000..ae63f761c3 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/RequestScopeDestroyOnlyComponent.java @@ -0,0 +1,36 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.mock.components; + +import org.osoa.sca.annotations.Destroy; +import org.osoa.sca.annotations.Scope; + +@Scope("REQUEST") +public class RequestScopeDestroyOnlyComponent extends SessionScopeComponentImpl { + + boolean destroyed = false; + + public boolean isDestroyed() { + return destroyed; + } + + @Destroy + public void destroy() { + destroyed = true; + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/RequestScopeInitDestroyComponent.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/RequestScopeInitDestroyComponent.java new file mode 100644 index 0000000000..67f61df36d --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/RequestScopeInitDestroyComponent.java @@ -0,0 +1,36 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.mock.components; + +import org.osoa.sca.annotations.Destroy; +import org.osoa.sca.annotations.Scope; + +@Scope("REQUEST") +public class RequestScopeInitDestroyComponent extends SessionScopeInitOnlyComponent { + + boolean destroyed = false; + + public boolean isDestroyed() { + return destroyed; + } + + @Destroy + public void destroy() { + destroyed = true; + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/RequestScopeInitOnlyComponent.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/RequestScopeInitOnlyComponent.java new file mode 100644 index 0000000000..c6c621f518 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/RequestScopeInitOnlyComponent.java @@ -0,0 +1,37 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.mock.components; + +import org.osoa.sca.annotations.Init; +import org.osoa.sca.annotations.Scope; + +@Scope("REQUEST") +public class RequestScopeInitOnlyComponent extends SessionScopeComponentImpl { + + boolean initialized = false; + + public boolean isInitialized() { + return initialized; + } + + @Init + public void init() { + initialized = true; + } + + +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/SessionScopeComponent.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/SessionScopeComponent.java new file mode 100644 index 0000000000..236e083a2b --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/SessionScopeComponent.java @@ -0,0 +1,28 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.mock.components; + +import org.osoa.sca.annotations.Scope; + +/** + * @version $Rev$ $Date$ + */ +@Scope("SESSION") +public interface SessionScopeComponent extends GenericComponent { + +} + diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/SessionScopeComponentImpl.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/SessionScopeComponentImpl.java new file mode 100644 index 0000000000..265969a450 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/SessionScopeComponentImpl.java @@ -0,0 +1,28 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.mock.components; + +import org.osoa.sca.annotations.Scope; + +/** + * @version $Rev$ $Date$ + */ +@Scope("SESSION") +public class SessionScopeComponentImpl extends AbstractGenericComponent implements + SessionScopeComponent { + +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/SessionScopeDestroyOnlyComponent.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/SessionScopeDestroyOnlyComponent.java new file mode 100644 index 0000000000..be20a23d29 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/SessionScopeDestroyOnlyComponent.java @@ -0,0 +1,34 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.mock.components; + +import org.osoa.sca.annotations.Destroy; + +public class SessionScopeDestroyOnlyComponent extends SessionScopeComponentImpl { + + boolean destroyed = false; + + public boolean isDestroyed() { + return destroyed; + } + + @Destroy + public void destroy() { + destroyed = true; + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/SessionScopeInitDestroyComponent.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/SessionScopeInitDestroyComponent.java new file mode 100644 index 0000000000..32aa0142a4 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/SessionScopeInitDestroyComponent.java @@ -0,0 +1,34 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.mock.components; + +import org.osoa.sca.annotations.Destroy; + +public class SessionScopeInitDestroyComponent extends SessionScopeInitOnlyComponent { + + boolean destroyed = false; + + public boolean isDestroyed() { + return destroyed; + } + + @Destroy + public void destroy() { + destroyed = true; + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/SessionScopeInitOnlyComponent.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/SessionScopeInitOnlyComponent.java new file mode 100644 index 0000000000..a518a9b244 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/SessionScopeInitOnlyComponent.java @@ -0,0 +1,35 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.mock.components; + +import org.osoa.sca.annotations.Init; + +public class SessionScopeInitOnlyComponent extends SessionScopeComponentImpl { + + boolean initialized = false; + + public boolean isInitialized() { + return initialized; + } + + @Init + public void init() { + initialized = true; + } + + +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/Source.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/Source.java new file mode 100644 index 0000000000..1f918590f2 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/Source.java @@ -0,0 +1,32 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package org.apache.tuscany.container.java.mock.components; + +import java.util.List; + +/** + * Implementations are used in wiring tests + * + * @version $Rev$ $Date$ + */ +public interface Source { + + public Target getTarget(); + + public List<Target> getTargets(); + + public List<Target> getTargetsThroughField(); + +} + diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/SourceImpl.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/SourceImpl.java new file mode 100644 index 0000000000..a2588bae5e --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/SourceImpl.java @@ -0,0 +1,63 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package org.apache.tuscany.container.java.mock.components; + +import java.util.List; + +/** + * Mock system component implementation used in wiring tests + * + * @version $Rev$ $Date$ + */ +public class SourceImpl implements Source { + + private Target target; + + private List<Target> targets; + + private List<Target> targetsThroughField; + + public void setTarget(Target target) { + this.target = target; + } + + public Target getTarget() { + return target; + } + + public List<Target> getTargets() { + return targets; + } + + public void setTargets(List<Target> targets) { + this.targets = targets; + } + + public List<Target> getTargetsThroughField() { + return targetsThroughField; + } + + + private Target[] targetsArray; + + public Target[] getArrayOfTargets() { + return targetsArray; + } + + public void setArrayOfTargets(Target[] targets) { + targetsArray = targets; + } + + +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/StatelessComponent.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/StatelessComponent.java new file mode 100644 index 0000000000..3fe84dd785 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/StatelessComponent.java @@ -0,0 +1,28 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.mock.components; + +import org.osoa.sca.annotations.Scope; + +/** + * @version $Rev$ $Date$ + */ +@Scope("STATELESS") +public interface StatelessComponent extends GenericComponent { + +} + diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/StatelessComponentImpl.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/StatelessComponentImpl.java new file mode 100644 index 0000000000..8b806d6a2e --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/StatelessComponentImpl.java @@ -0,0 +1,25 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.mock.components; + +/** + * @version $Rev$ $Date$ + */ +public class StatelessComponentImpl extends AbstractGenericComponent implements + StatelessComponent { + +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/Target.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/Target.java new file mode 100644 index 0000000000..a56e52c898 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/Target.java @@ -0,0 +1,27 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package org.apache.tuscany.container.java.mock.components; + +/** + * Implementations are used in wiring tests + * + * @version $Rev$ $Date$ + */ +public interface Target { + + public String getString(); + + public void setString(String val); +} + diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/TargetImpl.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/TargetImpl.java new file mode 100644 index 0000000000..5a10bfdbc1 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/TargetImpl.java @@ -0,0 +1,33 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package org.apache.tuscany.container.java.mock.components; + +/** + * Mock system component implementation used in wiring tests + * + * @version $Rev$ $Date$ + */ +public class TargetImpl implements Target { + + private String theString; + + public String getString() { + return theString; + } + + public void setString(String val) { + theString = val; + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/BasicModuleScopeTestCase.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/BasicModuleScopeTestCase.java new file mode 100644 index 0000000000..557f306ad2 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/BasicModuleScopeTestCase.java @@ -0,0 +1,139 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.scopes; + +import java.util.ArrayList; +import java.util.List; + +import junit.framework.Assert; +import junit.framework.TestCase; +import org.apache.tuscany.container.java.builder.JavaContextFactoryBuilder; +import org.apache.tuscany.container.java.mock.MockFactory; +import org.apache.tuscany.container.java.mock.components.ModuleScopeComponentImpl; +import org.apache.tuscany.container.java.mock.components.ModuleScopeInitDestroyComponent; +import org.apache.tuscany.core.builder.BuilderException; +import org.apache.tuscany.core.builder.ContextFactory; +import org.apache.tuscany.core.builder.system.DefaultPolicyBuilderRegistry; +import org.apache.tuscany.core.builder.system.PolicyBuilderRegistry; +import org.apache.tuscany.core.config.ComponentTypeIntrospector; +import org.apache.tuscany.core.config.ConfigurationLoadException; +import org.apache.tuscany.core.context.Context; +import org.apache.tuscany.core.context.EventContext; +import org.apache.tuscany.core.context.event.ModuleStart; +import org.apache.tuscany.core.context.event.ModuleStop; +import org.apache.tuscany.core.context.impl.EventContextImpl; +import org.apache.tuscany.core.context.scope.ModuleScopeContext; +import org.apache.tuscany.core.message.impl.MessageFactoryImpl; +import org.apache.tuscany.core.wire.jdk.JDKWireFactoryFactory; +import org.apache.tuscany.core.wire.service.DefaultWireFactoryService; +import org.apache.tuscany.core.wire.service.WireFactoryService; +import org.apache.tuscany.model.assembly.AtomicComponent; +import org.apache.tuscany.model.assembly.ComponentType; +import org.apache.tuscany.model.assembly.Scope; + +/** + * Unit tests for the module scope container + * + * @version $Rev$ $Date$ + */ +public class BasicModuleScopeTestCase extends TestCase { + + /** + * Tests instance identity is properly maintained + */ + public void testInstanceManagement() throws Exception { + EventContext ctx = new EventContextImpl(); + ModuleScopeContext scope = new ModuleScopeContext(ctx); + scope.registerFactories(createConfigurations()); + scope.start(); + // first request + scope.onEvent(new ModuleStart(this)); + ModuleScopeComponentImpl comp1 = (ModuleScopeComponentImpl) scope.getContext("TestService1").getInstance(null); + Assert.assertNotNull(comp1); + // second request + ModuleScopeComponentImpl comp2 = (ModuleScopeComponentImpl) scope.getContext("TestService1").getInstance(null); + Assert.assertNotNull(comp2); + Assert.assertSame(comp1, comp2); + scope.onEvent(new ModuleStop(this)); + scope.stop(); + } + + public void testSetNullComponents() throws Exception { + EventContext ctx = new EventContextImpl(); + ModuleScopeContext scope = new ModuleScopeContext(ctx); + scope.registerFactories(createConfigurations()); + scope.start(); + scope.onEvent(new ModuleStart(this)); + scope.onEvent(new ModuleStop(this)); + scope.stop(); + } + + public void testRegisterContextBeforeStart() throws Exception { + EventContext ctx = new EventContextImpl(); + ModuleScopeContext scope = new ModuleScopeContext(ctx); + scope.registerFactories(createConfigurations()); + scope.start(); + scope.registerFactory(createConfiguration("NewTestService")); + scope.onEvent(new ModuleStart(this)); + ModuleScopeInitDestroyComponent comp2 = (ModuleScopeInitDestroyComponent) scope.getContext("NewTestService").getInstance(null); + Assert.assertNotNull(comp2); + Assert.assertTrue(comp2.isInitialized()); + scope.onEvent(new ModuleStop(this)); + Assert.assertTrue(comp2.isDestroyed()); + scope.stop(); + } + + public void testRegisterContextAfterStart() throws Exception { + EventContext ctx = new EventContextImpl(); + ModuleScopeContext scope = new ModuleScopeContext(ctx); + scope.start(); + scope.registerFactory(createConfiguration("NewTestService")); + scope.onEvent(new ModuleStart(this)); + scope.registerFactories(createConfigurations()); + ModuleScopeInitDestroyComponent comp2 = (ModuleScopeInitDestroyComponent) scope.getContext("NewTestService").getInstance(null); + Assert.assertNotNull(comp2); + Assert.assertTrue(comp2.isInitialized()); + scope.onEvent(new ModuleStop(this)); + Assert.assertTrue(comp2.isDestroyed()); + scope.stop(); + } + + + private List<ContextFactory<Context>> createConfigurations() throws BuilderException, ConfigurationLoadException { + PolicyBuilderRegistry policyRegistry = new DefaultPolicyBuilderRegistry(); + WireFactoryService wireService = new DefaultWireFactoryService(new MessageFactoryImpl(), new JDKWireFactoryFactory(), policyRegistry); + JavaContextFactoryBuilder builder = new JavaContextFactoryBuilder(wireService); + AtomicComponent component = MockFactory.createComponent("TestService1", ModuleScopeComponentImpl.class, Scope.MODULE); + builder.build(component); + List<ContextFactory<Context>> configs = new ArrayList<ContextFactory<Context>>(); + configs.add((ContextFactory<Context>) component.getContextFactory()); + return configs; + } + + private ContextFactory<Context> createConfiguration(String name) throws BuilderException, ConfigurationLoadException { + PolicyBuilderRegistry policyRegistry = new DefaultPolicyBuilderRegistry(); + WireFactoryService wireService = new DefaultWireFactoryService(new MessageFactoryImpl(), new JDKWireFactoryFactory(), policyRegistry); + JavaContextFactoryBuilder builder = new JavaContextFactoryBuilder(wireService); + AtomicComponent component = MockFactory.createComponent(name, ModuleScopeInitDestroyComponent.class, + Scope.MODULE); + ComponentTypeIntrospector introspector = MockFactory.getIntrospector(); + ComponentType type = introspector.introspect(ModuleScopeInitDestroyComponent.class); + component.getImplementation().setComponentType(type); + builder.build(component); + return (ContextFactory<Context>) component.getContextFactory(); + } +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/BasicRequestScopeTestCase.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/BasicRequestScopeTestCase.java new file mode 100644 index 0000000000..e53b9fc9ac --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/BasicRequestScopeTestCase.java @@ -0,0 +1,158 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.scopes; + +import java.util.ArrayList; +import java.util.List; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.apache.tuscany.container.java.builder.JavaContextFactoryBuilder; +import org.apache.tuscany.container.java.mock.MockFactory; +import org.apache.tuscany.container.java.mock.components.RequestScopeComponent; +import org.apache.tuscany.container.java.mock.components.RequestScopeComponentImpl; +import org.apache.tuscany.core.builder.BuilderException; +import org.apache.tuscany.core.builder.ContextFactory; +import org.apache.tuscany.core.builder.system.DefaultPolicyBuilderRegistry; +import org.apache.tuscany.core.context.EventContext; +import org.apache.tuscany.core.context.Context; +import org.apache.tuscany.core.context.event.RequestEnd; +import org.apache.tuscany.core.context.impl.EventContextImpl; +import org.apache.tuscany.core.context.scope.RequestScopeContext; +import org.apache.tuscany.core.wire.service.WireFactoryService; +import org.apache.tuscany.core.wire.service.DefaultWireFactoryService; +import org.apache.tuscany.core.wire.jdk.JDKWireFactoryFactory; +import org.apache.tuscany.core.message.impl.MessageFactoryImpl; +import org.apache.tuscany.core.config.ConfigurationLoadException; +import org.apache.tuscany.model.assembly.Scope; +import org.apache.tuscany.model.assembly.AtomicComponent; + +/** + * Unit tests for the request scope container + * + * @version $Rev$ $Date$ + */ +public class BasicRequestScopeTestCase extends TestCase { + + /** + * Tests instance identity is properly maintained + */ + public void testInstanceManagement() throws Exception { + EventContext ctx = new EventContextImpl(); + RequestScopeContext scope = new RequestScopeContext(ctx); + scope.registerFactories(createConfigurations()); + scope.start(); + + // first request + RequestScopeComponentImpl comp1 = (RequestScopeComponentImpl) scope.getContext("TestService1").getInstance(null); + Assert.assertNotNull(comp1); + Object id = new Object(); + scope.onEvent(new RequestEnd(this,id)); + + // second request + RequestScopeComponentImpl comp2 = (RequestScopeComponentImpl) scope.getContext("TestService1").getInstance(null); + Assert.assertNotNull(comp2); + Assert.assertNotSame(comp1, comp2); + Object id2 = new Object(); + scope.onEvent(new RequestEnd(this,id2)); + + scope.stop(); + } + + public void testRegisterContextBeforeRequest() throws Exception { + EventContext ctx = new EventContextImpl(); + RequestScopeContext scope = new RequestScopeContext(ctx); + scope.registerFactories(createConfigurations()); + scope.registerFactory(createConfiguration("NewTestService")); + scope.start(); + RequestScopeComponent comp1 = (RequestScopeComponent) scope.getContext("TestService1").getInstance(null); + Assert.assertNotNull(comp1); + RequestScopeComponent comp2 = (RequestScopeComponent) scope.getContext("NewTestService").getInstance(null); + Assert.assertNotNull(comp2); + Object id = new Object(); + scope.onEvent(new RequestEnd(this,id)); + scope.stop(); + } + + public void testRegisterContextAfterRequest() throws Exception { + EventContext ctx = new EventContextImpl(); + RequestScopeContext scope = new RequestScopeContext(ctx); + scope.registerFactories(createConfigurations()); + scope.start(); + RequestScopeComponent comp1 = (RequestScopeComponent) scope.getContext("TestService1").getInstance(null); + Assert.assertNotNull(comp1); + scope.registerFactory(createConfiguration("NewTestService")); + RequestScopeComponent comp2 = (RequestScopeComponent) scope.getContext("NewTestService").getInstance(null); + Assert.assertNotNull(comp2); + Object id = new Object(); + scope.onEvent(new RequestEnd(this,id)); + scope.stop(); + } + + /** + * Tests setting no components in the scope + */ + public void testSetNullComponents() throws Exception { + EventContext ctx = new EventContextImpl(); + RequestScopeContext scope = new RequestScopeContext(ctx); + scope.registerFactories(createConfigurations()); + scope.start(); + scope.stop(); + } + + public void testGetComponentByKey() throws Exception { + EventContext ctx = new EventContextImpl(); + RequestScopeContext scope = new RequestScopeContext(ctx); + scope.registerFactories(createConfigurations()); + scope.start(); + + RequestScopeComponentImpl comp1 = (RequestScopeComponentImpl) scope.getContext("TestService1").getInstance(null); + Assert.assertNotNull(comp1); + Object id = new Object(); + scope.onEvent(new RequestEnd(this,id)); + + // second request + // should be null since the other context (thread) expired w/ onEvent(..) + Assert.assertNull(scope.getContextByKey("TestService1", Thread.currentThread())); + // Note should test better using concurrent threads to pull the instance + + scope.stop(); + } + + + private List<ContextFactory<Context>> createConfigurations() throws BuilderException, ConfigurationLoadException { + AtomicComponent component = MockFactory.createComponent("TestService1", RequestScopeComponentImpl.class, + Scope.REQUEST); + WireFactoryService wireService = new DefaultWireFactoryService(new MessageFactoryImpl(), new JDKWireFactoryFactory(), new DefaultPolicyBuilderRegistry()); + JavaContextFactoryBuilder builder = new JavaContextFactoryBuilder(wireService); + builder.build(component); + List<ContextFactory<Context>> configs = new ArrayList<ContextFactory<Context>>(); + configs.add((ContextFactory<Context>) component.getContextFactory()); + return configs; + } + + private ContextFactory<Context> createConfiguration(String name) throws BuilderException, ConfigurationLoadException { + AtomicComponent component = MockFactory.createComponent(name, RequestScopeComponentImpl.class, + Scope.REQUEST); + WireFactoryService wireService = new DefaultWireFactoryService(new MessageFactoryImpl(), new JDKWireFactoryFactory(), new DefaultPolicyBuilderRegistry()); + JavaContextFactoryBuilder builder = new JavaContextFactoryBuilder(wireService); + builder.build(component); + return (ContextFactory<Context>) component.getContextFactory(); + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/BasicSessionScopeTestCase.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/BasicSessionScopeTestCase.java new file mode 100644 index 0000000000..8bee9a9741 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/BasicSessionScopeTestCase.java @@ -0,0 +1,238 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.scopes; + +import java.util.ArrayList; +import java.util.List; + +import junit.framework.Assert; +import junit.framework.TestCase; +import org.apache.tuscany.container.java.builder.JavaContextFactoryBuilder; +import org.apache.tuscany.container.java.mock.MockFactory; +import org.apache.tuscany.container.java.mock.components.SessionScopeComponent; +import org.apache.tuscany.container.java.mock.components.SessionScopeComponentImpl; +import org.apache.tuscany.container.java.mock.components.SessionScopeInitDestroyComponent; +import org.apache.tuscany.core.builder.BuilderException; +import org.apache.tuscany.core.builder.ContextFactory; +import org.apache.tuscany.core.builder.system.DefaultPolicyBuilderRegistry; +import org.apache.tuscany.core.config.ComponentTypeIntrospector; +import org.apache.tuscany.core.config.ConfigurationLoadException; +import org.apache.tuscany.core.context.Context; +import org.apache.tuscany.core.context.EventContext; +import org.apache.tuscany.core.context.event.HttpSessionEnd; +import org.apache.tuscany.core.context.event.HttpSessionEvent; +import org.apache.tuscany.core.context.event.RequestEnd; +import org.apache.tuscany.core.context.impl.EventContextImpl; +import org.apache.tuscany.core.context.scope.SessionScopeContext; +import org.apache.tuscany.core.message.impl.MessageFactoryImpl; +import org.apache.tuscany.core.wire.jdk.JDKWireFactoryFactory; +import org.apache.tuscany.core.wire.service.DefaultWireFactoryService; +import org.apache.tuscany.core.wire.service.WireFactoryService; +import org.apache.tuscany.model.assembly.AtomicComponent; +import org.apache.tuscany.model.assembly.ComponentType; +import org.apache.tuscany.model.assembly.Scope; + +/** + * Unit tests for the Http session scope container + * + * @version $Rev$ $Date$ + */ +public class BasicSessionScopeTestCase extends TestCase { + + /** + * Tests instance identity is properly maintained + */ + public void testInstanceManagement() throws Exception { + EventContext ctx = new EventContextImpl(); + SessionScopeContext scope = new SessionScopeContext(ctx); + scope.registerFactories(createConfigurations()); + scope.start(); + Object session = new Object(); + Object session2 = new Object(); + // first request + ctx.setIdentifier(HttpSessionEvent.HTTP_IDENTIFIER, session); + SessionScopeComponent comp1 = (SessionScopeComponent) scope.getContext("TestService1").getInstance(null); + Assert.assertNotNull(comp1); + ctx.clearIdentifier(HttpSessionEvent.HTTP_IDENTIFIER); + + // second request + ctx.setIdentifier(HttpSessionEvent.HTTP_IDENTIFIER, session); + SessionScopeComponent comp2 = (SessionScopeComponent) scope.getContext("TestService1").getInstance(null); + Assert.assertNotNull(comp2); + Assert.assertSame(comp1, comp2); + ctx.clearIdentifier(HttpSessionEvent.HTTP_IDENTIFIER); + + // third request, different session + ctx.setIdentifier(HttpSessionEvent.HTTP_IDENTIFIER, session2); + SessionScopeComponent comp3 = (SessionScopeComponent) scope.getContext("TestService1").getInstance(null); + Assert.assertNotNull(comp3); + Assert.assertNotSame(comp1, comp3); // should be different instances + ctx.clearIdentifier(HttpSessionEvent.HTTP_IDENTIFIER); + + scope.onEvent(new HttpSessionEnd(this, session)); + scope.onEvent(new HttpSessionEnd(this, session2)); + scope.stop(); + } + + /** + * Tests setting no components in the scope + */ + public void testSetNullComponents() throws Exception { + EventContext ctx = new EventContextImpl(); + SessionScopeContext scope = new SessionScopeContext(ctx); + scope.registerFactories(new ArrayList<ContextFactory<Context>>()); + scope.start(); + scope.stop(); + } + + public void testGetContextByKey() throws Exception { + EventContext ctx = new EventContextImpl(); + SessionScopeContext scope = new SessionScopeContext(ctx); + scope.registerFactories(createConfigurations()); + scope.start(); + Object session = new Object(); + Object session2 = new Object(); + + // first request + ctx.setIdentifier(HttpSessionEvent.HTTP_IDENTIFIER, session); + SessionScopeComponent comp1 = (SessionScopeComponent) scope.getContext("TestService1").getInstance(null); + Assert.assertNotNull(comp1); + ctx.clearIdentifier(HttpSessionEvent.HTTP_IDENTIFIER); + + // second request, different session + ctx.setIdentifier(HttpSessionEvent.HTTP_IDENTIFIER, session2); + SessionScopeComponent comp2 = (SessionScopeComponent) scope.getContextByKey("TestService1", session) + .getInstance(null); + SessionScopeComponent comp3 = (SessionScopeComponent) scope.getContextByKey("TestService1", session) + .getInstance(null); + Assert.assertNotNull(comp2); + Object id = new Object(); + scope.onEvent(new RequestEnd(this, id)); + Assert.assertSame(comp1, comp2); // should be same instances + Assert.assertSame(comp2, comp3); // should not be same instances + ctx.clearIdentifier(HttpSessionEvent.HTTP_IDENTIFIER); + + // shutdown sessions + scope.onEvent(new HttpSessionEnd(this, session)); + scope.onEvent(new HttpSessionEnd(this, session2)); + + scope.stop(); + } + + public void testRegisterContextBeforeSession() throws Exception { + EventContext ctx = new EventContextImpl(); + SessionScopeContext scope = new SessionScopeContext(ctx); + scope.registerFactories(createConfigurations()); + scope.start(); + Object session = new Object(); + scope.registerFactory(createConfiguration("NewTestService")); + + // first request + ctx.setIdentifier(HttpSessionEvent.HTTP_IDENTIFIER, session); + + SessionScopeInitDestroyComponent comp2 = (SessionScopeInitDestroyComponent) scope.getContext("NewTestService") + .getInstance(null); + Assert.assertNotNull(comp2); + Assert.assertTrue(comp2.isInitialized()); + ctx.clearIdentifier(HttpSessionEvent.HTTP_IDENTIFIER); + + // second request different session + Object session2 = new Object(); + ctx.setIdentifier(HttpSessionEvent.HTTP_IDENTIFIER, session2); + SessionScopeInitDestroyComponent comp3 = (SessionScopeInitDestroyComponent) scope.getContext("NewTestService") + .getInstance(null); + Assert.assertNotNull(comp3); + Assert.assertNotSame(comp2, comp3); + Assert.assertTrue(comp3.isInitialized()); + ctx.clearIdentifier(HttpSessionEvent.HTTP_IDENTIFIER); + + scope.onEvent(new HttpSessionEnd(this, session)); + Assert.assertTrue(comp2.isDestroyed()); + + scope.onEvent(new HttpSessionEnd(this, session2)); + Assert.assertTrue(comp3.isDestroyed()); + scope.stop(); + } + + /** + * Tests runtime context registration + */ + public void testRegisterContextAfterSession() throws Exception { + EventContext ctx = new EventContextImpl(); + SessionScopeContext scope = new SessionScopeContext(ctx); + scope.registerFactories(createConfigurations()); + scope.start(); + Object session = new Object(); + + // first request + ctx.setIdentifier(HttpSessionEvent.HTTP_IDENTIFIER, session); + SessionScopeComponent comp1 = (SessionScopeComponent) scope.getContext("TestService1").getInstance(null); + Assert.assertNotNull(comp1); + ctx.clearIdentifier(HttpSessionEvent.HTTP_IDENTIFIER); + + scope.registerFactory(createConfiguration("NewTestService")); + + // second request + ctx.setIdentifier(HttpSessionEvent.HTTP_IDENTIFIER, session); + SessionScopeInitDestroyComponent comp2 = (SessionScopeInitDestroyComponent) scope.getContext("NewTestService") + .getInstance(null); + Assert.assertNotNull(comp2); + Assert.assertTrue(comp2.isInitialized()); + ctx.clearIdentifier(HttpSessionEvent.HTTP_IDENTIFIER); + + // third request different session + Object session2 = new Object(); + ctx.setIdentifier(HttpSessionEvent.HTTP_IDENTIFIER, session2); + SessionScopeInitDestroyComponent comp3 = (SessionScopeInitDestroyComponent) scope.getContext("NewTestService") + .getInstance(null); + Assert.assertNotNull(comp3); + Assert.assertNotSame(comp2, comp3); + Assert.assertTrue(comp3.isInitialized()); + ctx.clearIdentifier(HttpSessionEvent.HTTP_IDENTIFIER); + + scope.onEvent(new HttpSessionEnd(this, session)); + Assert.assertTrue(comp2.isDestroyed()); + + scope.onEvent(new HttpSessionEnd(this, session2)); + Assert.assertTrue(comp3.isDestroyed()); + scope.stop(); + } + + private List<ContextFactory<Context>> createConfigurations() throws BuilderException, ConfigurationLoadException { + WireFactoryService wireService = new DefaultWireFactoryService(new MessageFactoryImpl(), new JDKWireFactoryFactory(), new DefaultPolicyBuilderRegistry()); + JavaContextFactoryBuilder builder = new JavaContextFactoryBuilder(wireService); + AtomicComponent component = MockFactory.createComponent("TestService1", SessionScopeComponentImpl.class, Scope.SESSION); + ComponentTypeIntrospector introspector = MockFactory.getIntrospector(); + ComponentType type = introspector.introspect(SessionScopeComponentImpl.class); + component.getImplementation().setComponentType(type); + builder.build(component); + List<ContextFactory<Context>> configs = new ArrayList<ContextFactory<Context>>(); + configs.add((ContextFactory<Context>) component.getContextFactory()); + return configs; + } + + private ContextFactory<Context> createConfiguration(String name) throws BuilderException, ConfigurationLoadException { + WireFactoryService wireService = new DefaultWireFactoryService(new MessageFactoryImpl(), new JDKWireFactoryFactory(), new DefaultPolicyBuilderRegistry()); + JavaContextFactoryBuilder builder = new JavaContextFactoryBuilder(wireService); + AtomicComponent component = MockFactory.createComponent(name, SessionScopeInitDestroyComponent.class, Scope.SESSION); + ComponentTypeIntrospector introspector = MockFactory.getIntrospector(); + ComponentType type = introspector.introspect(SessionScopeInitDestroyComponent.class); + component.getImplementation().setComponentType(type); + builder.build(component); + return (ContextFactory<Context>) component.getContextFactory(); + } +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/BasicStatelessScopeTestCase.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/BasicStatelessScopeTestCase.java new file mode 100644 index 0000000000..3765c8bf27 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/BasicStatelessScopeTestCase.java @@ -0,0 +1,129 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.scopes; + +import java.util.ArrayList; +import java.util.List; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.apache.tuscany.container.java.builder.JavaContextFactoryBuilder; +import org.apache.tuscany.container.java.mock.MockFactory; +import org.apache.tuscany.container.java.mock.components.StatelessComponent; +import org.apache.tuscany.container.java.mock.components.StatelessComponentImpl; +import org.apache.tuscany.core.builder.BuilderException; +import org.apache.tuscany.core.builder.ContextFactory; +import org.apache.tuscany.core.builder.system.DefaultPolicyBuilderRegistry; +import org.apache.tuscany.core.context.EventContext; +import org.apache.tuscany.core.context.Context; +import org.apache.tuscany.core.context.impl.EventContextImpl; +import org.apache.tuscany.core.context.scope.StatelessScopeContext; +import org.apache.tuscany.core.wire.service.WireFactoryService; +import org.apache.tuscany.core.wire.service.DefaultWireFactoryService; +import org.apache.tuscany.core.wire.jdk.JDKWireFactoryFactory; +import org.apache.tuscany.core.message.impl.MessageFactoryImpl; +import org.apache.tuscany.core.config.ConfigurationLoadException; +import org.apache.tuscany.model.assembly.Scope; +import org.apache.tuscany.model.assembly.AtomicComponent; + +/** + * Unit tests for the module scope container + * + * @version $Rev$ $Date$ + */ +public class BasicStatelessScopeTestCase extends TestCase { + + /** + * Tests instance identity is properly maintained + */ + public void testInstanceManagement() throws Exception { + EventContext ctx = new EventContextImpl(); + StatelessScopeContext scope = new StatelessScopeContext(ctx); + scope.registerFactories(createConfigurations()); + scope.start(); + // first request + StatelessComponentImpl comp1 = (StatelessComponentImpl) scope.getContext("TestService1").getInstance(null); + Assert.assertNotNull(comp1); + // second request + StatelessComponentImpl comp2 = (StatelessComponentImpl) scope.getContext("TestService1").getInstance(null); + Assert.assertNotNull(comp2); + Assert.assertNotSame(comp1, comp2); + scope.stop(); + } + + public void testRegisterContextBeforeRequest() throws Exception { + EventContext ctx = new EventContextImpl(); + StatelessScopeContext scope = new StatelessScopeContext(ctx); + scope.registerFactories(createConfigurations()); + scope.registerFactory(createConfiguration("NewTestService")); + scope.start(); + StatelessComponent comp1 = (StatelessComponent) scope.getContext("TestService1").getInstance(null); + Assert.assertNotNull(comp1); + StatelessComponent comp2 = (StatelessComponent) scope.getContext("NewTestService").getInstance(null); + Assert.assertNotNull(comp2); + scope.stop(); + } + + public void testRegisterContextAfterRequest() throws Exception { + EventContext ctx = new EventContextImpl(); + StatelessScopeContext scope = new StatelessScopeContext(ctx); + scope.registerFactories(createConfigurations()); + scope.start(); + StatelessComponent comp1 = (StatelessComponent) scope.getContext("TestService1").getInstance(null); + Assert.assertNotNull(comp1); + scope.registerFactory(createConfiguration("NewTestService")); + StatelessComponent comp2 = (StatelessComponent) scope.getContext("NewTestService").getInstance(null); + Assert.assertNotNull(comp2); + scope.stop(); + } + + + /** + * Tests setting no components in the scope + */ + public void testSetNullComponents() throws Exception { + EventContext ctx = new EventContextImpl(); + StatelessScopeContext scope = new StatelessScopeContext(ctx); + scope.registerFactories(createConfigurations()); + scope.start(); + scope.stop(); + } + + private List<ContextFactory<Context>> createConfigurations() + throws NoSuchMethodException, BuilderException, ConfigurationLoadException { + AtomicComponent component = MockFactory.createComponent("TestService1", StatelessComponentImpl.class, + Scope.INSTANCE); + WireFactoryService wireService = new DefaultWireFactoryService(new MessageFactoryImpl(), new JDKWireFactoryFactory(), new DefaultPolicyBuilderRegistry()); + JavaContextFactoryBuilder builder = new JavaContextFactoryBuilder(wireService); + builder.build(component); + List<ContextFactory<Context>> configs = new ArrayList(); + configs.add((ContextFactory<Context>) component.getContextFactory()); + return configs; + } + + private ContextFactory<Context> createConfiguration(String name) + throws NoSuchMethodException, BuilderException, ConfigurationLoadException { + AtomicComponent component = MockFactory.createComponent(name, StatelessComponentImpl.class, + Scope.INSTANCE); + WireFactoryService wireService = new DefaultWireFactoryService(new MessageFactoryImpl(), new JDKWireFactoryFactory(),new DefaultPolicyBuilderRegistry()); + JavaContextFactoryBuilder builder = new JavaContextFactoryBuilder(wireService); + builder.build(component); + return (ContextFactory<Context>) component.getContextFactory(); + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/CompositeScopeTestCase.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/CompositeScopeTestCase.java new file mode 100644 index 0000000000..d5b5a29e9c --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/CompositeScopeTestCase.java @@ -0,0 +1,188 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" + * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ +package org.apache.tuscany.container.java.scopes; + +import java.util.ArrayList; +import java.util.List; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.apache.tuscany.container.java.builder.JavaContextFactoryBuilder; +import org.apache.tuscany.container.java.mock.MockFactory; +import org.apache.tuscany.container.java.mock.components.GenericComponent; +import org.apache.tuscany.container.java.mock.components.ModuleScopeComponentImpl; +import org.apache.tuscany.container.java.mock.components.SessionScopeComponentImpl; +import org.apache.tuscany.core.builder.BuilderException; +import org.apache.tuscany.core.builder.system.DefaultPolicyBuilderRegistry; +import org.apache.tuscany.core.context.CompositeContext; +import org.apache.tuscany.core.context.EventContext; +import org.apache.tuscany.core.context.event.ModuleStart; +import org.apache.tuscany.core.context.event.RequestStart; +import org.apache.tuscany.core.context.event.HttpSessionBound; +import org.apache.tuscany.core.context.event.RequestEnd; +import org.apache.tuscany.core.context.event.HttpSessionEnd; +import org.apache.tuscany.core.context.event.ModuleStop; +import org.apache.tuscany.core.context.impl.CompositeContextImpl; +import org.apache.tuscany.core.context.impl.EventContextImpl; +import org.apache.tuscany.core.context.scope.CompositeScopeContext; +import org.apache.tuscany.core.wire.service.WireFactoryService; +import org.apache.tuscany.core.wire.service.DefaultWireFactoryService; +import org.apache.tuscany.core.wire.jdk.JDKWireFactoryFactory; +import org.apache.tuscany.core.message.impl.MessageFactoryImpl; +import org.apache.tuscany.core.config.ConfigurationLoadException; +import org.apache.tuscany.model.assembly.Extensible; +import org.apache.tuscany.model.assembly.Scope; +import org.apache.tuscany.model.assembly.AtomicComponent; + +/** + * Tests component nesting. This test needs to be in the container.java progject since it relies on Java POJOs for scope + * testing. + * + * @version $Rev$ $Date$ + */ +public class CompositeScopeTestCase extends TestCase { + + /** + * Ensures scope events are propagated in an composite scope + */ + public void testCompositeScopePropagation() throws Exception { + EventContext ctx = new EventContextImpl(); + CompositeContext moduleComponentCtx = new CompositeContextImpl(); + moduleComponentCtx.setName("testMC"); + moduleComponentCtx.start(); + CompositeScopeContext scopeContainer = new CompositeScopeContext(ctx); + scopeContainer.registerFactory(MockFactory.createCompositeConfiguration("CompositeComponent")); + scopeContainer.start(); + CompositeContext child = (CompositeContext) scopeContainer.getContext("CompositeComponent"); + List<Extensible> models = createAssembly(); + for (Extensible model : models) { + child.registerModelObject(model); + } + + scopeContainer.onEvent(new ModuleStart(this)); + Object session = new Object(); + Object id = new Object(); + //ctx.setIdentifier(EventContext.SESSION,session); + scopeContainer.onEvent(new RequestStart(this,id)); + scopeContainer.onEvent(new HttpSessionBound(this,session)); + CompositeContext componentCtx = (CompositeContext) scopeContainer.getContext("CompositeComponent"); + GenericComponent testService1 = (GenericComponent) componentCtx.getContext("TestService1").getInstance(null); + GenericComponent testService2 = (GenericComponent) componentCtx.getContext("TestService2").getInstance(null); + GenericComponent testService3 = (GenericComponent) componentCtx.getContext("TestService3").getInstance(null); + Assert.assertNotNull(testService1); + Assert.assertNotNull(testService2); + Assert.assertNotNull(testService3); + scopeContainer.onEvent(new RequestEnd(this,id)); + scopeContainer.onEvent(new RequestStart(this,id)); + scopeContainer.onEvent(new HttpSessionBound(this,session)); + + GenericComponent testService2a = (GenericComponent) componentCtx.getContext("TestService2").getInstance(null); + Assert.assertNotNull(testService2a); + GenericComponent testService3a = (GenericComponent) componentCtx.getContext("TestService3").getInstance(null); + Assert.assertNotNull(testService3a); + Assert.assertEquals(testService2, testService2a); + Assert.assertNotSame(testService3, testService3a); + scopeContainer.onEvent(new RequestEnd(this,id)); + scopeContainer.onEvent(new HttpSessionEnd(this,session)); + + Object session2 = new Object(); + Object id2 = new Object(); + scopeContainer.onEvent(new RequestStart(this,id2)); + scopeContainer.onEvent(new HttpSessionBound(this,session2)); + GenericComponent testService2b = (GenericComponent) componentCtx.getContext("TestService2").getInstance(null); + Assert.assertNotNull(testService2b); + Assert.assertNotSame(testService2, testService2b); + + scopeContainer.onEvent(new RequestEnd(this,id2)); + scopeContainer.onEvent(new HttpSessionEnd(this,session2)); + + } + + /** + * Ensures only child entry points (and not components) are accessible from parents + */ + public void testCompositeNoEntryPoint() throws Exception { + EventContext ctx = new EventContextImpl(); + CompositeContext moduleComponentCtx = new CompositeContextImpl(); + moduleComponentCtx.setName("testMC"); + CompositeScopeContext scopeContainer = new CompositeScopeContext(ctx); + scopeContainer.registerFactory(MockFactory.createCompositeConfiguration("CompositeComponent")); + scopeContainer.start(); + CompositeContext child = (CompositeContext) scopeContainer.getContext("CompositeComponent"); + List<Extensible> parts = createAssembly(); + for (Extensible part : parts) { + child.registerModelObject(part); + } + scopeContainer.onEvent(new ModuleStart(this)); + scopeContainer.getContext("CompositeComponent"); + } + + /** + * Tests adding a context before its parent has been started + */ + public void testRegisterContextBeforeStart() throws Exception { + EventContext ctx = new EventContextImpl(); + CompositeContext moduleComponentCtx = new CompositeContextImpl(); + moduleComponentCtx.setName("testMC"); + CompositeScopeContext scopeContainer = new CompositeScopeContext(ctx); + scopeContainer.registerFactory(MockFactory.createCompositeConfiguration("CompositeComponent")); + scopeContainer.start(); + scopeContainer.onEvent(new ModuleStart(this)); + scopeContainer.getContext("CompositeComponent"); + scopeContainer.onEvent(new ModuleStop(this)); + scopeContainer.stop(); + } + + /** + * Tests adding a context after its parent has been started + */ + public void testRegisterContextAfterStart() throws Exception { + EventContext ctx = new EventContextImpl(); + CompositeContext moduleComponentCtx = new CompositeContextImpl(); + moduleComponentCtx.setName("testMC"); + CompositeScopeContext scopeContainer = new CompositeScopeContext(ctx); + scopeContainer.start(); + + scopeContainer.onEvent(new ModuleStart(this)); + scopeContainer.registerFactory(MockFactory.createCompositeConfiguration("CompositeComponent")); + scopeContainer.getContext("CompositeComponent"); + scopeContainer.onEvent(new ModuleStop(this)); + scopeContainer.stop(); + } + + /** + * Creats an assembly containing a module-scoped component definition, a session-scoped component definition, and a + * request-scoped component definition + * + */ + private List<Extensible> createAssembly() throws BuilderException, ConfigurationLoadException { + WireFactoryService wireService = new DefaultWireFactoryService(new MessageFactoryImpl(), new JDKWireFactoryFactory(), new DefaultPolicyBuilderRegistry()); + JavaContextFactoryBuilder builder = new JavaContextFactoryBuilder(wireService); + AtomicComponent component = MockFactory.createComponent("TestService1", ModuleScopeComponentImpl.class, Scope.MODULE); + AtomicComponent sessionComponent = MockFactory.createComponent("TestService2", SessionScopeComponentImpl.class, + Scope.SESSION); + AtomicComponent requestComponent = MockFactory.createComponent("TestService3", SessionScopeComponentImpl.class, + Scope.REQUEST); + builder.build(component); + builder.build(sessionComponent); + builder.build(requestComponent); + List<Extensible> configs = new ArrayList<Extensible>(); + configs.add(component); + configs.add(sessionComponent); + configs.add(requestComponent); + return configs; + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/DependencyLifecycleTestCase.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/DependencyLifecycleTestCase.java new file mode 100644 index 0000000000..dc3fe3efcb --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/DependencyLifecycleTestCase.java @@ -0,0 +1,93 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.scopes; + +import junit.framework.TestCase; +import org.apache.tuscany.container.java.mock.MockContextFactory; +import org.apache.tuscany.core.context.EventContext; +import org.apache.tuscany.core.context.event.ModuleStart; +import org.apache.tuscany.core.context.event.ModuleStop; +import org.apache.tuscany.core.context.event.HttpSessionBound; +import org.apache.tuscany.core.context.event.HttpSessionEvent; +import org.apache.tuscany.core.context.event.HttpSessionEnd; +import org.apache.tuscany.core.context.event.RequestStart; +import org.apache.tuscany.core.context.event.RequestEnd; +import org.apache.tuscany.core.context.impl.EventContextImpl; +import org.apache.tuscany.core.context.scope.ModuleScopeContext; +import org.apache.tuscany.core.context.scope.SessionScopeContext; +import org.apache.tuscany.core.context.scope.RequestScopeContext; +import org.apache.tuscany.model.assembly.Scope; + +/** + * Tests that dependencies are initalized and destroyed in the proper order (i.e. LIFO) + * + * @version $Rev: 393992 $ $Date: 2006-04-13 18:01:05 -0700 (Thu, 13 Apr 2006) $ + */ +public class DependencyLifecycleTestCase extends TestCase { + + + + public void testInitDestroyOrderModuleScope() throws Exception { + EventContext ctx = new EventContextImpl(); + ModuleScopeContext scope = new ModuleScopeContext(ctx); + scope.registerFactories(MockContextFactory.createWiredContexts(Scope.MODULE,scope)); + scope.start(); + scope.onEvent(new ModuleStart(this)); + OrderedDependentPojo source = (OrderedDependentPojo) scope.getContext("source").getInstance(null); + assertNotNull(source.getPojo()); + // expire module + assertEquals(2,source.getNumberInstantiated()); + scope.onEvent(new ModuleStop(this)); + assertEquals(0,source.getNumberInstantiated()); + scope.stop(); + } + + public void testInitDestroyOrderSessionScope() throws Exception { + EventContext ctx = new EventContextImpl(); + SessionScopeContext scope = new SessionScopeContext(ctx); + scope.registerFactories(MockContextFactory.createWiredContexts(Scope.SESSION,scope)); + scope.start(); + Object session = new Object(); + ctx.setIdentifier(HttpSessionEvent.HTTP_IDENTIFIER,session); + scope.onEvent(new HttpSessionBound(this,session)); + OrderedDependentPojo source = (OrderedDependentPojo) scope.getContext("source").getInstance(null); + assertNotNull(source.getPojo()); + // expire module + assertEquals(2,source.getNumberInstantiated()); + scope.onEvent(new HttpSessionEnd(this,session)); + assertEquals(0,source.getNumberInstantiated()); + scope.stop(); + } + + + public void testInitDestroyOrderRequestScope() throws Exception { + EventContext ctx = new EventContextImpl(); + RequestScopeContext scope = new RequestScopeContext(ctx); + scope.registerFactories(MockContextFactory.createWiredContexts(Scope.REQUEST,scope)); + scope.start(); + Object request = new Object(); + scope.onEvent(new RequestStart(this,request)); + OrderedDependentPojo source = (OrderedDependentPojo) scope.getContext("source").getInstance(null); + assertNotNull(source.getPojo()); + // expire module + assertEquals(2,source.getNumberInstantiated()); + scope.onEvent(new RequestEnd(this,request)); + assertEquals(0,source.getNumberInstantiated()); + scope.stop(); + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/ModuleScopeLifecycleTestCase.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/ModuleScopeLifecycleTestCase.java new file mode 100644 index 0000000000..904e218c08 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/ModuleScopeLifecycleTestCase.java @@ -0,0 +1,248 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.scopes; + +import java.util.ArrayList; +import java.util.List; + +import junit.framework.Assert; +import junit.framework.TestCase; +import org.apache.tuscany.container.java.builder.JavaContextFactoryBuilder; +import org.apache.tuscany.container.java.mock.MockFactory; +import org.apache.tuscany.container.java.mock.components.ModuleScopeDestroyOnlyComponent; +import org.apache.tuscany.container.java.mock.components.ModuleScopeEagerInitComponent; +import org.apache.tuscany.container.java.mock.components.ModuleScopeEagerInitDestroyComponent; +import org.apache.tuscany.container.java.mock.components.ModuleScopeInitDestroyComponent; +import org.apache.tuscany.container.java.mock.components.ModuleScopeInitOnlyComponent; +import org.apache.tuscany.core.builder.BuilderException; +import org.apache.tuscany.core.builder.ContextFactory; +import org.apache.tuscany.core.builder.system.DefaultPolicyBuilderRegistry; +import org.apache.tuscany.core.config.ComponentTypeIntrospector; +import org.apache.tuscany.core.config.ConfigurationLoadException; +import org.apache.tuscany.core.context.Context; +import org.apache.tuscany.core.context.EventContext; +import org.apache.tuscany.core.context.event.ModuleStart; +import org.apache.tuscany.core.context.event.ModuleStop; +import org.apache.tuscany.core.context.impl.EventContextImpl; +import org.apache.tuscany.core.context.scope.ModuleScopeContext; +import org.apache.tuscany.core.message.impl.MessageFactoryImpl; +import org.apache.tuscany.core.wire.jdk.JDKWireFactoryFactory; +import org.apache.tuscany.core.wire.service.DefaultWireFactoryService; +import org.apache.tuscany.core.wire.service.WireFactoryService; +import org.apache.tuscany.model.assembly.AtomicComponent; +import org.apache.tuscany.model.assembly.ComponentType; +import org.apache.tuscany.model.assembly.Scope; + +/** + * Lifecycle unit tests for the module scope container + * + * @version $Rev$ $Date$ + */ +public class ModuleScopeLifecycleTestCase extends TestCase { + + JavaContextFactoryBuilder builder; + + public void testInitDestroy() throws Exception { + EventContext ctx = new EventContextImpl(); + ModuleScopeContext scope = new ModuleScopeContext(ctx); + scope.registerFactories(createComponents()); + scope.start(); + scope.onEvent(new ModuleStart(this)); + ModuleScopeInitDestroyComponent initDestroy = (ModuleScopeInitDestroyComponent) scope.getContext( + "TestServiceInitDestroy").getInstance(null); + Assert.assertNotNull(initDestroy); + ModuleScopeInitOnlyComponent initOnly = (ModuleScopeInitOnlyComponent) scope.getContext("TestServiceInitOnly") + .getInstance(null); + Assert.assertNotNull(initOnly); + ModuleScopeDestroyOnlyComponent destroyOnly = (ModuleScopeDestroyOnlyComponent) scope.getContext( + "TestServiceDestroyOnly").getInstance(null); + Assert.assertNotNull(destroyOnly); + + Assert.assertTrue(initDestroy.isInitialized()); + Assert.assertTrue(initOnly.isInitialized()); + Assert.assertFalse(initDestroy.isDestroyed()); + Assert.assertFalse(destroyOnly.isDestroyed()); + + // expire module + scope.onEvent(new ModuleStop(this)); + + Assert.assertTrue(initDestroy.isDestroyed()); + Assert.assertTrue(destroyOnly.isDestroyed()); + + scope.stop(); + } + + public void testEagerInit() throws Exception { + EventContext ctx = new EventContextImpl(); + ModuleScopeContext scope = new ModuleScopeContext(ctx); + scope.registerFactories(createEagerInitComponents()); + scope.start(); + scope.onEvent(new ModuleStart(this)); + ModuleScopeEagerInitDestroyComponent initDestroy = (ModuleScopeEagerInitDestroyComponent) scope.getContext( + "TestServiceEagerInitDestroy").getInstance(null); + Assert.assertNotNull(initDestroy); + ModuleScopeEagerInitComponent initOnly = (ModuleScopeEagerInitComponent) scope + .getContext("TestServiceEagerInit").getInstance(null); + Assert.assertNotNull(initOnly); + + Assert.assertTrue(initDestroy.isInitialized()); + Assert.assertTrue(initOnly.isInitialized()); + Assert.assertFalse(initDestroy.isDestroyed()); + + // expire module + scope.onEvent(new ModuleStop(this)); + + Assert.assertTrue(initDestroy.isDestroyed()); + + scope.stop(); + + } + + public void testDestroyOrder() throws Exception { + EventContext ctx = new EventContextImpl(); + ModuleScopeContext scope = new ModuleScopeContext(ctx); + scope.registerFactories(createOrderedInitComponents()); + scope.start(); + scope.onEvent(new ModuleStart(this)); + OrderedInitPojo one = (OrderedInitPojo) scope.getContext("one").getInstance(null); + Assert.assertNotNull(one); + Assert.assertEquals(1, one.getNumberInstantiated()); + Assert.assertEquals(1, one.getInitOrder()); + + OrderedInitPojo two = (OrderedInitPojo) scope.getContext("two").getInstance(null); + Assert.assertNotNull(two); + Assert.assertEquals(2, two.getNumberInstantiated()); + Assert.assertEquals(2, two.getInitOrder()); + + OrderedInitPojo three = (OrderedInitPojo) scope.getContext("three").getInstance(null); + Assert.assertNotNull(three); + Assert.assertEquals(3, three.getNumberInstantiated()); + Assert.assertEquals(3, three.getInitOrder()); + + // expire module + scope.onEvent(new ModuleStop(this)); + Assert.assertEquals(0, one.getNumberInstantiated()); + scope.stop(); + } + + public void testEagerInitDestroyOrder() throws Exception { + EventContext ctx = new EventContextImpl(); + ModuleScopeContext scope = new ModuleScopeContext(ctx); + scope.registerFactories(createOrderedEagerInitComponents()); + scope.start(); + scope.onEvent(new ModuleStart(this)); + OrderedEagerInitPojo one = (OrderedEagerInitPojo) scope.getContext("one").getInstance(null); + Assert.assertNotNull(one); + + OrderedEagerInitPojo two = (OrderedEagerInitPojo) scope.getContext("two").getInstance(null); + Assert.assertNotNull(two); + + OrderedEagerInitPojo three = (OrderedEagerInitPojo) scope.getContext("three").getInstance(null); + Assert.assertNotNull(three); + + // expire module + scope.onEvent(new ModuleStop(this)); + Assert.assertEquals(0, one.getNumberInstantiated()); + scope.stop(); + } + + + private List<ContextFactory<Context>> createComponents() throws BuilderException, ConfigurationLoadException { + AtomicComponent[] ca = new AtomicComponent[3]; + ca[0] = MockFactory.createComponent("TestServiceInitDestroy", ModuleScopeInitDestroyComponent.class, + Scope.MODULE); + ca[1] = MockFactory.createComponent("TestServiceInitOnly", ModuleScopeInitOnlyComponent.class, + Scope.MODULE); + ca[2] = MockFactory.createComponent("TestServiceDestroyOnly", ModuleScopeDestroyOnlyComponent.class, + Scope.MODULE); + List<ContextFactory<Context>> configs = new ArrayList<ContextFactory<Context>>(); + ComponentTypeIntrospector introspector = MockFactory.getIntrospector(); + ca[0].getImplementation().setComponentType(introspector.introspect(ModuleScopeInitDestroyComponent.class)); + ca[1].getImplementation().setComponentType(introspector.introspect(ModuleScopeInitOnlyComponent.class)); + ca[2].getImplementation().setComponentType(introspector.introspect(ModuleScopeDestroyOnlyComponent.class)); + for (AtomicComponent aCa : ca) { + builder.build(aCa); + configs.add((ContextFactory<Context>) aCa.getContextFactory()); + + } + return configs; + } + + private List<ContextFactory<Context>> createEagerInitComponents() throws + BuilderException, ConfigurationLoadException { + AtomicComponent[] ca = new AtomicComponent[2]; + ca[0] = MockFactory.createComponent("TestServiceEagerInitDestroy", ModuleScopeEagerInitDestroyComponent.class, + Scope.MODULE); + ca[1] = MockFactory.createComponent("TestServiceEagerInit", ModuleScopeEagerInitComponent.class, + Scope.MODULE); + List<ContextFactory<Context>> configs = new ArrayList<ContextFactory<Context>>(); + ComponentTypeIntrospector introspector = MockFactory.getIntrospector(); + ComponentType type = introspector.introspect(OrderedInitPojo.class); + ca[0].getImplementation().setComponentType(introspector.introspect(ModuleScopeEagerInitDestroyComponent.class)); + ca[1].getImplementation().setComponentType(introspector.introspect(ModuleScopeEagerInitComponent.class)); + for (AtomicComponent aCa : ca) { + builder.build(aCa); + configs.add((ContextFactory<Context>) aCa.getContextFactory()); + } + return configs; + } + + private List<ContextFactory<Context>> createOrderedInitComponents() throws + BuilderException, ConfigurationLoadException { + AtomicComponent[] ca = new AtomicComponent[3]; + ca[0] = MockFactory.createComponent("one", OrderedInitPojo.class, Scope.MODULE); + ca[1] = MockFactory.createComponent("two", OrderedInitPojo.class, Scope.MODULE); + ca[2] = MockFactory.createComponent("three", OrderedInitPojo.class, Scope.MODULE); + List<ContextFactory<Context>> configs = new ArrayList<ContextFactory<Context>>(); + ComponentTypeIntrospector introspector = MockFactory.getIntrospector(); + ComponentType type = introspector.introspect(OrderedInitPojo.class); + ca[0].getImplementation().setComponentType(type); + ca[1].getImplementation().setComponentType(type); + ca[2].getImplementation().setComponentType(type); + for (AtomicComponent aCa : ca) { + builder.build(aCa); + configs.add((ContextFactory<Context>) aCa.getContextFactory()); + } + return configs; + } + + private List<ContextFactory<Context>> createOrderedEagerInitComponents() throws + BuilderException, ConfigurationLoadException { + AtomicComponent[] ca = new AtomicComponent[3]; + ca[0] = MockFactory.createComponent("one", OrderedEagerInitPojo.class, Scope.MODULE); + ca[1] = MockFactory.createComponent("two", OrderedEagerInitPojo.class, Scope.MODULE); + ca[2] = MockFactory.createComponent("three", OrderedEagerInitPojo.class, Scope.MODULE); + ComponentTypeIntrospector introspector = MockFactory.getIntrospector(); + ComponentType type = introspector.introspect(OrderedEagerInitPojo.class); + ca[0].getImplementation().setComponentType(type); + ca[1].getImplementation().setComponentType(type); + ca[2].getImplementation().setComponentType(type); + List<ContextFactory<Context>> configs = new ArrayList<ContextFactory<Context>>(); + for (AtomicComponent aCa : ca) { + builder.build(aCa); + configs.add((ContextFactory<Context>) aCa.getContextFactory()); + + } + return configs; + } + + protected void setUp() throws Exception { + super.setUp(); + WireFactoryService wireService = new DefaultWireFactoryService(new MessageFactoryImpl(), new JDKWireFactoryFactory(), new DefaultPolicyBuilderRegistry()); + builder = new JavaContextFactoryBuilder(wireService); + } +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/OrderException.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/OrderException.java new file mode 100644 index 0000000000..fc5f7c8c58 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/OrderException.java @@ -0,0 +1,38 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.scopes; + +public class OrderException extends Exception { + + public OrderException() { + super(); + } + + public OrderException(String message) { + super(message); + } + + public OrderException(String message, Throwable cause) { + super(message, cause); + } + + public OrderException(Throwable cause) { + super(cause); + } + +} + diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/OrderedDependentPojo.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/OrderedDependentPojo.java new file mode 100644 index 0000000000..f8fe2af7be --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/OrderedDependentPojo.java @@ -0,0 +1,34 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.scopes; + +/** + * @version $$Rev$$ $$Date$$ + */ +public class OrderedDependentPojo extends OrderedInitPojo { + + private OrderedDependentPojo pojo; + + public OrderedDependentPojo getPojo() { + return pojo; + } + + public void setPojo(OrderedDependentPojo pojo) { + this.pojo = pojo; + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/OrderedEagerInitPojo.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/OrderedEagerInitPojo.java new file mode 100644 index 0000000000..f9aeefccbe --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/OrderedEagerInitPojo.java @@ -0,0 +1,56 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.scopes; + +import org.osoa.sca.annotations.Destroy; +import org.osoa.sca.annotations.Init; +import org.osoa.sca.annotations.Scope; + +@Scope("MODULE") +public class OrderedEagerInitPojo { + + private static Object lock = new Object(); + private static int numberInstantied; + private int initOrder; + + @Init(eager = true) + public void init() { + synchronized (lock) { + ++numberInstantied; + initOrder = numberInstantied; + } + } + + @Destroy + public void destroy() throws OrderException { + synchronized (lock) { + if (initOrder != numberInstantied) { + throw new OrderException("Instance shutdown done out of order"); + } + --numberInstantied; + } + } + + public int getNumberInstantiated() { + return numberInstantied; + } + + public int getInitOrder() { + return initOrder; + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/OrderedInitPojo.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/OrderedInitPojo.java new file mode 100644 index 0000000000..b4d4eb03ba --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/OrderedInitPojo.java @@ -0,0 +1,56 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.scopes; + +import org.osoa.sca.annotations.Destroy; +import org.osoa.sca.annotations.Init; +import org.osoa.sca.annotations.Scope; + +@Scope("MODULE") +public class OrderedInitPojo { + + private static Object lock = new Object(); + private static int numberInstantied; + private int initOrder; + + @Init + public void init() { + synchronized (lock) { + ++numberInstantied; + initOrder = numberInstantied; + } + } + + @Destroy + public void destroy() throws OrderException { + synchronized (lock) { + if (initOrder != numberInstantied) { + throw new OrderException("Instance shutdown done out of order"); + } + --numberInstantied; + } + } + + public int getNumberInstantiated() { + return numberInstantied; + } + + public int getInitOrder() { + return initOrder; + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/RequestScopeLifecycleTestCase.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/RequestScopeLifecycleTestCase.java new file mode 100644 index 0000000000..bca1e57cbc --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/RequestScopeLifecycleTestCase.java @@ -0,0 +1,166 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.scopes; + +import java.util.ArrayList; +import java.util.List; + +import junit.framework.Assert; +import junit.framework.TestCase; +import org.apache.tuscany.container.java.builder.JavaContextFactoryBuilder; +import org.apache.tuscany.container.java.mock.MockFactory; +import org.apache.tuscany.container.java.mock.components.RequestScopeDestroyOnlyComponent; +import org.apache.tuscany.container.java.mock.components.RequestScopeInitDestroyComponent; +import org.apache.tuscany.container.java.mock.components.RequestScopeInitOnlyComponent; +import org.apache.tuscany.core.builder.BuilderException; +import org.apache.tuscany.core.builder.ContextFactory; +import org.apache.tuscany.core.builder.system.DefaultPolicyBuilderRegistry; +import org.apache.tuscany.core.config.ComponentTypeIntrospector; +import org.apache.tuscany.core.config.ConfigurationLoadException; +import org.apache.tuscany.core.context.Context; +import org.apache.tuscany.core.context.EventContext; +import org.apache.tuscany.core.context.event.RequestEnd; +import org.apache.tuscany.core.context.impl.EventContextImpl; +import org.apache.tuscany.core.context.scope.RequestScopeContext; +import org.apache.tuscany.core.message.impl.MessageFactoryImpl; +import org.apache.tuscany.core.wire.jdk.JDKWireFactoryFactory; +import org.apache.tuscany.core.wire.service.DefaultWireFactoryService; +import org.apache.tuscany.core.wire.service.WireFactoryService; +import org.apache.tuscany.model.assembly.AtomicComponent; +import org.apache.tuscany.model.assembly.ComponentType; +import org.apache.tuscany.model.assembly.Scope; + +/** + * Lifecycle unit tests for the Http session scope container + * + * @version $Rev$ $Date$ + */ +public class RequestScopeLifecycleTestCase extends TestCase { + + /** + * Tests instance identity is properly maintained + */ + public void testInitDestroy() throws Exception { + EventContext ctx = new EventContextImpl(); + RequestScopeContext scope = new RequestScopeContext(ctx); + scope.registerFactories(createComponents()); + scope.start(); + RequestScopeInitDestroyComponent initDestroy = (RequestScopeInitDestroyComponent) scope.getContext( + "TestServiceInitDestroy").getInstance(null); + Assert.assertNotNull(initDestroy); + RequestScopeInitOnlyComponent initOnly = (RequestScopeInitOnlyComponent) scope.getContext("TestServiceInitOnly") + .getInstance(null); + Assert.assertNotNull(initOnly); + RequestScopeDestroyOnlyComponent destroyOnly = (RequestScopeDestroyOnlyComponent) scope.getContext( + "TestServiceDestroyOnly").getInstance(null); + Assert.assertNotNull(destroyOnly); + + Assert.assertTrue(initDestroy.isInitialized()); + Assert.assertTrue(initOnly.isInitialized()); + Assert.assertFalse(initDestroy.isDestroyed()); + Assert.assertFalse(destroyOnly.isDestroyed()); + + // end request + scope.onEvent(new RequestEnd(this, new Object())); + Assert.assertTrue(initDestroy.isDestroyed()); + Assert.assertTrue(destroyOnly.isDestroyed()); + + scope.stop(); + } + + /** + * Test instances destroyed in proper (i.e. reverse) order + */ + public void testDestroyOrder() throws Exception { + EventContext ctx = new EventContextImpl(); + RequestScopeContext scope = new RequestScopeContext(ctx); + scope.registerFactories(createOrderedInitComponents()); + scope.start(); + // request start + RequestScopedOrderedInitPojo one = (RequestScopedOrderedInitPojo) scope.getContext("one").getInstance(null); + Assert.assertNotNull(one); + Assert.assertEquals(1, one.getNumberInstantiated()); + Assert.assertEquals(1, one.getInitOrder()); + + RequestScopedOrderedInitPojo two = (RequestScopedOrderedInitPojo) scope.getContext("two").getInstance(null); + Assert.assertNotNull(two); + Assert.assertEquals(2, two.getNumberInstantiated()); + Assert.assertEquals(2, two.getInitOrder()); + + RequestScopedOrderedInitPojo three = (RequestScopedOrderedInitPojo) scope.getContext("three").getInstance(null); + Assert.assertNotNull(three); + Assert.assertEquals(3, three.getNumberInstantiated()); + Assert.assertEquals(3, three.getInitOrder()); + + // end request + scope.onEvent(new RequestEnd(this, new Object())); + + Assert.assertEquals(0, one.getNumberInstantiated()); + scope.stop(); + } + + + JavaContextFactoryBuilder builder; + + private List<ContextFactory<Context>> createComponents() throws BuilderException, ConfigurationLoadException { + AtomicComponent[] ca = new AtomicComponent[3]; + ca[0] = MockFactory.createComponent("TestServiceInitDestroy", RequestScopeInitDestroyComponent.class, + Scope.REQUEST); + ca[1] = MockFactory.createComponent("TestServiceInitOnly", RequestScopeInitOnlyComponent.class, + Scope.REQUEST); + ca[2] = MockFactory.createComponent("TestServiceDestroyOnly", RequestScopeDestroyOnlyComponent.class, + Scope.REQUEST); + ComponentTypeIntrospector introspector = MockFactory.getIntrospector(); + ca[0].getImplementation().setComponentType(introspector.introspect(RequestScopeInitDestroyComponent.class)); + ca[1].getImplementation().setComponentType(introspector.introspect(RequestScopeInitOnlyComponent.class)); + ca[2].getImplementation().setComponentType(introspector.introspect(RequestScopeDestroyOnlyComponent.class)); + List<ContextFactory<Context>> configs = new ArrayList<ContextFactory<Context>>(); + for (AtomicComponent aCa : ca) { + builder.build(aCa); + configs.add((ContextFactory<Context>) aCa.getContextFactory()); + + } + return configs; + } + + private List<ContextFactory<Context>> createOrderedInitComponents() throws + BuilderException, ConfigurationLoadException { + AtomicComponent[] ca = new AtomicComponent[3]; + ca[0] = MockFactory.createComponent("one", RequestScopedOrderedInitPojo.class, Scope.REQUEST); + ca[1] = MockFactory.createComponent("two", RequestScopedOrderedInitPojo.class, Scope.REQUEST); + ca[2] = MockFactory.createComponent("three", RequestScopedOrderedInitPojo.class, Scope.REQUEST); + ComponentTypeIntrospector introspector = MockFactory.getIntrospector(); + ComponentType type = introspector.introspect(RequestScopedOrderedInitPojo.class); + ca[0].getImplementation().setComponentType(type); + ca[1].getImplementation().setComponentType(type); + ca[2].getImplementation().setComponentType(type); + List<ContextFactory<Context>> configs = new ArrayList<ContextFactory<Context>>(); + for (AtomicComponent aCa : ca) { + builder.build(aCa); + configs.add((ContextFactory<Context>) aCa.getContextFactory()); + + } + return configs; + } + + protected void setUp() throws Exception { + super.setUp(); + WireFactoryService wireService = new DefaultWireFactoryService(new MessageFactoryImpl(), new JDKWireFactoryFactory(), new DefaultPolicyBuilderRegistry()); + builder = new JavaContextFactoryBuilder(wireService); + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/RequestScopedOrderedInitPojo.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/RequestScopedOrderedInitPojo.java new file mode 100644 index 0000000000..717c7008c9 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/RequestScopedOrderedInitPojo.java @@ -0,0 +1,56 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.scopes; + +import org.osoa.sca.annotations.Scope; +import org.osoa.sca.annotations.Init; +import org.osoa.sca.annotations.Destroy; + +@Scope("REQUEST") +public class RequestScopedOrderedInitPojo { + + private static Object lock = new Object(); + private static int numberInstantied; + private int initOrder; + + @Init + public void init() { + synchronized (RequestScopedOrderedInitPojo.lock) { + ++RequestScopedOrderedInitPojo.numberInstantied; + initOrder = RequestScopedOrderedInitPojo.numberInstantied; + } + } + + @Destroy + public void destroy() throws OrderException { + synchronized (RequestScopedOrderedInitPojo.lock) { + if (initOrder != RequestScopedOrderedInitPojo.numberInstantied) { + throw new OrderException("Instance shutdown done out of order"); + } + --RequestScopedOrderedInitPojo.numberInstantied; + } + } + + public int getNumberInstantiated() { + return RequestScopedOrderedInitPojo.numberInstantied; + } + + public int getInitOrder() { + return initOrder; + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/SessionScopeLifecycleTestCase.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/SessionScopeLifecycleTestCase.java new file mode 100644 index 0000000000..80d8cb71cb --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/SessionScopeLifecycleTestCase.java @@ -0,0 +1,176 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.scopes; + +import java.util.ArrayList; +import java.util.List; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.apache.tuscany.container.java.builder.JavaContextFactoryBuilder; +import org.apache.tuscany.container.java.mock.MockFactory; +import org.apache.tuscany.container.java.mock.components.SessionScopeDestroyOnlyComponent; +import org.apache.tuscany.container.java.mock.components.SessionScopeInitDestroyComponent; +import org.apache.tuscany.container.java.mock.components.SessionScopeInitOnlyComponent; +import org.apache.tuscany.core.builder.BuilderException; +import org.apache.tuscany.core.builder.ContextFactory; +import org.apache.tuscany.core.builder.system.DefaultPolicyBuilderRegistry; +import org.apache.tuscany.core.context.EventContext; +import org.apache.tuscany.core.context.Context; +import org.apache.tuscany.core.context.event.HttpSessionEnd; +import org.apache.tuscany.core.context.event.HttpSessionEvent; +import org.apache.tuscany.core.context.impl.EventContextImpl; +import org.apache.tuscany.core.context.scope.SessionScopeContext; +import org.apache.tuscany.core.wire.service.WireFactoryService; +import org.apache.tuscany.core.wire.service.DefaultWireFactoryService; +import org.apache.tuscany.core.wire.jdk.JDKWireFactoryFactory; +import org.apache.tuscany.core.message.impl.MessageFactoryImpl; +import org.apache.tuscany.core.config.ComponentTypeIntrospector; +import org.apache.tuscany.core.config.ConfigurationLoadException; +import org.apache.tuscany.model.assembly.Scope; +import org.apache.tuscany.model.assembly.AtomicComponent; +import org.apache.tuscany.model.assembly.ComponentType; + +/** + * Lifecycle unit tests for the Http session scope container + * + * @version $Rev$ $Date$ + */ +public class SessionScopeLifecycleTestCase extends TestCase { + + /** + * Tests instance identity is properly maintained + */ + public void testInitDestroy() throws Exception { + EventContext ctx = new EventContextImpl(); + SessionScopeContext scope = new SessionScopeContext(ctx); + scope.registerFactories(createComponents()); + scope.start(); + Object session = new Object(); + // first request, no need to notify scope container since sessions are + // evaluated lazily + ctx.setIdentifier(HttpSessionEvent.HTTP_IDENTIFIER,session); + SessionScopeInitDestroyComponent initDestroy = (SessionScopeInitDestroyComponent) scope.getContext( + "TestServiceInitDestroy").getInstance(null); + Assert.assertNotNull(initDestroy); + SessionScopeInitOnlyComponent initOnly = (SessionScopeInitOnlyComponent) scope.getContext("TestServiceInitOnly") + .getInstance(null); + Assert.assertNotNull(initOnly); + SessionScopeDestroyOnlyComponent destroyOnly = (SessionScopeDestroyOnlyComponent) scope.getContext( + "TestServiceDestroyOnly").getInstance(null); + Assert.assertNotNull(destroyOnly); + + Assert.assertTrue(initDestroy.isInitialized()); + Assert.assertTrue(initOnly.isInitialized()); + Assert.assertFalse(initDestroy.isDestroyed()); + Assert.assertFalse(destroyOnly.isDestroyed()); + // end request + ctx.clearIdentifier(HttpSessionEvent.HTTP_IDENTIFIER); + // expire session + scope.onEvent(new HttpSessionEnd(this,session)); + Assert.assertTrue(initDestroy.isDestroyed()); + Assert.assertTrue(destroyOnly.isDestroyed()); + + scope.stop(); + } + + /** + * Test instances destroyed in proper (i.e. reverse) order + */ + public void testDestroyOrder() throws Exception { + EventContext ctx = new EventContextImpl(); + SessionScopeContext scope = new SessionScopeContext(ctx); + scope.registerFactories(createOrderedInitComponents()); + scope.start(); + Object session = new Object(); + // request start + ctx.setIdentifier(HttpSessionEvent.HTTP_IDENTIFIER,session); + + SessionScopedOrderedInitPojo one = (SessionScopedOrderedInitPojo) scope.getContext("one").getInstance(null); + Assert.assertNotNull(one); + Assert.assertEquals(1, one.getNumberInstantiated()); + Assert.assertEquals(1, one.getInitOrder()); + + SessionScopedOrderedInitPojo two = (SessionScopedOrderedInitPojo) scope.getContext("two").getInstance(null); + Assert.assertNotNull(two); + Assert.assertEquals(2, two.getNumberInstantiated()); + Assert.assertEquals(2, two.getInitOrder()); + + SessionScopedOrderedInitPojo three = (SessionScopedOrderedInitPojo) scope.getContext("three").getInstance(null); + Assert.assertNotNull(three); + Assert.assertEquals(3, three.getNumberInstantiated()); + Assert.assertEquals(3, three.getInitOrder()); + + // end request + ctx.clearIdentifier(HttpSessionEvent.HTTP_IDENTIFIER); + + // expire session + scope.onEvent(new HttpSessionEnd(this, session)); + Assert.assertEquals(0, one.getNumberInstantiated()); + scope.stop(); + } + + JavaContextFactoryBuilder builder; + + private List<ContextFactory<Context>> createComponents() throws BuilderException, ConfigurationLoadException { + AtomicComponent[] ca = new AtomicComponent[3]; + ca[0] = MockFactory.createComponent("TestServiceInitDestroy", SessionScopeInitDestroyComponent.class, + Scope.SESSION); + ca[1] = MockFactory.createComponent("TestServiceInitOnly", SessionScopeInitOnlyComponent.class, Scope.SESSION); + ca[2] = MockFactory.createComponent("TestServiceDestroyOnly", SessionScopeDestroyOnlyComponent.class, + Scope.SESSION); + ComponentTypeIntrospector introspector = MockFactory.getIntrospector(); + ca[0].getImplementation().setComponentType(introspector.introspect(SessionScopeInitDestroyComponent.class)); + ca[1].getImplementation().setComponentType(introspector.introspect(SessionScopeInitOnlyComponent.class)); + ca[2].getImplementation().setComponentType(introspector.introspect(SessionScopeDestroyOnlyComponent.class)); + List<ContextFactory<Context>> configs = new ArrayList<ContextFactory<Context>>(); + for (AtomicComponent aCa : ca) { + builder.build(aCa); + configs.add((ContextFactory<Context>) aCa.getContextFactory()); + + } + return configs; + } + + private List<ContextFactory<Context>> createOrderedInitComponents() throws + BuilderException, ConfigurationLoadException { + AtomicComponent[] ca = new AtomicComponent[3]; + ca[0] = MockFactory.createComponent("one", SessionScopedOrderedInitPojo.class, Scope.SESSION); + ca[1] = MockFactory.createComponent("two", SessionScopedOrderedInitPojo.class, Scope.SESSION); + ca[2] = MockFactory.createComponent("three", SessionScopedOrderedInitPojo.class, Scope.SESSION); + ComponentTypeIntrospector introspector = MockFactory.getIntrospector(); + ComponentType type = introspector.introspect(SessionScopedOrderedInitPojo.class); + ca[0].getImplementation().setComponentType(type); + ca[1].getImplementation().setComponentType(type); + ca[2].getImplementation().setComponentType(type); + List<ContextFactory<Context>> configs = new ArrayList<ContextFactory<Context>>(); + for (AtomicComponent aCa : ca) { + builder.build(aCa); + configs.add((ContextFactory<Context>) aCa.getContextFactory()); + + } + return configs; + } + + protected void setUp() throws Exception { + super.setUp(); + WireFactoryService wireService = new DefaultWireFactoryService(new MessageFactoryImpl(), new JDKWireFactoryFactory(),new DefaultPolicyBuilderRegistry()); + builder = new JavaContextFactoryBuilder(wireService); + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/SessionScopedOrderedInitPojo.java b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/SessionScopedOrderedInitPojo.java new file mode 100644 index 0000000000..683247a5c8 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/SessionScopedOrderedInitPojo.java @@ -0,0 +1,56 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.scopes; + +import org.osoa.sca.annotations.Scope; +import org.osoa.sca.annotations.Init; +import org.osoa.sca.annotations.Destroy; + +@Scope("SESSION") +public class SessionScopedOrderedInitPojo { + + private static Object lock = new Object(); + private static int numberInstantied; + private int initOrder; + + @Init + public void init() { + synchronized (SessionScopedOrderedInitPojo.lock) { + ++SessionScopedOrderedInitPojo.numberInstantied; + initOrder = SessionScopedOrderedInitPojo.numberInstantied; + } + } + + @Destroy + public void destroy() throws OrderException { + synchronized (SessionScopedOrderedInitPojo.lock) { + if (initOrder != SessionScopedOrderedInitPojo.numberInstantied) { + throw new OrderException("Instance shutdown done out of order"); + } + --SessionScopedOrderedInitPojo.numberInstantied; + } + } + + public int getNumberInstantiated() { + return SessionScopedOrderedInitPojo.numberInstantied; + } + + public int getInitOrder() { + return initOrder; + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/resources/helloworld/example.wsdl b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/resources/helloworld/example.wsdl new file mode 100644 index 0000000000..3a23e7b717 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/resources/helloworld/example.wsdl @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Copyright (c) 2005 The Apache Software Foundation or its licensors, as applicable. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + --> +<wsdl:definitions targetNamespace="http://www.example.org" + xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" + name="example"> + + <wsdl:portType name="HelloWorld"> + </wsdl:portType> +</wsdl:definitions> diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/resources/helloworld/sca.module b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/resources/helloworld/sca.module new file mode 100644 index 0000000000..d5bc2cd5f9 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/resources/helloworld/sca.module @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Copyright (c) 2005 The Apache Software Foundation or its licensors, as applicable. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + --> +<module xmlns="http://www.osoa.org/xmlns/sca/0.9" xmlns:v="http://www.osoa.org/xmlns/sca/values/0.9" + name="Helloworld"> + + <component name="HelloWorld"> + <implementation.java class="org.apache.tuscany.container.java.integration.HelloWorldImpl"/> + </component> + +<!-- + <import.wsdl wsdlLocation="example.wsdl"/> + + <externalService name="external"> + <interface.wsdl interface="http://www.example.org#wsdl.interface(HelloWorld)"/> + </externalService> +--> + +</module> diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/resources/helloworldmc/sca.module b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/resources/helloworldmc/sca.module new file mode 100644 index 0000000000..8c590976de --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/resources/helloworldmc/sca.module @@ -0,0 +1,40 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Copyright (c) 2005 The Apache Software Foundation or its licensors, as applicable. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + --> +<module xmlns="http://www.osoa.org/xmlns/sca/0.9" xmlns:v="http://www.osoa.org/xmlns/sca/values/0.9" + name="HelloworldMC"> + + <component name="HelloWorld"> + <implementation.java class="org.apache.tuscany.container.java.integration.HelloWorldMCImpl"/> + <references> + <!-- <v:greetingProvider>GreetingProvider</v:greetingProvider>--> + </references> + <properties> + <v:bar>bar</v:bar> + <v:locale>en</v:locale> + </properties> + </component> + <wire> + <source.uri>HelloWorld/greetingProvider</source.uri> + <target.uri>GreetingProvider</target.uri> + </wire> + <component name="GreetingProvider"> + <implementation.java class="org.apache.tuscany.container.java.integration.GreetingProviderImpl"/> + <properties> + <v:greeting>Hello </v:greeting> + </properties> + </component> +</module> diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/resources/org/apache/tuscany/container/java/assembly/tests/sca.module b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/resources/org/apache/tuscany/container/java/assembly/tests/sca.module new file mode 100644 index 0000000000..d0f0856225 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/resources/org/apache/tuscany/container/java/assembly/tests/sca.module @@ -0,0 +1,54 @@ +<?xml version="1.0" encoding="ASCII"?>
+<!--
+ Copyright (c) 2005 The Apache Software Foundation or its licensors, as applicable.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ -->
+<module xmlns="http://www.osoa.org/xmlns/sca/0.9" xmlns:v="http://www.osoa.org/xmlns/sca/values/0.9"
+
+ name="tuscany.container.java.assembly.tests.bigbank.account">
+
+ <entryPoint name="AccountService">
+ <interface.java interface="org.apache.tuscany.container.java.assembly.tests.bigbank.account.services.account.AccountService"/>
+ <binding.ws port="http://www.bigbank.com/AccountService#wsdl.endpoint(AccountService/AccountServiceSOAP)"/>
+ <reference>AccountServiceComponent</reference>
+ </entryPoint>
+
+ <component name="AccountServiceComponent">
+ <implementation.java class="org.apache.tuscany.container.java.assembly.tests.bigbank.account.services.account.AccountServiceImpl"/>
+ <properties>
+ <v:currency overridable="may">EURO</v:currency>
+ </properties>
+ <references>
+ <v:accountDataService>AccountDataServiceComponent</v:accountDataService>
+ <v:stockQuoteService>StockQuoteService</v:stockQuoteService>
+ </references>
+ </component>
+
+ <component name="AccountDataServiceComponent">
+ <implementation.java class="org.apache.tuscany.container.java.assembly.tests.bigbank.account.services.accountdata.AccountDataServiceImpl"/>
+ </component>
+
+ <component name="StockQuoteService">
+ <implementation.java class="org.apache.tuscany.container.java.assembly.tests.bigbank.account.services.stockquote.StockQuoteServiceImpl"/>
+ </component>
+
+ <!--
+ <externalService name="StockQuoteService">
+ <interface.java interface="org.apache.tuscany.container.java.assembly.tests.bigbank.account.services.stockquote"/>
+ <binding.ws port="http://www.quickstockquote.com/StockQuoteService#wsdl.endpoint(StockQuote/StockQuoteServiceSOAP)"/>
+ </externalService>
+ -->
+
+</module>
+
diff --git a/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/resources/org/apache/tuscany/container/java/config/ModuleComponentLoaderTest1.module b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/resources/org/apache/tuscany/container/java/config/ModuleComponentLoaderTest1.module new file mode 100644 index 0000000000..46169aa304 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060522/java/sca/containers/container.java/src/test/resources/org/apache/tuscany/container/java/config/ModuleComponentLoaderTest1.module @@ -0,0 +1,24 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright (c) 2005 The Apache Software Foundation or its licensors, as applicable.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ -->
+<module xmlns="http://www.osoa.org/xmlns/sca/0.9"
+ xmlns:v="http://www.osoa.org/xmlns/sca/values/0.9"
+ name="ModuleComponentLoaderTest1">
+
+ <component name="HelloWorldServiceComponent">
+ <implementation.java class="org.apache.tuscany.container.java.assembly.mock.HelloWorldImpl"/>
+ </component>
+</module>
|