summaryrefslogtreecommitdiffstats
path: root/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java')
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/binding/local/AbstractLocalTargetInvokerTestCase.java72
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/binding/local/LocalBindingBuilderTestCase.java40
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/binding/local/LocalBindingLoaderTestCase.java70
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/binding/local/LocalCallbackTargetInvokerInvocationExceptionTestCase.java84
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/binding/local/LocalCallbackTargetInvokerTestCase.java83
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/binding/local/LocalCallbackTargetInvokerThrowableTestCase.java89
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/binding/local/LocalTargetInvokerTestCase.java115
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/bootstrap/BootstrapperTestCase.java42
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/builder/AtomicConnectorTestCase.java201
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/builder/BuilderRegistryNoBindingsTestCase.java89
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/builder/BuilderRegistryTestCase.java190
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/builder/ConnectorImplTestCase.java320
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/builder/IllegalCallbackExceptionTestCase.java40
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/builder/IncompatibleInterfacesExceptionTestCase.java38
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/builder/InvalidSourceTypeExceptionTestCase.java39
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/builder/InvalidTargetTypeExceptionTestCase.java39
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/builder/ReferenceConnectorTestCase.java156
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/builder/ServiceConnectorTestCase.java152
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/builder/TargetServiceNotFoundExceptionTestCase.java38
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/builder/WirePostProcessorRegistryImplTestCase.java48
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/builder/WiringExceptionFormatterTestCase.java70
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/ComponentContextImplTestCase.java91
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/ComponentManagerImplTestCase.java90
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/JavaObjectRegistrationTestCase.java76
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/SystemSingletonAtomicComponentTestCase.java82
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/WorkContextImplTestCase.java65
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/event/EventTestCase.java69
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/AbstractScopeContainerTestCase.java126
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/BasicCompositeScopeTestCase.java134
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/BasicConversationalScopeTestCase.java136
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/BasicHttpSessionScopeTestCase.java152
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/BasicRequestScopeTestCase.java135
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/BasicStatelessScopeTestCase.java127
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/CompositeScopeInitDestroyErrorTestCase.java79
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/CompositeScopeInstanceLifecycleTestCase.java186
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/CompositeScopeObjectFactoryTestCase.java38
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/CompositeScopeRestartTestCase.java100
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeContainerDestroyOnExpirationTestCase.java121
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeContainerMaxAgeTestCase.java75
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeContainerMaxIdleTimeTestCase.java78
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeContainerPersistenceTestCase.java182
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeInstanceLifecycleTestCase.java70
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeRestartTestCase.java113
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/DependencyLifecycleTestCase.java170
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/HttpSessionScopeInitDestroyErrorTestCase.java68
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/HttpSessionScopeInstanceLifecycleTestCase.java136
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/HttpSessionScopeRestartTestCase.java106
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/InstanceWrapperBaseTestClass.java64
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/InstanceWrapperTestCase.java66
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/MockFactory.java125
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/RequestScopeInitDestroyErrorTestCase.java62
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/RequestScopeInstanceLifecycleTestCase.java129
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/RequestScopeRestartTestCase.java100
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/ScopeRegistryTestCase.java80
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/StatelessScopeContainerTestCase.java48
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/StatelessScopeObjectFactoryTestCase.java37
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/WorkContextTestCase.java212
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingInterceptorTestCase.java126
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingJavaInterfaceProcessorTestCase.java79
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingLoaderTestCase.java79
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingRegistryImplTestCase.java87
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingTestCase.java49
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingWirePostProcessorOptimizationTestCase.java89
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingWirePostProcessorTestCase.java94
-rwxr-xr-xsca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/impl/DirectedGraphTestCase.java89
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/impl/IDLTransformerTestCase.java220
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/impl/MediatorImplTestCase.java118
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/impl/PassByValueInterceptorTestCase.java69
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/impl/PassByValueWirePostProcessorTestCase.java174
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/impl/TransformerRegistryImplTestCase.java106
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/javabeans/DOMNode2JavaBeanTransformerTestCase.java178
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/javabeans/JavaBean2DOMNodeTransformerTestCase.java126
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/xml/DOM2StAXTestCase.java76
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/xml/DataPipeTestCase.java89
-rwxr-xr-xsca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/xml/Node2StringTestCase.java35
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/xml/PushTransformationTestCase.java81
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/xml/StAXHelperTestCase.java47
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/xml/TraxTransformerTestCase.java99
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/deployer/BootstrapDeployerTestCase.java170
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/idl/java/ConversationalIntrospectionTestCase.java80
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/idl/java/JavaInterfaceProcessorRegistryImplTestCase.java100
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/IntrospectionRegistryTestCase.java123
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/PhysicalComponentTestCase.java80
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/PojoAtomicComponentTestCase.java193
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeBuilderTestCase.java199
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeComponentImplTestCase.java79
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeLoaderTestCase.java201
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeLoaderWireResolutionTestCase.java230
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/composite/DuplicateRegistrationTestCase.java120
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/composite/ImplementationCompositeLoaderTestCase.java194
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/composite/ManagedRequestContextTestCase.java42
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/composite/ReferenceImplTestCase.java55
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/composite/ServiceImplTestCase.java56
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/composite/SystemComponentBuilderTestCase.java182
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaAtomicComponentMetadataInjectionTestCase.java37
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaAtomicComponentNegativeMetadataTestCase.java49
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaBuilderPropertyTestCase.java139
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderConversationIDTestCase.java81
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderMetadataTestCase.java132
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderReferenceTestCase.java145
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderResourceTestCase.java81
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentTypeLoaderTestCase.java75
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaReferenceWireTestCase.java155
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerBasicInvocationTestCase.java188
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerMediationTestCase.java61
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerNonBlockingInvocationTestCase.java225
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerSequenceTestCase.java117
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerStatelessDestroyTestCase.java54
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerTestCase.java53
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/java/MultiplicityTestCase.java34
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/java/ResourceInjectionTestCase.java111
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/java/integration/CallbackInvocationTestCase.java347
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/java/integration/WireToScopedJavaTestCase.java212
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/AllowsPassByReferenceProcessorTestCase.java59
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorProcessorExtensibilityTestCase.java82
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorProcessorTestCase.java167
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorPropertyTestCase.java169
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorReferenceTestCase.java176
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorResourceTestCase.java166
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/ContextProcessorTestCase.java196
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConversationProcessorTestCase.java152
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConvertTimeMillisTestCase.java110
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/DestroyProcessorTestCase.java100
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/EagerInitProcessorTestCase.java60
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicAndPropertyTestCase.java70
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicConstructorTestCase.java297
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicPojoProcessorTestCase.java396
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeutisticExtensibleConstructorTestCase.java129
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/ImplementationProcessorServiceTestCase.java113
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/ImplementationProcessorServiceUniqueTestCase.java67
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/InitProcessorTestCase.java98
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/MonitorProcessorTestCase.java180
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/PropertyProcessorTestCase.java208
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/ReferenceProcessorTestCase.java232
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/ResourceProcessorTestCase.java117
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/ScopeProcessorTestCase.java128
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/ServiceCallbackTestCase.java166
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/ServiceProcessorTestCase.java151
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/system/builder/SystemComponentBuilderResourceTestCase.java94
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/system/component/SystemAtomicComponentTestCase.java127
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/system/component/SystemAtomicComponentWireInvocationTestCase.java63
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/system/loader/SystemComponentTypeLoaderTestCase.java82
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/system/loader/SystemImplementationLoaderTestCase.java106
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/injection/CallbackWireObjectFactoryTestCase.java52
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/injection/FieldInjectorTestCase.java48
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/injection/JNDIObjectFactoryTestCase.java61
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/injection/MethodEventInvokerTestCase.java72
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/injection/MethodInjectorTestCase.java79
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/injection/PojoObjectFactoryTestCase.java76
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/injection/RequestContextObjectFactoryTestCase.java37
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/injection/ResourceObjectFactoryTestCase.java91
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/injection/SingletonObjectFactoryTestCase.java33
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/integration/conversation/AbstractConversationTestCase.java52
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/integration/conversation/ConversationIdleExpireTestCase.java149
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/integration/conversation/ConversationMaxAgeExpireTestCase.java154
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/integration/conversation/ConversationStartStopEndTestCase.java148
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/integration/implementation/IntrospectionRegistryIntegrationTestCase.java131
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/integration/implementation/system/builder/SystemBuilderPropertyTestCase.java90
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/integration/mock/MockFactory.java209
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/integration/scope/ScopeReferenceTestCase.java785
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/integration/wire/DifferentInterfaceWireTestCase.java136
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/integration/wire/ReferenceInjectionTestCase.java76
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/integration/wire/oneway/OneWayWireToJavaInvocationTestCase.java126
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderNoBindingTestCase.java103
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderNoReferenceTestCase.java113
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderPropertyTestCase.java81
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderRefTestCase.java159
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderTestCase.java245
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderValidationTestCase.java169
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/loader/ComponentTypeElementLoaderTestCase.java88
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/loader/DependencyLoaderTestCase.java124
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/loader/IncludeLoaderTestCase.java176
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/loader/JNDIPropertyFactoryTestCase.java81
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/loader/LoaderExceptionFormatterTestCase.java47
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/loader/PolicySetLoaderTestCase.java71
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/loader/PropertyParsingTestCase.java77
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/loader/ReferenceLoaderTestCase.java137
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/loader/ServiceLoaderPromoteTestCase.java86
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/loader/ServiceLoaderTestCase.java161
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/loader/StAXLoaderRegistryImplTestCase.java131
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/loader/StringParserPropertyFactoryTestCase.java128
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/loader/WireLoaderTestCase.java181
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/marshaller/JavaPhysicalChangeSetMarshallerTest.java154
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/binding/MockServiceBinding.java62
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/AsyncTarget.java31
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/BadContextPojo.java28
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/BadNamePojo.java26
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/BasicInterface.java30
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/BasicInterfaceImpl.java66
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeComponent.java31
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeComponentImpl.java40
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeDestroyOnlyComponent.java36
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeInitDestroyComponent.java39
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeInitOnlyComponent.java42
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeComponent.java29
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeComponentImpl.java29
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeDestroyOnlyComponent.java37
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeInitDestroyComponent.java38
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeInitOnlyComponent.java38
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/OrderException.java40
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/OrderedDependentPojo.java29
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/OrderedDependentPojoImpl.java36
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/OrderedEagerInitPojo.java60
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/OrderedInitPojo.java28
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/OrderedInitPojoImpl.java61
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/OtherTarget.java31
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/OtherTargetImpl.java39
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/RequestScopeComponent.java30
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/RequestScopeDestroyOnlyComponent.java38
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/RequestScopeInitDestroyComponent.java38
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/RequestScopeInitOnlyComponent.java39
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/SessionScopeComponent.java30
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/SessionScopeComponentImpl.java30
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/SessionScopeInitDestroyComponent.java36
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/SessionScopeInitOnlyComponent.java37
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/SimpleTarget.java30
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/SimpleTargetImpl.java41
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/Source.java37
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/SourceImpl.java63
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/StatelessComponent.java30
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/StatelessComponentImpl.java27
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/Target.java32
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/TargetImpl.java38
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/wire/MockStaticInvoker.java97
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/wire/MockSyncInterceptor.java55
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/wire/MockTargetInvoker.java33
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/monitor/DefaultExceptionFormatterTestCase.java59
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/monitor/JavaLoggingTestCase.java153
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/policy/IntentRegistryImplTestCase.java152
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/policy/PolicyEngineImplTestCase.java140
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/property/PropertyHelperTestCase.java107
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/property/SimplePropertyObjectFactoryTestCase.java107
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/resolver/DefaultAutowireResolverTestCase.java177
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/services/artifact/LocalMavenRepositoryTestCase.java82
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/services/deployment/AssemblyServiceImplTestCase.java107
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/services/deployment/ContentTypeDescriberImplTestCase.java49
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/services/deployment/ContributionRepositoryTestCase.java67
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/services/deployment/ContributionServiceImplTestCase.java67
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/services/deployment/contribution/FolderContributionProcessorTestCase.java50
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/services/deployment/contribution/JarContributionProcessorTestCase.java46
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/services/deployment/contribution/JavaContributionProcessorTestCase.java86
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/services/host/DelegatingResourceHostRegistryTestCase.java147
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/services/store/memory/MemoryStoreTestCase.java166
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/services/work/jsr237/Jsr237WorkSchedulerTest.java81
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/services/work/jsr237/Jsr237WorkSchedulerTestCase.java100
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/services/work/jsr237/workmanager/ThreadPoolWorkManagerTestCase.java132
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/util/Bean1.java45
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/util/Bean2.java47
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/util/JavaIntrospectionHelperTestCase.java180
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/util/SuperBean.java48
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/BasicReferenceInvocationHandlerTestCase.java70
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/CallbackInterfaceInterceptorTestCase.java60
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/ContractCompatibilityTestCase.java372
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/IncompatibleServiceContractExceptionFormatterTestCase.java82
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/InvocationChainImplTestCase.java84
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/InvocationConfigurationErrorTestCase.java92
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/InvocationConfigurationTestCase.java92
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/InvocationHandlerTestCase.java129
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/NonBlockingInterceptorTestCase.java75
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/OptimizedWireObjectFactoryTestCase.java44
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/WireImplTestCase.java50
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/WireObjectFactoryTestCase.java138
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/WireOptimizationTestCase.java113
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/WireUtilsTestCase.java92
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandlerSerializationTestCase.java81
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandlerTestCase.java65
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKInvocationHandlerProxyTestCase.java82
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKInvocationHandlerSerializationTestCase.java129
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKInvocationHandlerTestCase.java156
-rw-r--r--sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKProxyTestCase.java57
270 files changed, 27776 insertions, 0 deletions
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/binding/local/AbstractLocalTargetInvokerTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/binding/local/AbstractLocalTargetInvokerTestCase.java
new file mode 100644
index 0000000000..dfda132671
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/binding/local/AbstractLocalTargetInvokerTestCase.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.binding.local;
+
+import org.apache.tuscany.spi.wire.Interceptor;
+import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.Message;
+import org.apache.tuscany.spi.wire.MessageImpl;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.mock.wire.MockTargetInvoker;
+import org.easymock.EasyMock;
+import org.easymock.IAnswer;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class AbstractLocalTargetInvokerTestCase extends TestCase {
+
+ public void testInvokerWithInterceptor() throws Throwable {
+ AbstractLocalTargetInvoker invoker = new MockTargetInvoker();
+ Interceptor interceptor = EasyMock.createMock(Interceptor.class);
+ interceptor.invoke(EasyMock.isA(Message.class));
+ EasyMock.expectLastCall().andStubAnswer(new IAnswer<Object>() {
+ public Object answer() throws Throwable {
+ Message msg = (Message) EasyMock.getCurrentArguments()[0];
+ if (msg.getTargetInvoker() == null) {
+ fail("Target invoker not set");
+ }
+ return null;
+ }
+ });
+ EasyMock.replay(interceptor);
+ InvocationChain chain = EasyMock.createMock(InvocationChain.class);
+ EasyMock.expect(chain.getHeadInterceptor()).andReturn(interceptor);
+ EasyMock.replay(chain);
+ invoker.invoke(chain, EasyMock.createNiceMock(TargetInvoker.class), new MessageImpl());
+ EasyMock.verify(chain);
+ EasyMock.verify(interceptor);
+ }
+
+ public void testShortCircuitInvoke() throws Throwable {
+ AbstractLocalTargetInvoker invoker = new MockTargetInvoker();
+ TargetInvoker targetInvoker = EasyMock.createMock(TargetInvoker.class);
+ EasyMock.expect(targetInvoker.invoke(EasyMock.isA(Message.class))).andReturn(new MessageImpl());
+ EasyMock.replay(targetInvoker);
+ InvocationChain chain = EasyMock.createMock(InvocationChain.class);
+ EasyMock.expect(chain.getHeadInterceptor()).andReturn(null);
+ EasyMock.replay(chain);
+ invoker.invoke(chain, targetInvoker, new MessageImpl());
+ EasyMock.verify(chain);
+ EasyMock.verify(targetInvoker);
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/binding/local/LocalBindingBuilderTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/binding/local/LocalBindingBuilderTestCase.java
new file mode 100644
index 0000000000..e628df47e2
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/binding/local/LocalBindingBuilderTestCase.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.binding.local;
+
+import java.net.URI;
+
+import org.apache.tuscany.spi.component.ServiceBinding;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class LocalBindingBuilderTestCase extends TestCase {
+
+ public void testBuild() throws Exception {
+ LocalBindingBuilder builder = new LocalBindingBuilder();
+ ServiceDefinition def = new ServiceDefinition();
+ def.setUri(new URI("#foo"));
+ ServiceBinding binding = builder.build(def, null, null);
+ assertEquals(LocalServiceBinding.class, binding.getClass());
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/binding/local/LocalBindingLoaderTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/binding/local/LocalBindingLoaderTestCase.java
new file mode 100644
index 0000000000..0c35ae9a09
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/binding/local/LocalBindingLoaderTestCase.java
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.binding.local;
+
+import java.net.URI;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.spi.loader.LoaderException;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class LocalBindingLoaderTestCase extends TestCase {
+ private LocalBindingLoader loader;
+
+ public void testParse() throws Exception {
+ XMLStreamReader reader = EasyMock.createMock(XMLStreamReader.class);
+ EasyMock.expect(reader.getAttributeValue(null, "uri")).andReturn("foo");
+ EasyMock.replay(reader);
+ LocalBindingDefinition definition = loader.load(null, reader, null);
+ assertEquals(new URI("foo"), definition.getTargetUri());
+ EasyMock.verify(reader);
+ }
+
+ public void testNoUri() throws Exception {
+ XMLStreamReader reader = EasyMock.createMock(XMLStreamReader.class);
+ EasyMock.expect(reader.getAttributeValue(null, "uri")).andReturn(null);
+ EasyMock.replay(reader);
+ LocalBindingDefinition definition = loader.load(null, reader, null);
+ assertNull(definition.getTargetUri());
+ EasyMock.verify(reader);
+ }
+
+ public void testBadUri() throws Exception {
+ XMLStreamReader reader = EasyMock.createMock(XMLStreamReader.class);
+ EasyMock.expect(reader.getAttributeValue(null, "uri")).andReturn("foo foo");
+ EasyMock.replay(reader);
+ try {
+ loader.load(null, reader, null);
+ fail();
+ } catch (LoaderException e) {
+ // expected
+ }
+ EasyMock.verify(reader);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ loader = new LocalBindingLoader(null);
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/binding/local/LocalCallbackTargetInvokerInvocationExceptionTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/binding/local/LocalCallbackTargetInvokerInvocationExceptionTestCase.java
new file mode 100644
index 0000000000..9b83d95918
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/binding/local/LocalCallbackTargetInvokerInvocationExceptionTestCase.java
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.binding.local;
+
+import java.lang.reflect.Type;
+
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.wire.Interceptor;
+import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.Message;
+import org.apache.tuscany.spi.wire.MessageImpl;
+import org.apache.tuscany.spi.wire.Wire;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.wire.InvocationChainImpl;
+import org.apache.tuscany.core.wire.WireImpl;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class LocalCallbackTargetInvokerInvocationExceptionTestCase extends TestCase {
+
+ /**
+ * Verfies an InvocationTargetException thrown when invoking the target is propagated to the client correctly and
+ * the originating error is unwrapped
+ */
+ public void testThrowableTargetInvocation() throws Exception {
+ Operation<Type> operation = new Operation<Type>("echo", null, null, null);
+ Interceptor head = new ErrorInterceptor();
+ InvocationChain chain = new InvocationChainImpl(operation);
+ chain.addInterceptor(head);
+ Wire wire = new WireImpl();
+ wire.addCallbackInvocationChain(operation, chain);
+ LocalCallbackTargetInvoker invoker = new LocalCallbackTargetInvoker(operation, wire);
+ Message msg = new MessageImpl();
+ msg.setBody("foo");
+ Message response = invoker.invoke(msg);
+ assertTrue(response.isFault());
+ Object body = response.getBody();
+ assertTrue(SomeException.class.equals(body.getClass()));
+ }
+
+ private class SomeException extends Exception {
+
+ }
+
+ private class ErrorInterceptor implements Interceptor {
+
+ public Message invoke(Message msg) {
+ msg.setBodyWithFault(new SomeException());
+ return msg;
+ }
+
+ public void setNext(Interceptor next) {
+
+ }
+
+ public Interceptor getNext() {
+ return null;
+ }
+
+ public boolean isOptimizable() {
+ return false;
+ }
+ }
+
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/binding/local/LocalCallbackTargetInvokerTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/binding/local/LocalCallbackTargetInvokerTestCase.java
new file mode 100644
index 0000000000..d922ec8033
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/binding/local/LocalCallbackTargetInvokerTestCase.java
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.binding.local;
+
+import java.lang.reflect.Type;
+import java.net.URI;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.wire.Interceptor;
+import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.Message;
+import org.apache.tuscany.spi.wire.MessageImpl;
+import org.apache.tuscany.spi.wire.Wire;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class LocalCallbackTargetInvokerTestCase extends TestCase {
+ private Wire wire;
+ private Message message;
+ private InvocationChain chain;
+ private Interceptor head;
+ private LocalCallbackTargetInvoker invoker;
+
+ /**
+ * Verfies the normal execution path through a callback
+ */
+ public void testNormalPathMessageInvocation() throws Exception {
+ Message response = invoker.invoke(message);
+ assertEquals("response", response.getBody());
+ EasyMock.verify(wire);
+ EasyMock.verify(chain);
+ EasyMock.verify(head);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ URI targetAddress = URI.create("from");
+ message = new MessageImpl();
+ message.pushCallbackUri(targetAddress);
+ message.setBody("foo");
+ Message response = new MessageImpl();
+ response.setBody("response");
+ Operation<Type> operation = new Operation<Type>("echo", null, null, null);
+ head = EasyMock.createMock(Interceptor.class);
+ EasyMock.expect(head.invoke(EasyMock.isA(Message.class))).andReturn(response);
+ EasyMock.replay(head);
+ chain = EasyMock.createMock(InvocationChain.class);
+ EasyMock.expect(chain.getTargetInvoker()).andReturn(null);
+ EasyMock.expect(chain.getHeadInterceptor()).andReturn(head);
+ EasyMock.replay(chain);
+ Map<Operation<?>, InvocationChain> chains = new HashMap<Operation<?>, InvocationChain>();
+ chains.put(operation, chain);
+ wire = EasyMock.createMock(Wire.class);
+ EasyMock.expect(wire.getCallbackInvocationChains()).andReturn(chains);
+ EasyMock.replay(wire);
+
+ invoker = new LocalCallbackTargetInvoker(operation, wire);
+ }
+
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/binding/local/LocalCallbackTargetInvokerThrowableTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/binding/local/LocalCallbackTargetInvokerThrowableTestCase.java
new file mode 100644
index 0000000000..0c06842a60
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/binding/local/LocalCallbackTargetInvokerThrowableTestCase.java
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.binding.local;
+
+import java.lang.reflect.Type;
+
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.wire.Interceptor;
+import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.Message;
+import org.apache.tuscany.spi.wire.MessageImpl;
+import org.apache.tuscany.spi.wire.Wire;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.wire.InvocationChainImpl;
+import org.apache.tuscany.core.wire.WireImpl;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class LocalCallbackTargetInvokerThrowableTestCase extends TestCase {
+ private LocalCallbackTargetInvoker invoker;
+
+ /**
+ * Verfies an exception thrown in the target is propagated to the client correctly
+ */
+ public void testThrowableTargetInvocation() throws Exception {
+ Message message = new MessageImpl();
+ message.setBody("foo");
+ Message response = invoker.invoke(message);
+ assertTrue(response.isFault());
+ Object body = response.getBody();
+ if (!(body instanceof InsidiousException)) {
+ fail();
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ protected void setUp() throws Exception {
+ super.setUp();
+ Operation<Type> operation = new Operation<Type>("echo", null, null, null);
+ InvocationChain chain = new InvocationChainImpl(operation);
+ chain.addInterceptor(new InsidiuousInterceptor());
+ Wire wire = new WireImpl();
+ wire.addCallbackInvocationChain(operation, chain);
+ invoker = new LocalCallbackTargetInvoker(operation, wire);
+ }
+
+ private class InsidiousException extends RuntimeException {
+
+ }
+
+ private class InsidiuousInterceptor implements Interceptor {
+
+ public Message invoke(Message msg) throws InsidiousException {
+ throw new InsidiousException();
+ }
+
+ public void setNext(Interceptor next) {
+
+ }
+
+ public Interceptor getNext() {
+ return null;
+ }
+
+ public boolean isOptimizable() {
+ return false;
+ }
+ }
+
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/binding/local/LocalTargetInvokerTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/binding/local/LocalTargetInvokerTestCase.java
new file mode 100644
index 0000000000..e49447164d
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/binding/local/LocalTargetInvokerTestCase.java
@@ -0,0 +1,115 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.binding.local;
+
+import java.net.URI;
+
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.Message;
+import org.apache.tuscany.spi.wire.MessageImpl;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+import org.apache.tuscany.spi.wire.Wire;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.wire.InvocationChainImpl;
+import org.apache.tuscany.core.wire.WireImpl;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class LocalTargetInvokerTestCase extends TestCase {
+ private ServiceContract<Object> serviceContract;
+ private Operation<Object> operation;
+
+ public void testInvoke() {
+ TargetInvoker targetInvoker = EasyMock.createMock(TargetInvoker.class);
+ EasyMock.expect(targetInvoker.invoke(EasyMock.isA(Message.class))).andReturn(new MessageImpl());
+ EasyMock.replay(targetInvoker);
+ InvocationChain chain = new InvocationChainImpl(operation);
+ chain.setTargetInvoker(targetInvoker);
+ Wire wire = new WireImpl();
+ wire.addInvocationChain(operation, chain);
+ wire.setSourceContract(serviceContract);
+ TargetInvoker invoker = new LocalTargetInvoker(operation, wire);
+ Message msg = invoker.invoke(new MessageImpl());
+ assertFalse(msg.isFault());
+ EasyMock.verify(targetInvoker);
+ }
+
+ public void testCallbackSetInvoke() {
+ ServiceContract<?> contract = new ServiceContract<Object>() {
+
+ };
+ contract.setCallbackClass(Object.class);
+ TargetInvoker targetInvoker = EasyMock.createMock(TargetInvoker.class);
+ EasyMock.expect(targetInvoker.invoke(EasyMock.isA(Message.class))).andReturn(new MessageImpl());
+ EasyMock.replay(targetInvoker);
+
+ InvocationChain chain = new InvocationChainImpl(operation);
+ chain.setTargetInvoker(targetInvoker);
+ InvocationChain callbackChain = new InvocationChainImpl(operation);
+ Wire wire = new WireImpl();
+ wire.addInvocationChain(operation, chain);
+ wire.addCallbackInvocationChain(operation, callbackChain);
+ wire.setSourceContract(serviceContract);
+ URI uri = URI.create("foo");
+ wire.setSourceUri(uri);
+ wire.addInvocationChain(operation, chain);
+ TargetInvoker invoker = new LocalTargetInvoker(operation, wire);
+ Message msg = EasyMock.createMock(Message.class);
+ msg.pushCallbackUri(EasyMock.eq(uri));
+ EasyMock.replay(msg);
+ invoker.invoke(msg);
+ EasyMock.verify(msg);
+ EasyMock.verify(targetInvoker);
+ }
+
+ public void testFaultInvoke() {
+ TargetInvoker targetInvoker = EasyMock.createMock(TargetInvoker.class);
+ EasyMock.expect(targetInvoker.invoke(EasyMock.isA(Message.class))).andThrow(new TestException());
+ EasyMock.replay(targetInvoker);
+
+ InvocationChain chain = new InvocationChainImpl(operation);
+ chain.setTargetInvoker(targetInvoker);
+ Wire wire = new WireImpl();
+ wire.setSourceContract(serviceContract);
+ wire.addInvocationChain(operation, chain);
+ TargetInvoker invoker = new LocalTargetInvoker(operation, wire);
+ Message msg = invoker.invoke(new MessageImpl());
+ assertTrue(msg.isFault());
+ assertTrue(msg.getBody() instanceof TestException);
+ EasyMock.verify(targetInvoker);
+ }
+
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ serviceContract = new ServiceContract<Object>() {
+ };
+ operation = new Operation<Object>("foo", null, null, null);
+ }
+
+
+ private class TestException extends RuntimeException {
+
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/bootstrap/BootstrapperTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/bootstrap/BootstrapperTestCase.java
new file mode 100644
index 0000000000..75c18a8230
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/bootstrap/BootstrapperTestCase.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.bootstrap;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.core.deployer.DeployerImpl;
+import org.apache.tuscany.core.monitor.NullMonitorFactory;
+
+/**
+ * Verifies the default bootstrapper can be instantiated
+ *
+ * @version $Rev$ $Date$
+ */
+public class BootstrapperTestCase extends TestCase {
+ private Bootstrapper bootstrapper;
+
+ public void testDeployerBootstrap() {
+ DeployerImpl deployer = (DeployerImpl) bootstrapper.createDeployer();
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ bootstrapper = new DefaultBootstrapper(new NullMonitorFactory(), null, null, null, null);
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/builder/AtomicConnectorTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/builder/AtomicConnectorTestCase.java
new file mode 100644
index 0000000000..b83f0fe57c
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/builder/AtomicConnectorTestCase.java
@@ -0,0 +1,201 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.builder;
+
+import java.net.URI;
+
+import org.apache.tuscany.spi.builder.Connector;
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.Reference;
+import org.apache.tuscany.spi.component.ReferenceBinding;
+import org.apache.tuscany.spi.component.Service;
+import org.apache.tuscany.spi.component.ServiceBinding;
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.idl.java.JavaInterfaceProcessorRegistry;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.ComponentType;
+import org.apache.tuscany.spi.model.Implementation;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.Property;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.ReferenceTarget;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+import org.apache.tuscany.spi.wire.Wire;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.component.ComponentManager;
+import org.apache.tuscany.core.component.ComponentManagerImpl;
+import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
+import org.apache.tuscany.core.implementation.composite.CompositeComponentImpl;
+import org.apache.tuscany.core.implementation.composite.ReferenceImpl;
+import org.apache.tuscany.core.implementation.composite.ServiceImpl;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class AtomicConnectorTestCase extends TestCase {
+ private static final URI PARENT = URI.create("parent");
+ private static final URI SOURCE = URI.create("source");
+ private static final URI TARGET = URI.create("parent#target");
+ private static final URI TARGET_NOFRAGMENT = URI.create("target");
+ private static final URI REFERENCE_NAME = URI.create("#ref");
+ private ComponentManager manager;
+ private Connector connector;
+ private ServiceContract<?> contract;
+
+ /**
+ * Verifies connecting a wire from an atomic component to a target atomic component
+ */
+ @SuppressWarnings({"unchecked"})
+ public void testConnectToAtomic() throws Exception {
+ AtomicComponent source = EasyMock.createMock(AtomicComponent.class);
+ EasyMock.expect(source.getUri()).andReturn(SOURCE).atLeastOnce();
+ EasyMock.expect(source.getScope()).andReturn(Scope.COMPOSITE);
+ source.attachWire(EasyMock.isA(Wire.class));
+ EasyMock.replay(source);
+ manager.register(source);
+
+ AtomicComponent target = EasyMock.createMock(AtomicComponent.class);
+ EasyMock.expect(target.getScope()).andReturn(Scope.COMPOSITE);
+ EasyMock.expect(target.isOptimizable()).andReturn(false);
+ EasyMock.expect(target.getUri()).andReturn(TARGET_NOFRAGMENT).atLeastOnce();
+ target.createTargetInvoker((String) EasyMock.isNull(), EasyMock.isA(Operation.class));
+ EasyMock.expectLastCall().andReturn(null);
+ EasyMock.replay(target);
+ manager.register(target);
+
+ Implementation impl = new Implementation() {
+ };
+ ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>> type =
+ new ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>>();
+ ReferenceDefinition referenceDefinition = new ReferenceDefinition(REFERENCE_NAME, contract);
+ type.add(referenceDefinition);
+ impl.setComponentType(type);
+
+ ComponentDefinition<?> definition = new ComponentDefinition(impl);
+ definition.setUri(SOURCE);
+ ReferenceTarget referenceTarget = new ReferenceTarget();
+ referenceTarget.setReferenceName(REFERENCE_NAME);
+ referenceTarget.addTarget(TARGET_NOFRAGMENT);
+ definition.add(referenceTarget);
+
+ connector.connect(definition);
+ EasyMock.verify(source);
+ EasyMock.verify(target);
+ }
+
+ @SuppressWarnings({"unchecked"})
+ public void testConnectToReference() throws Exception {
+ AtomicComponent source = EasyMock.createMock(AtomicComponent.class);
+ EasyMock.expect(source.getUri()).andReturn(SOURCE).atLeastOnce();
+ source.attachWire(EasyMock.isA(Wire.class));
+ EasyMock.expect(source.getScope()).andReturn(Scope.COMPOSITE);
+ EasyMock.replay(source);
+ manager.register(source);
+
+ ReferenceBinding binding = EasyMock.createMock(ReferenceBinding.class);
+ binding.createTargetInvoker(EasyMock.isA(String.class), EasyMock.isA(Operation.class));
+ EasyMock.expectLastCall().andReturn(null);
+ EasyMock.replay(binding);
+
+ Reference reference = new ReferenceImpl(TARGET, contract);
+ reference.addReferenceBinding(binding);
+
+ Component component = new CompositeComponentImpl(PARENT);
+ component.register(reference);
+ manager.register(component);
+
+ Implementation impl = new Implementation() {
+ };
+ ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>> type =
+ new ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>>();
+ ReferenceDefinition referenceDefinition = new ReferenceDefinition(REFERENCE_NAME, contract);
+ type.add(referenceDefinition);
+ impl.setComponentType(type);
+
+ ComponentDefinition<?> definition = new ComponentDefinition(impl);
+ definition.setUri(SOURCE);
+ ReferenceTarget referenceTarget = new ReferenceTarget();
+ referenceTarget.setReferenceName(REFERENCE_NAME);
+ referenceTarget.addTarget(TARGET);
+ definition.add(referenceTarget);
+
+ connector.connect(definition);
+ EasyMock.verify(source);
+ EasyMock.verify(binding);
+ }
+
+ @SuppressWarnings({"unchecked"})
+ public void testConnectToService() throws Exception {
+ AtomicComponent source = EasyMock.createMock(AtomicComponent.class);
+ EasyMock.expect(source.getUri()).andReturn(SOURCE).atLeastOnce();
+ EasyMock.expect(source.getScope()).andReturn(Scope.COMPOSITE);
+ source.attachWire(EasyMock.isA(Wire.class));
+ EasyMock.replay(source);
+ manager.register(source);
+
+ ServiceBinding binding = EasyMock.createMock(ServiceBinding.class);
+ binding.createTargetInvoker(EasyMock.isA(String.class), EasyMock.isA(Operation.class));
+ EasyMock.expectLastCall().andReturn(null);
+ EasyMock.replay(binding);
+
+ Service service = new ServiceImpl(TARGET, contract);
+ service.addServiceBinding(binding);
+
+ Component component = new CompositeComponentImpl(PARENT);
+ component.register(service);
+ manager.register(component);
+
+ Implementation impl = new Implementation() {
+ };
+ ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>> type =
+ new ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>>();
+ ReferenceDefinition referenceDefinition = new ReferenceDefinition(REFERENCE_NAME, contract);
+ type.add(referenceDefinition);
+ impl.setComponentType(type);
+
+ ComponentDefinition<?> definition = new ComponentDefinition(impl);
+ definition.setUri(SOURCE);
+ ReferenceTarget referenceTarget = new ReferenceTarget();
+ referenceTarget.setReferenceName(REFERENCE_NAME);
+ referenceTarget.addTarget(TARGET);
+ definition.add(referenceTarget);
+
+ connector.connect(definition);
+ EasyMock.verify(source);
+ EasyMock.verify(binding);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ manager = new ComponentManagerImpl();
+ connector = new ConnectorImpl(null, manager, null, null);
+ JavaInterfaceProcessorRegistry registry = new JavaInterfaceProcessorRegistryImpl();
+ contract = registry.introspect(Foo.class);
+ }
+
+
+ private interface Foo {
+ void bar();
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/builder/BuilderRegistryNoBindingsTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/builder/BuilderRegistryNoBindingsTestCase.java
new file mode 100644
index 0000000000..f13ed3367d
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/builder/BuilderRegistryNoBindingsTestCase.java
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.builder;
+
+import java.net.URI;
+
+import org.apache.tuscany.spi.builder.BuilderRegistry;
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.component.Reference;
+import org.apache.tuscany.spi.component.ReferenceBinding;
+import org.apache.tuscany.spi.component.Service;
+import org.apache.tuscany.spi.component.ServiceBinding;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.model.Multiplicity;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.binding.local.LocalBindingBuilder;
+import org.apache.tuscany.core.binding.local.LocalBindingDefinition;
+import org.apache.tuscany.core.binding.local.LocalReferenceBinding;
+import org.apache.tuscany.core.binding.local.LocalServiceBinding;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class BuilderRegistryNoBindingsTestCase extends TestCase {
+ private DeploymentContext deploymentContext;
+ private Component parent;
+ private BuilderRegistry registry;
+
+ public void testNoServiceBindings() throws Exception {
+ ServiceBinding binding = EasyMock.createNiceMock(ServiceBinding.class);
+ EasyMock.replay(binding);
+ ServiceDefinition definition = new ServiceDefinition(URI.create("#foo"), null, false);
+ definition.setTarget(new URI("foo"));
+ EasyMock.replay(deploymentContext);
+ EasyMock.replay(parent);
+
+ Service service = registry.build(definition, deploymentContext);
+
+ assertEquals(1, service.getServiceBindings().size());
+ assertTrue(service.getServiceBindings().get(0) instanceof LocalServiceBinding);
+ EasyMock.verify(deploymentContext);
+ EasyMock.verify(parent);
+ }
+
+ public void testReferenceBindingBuilderDispatch() throws Exception {
+ ReferenceBinding binding = EasyMock.createNiceMock(ReferenceBinding.class);
+ EasyMock.replay(binding);
+ ReferenceDefinition definition = new ReferenceDefinition(URI.create("#foo"), null, Multiplicity.ONE_ONE);
+ EasyMock.replay(deploymentContext);
+ EasyMock.replay(parent);
+
+ Reference reference = registry.build(definition, deploymentContext);
+
+ assertEquals(1, reference.getReferenceBindings().size());
+ assertTrue(reference.getReferenceBindings().get(0) instanceof LocalReferenceBinding);
+ EasyMock.verify(deploymentContext);
+ EasyMock.verify(parent);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ deploymentContext = EasyMock.createMock(DeploymentContext.class);
+ parent = EasyMock.createNiceMock(Component.class);
+ registry = new BuilderRegistryImpl(null);
+ registry.register(LocalBindingDefinition.class, new LocalBindingBuilder());
+ }
+
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/builder/BuilderRegistryTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/builder/BuilderRegistryTestCase.java
new file mode 100644
index 0000000000..34173154b8
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/builder/BuilderRegistryTestCase.java
@@ -0,0 +1,190 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.builder;
+
+import java.net.URI;
+import java.util.Map;
+
+import org.apache.tuscany.spi.builder.BindingBuilder;
+import org.apache.tuscany.spi.builder.BuilderConfigException;
+import org.apache.tuscany.spi.builder.BuilderRegistry;
+import org.apache.tuscany.spi.builder.ComponentBuilder;
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.component.Reference;
+import org.apache.tuscany.spi.component.ReferenceBinding;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.ScopeRegistry;
+import org.apache.tuscany.spi.component.Service;
+import org.apache.tuscany.spi.component.ServiceBinding;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.model.BindingDefinition;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.ComponentType;
+import org.apache.tuscany.spi.model.CompositeComponentType;
+import org.apache.tuscany.spi.model.CompositeImplementation;
+import org.apache.tuscany.spi.model.Implementation;
+import static org.apache.tuscany.spi.model.Multiplicity.ONE_ONE;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class BuilderRegistryTestCase extends TestCase {
+ private DeploymentContext deploymentContext;
+ private ScopeContainer scopeContainer;
+ private Map<URI, Component> components;
+
+ //private BuilderRegistryImpl registry;
+ private Component parent;
+
+ @SuppressWarnings({"unchecked"})
+ public void testRegistration() throws Exception {
+ URI componentId = URI.create("sca://localhost/component");
+ CompositeImplementation implementation = new CompositeImplementation();
+ ComponentDefinition<CompositeImplementation> componentDefinition =
+ new ComponentDefinition<CompositeImplementation>(implementation);
+ componentDefinition.getImplementation().setComponentType(new CompositeComponentType());
+
+ Component component = EasyMock.createMock(Component.class);
+ component.setDefaultPropertyValues(componentDefinition.getPropertyValues());
+ component.setScopeContainer(scopeContainer);
+ EasyMock.expect(component.getUri()).andReturn(componentId);
+ EasyMock.replay(component);
+
+ EasyMock.expect(deploymentContext.getCompositeScope()).andReturn(scopeContainer);
+ EasyMock.expect(deploymentContext.getComponents()).andReturn(components);
+ EasyMock.replay(deploymentContext);
+
+ EasyMock.expect(components.put(componentId, component)).andReturn(null);
+ EasyMock.replay(components);
+
+ ComponentBuilder builder = EasyMock.createMock(ComponentBuilder.class);
+ EasyMock.expect(builder.build(componentDefinition, deploymentContext)).andReturn(component);
+ EasyMock.replay(builder);
+
+ BuilderRegistry registry = new BuilderRegistryImpl(null);
+ registry.register(CompositeImplementation.class, builder);
+
+ assertSame(component, registry.build(componentDefinition, deploymentContext));
+ EasyMock.verify(builder);
+ }
+
+ @SuppressWarnings({"unchecked"})
+ public void testServiceBindingBuilderDispatch() throws Exception {
+ BuilderRegistry registry = new BuilderRegistryImpl(null);
+ ServiceBinding binding = EasyMock.createNiceMock(ServiceBinding.class);
+ EasyMock.replay(binding);
+ BindingBuilder<MockBindingDefinition> builder = EasyMock.createMock(BindingBuilder.class);
+ EasyMock.expect(builder.build(
+ EasyMock.isA(ServiceDefinition.class),
+ EasyMock.isA(MockBindingDefinition.class),
+ EasyMock.isA(DeploymentContext.class))).andReturn(binding).times(2);
+ EasyMock.replay(builder);
+ registry.register(MockBindingDefinition.class, builder);
+ ServiceDefinition definition = new ServiceDefinition(URI.create("#foo"), null, false);
+ definition.addBinding(new MockBindingDefinition());
+ definition.addBinding(new MockBindingDefinition());
+ definition.setTarget(new URI("foo"));
+ Service service = registry.build(definition, deploymentContext);
+ assertEquals(2, service.getServiceBindings().size());
+ }
+
+ @SuppressWarnings({"unchecked"})
+ public void testReferenceBindingBuilderDispatch() throws Exception {
+ BuilderRegistry registry = new BuilderRegistryImpl(null);
+ ReferenceBinding binding = EasyMock.createNiceMock(ReferenceBinding.class);
+ EasyMock.replay(binding);
+ BindingBuilder<MockBindingDefinition> builder = EasyMock.createMock(BindingBuilder.class);
+ EasyMock.expect(builder.build(
+ EasyMock.isA(ReferenceDefinition.class),
+ EasyMock.isA(MockBindingDefinition.class),
+ EasyMock.isA(DeploymentContext.class))).andReturn(binding).times(2);
+ EasyMock.replay(builder);
+ registry.register(MockBindingDefinition.class, builder);
+ ReferenceDefinition definition = new ReferenceDefinition(URI.create("#foo"), null, ONE_ONE);
+ definition.addBinding(new MockBindingDefinition());
+ definition.addBinding(new MockBindingDefinition());
+ Reference reference = registry.build(definition, deploymentContext);
+ assertEquals(2, reference.getReferenceBindings().size());
+ }
+
+ @SuppressWarnings({"unchecked"})
+ public void testNoConversationalContract() throws Exception {
+ ScopeRegistry scopeRegistry = EasyMock.createMock(ScopeRegistry.class);
+ ScopeContainer scopeContainer = EasyMock.createNiceMock(ScopeContainer.class);
+ EasyMock.expect(scopeRegistry.getScopeContainer(EasyMock.isA(Scope.class))).andReturn(scopeContainer);
+ EasyMock.replay(scopeRegistry);
+ BuilderRegistry registry = new BuilderRegistryImpl(scopeRegistry);
+
+ AtomicComponent component = EasyMock.createNiceMock(AtomicComponent.class);
+ EasyMock.replay(component);
+ ComponentBuilder<FooImplementation> builder = EasyMock.createMock(ComponentBuilder.class);
+ EasyMock.expect(builder.build(
+ EasyMock.isA(ComponentDefinition.class),
+ EasyMock.isA(DeploymentContext.class))).andReturn(component);
+ EasyMock.replay(builder);
+ registry.register(FooImplementation.class, builder);
+
+ FooImplementation impl = new FooImplementation();
+ ComponentType componentType = new ComponentType();
+ componentType.setImplementationScope(Scope.CONVERSATION);
+ impl.setComponentType(componentType);
+ URI uri = URI.create("foo");
+ ComponentDefinition<FooImplementation> definition = new ComponentDefinition<FooImplementation>(uri, impl);
+ try {
+ registry.build(definition, deploymentContext);
+ fail("Should throw NoConversationalContractException");
+ } catch (NoConversationalContractException e) {
+ // expected
+ }
+ }
+
+ @SuppressWarnings({"unchecked"})
+ protected void setUp() throws Exception {
+ super.setUp();
+ deploymentContext = EasyMock.createMock(DeploymentContext.class);
+ parent = EasyMock.createNiceMock(Component.class);
+ scopeContainer = EasyMock.createMock(ScopeContainer.class);
+ components = EasyMock.createMock(Map.class);
+ }
+
+ private class MockBuilder implements ComponentBuilder<CompositeImplementation> {
+ public Component build(
+ ComponentDefinition componentDefinition,
+ DeploymentContext deploymentContext) throws BuilderConfigException {
+ return null;
+ }
+ }
+
+ private class MockBindingDefinition extends BindingDefinition {
+
+ }
+
+ private class FooImplementation extends Implementation<ComponentType> {
+
+ }
+
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/builder/ConnectorImplTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/builder/ConnectorImplTestCase.java
new file mode 100644
index 0000000000..5c966e0bc5
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/builder/ConnectorImplTestCase.java
@@ -0,0 +1,320 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.builder;
+
+import java.lang.reflect.Type;
+import java.net.URI;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.ComponentType;
+import org.apache.tuscany.spi.model.Implementation;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.Property;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.ReferenceTarget;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+import org.apache.tuscany.spi.wire.Interceptor;
+import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.Wire;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.component.ComponentManager;
+import org.apache.tuscany.core.component.ComponentManagerImpl;
+import org.apache.tuscany.core.wire.InvokerInterceptor;
+import org.apache.tuscany.core.wire.NonBlockingInterceptor;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ConnectorImplTestCase extends TestCase {
+ private TestConnector connector;
+ private ComponentManager manager;
+
+ public void testConnectTargetNotFound() throws Exception {
+ Implementation<ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>>> impl =
+ new Implementation<ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>>>() {
+ };
+ ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>> type =
+ new ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>>();
+ URI refUri = URI.create("ref");
+ ReferenceDefinition referenceDefinition = new ReferenceDefinition(refUri, null);
+ referenceDefinition.setRequired(true);
+ type.add(referenceDefinition);
+ impl.setComponentType(type);
+
+ URI sourceUri = URI.create("source");
+ ComponentDefinition<?> definition =
+ new ComponentDefinition<Implementation<ComponentType<ServiceDefinition,
+ ReferenceDefinition, Property<?>>>>(impl);
+ definition.setUri(sourceUri);
+ ReferenceTarget referenceTarget = new ReferenceTarget();
+ referenceTarget.setReferenceName(refUri);
+ referenceTarget.addTarget(URI.create("NotThere"));
+ definition.add(referenceTarget);
+ Component component = EasyMock.createMock(Component.class);
+ EasyMock.expect(component.getUri()).andReturn(sourceUri);
+ EasyMock.replay(component);
+ manager.register(component);
+ try {
+ connector.connect(definition);
+ fail();
+ } catch (ComponentNotFoundException e) {
+ // expected
+ }
+ }
+
+ /**
+ * Verifies a non-existent target does not throw an error.
+ * <p/>
+ * TODO JFM when the allocator is in place it should optimize connecting to non-existent targets but keep it for
+ * now
+ */
+ public void testConnectTargetNotFoundNonRequiredReference() throws Exception {
+ Implementation<ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>>> impl =
+ new Implementation<ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>>>() {
+ };
+ ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>> type =
+ new ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>>();
+ URI refUri = URI.create("ref");
+ ReferenceDefinition referenceDefinition = new ReferenceDefinition(refUri, null);
+ referenceDefinition.setRequired(false);
+ type.add(referenceDefinition);
+ impl.setComponentType(type);
+
+ URI sourceUri = URI.create("source");
+ ComponentDefinition<?> definition =
+ new ComponentDefinition<Implementation<ComponentType<ServiceDefinition,
+ ReferenceDefinition, Property<?>>>>(impl);
+ definition.setUri(sourceUri);
+ ReferenceTarget referenceTarget = new ReferenceTarget();
+ referenceTarget.setReferenceName(refUri);
+ referenceTarget.addTarget(URI.create("NotThere"));
+ definition.add(referenceTarget);
+ Component component = EasyMock.createMock(Component.class);
+ EasyMock.expect(component.getUri()).andReturn(sourceUri);
+ EasyMock.replay(component);
+ manager.register(component);
+ connector.connect(definition);
+ }
+
+ public void testNonOptimizableTargetComponent() throws Exception {
+ AtomicComponent source = EasyMock.createMock(AtomicComponent.class);
+ EasyMock.expect(source.getScope()).andReturn(Scope.COMPOSITE);
+ EasyMock.replay(source);
+
+ AtomicComponent target = EasyMock.createMock(AtomicComponent.class);
+ EasyMock.expect(target.getScope()).andReturn(Scope.COMPOSITE);
+ EasyMock.expect(target.isOptimizable()).andReturn(false);
+ EasyMock.replay(target);
+
+ Wire wire = EasyMock.createMock(Wire.class);
+ wire.setOptimizable(false);
+ EasyMock.replay(wire);
+ connector.optimize(source, target, wire);
+ EasyMock.verify(source);
+ EasyMock.verify(target);
+ EasyMock.verify(wire);
+ }
+
+ public void testOptimizableTargetComponent() throws Exception {
+ AtomicComponent source = EasyMock.createMock(AtomicComponent.class);
+ EasyMock.expect(source.getScope()).andReturn(Scope.COMPOSITE);
+ EasyMock.replay(source);
+
+ AtomicComponent target = EasyMock.createMock(AtomicComponent.class);
+ EasyMock.expect(target.getScope()).andReturn(Scope.COMPOSITE);
+ EasyMock.expect(target.isOptimizable()).andReturn(true);
+ EasyMock.replay(target);
+
+ Wire wire = EasyMock.createMock(Wire.class);
+ wire.setOptimizable(true);
+ wire.setTarget(EasyMock.eq(target));
+ wire.getInvocationChains();
+ EasyMock.expectLastCall().andReturn(Collections.emptyMap());
+ wire.getCallbackInvocationChains();
+ EasyMock.expectLastCall().andReturn(Collections.emptyMap());
+ EasyMock.replay(wire);
+ connector.optimize(source, target, wire);
+ EasyMock.verify(source);
+ EasyMock.verify(target);
+ }
+
+ public void testIsOptimizable() {
+ assertTrue(connector.isOptimizable(Scope.STATELESS, Scope.STATELESS));
+ assertTrue(connector.isOptimizable(Scope.STATELESS, Scope.COMPOSITE));
+ assertFalse(connector.isOptimizable(Scope.STATELESS, Scope.CONVERSATION));
+ assertTrue(connector.isOptimizable(Scope.STATELESS, Scope.REQUEST));
+ assertTrue(connector.isOptimizable(Scope.STATELESS, Scope.SESSION));
+ assertTrue(connector.isOptimizable(Scope.STATELESS, Scope.SYSTEM));
+
+ assertTrue(connector.isOptimizable(Scope.COMPOSITE, Scope.COMPOSITE));
+ assertFalse(connector.isOptimizable(Scope.COMPOSITE, Scope.CONVERSATION));
+ assertFalse(connector.isOptimizable(Scope.COMPOSITE, Scope.REQUEST));
+ assertFalse(connector.isOptimizable(Scope.COMPOSITE, Scope.SESSION));
+ assertFalse(connector.isOptimizable(Scope.COMPOSITE, Scope.STATELESS));
+ assertTrue(connector.isOptimizable(Scope.COMPOSITE, Scope.SYSTEM));
+
+ assertFalse(connector.isOptimizable(Scope.CONVERSATION, Scope.COMPOSITE));
+ assertFalse(connector.isOptimizable(Scope.CONVERSATION, Scope.CONVERSATION));
+ assertFalse(connector.isOptimizable(Scope.CONVERSATION, Scope.REQUEST));
+ assertFalse(connector.isOptimizable(Scope.CONVERSATION, Scope.SESSION));
+ assertFalse(connector.isOptimizable(Scope.CONVERSATION, Scope.STATELESS));
+ assertFalse(connector.isOptimizable(Scope.CONVERSATION, Scope.SYSTEM));
+
+ assertTrue(connector.isOptimizable(Scope.REQUEST, Scope.COMPOSITE));
+ assertFalse(connector.isOptimizable(Scope.REQUEST, Scope.CONVERSATION));
+ assertTrue(connector.isOptimizable(Scope.REQUEST, Scope.REQUEST));
+ assertTrue(connector.isOptimizable(Scope.REQUEST, Scope.SESSION));
+ assertFalse(connector.isOptimizable(Scope.REQUEST, Scope.STATELESS));
+ assertTrue(connector.isOptimizable(Scope.REQUEST, Scope.SYSTEM));
+
+ assertTrue(connector.isOptimizable(Scope.SESSION, Scope.COMPOSITE));
+ assertFalse(connector.isOptimizable(Scope.SESSION, Scope.CONVERSATION));
+ assertFalse(connector.isOptimizable(Scope.SESSION, Scope.REQUEST));
+ assertTrue(connector.isOptimizable(Scope.SESSION, Scope.SESSION));
+ assertFalse(connector.isOptimizable(Scope.SESSION, Scope.STATELESS));
+ assertTrue(connector.isOptimizable(Scope.SESSION, Scope.SYSTEM));
+
+ assertTrue(connector.isOptimizable(Scope.SYSTEM, Scope.COMPOSITE));
+ assertFalse(connector.isOptimizable(Scope.SYSTEM, Scope.CONVERSATION));
+ assertFalse(connector.isOptimizable(Scope.SYSTEM, Scope.REQUEST));
+ assertFalse(connector.isOptimizable(Scope.SYSTEM, Scope.SESSION));
+ assertFalse(connector.isOptimizable(Scope.SYSTEM, Scope.STATELESS));
+ assertTrue(connector.isOptimizable(Scope.SYSTEM, Scope.SYSTEM));
+
+ assertFalse(connector.isOptimizable(Scope.UNDEFINED, Scope.COMPOSITE));
+ assertFalse(connector.isOptimizable(Scope.UNDEFINED, Scope.CONVERSATION));
+ assertFalse(connector.isOptimizable(Scope.UNDEFINED, Scope.REQUEST));
+ assertFalse(connector.isOptimizable(Scope.UNDEFINED, Scope.SESSION));
+ assertFalse(connector.isOptimizable(Scope.UNDEFINED, Scope.STATELESS));
+ assertFalse(connector.isOptimizable(Scope.UNDEFINED, Scope.SYSTEM));
+
+ }
+
+ public void testCreateSyncForwardWire() throws Exception {
+ ServiceContract<Type> contract = new ServiceContract<Type>() {
+
+ };
+ Operation<Type> operation = new Operation<Type>("operation", null, null, null);
+ Map<String, Operation<Type>> operations = new HashMap<String, Operation<Type>>();
+ operations.put("operation", operation);
+ contract.setOperations(operations);
+ Wire wire = connector.createWire(URI.create("target"), URI.create("#ref"), contract, Wire.LOCAL_BINDING);
+ assertEquals(1, wire.getInvocationChains().size());
+ InvocationChain chain = wire.getInvocationChains().get(operation);
+ Interceptor head = chain.getHeadInterceptor();
+ assertTrue(head instanceof InvokerInterceptor);
+ }
+
+ public void testCreateSyncCallbackWire() throws Exception {
+ ServiceContract<Type> contract = new ServiceContract<Type>() {
+
+ };
+
+ Operation<Type> operation = new Operation<Type>("operation", null, null, null);
+ Map<String, Operation<Type>> operations = new HashMap<String, Operation<Type>>();
+ operations.put("operation", operation);
+ contract.setOperations(operations);
+
+ Operation<Type> callbackOperation = new Operation<Type>("operation", null, null, null);
+ Map<String, Operation<Type>> callbackOperations = new HashMap<String, Operation<Type>>();
+ callbackOperations.put("operation", callbackOperation);
+ contract.setCallbackOperations(callbackOperations);
+
+ Wire wire = connector.createWire(URI.create("target"), URI.create("#ref"), contract, Wire.LOCAL_BINDING);
+ assertEquals(1, wire.getCallbackInvocationChains().size());
+ InvocationChain chain = wire.getCallbackInvocationChains().get(callbackOperation);
+ Interceptor head = chain.getHeadInterceptor();
+ assertTrue(head instanceof InvokerInterceptor);
+ }
+
+ public void testCreateNonBlockingForwardWire() throws Exception {
+ ServiceContract<Type> contract = new ServiceContract<Type>() {
+
+ };
+ Operation<Type> operation = new Operation<Type>("operation", null, null, null);
+ operation.setNonBlocking(true);
+ Map<String, Operation<Type>> operations = new HashMap<String, Operation<Type>>();
+ operations.put("operation", operation);
+ contract.setOperations(operations);
+ Wire wire = connector.createWire(URI.create("target"), URI.create("#ref"), contract, Wire.LOCAL_BINDING);
+ assertEquals(1, wire.getInvocationChains().size());
+ InvocationChain chain = wire.getInvocationChains().get(operation);
+ Interceptor head = chain.getHeadInterceptor();
+ assertTrue(head instanceof NonBlockingInterceptor);
+ assertTrue(head.getNext() instanceof InvokerInterceptor);
+ }
+
+ public void testCreateNonBlockingCallbackWire() throws Exception {
+ ServiceContract<Type> contract = new ServiceContract<Type>() {
+
+ };
+
+ Operation<Type> operation = new Operation<Type>("operation", null, null, null);
+ operation.setNonBlocking(true);
+ Map<String, Operation<Type>> operations = new HashMap<String, Operation<Type>>();
+ operations.put("operation", operation);
+ contract.setOperations(operations);
+
+ Operation<Type> callbackOperation = new Operation<Type>("operation", null, null, null);
+ callbackOperation.setNonBlocking(true);
+ Map<String, Operation<Type>> callbackOperations = new HashMap<String, Operation<Type>>();
+ callbackOperations.put("operation", callbackOperation);
+ contract.setCallbackOperations(callbackOperations);
+
+ Wire wire = connector.createWire(URI.create("target"), URI.create("#ref"), contract, Wire.LOCAL_BINDING);
+ assertEquals(1, wire.getCallbackInvocationChains().size());
+ InvocationChain chain = wire.getCallbackInvocationChains().get(callbackOperation);
+ Interceptor head = chain.getHeadInterceptor();
+ assertTrue(head instanceof NonBlockingInterceptor);
+ assertTrue(head.getNext() instanceof InvokerInterceptor);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ manager = new ComponentManagerImpl();
+ connector = new TestConnector(manager);
+ }
+
+ private class TestConnector extends ConnectorImpl {
+
+ public TestConnector(ComponentManager componentManager) {
+ super(componentManager);
+ }
+
+ protected Wire createWire(URI sourceURI, URI targetUri, ServiceContract<?> contract, QName bindingType) {
+ return super.createWire(sourceURI, targetUri, contract, bindingType);
+ }
+
+ public boolean isOptimizable(Scope pReferrer, Scope pReferee) {
+ return super.isOptimizable(pReferrer, pReferee);
+ }
+
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/builder/IllegalCallbackExceptionTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/builder/IllegalCallbackExceptionTestCase.java
new file mode 100644
index 0000000000..c6a9927db3
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/builder/IllegalCallbackExceptionTestCase.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.builder;
+
+import java.net.URI;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class IllegalCallbackExceptionTestCase extends TestCase {
+
+ public void testInstantiation() throws Exception {
+ URI sourceUri = URI.create("source");
+ URI targetUri = URI.create("target");
+ IllegalCallbackException e = new IllegalCallbackException("message", "identifier", sourceUri, targetUri);
+ assertEquals("message", e.getMessage());
+ assertEquals("identifier", e.getIdentifier());
+ assertEquals(sourceUri, e.getSourceUri());
+ assertEquals(targetUri, e.getTargetUri());
+
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/builder/IncompatibleInterfacesExceptionTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/builder/IncompatibleInterfacesExceptionTestCase.java
new file mode 100644
index 0000000000..5d370fcfc5
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/builder/IncompatibleInterfacesExceptionTestCase.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.builder;
+
+import java.net.URI;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class IncompatibleInterfacesExceptionTestCase extends TestCase {
+
+ public void testInstantiation() throws Exception {
+ URI sourceUri = URI.create("source");
+ URI targetUri = URI.create("target");
+ IncompatibleInterfacesException e = new IncompatibleInterfacesException(sourceUri, targetUri);
+ assertNotNull(e.getMessage());
+ assertEquals("source", e.getSourceUri().toString());
+ assertEquals("target", e.getTargetUri().toString());
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/builder/InvalidSourceTypeExceptionTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/builder/InvalidSourceTypeExceptionTestCase.java
new file mode 100644
index 0000000000..67ad003d58
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/builder/InvalidSourceTypeExceptionTestCase.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.builder;
+
+import java.net.URI;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class InvalidSourceTypeExceptionTestCase extends TestCase {
+
+ public void testInstantiation() throws Exception {
+ URI sourceUri = URI.create("source");
+ URI targetUri = URI.create("target");
+ InvalidSourceTypeException e = new InvalidSourceTypeException("message", sourceUri, targetUri);
+ assertEquals("message", e.getMessage());
+ assertEquals(sourceUri, e.getSourceUri());
+ assertEquals(targetUri, e.getTargetUri());
+
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/builder/InvalidTargetTypeExceptionTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/builder/InvalidTargetTypeExceptionTestCase.java
new file mode 100644
index 0000000000..61060293ce
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/builder/InvalidTargetTypeExceptionTestCase.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.builder;
+
+import java.net.URI;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class InvalidTargetTypeExceptionTestCase extends TestCase {
+
+ public void testInstantiation() throws Exception {
+ URI sourceUri = URI.create("source");
+ URI targetUri = URI.create("target");
+ InvalidTargetTypeException e = new InvalidTargetTypeException("message", sourceUri, targetUri);
+ assertEquals("message", e.getMessage());
+ assertEquals(sourceUri, e.getSourceUri());
+ assertEquals(targetUri, e.getTargetUri());
+
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/builder/ReferenceConnectorTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/builder/ReferenceConnectorTestCase.java
new file mode 100644
index 0000000000..53511db2cb
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/builder/ReferenceConnectorTestCase.java
@@ -0,0 +1,156 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.builder;
+
+import java.net.URI;
+
+import org.apache.tuscany.spi.builder.WiringException;
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.Reference;
+import org.apache.tuscany.spi.component.ReferenceBinding;
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.idl.java.JavaInterfaceProcessorRegistry;
+import org.apache.tuscany.spi.model.BindingDefinition;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.wire.Wire;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.component.ComponentManager;
+import org.apache.tuscany.core.component.ComponentManagerImpl;
+import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
+import org.apache.tuscany.core.implementation.composite.CompositeComponentImpl;
+import org.apache.tuscany.core.implementation.composite.ReferenceImpl;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ReferenceConnectorTestCase extends TestCase {
+ private static final URI PARENT = URI.create("parent");
+ private static final URI SOURCE = URI.create("parent#source");
+ private static final URI TARGET = URI.create("parent/target");
+ private static final URI REFERENCE_TARGET = URI.create("parent#target");
+ private ComponentManager manager;
+ private MockConnnector connector;
+ private ServiceContract<?> contract;
+
+ /**
+ * Verifies connecting a wire from an atomic component to a target atomic component
+ */
+ @SuppressWarnings({"unchecked"})
+ public void testConnectToAtomic() throws Exception {
+ ReferenceBinding binding = EasyMock.createMock(ReferenceBinding.class);
+ EasyMock.expect(binding.getTargetUri()).andReturn(TARGET);
+ EasyMock.expect(binding.getBindingType()).andReturn(Wire.LOCAL_BINDING).atLeastOnce();
+ binding.getBindingServiceContract();
+ EasyMock.expectLastCall().andReturn(contract);
+ binding.setWire(EasyMock.isA(Wire.class));
+ EasyMock.replay(binding);
+
+ Reference reference = new ReferenceImpl(SOURCE, contract);
+ reference.addReferenceBinding(binding);
+
+ Component component = new CompositeComponentImpl(PARENT);
+ component.register(reference);
+ manager.register(component);
+
+
+ AtomicComponent target = EasyMock.createMock(AtomicComponent.class);
+ EasyMock.expect(target.getUri()).andReturn(TARGET).atLeastOnce();
+ target.createTargetInvoker((String) EasyMock.isNull(), EasyMock.isA(Operation.class));
+ EasyMock.expectLastCall().andReturn(null);
+ EasyMock.replay(target);
+ manager.register(target);
+
+ ReferenceDefinition definition = new ReferenceDefinition(SOURCE, contract);
+ BindingDefinition bindingDefinition = new BindingDefinition(TARGET) {
+ };
+ definition.addBinding(bindingDefinition);
+
+ connector.connect(definition);
+
+ EasyMock.verify(binding);
+ EasyMock.verify(target);
+ }
+
+ @SuppressWarnings({"unchecked"})
+ public void testConnectToReference() throws Exception {
+ ReferenceBinding binding = EasyMock.createMock(ReferenceBinding.class);
+ EasyMock.expect(binding.getTargetUri()).andReturn(REFERENCE_TARGET);
+ EasyMock.expect(binding.getBindingType()).andReturn(Wire.LOCAL_BINDING).atLeastOnce();
+ binding.getBindingServiceContract();
+ EasyMock.expectLastCall().andReturn(contract);
+ binding.setWire(EasyMock.isA(Wire.class));
+ EasyMock.replay(binding);
+
+ Reference reference = new ReferenceImpl(SOURCE, contract);
+ reference.addReferenceBinding(binding);
+
+ Component component = new CompositeComponentImpl(PARENT);
+ component.register(reference);
+
+ ReferenceBinding refBinding = EasyMock.createMock(ReferenceBinding.class);
+ refBinding.createTargetInvoker(EasyMock.isA(String.class), EasyMock.isA(Operation.class));
+ EasyMock.expectLastCall().andReturn(null);
+ EasyMock.replay(refBinding);
+ Reference target = new ReferenceImpl(REFERENCE_TARGET, contract);
+ target.addReferenceBinding(refBinding);
+ component.register(target);
+ manager.register(component);
+
+ ReferenceDefinition definition = new ReferenceDefinition(SOURCE, contract);
+ BindingDefinition bindingDefinition = new BindingDefinition(TARGET) {
+ };
+ definition.addBinding(bindingDefinition);
+
+ connector.connect(definition);
+
+ EasyMock.verify(binding);
+ EasyMock.verify(refBinding);
+ }
+
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ manager = new ComponentManagerImpl();
+ connector = new MockConnnector(manager);
+ JavaInterfaceProcessorRegistry registry = new JavaInterfaceProcessorRegistryImpl();
+ contract = registry.introspect(Foo.class);
+ }
+
+
+ private interface Foo {
+ void bar();
+ }
+
+ private class MockConnnector extends ConnectorImpl {
+
+ public MockConnnector(ComponentManager componentManager) {
+ super(componentManager);
+ }
+
+ public void connect(ReferenceDefinition definition) throws WiringException {
+ super.connect(definition);
+ }
+ }
+
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/builder/ServiceConnectorTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/builder/ServiceConnectorTestCase.java
new file mode 100644
index 0000000000..32dede5a16
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/builder/ServiceConnectorTestCase.java
@@ -0,0 +1,152 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.builder;
+
+import java.net.URI;
+
+import org.apache.tuscany.spi.builder.WiringException;
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.Service;
+import org.apache.tuscany.spi.component.ServiceBinding;
+import org.apache.tuscany.spi.component.Reference;
+import org.apache.tuscany.spi.component.ReferenceBinding;
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.idl.java.JavaInterfaceProcessorRegistry;
+import org.apache.tuscany.spi.model.BindingDefinition;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+import org.apache.tuscany.spi.wire.Wire;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.component.ComponentManager;
+import org.apache.tuscany.core.component.ComponentManagerImpl;
+import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
+import org.apache.tuscany.core.implementation.composite.CompositeComponentImpl;
+import org.apache.tuscany.core.implementation.composite.ServiceImpl;
+import org.apache.tuscany.core.implementation.composite.ReferenceImpl;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ServiceConnectorTestCase extends TestCase {
+ private static final URI PARENT = URI.create("parent");
+ private static final URI SOURCE = URI.create("parent#source");
+ private static final URI TARGET = URI.create("parent/target");
+ private static final URI REFERENCE_TARGET = URI.create("parent#target");
+ private ComponentManager manager;
+ private MockConnnector connector;
+ private ServiceContract<?> contract;
+
+ /**
+ * Verifies connecting a wire from an atomic component to a target atomic component
+ */
+ @SuppressWarnings({"unchecked"})
+ public void testConnectToAtomic() throws Exception {
+ ServiceBinding binding = EasyMock.createMock(ServiceBinding.class);
+ EasyMock.expect(binding.getBindingType()).andReturn(Wire.LOCAL_BINDING);
+ binding.setWire(EasyMock.isA(Wire.class));
+ EasyMock.replay(binding);
+
+ Service service = new ServiceImpl(SOURCE, contract);
+ service.addServiceBinding(binding);
+
+ Component component = new CompositeComponentImpl(PARENT);
+ component.register(service);
+ manager.register(component);
+
+
+ AtomicComponent target = EasyMock.createMock(AtomicComponent.class);
+ EasyMock.expect(target.getUri()).andReturn(TARGET).atLeastOnce();
+ target.createTargetInvoker((String) EasyMock.isNull(), EasyMock.isA(Operation.class));
+ EasyMock.expectLastCall().andReturn(null);
+ EasyMock.replay(target);
+ manager.register(target);
+
+ ServiceDefinition definition = new ServiceDefinition(SOURCE, contract, false);
+ definition.setTarget(TARGET);
+ BindingDefinition bindingDefinition = new BindingDefinition(TARGET) {
+ };
+ definition.addBinding(bindingDefinition);
+ connector.connect(definition);
+
+ EasyMock.verify(binding);
+ EasyMock.verify(target);
+ }
+
+ @SuppressWarnings({"unchecked"})
+ public void testConnectToReference() throws Exception {
+ ServiceBinding binding = EasyMock.createMock(ServiceBinding.class);
+ EasyMock.expect(binding.getBindingType()).andReturn(Wire.LOCAL_BINDING);
+ binding.setWire(EasyMock.isA(Wire.class));
+ EasyMock.replay(binding);
+
+ Service service = new ServiceImpl(SOURCE, contract);
+ service.addServiceBinding(binding);
+
+ Component component = new CompositeComponentImpl(PARENT);
+ component.register(service);
+
+ ReferenceBinding refBinding = EasyMock.createMock(ReferenceBinding.class);
+ refBinding.createTargetInvoker(EasyMock.isA(String.class), EasyMock.isA(Operation.class));
+ EasyMock.expectLastCall().andReturn(null);
+ EasyMock.replay(refBinding);
+ Reference target = new ReferenceImpl(REFERENCE_TARGET, contract);
+ target.addReferenceBinding(refBinding);
+ component.register(target);
+ manager.register(component);
+
+ ServiceDefinition definition = new ServiceDefinition(SOURCE, contract, false);
+ definition.setTarget(REFERENCE_TARGET);
+ BindingDefinition bindingDefinition = new BindingDefinition(REFERENCE_TARGET) {
+ };
+ definition.addBinding(bindingDefinition);
+ connector.connect(definition);
+
+ EasyMock.verify(binding);
+ EasyMock.verify(refBinding);
+ }
+
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ manager = new ComponentManagerImpl();
+ connector = new MockConnnector(manager);
+ JavaInterfaceProcessorRegistry registry = new JavaInterfaceProcessorRegistryImpl();
+ contract = registry.introspect(Foo.class);
+ }
+
+
+ private interface Foo {
+ void bar();
+ }
+
+ private class MockConnnector extends ConnectorImpl {
+
+ public MockConnnector(ComponentManager componentManager) {
+ super(componentManager);
+ }
+
+ public void connect(ServiceDefinition definition) throws WiringException {
+ super.connect(definition);
+ }
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/builder/TargetServiceNotFoundExceptionTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/builder/TargetServiceNotFoundExceptionTestCase.java
new file mode 100644
index 0000000000..2d056ac964
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/builder/TargetServiceNotFoundExceptionTestCase.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.builder;
+
+import java.net.URI;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class TargetServiceNotFoundExceptionTestCase extends TestCase {
+
+ public void testInstantiation() throws Exception {
+ URI sourceUri = URI.create("source");
+ URI targetUri = URI.create("target");
+ TargetServiceNotFoundException e = new TargetServiceNotFoundException("message", sourceUri, targetUri);
+ assertEquals("message", e.getMessage());
+ assertEquals(sourceUri, e.getSourceUri());
+ assertEquals(targetUri, e.getTargetUri());
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/builder/WirePostProcessorRegistryImplTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/builder/WirePostProcessorRegistryImplTestCase.java
new file mode 100644
index 0000000000..fcd5f03189
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/builder/WirePostProcessorRegistryImplTestCase.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.builder;
+
+import org.apache.tuscany.spi.wire.Wire;
+import org.apache.tuscany.spi.wire.WirePostProcessor;
+import org.apache.tuscany.spi.wire.WirePostProcessorRegistry;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.verify;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class WirePostProcessorRegistryImplTestCase extends TestCase {
+
+ public void testRegisterUnregister() throws Exception {
+ WirePostProcessorRegistry registry = new WirePostProcessorRegistryImpl();
+ Wire wire = EasyMock.createMock(Wire.class);
+ WirePostProcessor processor = createMock(WirePostProcessor.class);
+ processor.process(EasyMock.eq(wire));
+ EasyMock.replay(processor);
+ registry.register(processor);
+ registry.process(wire);
+ registry.unregister(processor);
+ registry.process(wire);
+ verify(processor);
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/builder/WiringExceptionFormatterTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/builder/WiringExceptionFormatterTestCase.java
new file mode 100644
index 0000000000..e05a162d7a
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/builder/WiringExceptionFormatterTestCase.java
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.builder;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.net.URI;
+
+import org.apache.tuscany.spi.builder.WiringException;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.host.monitor.FormatterRegistry;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class WiringExceptionFormatterTestCase extends TestCase {
+ WiringExceptionFormatter formatter = new WiringExceptionFormatter(EasyMock.createNiceMock(FormatterRegistry.class));
+
+ public void testFormat() throws Exception {
+ WiringException e =
+ new MockWiringException("message", "identifier", URI.create("source"), URI.create("target"));
+ StringWriter writer = new StringWriter();
+ PrintWriter pw = new PrintWriter(writer);
+ formatter.write(pw, e);
+ String buffer = writer.toString();
+ assertTrue(buffer.indexOf("message") >= 0);
+ assertTrue(buffer.indexOf("identifier") >= 0);
+ assertTrue(buffer.indexOf("source") >= 0);
+ assertTrue(buffer.indexOf("target") >= 0);
+ }
+
+
+ public void testFormatNulls() throws Exception {
+ WiringException e = new MockWiringException("message",
+ "identifier",
+ null,
+ null);
+ StringWriter writer = new StringWriter();
+ PrintWriter pw = new PrintWriter(writer);
+ formatter.write(pw, e);
+ String buffer = writer.toString();
+ assertTrue(buffer.indexOf("message") >= 0);
+ assertTrue(buffer.indexOf("identifier") >= 0);
+ }
+
+ private class MockWiringException extends WiringException {
+
+ public MockWiringException(String message, String identifier, URI source, URI reference) {
+ super(message, identifier, source, reference);
+ }
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/ComponentContextImplTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/ComponentContextImplTestCase.java
new file mode 100644
index 0000000000..8bd25d3a16
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/ComponentContextImplTestCase.java
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.component;
+
+import java.net.URI;
+
+import junit.framework.TestCase;
+import org.easymock.classextension.EasyMock;
+
+import org.apache.tuscany.core.implementation.PojoAtomicComponent;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ComponentContextImplTestCase extends TestCase {
+ private PojoAtomicComponent component;
+ private ComponentContextImpl context;
+
+ public void testURI() {
+ URI uri = URI.create("foo");
+ EasyMock.expect(component.getUri()).andReturn(uri);
+ EasyMock.replay(component);
+ assertEquals(uri.toString(), context.getURI());
+ EasyMock.verify(component);
+ }
+
+ public void testGetProperty() {
+ String name = "foo";
+ String value = "bar";
+ EasyMock.expect(component.getProperty(String.class, name)).andReturn(value);
+ EasyMock.replay(component);
+ assertSame(value, context.getProperty(String.class, name));
+ EasyMock.verify(component);
+ }
+
+ public void testGetPropertyThatIsIncompatible() {
+ String name = "foo";
+ EasyMock.expect(component.getProperty(Integer.class, name)).andThrow(new ClassCastException());
+ EasyMock.replay(component);
+ try {
+ context.getProperty(Integer.class, name);
+ fail();
+ } catch (ClassCastException e) {
+ // expected
+ }
+ EasyMock.verify(component);
+ }
+
+ public void testGetPropertyThatIsSubclass() {
+ String name = "foo";
+ String value = "bar";
+ EasyMock.expect(component.getProperty(Object.class, name)).andReturn(value);
+ EasyMock.replay(component);
+ assertSame(value, context.getProperty(Object.class, name));
+ EasyMock.verify(component);
+ }
+
+ public void testGetService() {
+ String name = "foo";
+ FooService service = EasyMock.createMock(FooService.class);
+ EasyMock.expect(component.getService(FooService.class, name)).andReturn(service);
+ EasyMock.replay(component);
+ assertSame(service, context.getService(FooService.class, name));
+ EasyMock.verify(component);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ component = EasyMock.createMock(PojoAtomicComponent.class);
+ context = new ComponentContextImpl(component);
+ }
+
+ public interface FooService {
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/ComponentManagerImplTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/ComponentManagerImplTestCase.java
new file mode 100644
index 0000000000..c1710e9b8e
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/ComponentManagerImplTestCase.java
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.component;
+
+import java.net.URI;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.component.DuplicateNameException;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ComponentManagerImplTestCase extends TestCase {
+ private static final URI DOMAIN = URI.create("sca://localhost/");
+ private static final URI ROOT1 = DOMAIN.resolve("root1");
+ private static final URI GRANDCHILD = DOMAIN.resolve("parent/child2/grandchild");
+
+ private ComponentManagerImpl manager;
+
+ public void testRegister() throws Exception {
+ Component root = EasyMock.createMock(Component.class);
+ EasyMock.expect(root.getUri()).andReturn(ROOT1);
+ EasyMock.replay(root);
+ manager.register(root);
+ assertEquals(root, manager.getComponent(ROOT1));
+ EasyMock.verify(root);
+
+ EasyMock.reset(root);
+ EasyMock.expect(root.getUri()).andReturn(ROOT1);
+ EasyMock.replay(root);
+ manager.unregister(root);
+ EasyMock.verify(root);
+ assertEquals(null, manager.getComponent(ROOT1));
+ }
+
+ public void testRegisterGrandchild() throws Exception {
+ Component root = EasyMock.createMock(Component.class);
+ EasyMock.expect(root.getUri()).andReturn(GRANDCHILD);
+ EasyMock.replay(root);
+ manager.register(root);
+ assertEquals(root, manager.getComponent(GRANDCHILD));
+ EasyMock.verify(root);
+ }
+
+ public void testRegisterDuplicate() throws Exception {
+ Component root = EasyMock.createMock(Component.class);
+ EasyMock.expect(root.getUri()).andReturn(ROOT1);
+ EasyMock.replay(root);
+
+ Component duplicate = EasyMock.createMock(Component.class);
+ EasyMock.expect(duplicate.getUri()).andReturn(ROOT1);
+ EasyMock.replay(duplicate);
+
+ manager.register(root);
+ assertEquals(root, manager.getComponent(ROOT1));
+ try {
+ manager.register(duplicate);
+ fail();
+ } catch (DuplicateNameException e) {
+ // expected
+ }
+ assertEquals(root, manager.getComponent(ROOT1));
+ EasyMock.verify(root);
+ EasyMock.verify(duplicate);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ manager = new ComponentManagerImpl();
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/JavaObjectRegistrationTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/JavaObjectRegistrationTestCase.java
new file mode 100644
index 0000000000..e2ffb770fd
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/JavaObjectRegistrationTestCase.java
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.component;
+
+import java.net.URI;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.component.DuplicateNameException;
+import org.apache.tuscany.spi.model.ServiceContract;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class JavaObjectRegistrationTestCase extends TestCase {
+ private ComponentManager componentManager;
+
+ public void testRegistration() throws Exception {
+ MockComponent instance = new MockComponent();
+ URI uri = URI.create("foo");
+ ServiceContract<MockComponent> contract = new ServiceContract<MockComponent>(MockComponent.class) {
+ };
+ componentManager.registerJavaObject(uri, contract, instance);
+ Component component = componentManager.getComponent(URI.create("foo"));
+ assertTrue(component instanceof AtomicComponent);
+ MockComponent resolvedInstance = (MockComponent) ((AtomicComponent) component).getTargetInstance();
+ assertSame(instance, resolvedInstance);
+ }
+
+ public void testDuplicateRegistration() throws Exception {
+ MockComponent instance = new MockComponent();
+ URI uri = URI.create("foo");
+ ServiceContract<MockComponent> contract = new ServiceContract<MockComponent>(MockComponent.class) {
+ };
+ componentManager.registerJavaObject(uri, contract, instance);
+ try {
+ componentManager.registerJavaObject(uri, contract, instance);
+ fail();
+ } catch (DuplicateNameException e) {
+ // ok
+ }
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ componentManager = new ComponentManagerImpl();
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ private static class MockComponent {
+ public String hello(String message) {
+ return message;
+ }
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/SystemSingletonAtomicComponentTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/SystemSingletonAtomicComponentTestCase.java
new file mode 100644
index 0000000000..efa7456a52
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/SystemSingletonAtomicComponentTestCase.java
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.component;
+
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.tuscany.spi.component.TargetException;
+import org.apache.tuscany.spi.model.ServiceContract;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class SystemSingletonAtomicComponentTestCase extends TestCase {
+
+ public void testGetInstance() throws TargetException {
+ ServiceContract<Foo> contract = new ServiceContract<Foo>(Foo.class) {
+
+ };
+ FooImpl foo = new FooImpl();
+ SystemSingletonAtomicComponent<Foo, FooImpl> component =
+ new SystemSingletonAtomicComponent<Foo, FooImpl>(URI.create("foo"), contract, foo);
+ assertEquals(foo, component.getTargetInstance());
+ }
+
+ public void testGetInstanceMultipleServices() throws TargetException {
+ FooImpl foo = new FooImpl();
+ List<ServiceContract<?>> services = new ArrayList<ServiceContract<?>>();
+ services.add(new ServiceContract<Foo>(Foo.class) {
+ });
+ services.add(new ServiceContract<Bar>(Bar.class) {
+ });
+ SystemSingletonAtomicComponent<Foo, FooImpl> component =
+ new SystemSingletonAtomicComponent<Foo, FooImpl>(URI.create("foo"), services, foo);
+ assertEquals(foo, component.getTargetInstance());
+ }
+
+ public void testOptimizable() {
+ ServiceContract<Foo> contract = new ServiceContract<Foo>(Foo.class) {
+ };
+ FooImpl foo = new FooImpl();
+ SystemSingletonAtomicComponent<Foo, FooImpl> component =
+ new SystemSingletonAtomicComponent<Foo, FooImpl>(URI.create("foo"), contract, foo);
+ assertTrue(component.isOptimizable());
+ }
+
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ private interface Foo {
+
+ }
+
+ private interface Bar {
+
+ }
+
+ private class FooImpl implements Foo, Bar {
+
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/WorkContextImplTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/WorkContextImplTestCase.java
new file mode 100644
index 0000000000..aee910ddaf
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/WorkContextImplTestCase.java
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.component;
+
+import org.apache.tuscany.spi.component.WorkContext;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class WorkContextImplTestCase extends TestCase {
+
+ public void testPushPopServiceNames() throws Exception {
+ WorkContext context = new WorkContextImpl();
+ context.pushServiceName("foo");
+ context.pushServiceName("bar");
+ assertEquals("bar", context.getCurrentServiceName());
+ assertEquals("bar", context.popServiceName());
+ assertEquals("foo", context.getCurrentServiceName());
+ assertEquals("foo", context.popServiceName());
+ assertNull(context.getCurrentServiceName());
+ }
+
+ public void testGetCurrentServiceNamesNull() throws Exception {
+ WorkContext context = new WorkContextImpl();
+ assertNull(context.getCurrentServiceName());
+ }
+
+ public void testPopCurrentServiceNamesNull() throws Exception {
+ WorkContext context = new WorkContextImpl();
+ assertNull(context.popServiceName());
+ }
+
+ public void testClearServiceNames() throws Exception {
+ WorkContext context = new WorkContextImpl();
+ context.pushServiceName("foo");
+ context.pushServiceName("bar");
+ context.clearServiceNames();
+ assertNull(context.getCurrentServiceName());
+ }
+
+ public void testClearServiceNamesNull() throws Exception {
+ WorkContext context = new WorkContextImpl();
+ context.clearServiceNames();
+ assertNull(context.getCurrentServiceName());
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/event/EventTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/event/EventTestCase.java
new file mode 100644
index 0000000000..93cb50ddcb
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/event/EventTestCase.java
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.component.event;
+
+import java.net.URI;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class EventTestCase extends TestCase {
+ private URI uri = URI.create("foo");
+
+ public void testCompositeStart() {
+ ComponentStart event = new ComponentStart(this, uri);
+ assertEquals(uri, event.getComponentUri());
+ }
+
+ public void testCompositeStop() {
+ ComponentStop event = new ComponentStop(this, uri);
+ assertEquals(uri, event.getComponentUri());
+ }
+
+ public void testHttpSessionStart() {
+ Object id = new Object();
+ HttpSessionEvent event = new HttpSessionStart(this, id);
+ assertEquals(this, event.getSource());
+ assertEquals(id, event.getId());
+ }
+
+ public void testHttpSessionEnd() {
+ Object id = new Object();
+ HttpSessionEvent event = new HttpSessionEnd(this, id);
+ assertEquals(this, event.getSource());
+ assertEquals(id, event.getId());
+ }
+
+ public void testRequestStart() {
+ RequestStart event = new RequestStart(this);
+ assertEquals(this, event.getSource());
+ }
+
+ public void testReequestEnd() {
+ RequestEnd event = new RequestEnd(this);
+ assertEquals(this, event.getSource());
+ }
+
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/AbstractScopeContainerTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/AbstractScopeContainerTestCase.java
new file mode 100644
index 0000000000..f8f8dd5f60
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/AbstractScopeContainerTestCase.java
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.component.scope;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.event.Event;
+import org.apache.tuscany.spi.event.EventFilter;
+import org.apache.tuscany.spi.event.RuntimeEventListener;
+import org.apache.tuscany.spi.event.TrueFilter;
+import org.apache.tuscany.spi.model.Scope;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class AbstractScopeContainerTestCase extends TestCase {
+
+ public void testFireListener() {
+ TestContainer container = new TestContainer("foo");
+ RuntimeEventListener listener = EasyMock.createMock(RuntimeEventListener.class);
+ Event event = new TestEvent();
+ listener.onEvent(EasyMock.eq(event));
+ EasyMock.replay(listener);
+ container.addListener(listener);
+ container.publish(event);
+ EasyMock.verify(listener);
+ }
+
+ public void testRemoveListener() {
+ TestContainer container = new TestContainer("foo");
+ RuntimeEventListener listener = EasyMock.createMock(RuntimeEventListener.class);
+ EasyMock.replay(listener);
+ Event event = new TestEvent();
+ container.addListener(listener);
+ container.removeListener(listener);
+ container.publish(event);
+ EasyMock.verify(listener);
+ }
+
+ public void testFalseFilterListener() {
+ TestContainer container = new TestContainer("foo");
+ RuntimeEventListener listener = EasyMock.createMock(RuntimeEventListener.class);
+ Event event = new TestEvent();
+ EasyMock.replay(listener);
+ container.addListener(new FalseFilter(), listener);
+ container.publish(event);
+ EasyMock.verify(listener);
+ }
+
+ public void testTrueFilterListener() {
+ TestContainer container = new TestContainer("foo");
+ RuntimeEventListener listener = EasyMock.createMock(RuntimeEventListener.class);
+ Event event = new TestEvent();
+ listener.onEvent(EasyMock.eq(event));
+ EasyMock.replay(listener);
+ container.addListener(new TrueFilter(), listener);
+ container.publish(event);
+ EasyMock.verify(listener);
+ }
+
+ public void testToString() {
+ TestContainer container = new TestContainer("foo");
+ assertNotNull(container.toString());
+ }
+
+ private class TestContainer extends AbstractScopeContainer {
+
+ public TestContainer(String name) {
+ super(null, null);
+ }
+
+ protected InstanceWrapper getInstanceWrapper(AtomicComponent component, boolean create) {
+ return null;
+ }
+
+ public Scope getScope() {
+ return null;
+ }
+
+ public void register(AtomicComponent component) {
+
+ }
+
+ public void onEvent(Event event) {
+
+ }
+
+ public WorkContext getWorkContext() {
+ return super.getWorkContext();
+ }
+ }
+
+ private class TestEvent implements Event {
+ public Object getSource() {
+ return null;
+ }
+ }
+
+ private class FalseFilter implements EventFilter {
+
+ public boolean match(Event event) {
+ return false;
+ }
+ }
+
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/BasicCompositeScopeTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/BasicCompositeScopeTestCase.java
new file mode 100644
index 0000000000..b07de8a677
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/BasicCompositeScopeTestCase.java
@@ -0,0 +1,134 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.component.scope;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.TargetNotFoundException;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.component.event.ComponentStop;
+import org.apache.tuscany.core.implementation.PojoConfiguration;
+import org.apache.tuscany.core.implementation.system.component.SystemAtomicComponentImpl;
+import org.apache.tuscany.core.injection.EventInvoker;
+import org.apache.tuscany.core.injection.MethodEventInvoker;
+import org.apache.tuscany.core.injection.PojoObjectFactory;
+import org.apache.tuscany.core.mock.component.CompositeScopeInitDestroyComponent;
+
+/**
+ * @version $$Rev$$ $$Date$$
+ */
+public class BasicCompositeScopeTestCase extends TestCase {
+
+ private EventInvoker<Object> initInvoker;
+ private EventInvoker<Object> destroyInvoker;
+ private PojoObjectFactory<?> factory;
+
+ public void testLifecycleManagement() throws Exception {
+ CompositeScopeContainer scopeContext = new CompositeScopeContainer(null);
+ scopeContext.start();
+ AtomicComponent component = createComponent(scopeContext);
+ // start the request
+ CompositeScopeInitDestroyComponent o1 =
+ (CompositeScopeInitDestroyComponent) scopeContext.getInstance(component);
+ assertTrue(o1.isInitialized());
+ assertFalse(o1.isDestroyed());
+ CompositeScopeInitDestroyComponent o2 =
+ (CompositeScopeInitDestroyComponent) scopeContext.getInstance(component);
+ assertEquals(o1, o2);
+ scopeContext.onEvent(new ComponentStop(this, null));
+ assertTrue(o1.isDestroyed());
+ scopeContext.stop();
+ }
+
+
+ public void testGetAssociatedInstance() throws Exception {
+ CompositeScopeContainer scopeContext = new CompositeScopeContainer(null);
+ scopeContext.start();
+ AtomicComponent component = createComponent(scopeContext);
+ // start the request
+ scopeContext.getInstance(component);
+ scopeContext.getAssociatedInstance(component);
+ }
+
+ public void testGetAssociatedInstanceNonExistent() throws Exception {
+ CompositeScopeContainer scopeContext = new CompositeScopeContainer(null);
+ scopeContext.start();
+ AtomicComponent component = createComponent(scopeContext);
+ // start the request
+ try {
+ scopeContext.getAssociatedInstance(component);
+ fail();
+ } catch (TargetNotFoundException e) {
+ // expected
+ }
+ }
+
+ public void testCompositeIsolation() throws Exception {
+ CompositeScopeContainer scopeContext = new CompositeScopeContainer(null);
+ scopeContext.start();
+
+ AtomicComponent component = createComponent(scopeContext);
+
+ CompositeScopeInitDestroyComponent o1 =
+ (CompositeScopeInitDestroyComponent) scopeContext.getInstance(component);
+ assertTrue(o1.isInitialized());
+ assertFalse(o1.isDestroyed());
+
+ CompositeScopeInitDestroyComponent o2 =
+ (CompositeScopeInitDestroyComponent) scopeContext.getInstance(component);
+ assertSame(o1, o2);
+ scopeContext.onEvent(new ComponentStop(this, null));
+ assertTrue(o1.isDestroyed());
+ scopeContext.stop();
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ factory = new PojoObjectFactory<CompositeScopeInitDestroyComponent>(
+ CompositeScopeInitDestroyComponent.class.getConstructor((Class[]) null));
+ initInvoker = new MethodEventInvoker<Object>(CompositeScopeInitDestroyComponent.class.getMethod(
+ "init", (Class[]) null));
+ destroyInvoker = new MethodEventInvoker<Object>(CompositeScopeInitDestroyComponent.class.getMethod(
+ "destroy", (Class[]) null));
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ private AtomicComponent createComponent(ScopeContainer scopeContainer) {
+ PojoConfiguration configuration = new PojoConfiguration();
+ configuration.setInstanceFactory(factory);
+ configuration.setInitInvoker(initInvoker);
+ configuration.setDestroyInvoker(destroyInvoker);
+ try {
+ configuration.setName(new URI("foo"));
+ } catch (URISyntaxException e) {
+ // will not happen
+ }
+ SystemAtomicComponentImpl component = new SystemAtomicComponentImpl(configuration);
+ component.setScopeContainer(scopeContainer);
+ component.start();
+ return component;
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/BasicConversationalScopeTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/BasicConversationalScopeTestCase.java
new file mode 100644
index 0000000000..d15bfff4be
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/BasicConversationalScopeTestCase.java
@@ -0,0 +1,136 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.component.scope;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.services.store.StoreMonitor;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.component.WorkContextImpl;
+import org.apache.tuscany.core.component.event.ConversationEnd;
+import org.apache.tuscany.core.implementation.PojoConfiguration;
+import org.apache.tuscany.core.implementation.system.component.SystemAtomicComponentImpl;
+import org.apache.tuscany.core.injection.EventInvoker;
+import org.apache.tuscany.core.injection.MethodEventInvoker;
+import org.apache.tuscany.core.injection.PojoObjectFactory;
+import org.apache.tuscany.core.mock.component.ConversationalScopeInitDestroyComponent;
+import org.apache.tuscany.core.services.store.memory.MemoryStore;
+import org.easymock.EasyMock;
+
+/**
+ * @version $$Rev: 471111 $$ $$Date: 2006-11-03 23:06:48 -0500 (Fri, 03 Nov 2006) $$
+ */
+public class BasicConversationalScopeTestCase extends TestCase {
+
+ private EventInvoker<Object> initInvoker;
+ private EventInvoker<Object> destroyInvoker;
+ private PojoObjectFactory<?> factory;
+
+ public void testLifecycleManagement() throws Exception {
+ StoreMonitor monitor = EasyMock.createMock(StoreMonitor.class);
+ monitor.start(EasyMock.isA(String.class));
+ monitor.stop(EasyMock.isA(String.class));
+ MemoryStore store = new MemoryStore(monitor);
+ WorkContext workContext = new WorkContextImpl();
+ ConversationalScopeContainer scopeContext = new ConversationalScopeContainer(store, workContext, null);
+ scopeContext.start();
+ AtomicComponent atomicContext = createContext(scopeContext);
+ // start the request
+ String conversation = "conv";
+ workContext.setIdentifier(Scope.CONVERSATION, conversation);
+ ConversationalScopeInitDestroyComponent o1 =
+ (ConversationalScopeInitDestroyComponent) scopeContext.getInstance(atomicContext);
+ //assertTrue(o1.isInitialized());
+ assertFalse(o1.isDestroyed());
+ ConversationalScopeInitDestroyComponent o2 =
+ (ConversationalScopeInitDestroyComponent) scopeContext.getInstance(atomicContext);
+ assertSame(o1, o2);
+ scopeContext.onEvent(new ConversationEnd(this, conversation));
+ //assertTrue(o1.isDestroyed());
+ scopeContext.stop();
+ }
+
+ public void testCompositeIsolation() throws Exception {
+ StoreMonitor monitor = EasyMock.createMock(StoreMonitor.class);
+ monitor.start(EasyMock.isA(String.class));
+ monitor.stop(EasyMock.isA(String.class));
+ MemoryStore store = new MemoryStore(monitor);
+ WorkContext workContext = new WorkContextImpl();
+ ConversationalScopeContainer scopeContext = new ConversationalScopeContainer(store, workContext, null);
+ scopeContext.start();
+
+ AtomicComponent atomicContext = createContext(scopeContext);
+
+ String conversation1 = "conv";
+ workContext.setIdentifier(Scope.CONVERSATION, conversation1);
+ ConversationalScopeInitDestroyComponent o1 =
+ (ConversationalScopeInitDestroyComponent) scopeContext.getInstance(atomicContext);
+ //assertTrue(o1.isInitialized());
+ assertFalse(o1.isDestroyed());
+
+ String conversation2 = "conv2";
+ workContext.setIdentifier(Scope.CONVERSATION, conversation2);
+ ConversationalScopeInitDestroyComponent o2 =
+ (ConversationalScopeInitDestroyComponent) scopeContext.getInstance(atomicContext);
+ assertNotSame(o1, o2);
+
+ scopeContext.onEvent(new ConversationEnd(this, conversation1));
+ //assertTrue(o1.isDestroyed());
+ assertFalse(o2.isDestroyed());
+ scopeContext.onEvent(new ConversationEnd(this, conversation2));
+ //assertTrue(o2.isDestroyed());
+ scopeContext.stop();
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ factory = new PojoObjectFactory<ConversationalScopeInitDestroyComponent>(
+ ConversationalScopeInitDestroyComponent.class.getConstructor((Class[]) null));
+ initInvoker = new MethodEventInvoker<Object>(
+ ConversationalScopeInitDestroyComponent.class.getMethod("init", (Class[]) null));
+ destroyInvoker = new MethodEventInvoker<Object>(
+ ConversationalScopeInitDestroyComponent.class.getMethod("destroy", (Class[]) null));
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ private AtomicComponent createContext(ScopeContainer scopeContainer) {
+ PojoConfiguration configuration = new PojoConfiguration();
+ configuration.setInstanceFactory(factory);
+ configuration.setInitInvoker(initInvoker);
+ configuration.setDestroyInvoker(destroyInvoker);
+ try {
+ configuration.setName(new URI("foo"));
+ } catch (URISyntaxException e) {
+ // will not happen
+ }
+ SystemAtomicComponentImpl component = new SystemAtomicComponentImpl(configuration);
+ component.setScopeContainer(scopeContainer);
+ component.start();
+ return component;
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/BasicHttpSessionScopeTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/BasicHttpSessionScopeTestCase.java
new file mode 100644
index 0000000000..9392e92159
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/BasicHttpSessionScopeTestCase.java
@@ -0,0 +1,152 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.component.scope;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.TargetNotFoundException;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.model.Scope;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.component.WorkContextImpl;
+import org.apache.tuscany.core.component.event.HttpSessionEnd;
+import org.apache.tuscany.core.implementation.PojoConfiguration;
+import org.apache.tuscany.core.implementation.system.component.SystemAtomicComponentImpl;
+import org.apache.tuscany.core.injection.EventInvoker;
+import org.apache.tuscany.core.injection.MethodEventInvoker;
+import org.apache.tuscany.core.injection.PojoObjectFactory;
+import org.apache.tuscany.core.mock.component.SessionScopeInitDestroyComponent;
+
+/**
+ * @version $$Rev$$ $$Date$$
+ */
+public class BasicHttpSessionScopeTestCase extends TestCase {
+ private EventInvoker<Object> initInvoker;
+ private EventInvoker<Object> destroyInvoker;
+ private PojoObjectFactory<?> factory;
+
+ public void testLifecycleManagement() throws Exception {
+ WorkContext workContext = new WorkContextImpl();
+ HttpSessionScopeContainer scopeContext = new HttpSessionScopeContainer(workContext, null);
+ scopeContext.start();
+ AtomicComponent component = createComponent(scopeContext);
+ // start the request
+ Object session = new Object();
+ workContext.setIdentifier(Scope.SESSION, session);
+ SessionScopeInitDestroyComponent o1 =
+ (SessionScopeInitDestroyComponent) scopeContext.getInstance(component);
+ assertTrue(o1.isInitialized());
+ assertFalse(o1.isDestroyed());
+ SessionScopeInitDestroyComponent o2 =
+ (SessionScopeInitDestroyComponent) scopeContext.getInstance(component);
+ assertSame(o1, o2);
+ scopeContext.onEvent(new HttpSessionEnd(this, session));
+ assertTrue(o1.isDestroyed());
+ scopeContext.stop();
+ }
+
+ public void testGetAssociatedInstance() throws Exception {
+ WorkContext workContext = new WorkContextImpl();
+ HttpSessionScopeContainer scopeContext = new HttpSessionScopeContainer(workContext, null);
+ scopeContext.start();
+ AtomicComponent component = createComponent(scopeContext);
+ // start the request
+ Object session = new Object();
+ workContext.setIdentifier(Scope.SESSION, session);
+ scopeContext.getInstance(component);
+ scopeContext.getAssociatedInstance(component);
+ }
+
+ public void testGetAssociatedInstanceNonExistent() throws Exception {
+ WorkContext workContext = new WorkContextImpl();
+ HttpSessionScopeContainer scopeContext = new HttpSessionScopeContainer(workContext, null);
+ scopeContext.start();
+ AtomicComponent component = createComponent(scopeContext);
+ // start the request
+ Object session = new Object();
+ workContext.setIdentifier(Scope.SESSION, session);
+ try {
+ scopeContext.getAssociatedInstance(component);
+ fail();
+ } catch (TargetNotFoundException e) {
+ // expected
+ }
+ }
+
+ public void testSessionIsolation() throws Exception {
+ WorkContext workContext = new WorkContextImpl();
+ HttpSessionScopeContainer scopeContext = new HttpSessionScopeContainer(workContext, null);
+ scopeContext.start();
+
+ AtomicComponent component = createComponent(scopeContext);
+
+ Object session1 = new Object();
+ workContext.setIdentifier(Scope.SESSION, session1);
+ SessionScopeInitDestroyComponent o1 =
+ (SessionScopeInitDestroyComponent) scopeContext.getInstance(component);
+ assertTrue(o1.isInitialized());
+
+ Object session2 = new Object();
+ workContext.setIdentifier(Scope.SESSION, session2);
+ SessionScopeInitDestroyComponent o2 =
+ (SessionScopeInitDestroyComponent) scopeContext.getInstance(component);
+ assertNotSame(o1, o2);
+
+ scopeContext.onEvent(new HttpSessionEnd(this, session1));
+ assertTrue(o1.isDestroyed());
+ assertFalse(o2.isDestroyed());
+ scopeContext.onEvent(new HttpSessionEnd(this, session2));
+ assertTrue(o2.isDestroyed());
+ scopeContext.stop();
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ factory = new PojoObjectFactory<SessionScopeInitDestroyComponent>(
+ SessionScopeInitDestroyComponent.class.getConstructor((Class[]) null));
+ initInvoker = new MethodEventInvoker<Object>(
+ SessionScopeInitDestroyComponent.class.getMethod("init", (Class[]) null));
+ destroyInvoker = new MethodEventInvoker<Object>(
+ SessionScopeInitDestroyComponent.class.getMethod("destroy", (Class[]) null));
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ private AtomicComponent createComponent(ScopeContainer scopeContainer) {
+ PojoConfiguration configuration = new PojoConfiguration();
+ configuration.setInstanceFactory(factory);
+ configuration.setInitInvoker(initInvoker);
+ configuration.setDestroyInvoker(destroyInvoker);
+ try {
+ configuration.setName(new URI("foo"));
+ } catch (URISyntaxException e) {
+ // will not happen
+ }
+ SystemAtomicComponentImpl component = new SystemAtomicComponentImpl(configuration);
+ component.setScopeContainer(scopeContainer);
+ component.start();
+ return component;
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/BasicRequestScopeTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/BasicRequestScopeTestCase.java
new file mode 100644
index 0000000000..aa2f55d57f
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/BasicRequestScopeTestCase.java
@@ -0,0 +1,135 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.component.scope;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.TargetNotFoundException;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.component.event.RequestEnd;
+import org.apache.tuscany.core.implementation.PojoConfiguration;
+import org.apache.tuscany.core.implementation.system.component.SystemAtomicComponentImpl;
+import org.apache.tuscany.core.injection.EventInvoker;
+import org.apache.tuscany.core.injection.MethodEventInvoker;
+import org.apache.tuscany.core.injection.PojoObjectFactory;
+import org.apache.tuscany.core.mock.component.RequestScopeInitDestroyComponent;
+
+/**
+ * @version $$Rev$$ $$Date$$
+ */
+public class BasicRequestScopeTestCase extends TestCase {
+ private EventInvoker<Object> initInvoker;
+ private EventInvoker<Object> destroyInvoker;
+ private PojoObjectFactory<?> factory;
+
+ public void testLifecycleManagement() throws Exception {
+ RequestScopeContainer scopeContainer = new RequestScopeContainer(null, null);
+ scopeContainer.start();
+ AtomicComponent component = createComponent(scopeContainer);
+ // start the request
+ RequestScopeInitDestroyComponent o1 =
+ (RequestScopeInitDestroyComponent) scopeContainer.getInstance(component);
+ assertTrue(o1.isInitialized());
+ assertFalse(o1.isDestroyed());
+ RequestScopeInitDestroyComponent o2 =
+ (RequestScopeInitDestroyComponent) scopeContainer.getInstance(component);
+ assertSame(o1, o2);
+ scopeContainer.onEvent(new RequestEnd(this));
+ assertTrue(o1.isDestroyed());
+ scopeContainer.stop();
+ }
+
+ public void testGetAssociatedInstance() throws Exception {
+ RequestScopeContainer scopeContainer = new RequestScopeContainer(null, null);
+ scopeContainer.start();
+ AtomicComponent component = createComponent(scopeContainer);
+ // start the request
+ scopeContainer.getInstance(component);
+ scopeContainer.getAssociatedInstance(component);
+ scopeContainer.stop();
+ }
+
+ public void testGetAssociatedInstanceNonExistent() throws Exception {
+ RequestScopeContainer scopeContainer = new RequestScopeContainer(null, null);
+ scopeContainer.start();
+ AtomicComponent component = createComponent(scopeContainer);
+ // start the request
+ try {
+ scopeContainer.getAssociatedInstance(component);
+ fail();
+ } catch (TargetNotFoundException e) {
+ // expected
+ }
+ scopeContainer.stop();
+ }
+
+ public void testRequestIsolation() throws Exception {
+ RequestScopeContainer scopeContainer = new RequestScopeContainer(null, null);
+ scopeContainer.start();
+
+ AtomicComponent component = createComponent(scopeContainer);
+
+ RequestScopeInitDestroyComponent o1 =
+ (RequestScopeInitDestroyComponent) scopeContainer.getInstance(component);
+ assertTrue(o1.isInitialized());
+ scopeContainer.onEvent(new RequestEnd(this));
+ assertTrue(o1.isDestroyed());
+
+ RequestScopeInitDestroyComponent o2 =
+ (RequestScopeInitDestroyComponent) scopeContainer.getInstance(component);
+ assertNotSame(o1, o2);
+ scopeContainer.onEvent(new RequestEnd(this));
+ assertTrue(o2.isDestroyed());
+ scopeContainer.stop();
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ factory = new PojoObjectFactory<RequestScopeInitDestroyComponent>(
+ RequestScopeInitDestroyComponent.class.getConstructor((Class[]) null));
+ initInvoker = new MethodEventInvoker<Object>(
+ RequestScopeInitDestroyComponent.class.getMethod("init", (Class[]) null));
+ destroyInvoker = new MethodEventInvoker<Object>(
+ RequestScopeInitDestroyComponent.class.getMethod("destroy", (Class[]) null));
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ private AtomicComponent createComponent(ScopeContainer scopeContainer) {
+ PojoConfiguration configuration = new PojoConfiguration();
+ configuration.setInstanceFactory(factory);
+ configuration.setInitInvoker(initInvoker);
+ configuration.setDestroyInvoker(destroyInvoker);
+ try {
+ configuration.setName(new URI("foo"));
+ } catch (URISyntaxException e) {
+ // will not happen
+ }
+ SystemAtomicComponentImpl component = new SystemAtomicComponentImpl(configuration);
+ component.setScopeContainer(scopeContainer);
+ component.start();
+ return component;
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/BasicStatelessScopeTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/BasicStatelessScopeTestCase.java
new file mode 100644
index 0000000000..ca1bd2a35a
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/BasicStatelessScopeTestCase.java
@@ -0,0 +1,127 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.component.scope;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.TargetNotFoundException;
+import org.apache.tuscany.spi.component.WorkContext;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+import org.apache.tuscany.core.component.WorkContextImpl;
+import org.apache.tuscany.core.implementation.PojoConfiguration;
+import org.apache.tuscany.core.implementation.system.component.SystemAtomicComponentImpl;
+import org.apache.tuscany.core.injection.PojoObjectFactory;
+import org.apache.tuscany.core.mock.component.StatelessComponent;
+import org.apache.tuscany.core.mock.component.StatelessComponentImpl;
+
+/**
+ * Unit tests for the composite scope container
+ *
+ * @version $Rev$ $Date$
+ */
+public class BasicStatelessScopeTestCase extends TestCase {
+ private PojoObjectFactory<StatelessComponentImpl> factory;
+
+ /**
+ * Verfies instance identity is properly maintained
+ */
+ public void testInstanceManagement() throws Exception {
+ WorkContext ctx = new WorkContextImpl();
+ StatelessScopeContainer scope = new StatelessScopeContainer(ctx, null);
+ scope.start();
+ AtomicComponent component1 = createComponent(scope);
+ scope.register(component1);
+ AtomicComponent component2 = createComponent(scope);
+ scope.register(component2);
+ StatelessComponentImpl comp1 = (StatelessComponentImpl) scope.getInstance(component1);
+ Assert.assertNotNull(comp1);
+ StatelessComponentImpl comp2 = (StatelessComponentImpl) scope.getInstance(component2);
+ Assert.assertNotNull(comp2);
+ Assert.assertNotSame(comp1, comp2);
+ scope.stop();
+ }
+
+ public void testGetAssociatedInstance() throws Exception {
+ WorkContext ctx = new WorkContextImpl();
+ StatelessScopeContainer scope = new StatelessScopeContainer(ctx, null);
+ scope.start();
+ AtomicComponent component1 = createComponent(scope);
+ scope.register(component1);
+ try {
+ // always throws an exception, which is the semantic for stateless implementations
+ scope.getAssociatedInstance(component1);
+ fail();
+ } catch (TargetNotFoundException e) {
+ // expected
+ }
+ scope.stop();
+ }
+
+ public void testRegisterContextAfterRequest() throws Exception {
+ WorkContext ctx = new WorkContextImpl();
+ StatelessScopeContainer scope = new StatelessScopeContainer(ctx, null);
+
+ scope.start();
+ AtomicComponent component1 = createComponent(scope);
+ scope.register(component1);
+ StatelessComponent comp1 = (StatelessComponentImpl) scope.getInstance(component1);
+ Assert.assertNotNull(comp1);
+ AtomicComponent component2 = createComponent(scope);
+ scope.register(component2);
+ StatelessComponentImpl comp2 = (StatelessComponentImpl) scope.getInstance(component2);
+ Assert.assertNotNull(comp2);
+ scope.stop();
+ }
+
+
+ /**
+ * Tests setting no components in the scope
+ */
+ public void testSetNullComponents() throws Exception {
+ WorkContext ctx = new WorkContextImpl();
+ StatelessScopeContainer scope = new StatelessScopeContainer(ctx, null);
+ scope.start();
+ scope.stop();
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ factory =
+ new PojoObjectFactory<StatelessComponentImpl>(StatelessComponentImpl.class.getConstructor((Class[]) null));
+
+ }
+
+ private AtomicComponent createComponent(ScopeContainer scopeContainer) {
+ PojoConfiguration configuration = new PojoConfiguration();
+ configuration.setInstanceFactory(factory);
+ try {
+ configuration.setName(new URI("foo"));
+ } catch (URISyntaxException e) {
+ // will not happen
+ }
+ AtomicComponent component = new SystemAtomicComponentImpl(configuration);
+ component.setScopeContainer(scopeContainer);
+ return component;
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/CompositeScopeInitDestroyErrorTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/CompositeScopeInitDestroyErrorTestCase.java
new file mode 100644
index 0000000000..1391959989
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/CompositeScopeInitDestroyErrorTestCase.java
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.component.scope;
+
+import java.net.URI;
+
+import org.apache.tuscany.spi.ObjectCreationException;
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.ScopeContainerMonitor;
+import org.apache.tuscany.spi.component.TargetDestructionException;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.component.event.ComponentStart;
+import org.apache.tuscany.core.component.event.ComponentStop;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class CompositeScopeInitDestroyErrorTestCase extends TestCase {
+
+ public void testInitializeErrorMonitor() throws Exception {
+ ScopeContainerMonitor monitor;
+ monitor = EasyMock.createMock(ScopeContainerMonitor.class);
+ monitor.eagerInitializationError(EasyMock.isA(ObjectCreationException.class));
+ EasyMock.replay(monitor);
+ CompositeScopeContainer scope = new CompositeScopeContainer(monitor);
+ scope.start();
+ AtomicComponent component = EasyMock.createMock(AtomicComponent.class);
+ EasyMock.expect(component.getUri()).andReturn(URI.create("foo")).atLeastOnce();
+ EasyMock.expect(component.createInstance()).andThrow(new ObjectCreationException(""));
+ EasyMock.expect(component.getInitLevel()).andReturn(1);
+ EasyMock.replay(component);
+ scope.register(component);
+ scope.onEvent(new ComponentStart(this, null));
+ EasyMock.verify(monitor);
+ }
+
+ public void testDestroyErrorMonitor() throws Exception {
+ ScopeContainerMonitor monitor;
+ monitor = EasyMock.createMock(ScopeContainerMonitor.class);
+ monitor.destructionError(EasyMock.isA(TargetDestructionException.class));
+ EasyMock.replay(monitor);
+ CompositeScopeContainer scope = new CompositeScopeContainer(monitor);
+ scope.start();
+ AtomicComponent component = EasyMock.createMock(AtomicComponent.class);
+ EasyMock.expect(component.createInstance()).andReturn(new Object());
+ EasyMock.expect(component.getInitLevel()).andReturn(1);
+ component.init(EasyMock.isA(Object.class));
+ component.destroy(EasyMock.isA(Object.class));
+ EasyMock.expectLastCall().andThrow(new TargetDestructionException("", ""));
+ EasyMock.replay(component);
+ scope.register(component);
+ scope.onEvent(new ComponentStart(this, null));
+ scope.onEvent(new ComponentStop(this, null));
+ EasyMock.verify(monitor);
+ }
+
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/CompositeScopeInstanceLifecycleTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/CompositeScopeInstanceLifecycleTestCase.java
new file mode 100644
index 0000000000..e4efdcdbfa
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/CompositeScopeInstanceLifecycleTestCase.java
@@ -0,0 +1,186 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.component.scope;
+
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.TargetException;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.component.event.ComponentStart;
+import org.apache.tuscany.core.component.event.ComponentStop;
+import org.apache.tuscany.core.mock.component.OrderedInitPojo;
+import org.apache.tuscany.core.mock.component.OrderedInitPojoImpl;
+import org.easymock.EasyMock;
+import org.easymock.IAnswer;
+
+/**
+ * Lifecycle unit tests for the composite scope container
+ *
+ * @version $Rev$ $Date$
+ */
+public class CompositeScopeInstanceLifecycleTestCase extends TestCase {
+
+ /**
+ * Verify init and stop by scope container on an atomic component
+ *
+ * @throws Exception
+ */
+ public void testInitDestroy() throws Exception {
+ CompositeScopeContainer scope = new CompositeScopeContainer(null);
+ scope.start();
+ Foo comp = new Foo();
+ AtomicComponent component = EasyMock.createMock(AtomicComponent.class);
+ EasyMock.expect(component.createInstance()).andReturn(comp);
+ EasyMock.expect(component.getInitLevel()).andReturn(1).atLeastOnce();
+ component.init(EasyMock.eq(comp));
+ component.destroy(EasyMock.eq(comp));
+ EasyMock.replay(component);
+ scope.register(component);
+ scope.onEvent(new ComponentStart(this, null));
+ assertNotNull(scope.getInstance(component));
+ // expire composite
+ scope.onEvent(new ComponentStop(this, null));
+ scope.stop();
+ EasyMock.verify(component);
+ }
+
+ /**
+ * Verify init and stop by scope container on an atomic component when set to eager initialize
+ *
+ * @throws Exception
+ */
+ public void testEagerInitDestroy() throws Exception {
+ CompositeScopeContainer scope = new CompositeScopeContainer(null);
+ scope.start();
+ Foo comp = new Foo();
+ AtomicComponent initDestroyComponent = EasyMock.createMock(AtomicComponent.class);
+ EasyMock.expect(initDestroyComponent.createInstance()).andReturn(comp);
+ EasyMock.expect(initDestroyComponent.getInitLevel()).andReturn(1).atLeastOnce();
+ initDestroyComponent.init(EasyMock.eq(comp));
+ initDestroyComponent.destroy(EasyMock.eq(comp));
+ EasyMock.replay(initDestroyComponent);
+ scope.register(initDestroyComponent);
+ scope.onEvent(new ComponentStart(this, null));
+ // expire composite
+ scope.onEvent(new ComponentStop(this, null));
+ scope.stop();
+ EasyMock.verify(initDestroyComponent);
+ }
+
+
+ public void testDestroyOrder() throws Exception {
+ CompositeScopeContainer scope = new CompositeScopeContainer(null);
+ scope.start();
+
+ AtomicComponent oneComponent = createComponent(0);
+ scope.register(oneComponent);
+ AtomicComponent twoComponent = createComponent(0);
+ scope.register(twoComponent);
+ AtomicComponent threeComponent = createComponent(0);
+ scope.register(threeComponent);
+
+ scope.onEvent(new ComponentStart(this, null));
+ OrderedInitPojo one = (OrderedInitPojo) scope.getInstance(oneComponent);
+ assertNotNull(one);
+ assertEquals(1, one.getNumberInstantiated());
+ assertEquals(1, one.getInitOrder());
+
+ OrderedInitPojo two = (OrderedInitPojo) scope.getInstance(twoComponent);
+ assertNotNull(two);
+ assertEquals(2, two.getNumberInstantiated());
+ assertEquals(2, two.getInitOrder());
+
+ OrderedInitPojo three = (OrderedInitPojo) scope.getInstance(threeComponent);
+ assertNotNull(three);
+ assertEquals(3, three.getNumberInstantiated());
+ assertEquals(3, three.getInitOrder());
+
+ // expire composite
+ scope.onEvent(new ComponentStop(this, null));
+ assertEquals(0, one.getNumberInstantiated());
+ scope.stop();
+ EasyMock.verify(oneComponent);
+ EasyMock.verify(twoComponent);
+ EasyMock.verify(threeComponent);
+ }
+
+ public void testEagerInitDestroyOrder() throws Exception {
+ CompositeScopeContainer scope = new CompositeScopeContainer(null);
+ scope.start();
+
+ AtomicComponent oneComponent = createComponent(1);
+ scope.register(oneComponent);
+ AtomicComponent twoComponent = createComponent(1);
+ scope.register(twoComponent);
+ AtomicComponent threeComponent = createComponent(1);
+ scope.register(threeComponent);
+
+ scope.onEvent(new ComponentStart(this, null));
+ OrderedInitPojo one = (OrderedInitPojo) scope.getInstance(oneComponent);
+ assertNotNull(one);
+
+ OrderedInitPojo two = (OrderedInitPojo) scope.getInstance(twoComponent);
+ assertNotNull(two);
+
+ OrderedInitPojo three = (OrderedInitPojo) scope.getInstance(threeComponent);
+ assertNotNull(three);
+
+ // expire composite
+ scope.onEvent(new ComponentStop(this, null));
+ assertEquals(0, one.getNumberInstantiated());
+ scope.stop();
+ EasyMock.verify(oneComponent);
+ EasyMock.verify(twoComponent);
+ EasyMock.verify(threeComponent);
+ }
+
+ @SuppressWarnings("unchecked")
+ private AtomicComponent createComponent(int init) throws TargetException {
+ AtomicComponent component = EasyMock.createMock(AtomicComponent.class);
+ EasyMock.expect(component.createInstance()).andStubAnswer(new IAnswer() {
+ public Object answer() throws Throwable {
+ return new OrderedInitPojoImpl();
+ }
+ });
+ EasyMock.expect(component.getInitLevel()).andReturn(init).atLeastOnce();
+ component.init(EasyMock.isA(OrderedInitPojoImpl.class));
+ EasyMock.expectLastCall().andAnswer(new IAnswer() {
+ public Object answer() throws Throwable {
+ OrderedInitPojoImpl pojo = (OrderedInitPojoImpl) EasyMock.getCurrentArguments()[0];
+ pojo.init();
+ return null;
+ }
+ });
+ component.destroy(EasyMock.isA(OrderedInitPojoImpl.class));
+ EasyMock.expectLastCall().andAnswer(new IAnswer() {
+ public Object answer() throws Throwable {
+ OrderedInitPojoImpl pojo = (OrderedInitPojoImpl) EasyMock.getCurrentArguments()[0];
+ pojo.destroy();
+ return null;
+ }
+ });
+ EasyMock.replay(component);
+ return component;
+ }
+
+ private class Foo {
+
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/CompositeScopeObjectFactoryTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/CompositeScopeObjectFactoryTestCase.java
new file mode 100644
index 0000000000..611fbfc13f
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/CompositeScopeObjectFactoryTestCase.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.component.scope;
+
+import org.apache.tuscany.spi.component.ScopeRegistry;
+import org.apache.tuscany.spi.model.Scope;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class CompositeScopeObjectFactoryTestCase extends TestCase {
+
+ public void testCreation() {
+ ScopeRegistry registry = EasyMock.createMock(ScopeRegistry.class);
+ registry.registerFactory(EasyMock.isA(Scope.class), EasyMock.isA(CompositeScopeObjectFactory.class));
+
+ assertNotNull(new CompositeScopeObjectFactory(registry, null).getInstance());
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/CompositeScopeRestartTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/CompositeScopeRestartTestCase.java
new file mode 100644
index 0000000000..eaaed3a29e
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/CompositeScopeRestartTestCase.java
@@ -0,0 +1,100 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.component.scope;
+
+import java.lang.reflect.Constructor;
+import java.net.URI;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.component.event.ComponentStart;
+import org.apache.tuscany.core.component.event.ComponentStop;
+import org.apache.tuscany.core.implementation.PojoConfiguration;
+import org.apache.tuscany.core.implementation.system.component.SystemAtomicComponentImpl;
+import org.apache.tuscany.core.injection.MethodEventInvoker;
+import org.apache.tuscany.core.injection.PojoObjectFactory;
+
+/**
+ * Verifies the scope container properly disposes resources and canbe restarted
+ *
+ * @version $$Rev$$ $$Date$$
+ */
+public class CompositeScopeRestartTestCase extends TestCase {
+
+ public void testRestart() throws Exception {
+ CompositeScopeContainer scope = new CompositeScopeContainer(null);
+ scope.start();
+ MethodEventInvoker<Object> initInvoker =
+ new MethodEventInvoker<Object>(InitDestroyOnce.class.getMethod("init"));
+ MethodEventInvoker<Object> destroyInvoker =
+ new MethodEventInvoker<Object>(InitDestroyOnce.class.getMethod("destroy"));
+ PojoConfiguration configuration = new PojoConfiguration();
+ configuration.setInitInvoker(initInvoker);
+ configuration.setDestroyInvoker(destroyInvoker);
+ Constructor<InitDestroyOnce> ctr = InitDestroyOnce.class.getConstructor((Class<?>[]) null);
+ configuration.setInstanceFactory(new PojoObjectFactory<InitDestroyOnce>(ctr));
+ configuration.setName(new URI("InitDestroy"));
+ AtomicComponent component = new SystemAtomicComponentImpl(configuration);
+ component.setScopeContainer(scope);
+ component.start();
+
+ scope.onEvent(new ComponentStart(this, null));
+ Object instance = component.getTargetInstance();
+ assertSame(instance, component.getTargetInstance());
+
+ scope.onEvent(new ComponentStop(this, null));
+ scope.stop();
+ component.stop();
+
+ scope.start();
+ scope.onEvent(new ComponentStart(this, null));
+ component.start();
+ assertNotSame(instance, component.getTargetInstance());
+ scope.onEvent(new ComponentStop(this, null));
+ scope.stop();
+ component.stop();
+ }
+
+ public static class InitDestroyOnce {
+
+ private boolean initialized;
+ private boolean destroyed;
+
+ public InitDestroyOnce() {
+ }
+
+ public void init() {
+ if (!initialized) {
+ initialized = true;
+ } else {
+ fail("Scope did not clean up properly - Init called more than once");
+ }
+ }
+
+ public void destroy() {
+ if (!destroyed) {
+ destroyed = true;
+ } else {
+ fail("Scope did not clean up properly - Destroyed called more than once");
+ }
+ }
+
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeContainerDestroyOnExpirationTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeContainerDestroyOnExpirationTestCase.java
new file mode 100644
index 0000000000..a1a3616d0a
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeContainerDestroyOnExpirationTestCase.java
@@ -0,0 +1,121 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.component.scope;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.SCAObject;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.event.Event;
+import org.apache.tuscany.spi.event.EventFilter;
+import org.apache.tuscany.spi.event.RuntimeEventListener;
+import org.apache.tuscany.spi.services.store.RecoveryListener;
+import org.apache.tuscany.spi.services.store.Store;
+import org.apache.tuscany.spi.services.store.StoreExpirationEvent;
+import org.apache.tuscany.spi.services.store.StoreReadException;
+import org.apache.tuscany.spi.services.store.StoreWriteException;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.component.WorkContextImpl;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ConversationalScopeContainerDestroyOnExpirationTestCase extends TestCase {
+ private ScopeContainer container;
+ private TestStore store;
+ private AtomicComponent component;
+
+ /**
+ * Verifies the scope container registers a callback listener for component instance destroy events when a
+ * conversational instance expires
+ */
+ public void testDestroyNotification() throws Exception {
+ store.getListener().onEvent(new StoreExpirationEvent(this, component, new Object()));
+ EasyMock.verify(component);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ component = EasyMock.createMock(AtomicComponent.class);
+ component.destroy(EasyMock.isA(Object.class));
+ EasyMock.replay(component);
+ store = new TestStore();
+ WorkContext context = new WorkContextImpl();
+ container = new ConversationalScopeContainer(store, context, null);
+ container.start();
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ container.stop();
+ }
+
+ private class TestStore implements Store {
+ private RuntimeEventListener listener;
+
+ public RuntimeEventListener getListener() {
+ return listener;
+ }
+
+ public void insertRecord(SCAObject owner, String id, Object object, long expiration)
+ throws StoreWriteException {
+
+ }
+
+ public void updateRecord(SCAObject owner, String id, Object object, long expiration)
+ throws StoreWriteException {
+
+ }
+
+ public Object readRecord(SCAObject owner, String id) throws StoreReadException {
+ return null;
+ }
+
+ public void removeRecord(SCAObject owner, String id) throws StoreWriteException {
+
+ }
+
+ public void removeRecords() throws StoreWriteException {
+
+ }
+
+ public void recover(RecoveryListener listener) throws StoreReadException {
+
+ }
+
+ public void publish(Event object) {
+
+ }
+
+ public void addListener(RuntimeEventListener listener) {
+ this.listener = listener;
+ }
+
+ public void addListener(EventFilter filter, RuntimeEventListener listener) {
+
+ }
+
+ public void removeListener(RuntimeEventListener listener) {
+
+ }
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeContainerMaxAgeTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeContainerMaxAgeTestCase.java
new file mode 100644
index 0000000000..b41daeb7f1
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeContainerMaxAgeTestCase.java
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.component.scope;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.SCAObject;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.event.RuntimeEventListener;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.services.store.Store;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.component.WorkContextImpl;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ConversationalScopeContainerMaxAgeTestCase extends TestCase {
+
+ private ScopeContainer container;
+ private WorkContext context;
+ private Store store;
+ private AtomicComponent component;
+
+ public void testMaxAgeUpdate() throws Exception {
+ context.setIdentifier(Scope.CONVERSATION, "12345");
+ container.getInstance(component);
+ EasyMock.verify(store);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ ConversationalScopeContainerMaxAgeTestCase.Foo foo = new ConversationalScopeContainerMaxAgeTestCase.Foo();
+ context = new WorkContextImpl();
+ component = EasyMock.createMock(AtomicComponent.class);
+ EasyMock.expect(component.getMaxIdleTime()).andReturn(-1L).atLeastOnce();
+ EasyMock.expect(component.getMaxAge()).andReturn(600000L).atLeastOnce();
+ EasyMock.replay(component);
+ store = EasyMock.createMock(Store.class);
+ EasyMock.expect(store.readRecord(EasyMock.isA(SCAObject.class), EasyMock.isA(String.class))).andReturn(foo);
+ store.addListener(EasyMock.isA(RuntimeEventListener.class));
+ EasyMock.replay(store);
+ container = new ConversationalScopeContainer(store, context, null);
+ container.start();
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ context.clearIdentifier(Scope.CONVERSATION);
+ container.stop();
+ }
+
+ private class Foo {
+
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeContainerMaxIdleTimeTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeContainerMaxIdleTimeTestCase.java
new file mode 100644
index 0000000000..5719d698c8
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeContainerMaxIdleTimeTestCase.java
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.component.scope;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.SCAObject;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.event.RuntimeEventListener;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.services.store.Store;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.component.WorkContextImpl;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ConversationalScopeContainerMaxIdleTimeTestCase extends TestCase {
+
+ private ScopeContainer container;
+ private WorkContext context;
+ private Store store;
+ private AtomicComponent component;
+
+ public void testMaxIdleTimeUpdate() throws Exception {
+ context.setIdentifier(Scope.CONVERSATION, "12345");
+ container.getInstance(component);
+ EasyMock.verify(store);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ Foo foo = new Foo();
+ context = new WorkContextImpl();
+ component = EasyMock.createMock(AtomicComponent.class);
+ EasyMock.expect(component.getMaxIdleTime()).andReturn(600000L).atLeastOnce();
+ EasyMock.replay(component);
+ store = EasyMock.createMock(Store.class);
+ EasyMock.expect(store.readRecord(EasyMock.isA(SCAObject.class), EasyMock.isA(String.class))).andReturn(foo);
+ store.addListener(EasyMock.isA(RuntimeEventListener.class));
+ store.updateRecord(EasyMock.isA(SCAObject.class),
+ EasyMock.isA(String.class),
+ EasyMock.eq(foo),
+ EasyMock.anyLong());
+ EasyMock.replay(store);
+ container = new ConversationalScopeContainer(store, context, null);
+ container.start();
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ context.clearIdentifier(Scope.CONVERSATION);
+ container.stop();
+ }
+
+ private class Foo {
+
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeContainerPersistenceTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeContainerPersistenceTestCase.java
new file mode 100644
index 0000000000..f0824daffd
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeContainerPersistenceTestCase.java
@@ -0,0 +1,182 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.component.scope;
+
+import java.util.UUID;
+import java.net.URI;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.TargetNotFoundException;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.services.store.Store;
+import org.apache.tuscany.spi.services.store.StoreMonitor;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.component.WorkContextImpl;
+import org.apache.tuscany.core.services.store.memory.MemoryStore;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ConversationalScopeContainerPersistenceTestCase extends TestCase {
+ private ScopeContainer container;
+ private WorkContext context;
+
+ /**
+ * Verifies the scope container properly creates an instance
+ */
+ public void testNotYetPersistedInMemory() throws Exception {
+ String id = UUID.randomUUID().toString();
+ context.setIdentifier(Scope.CONVERSATION, id);
+ AtomicComponent component = EasyMock.createMock(AtomicComponent.class);
+ component.addListener(EasyMock.eq(container));
+ EasyMock.expect(component.createInstance()).andReturn(new Foo());
+ EasyMock.expect(component.getMaxAge()).andReturn(600000L).atLeastOnce();
+ component.init(EasyMock.isA(Object.class));
+ EasyMock.replay(component);
+ container.register(component);
+ assertTrue(container.getInstance(component) instanceof Foo);
+ EasyMock.verify(component);
+ }
+
+ public void testPersistNewInMemory() throws Exception {
+ String id = UUID.randomUUID().toString();
+ String id2 = UUID.randomUUID().toString();
+ context.setIdentifier(Scope.CONVERSATION, id);
+ AtomicComponent component = EasyMock.createMock(AtomicComponent.class);
+ component.addListener(EasyMock.eq(container));
+ EasyMock.expect(component.getMaxIdleTime()).andReturn(-1L).atLeastOnce();
+ EasyMock.replay(component);
+ container.register(component);
+ Foo foo = new Foo();
+ Foo foo2 = new Foo();
+ container.persistNew(component, id, foo, System.currentTimeMillis() + 100000);
+ assertEquals(foo, container.getInstance(component));
+ container.persistNew(component, id2, foo2, System.currentTimeMillis() + 100000);
+ context.setIdentifier(Scope.CONVERSATION, id2);
+ assertEquals(foo2, container.getInstance(component));
+ EasyMock.verify(component);
+ }
+
+ public void testPersistInMemory() throws Exception {
+ String id = UUID.randomUUID().toString();
+ context.setIdentifier(Scope.CONVERSATION, id);
+ AtomicComponent component = EasyMock.createMock(AtomicComponent.class);
+ component.addListener(EasyMock.eq(container));
+ EasyMock.expect(component.getMaxIdleTime()).andReturn(-1L).atLeastOnce();
+ EasyMock.replay(component);
+ container.register(component);
+ Foo foo = new Foo();
+ container.persistNew(component, id, foo, System.currentTimeMillis() + 100000);
+ assertEquals(foo, container.getInstance(component));
+ container.persist(component, id, foo, System.currentTimeMillis() + 100000);
+ assertEquals(foo, container.getInstance(component));
+ EasyMock.verify(component);
+ }
+
+ public void testRemoveInMemory() throws Exception {
+ String id = UUID.randomUUID().toString();
+ context.setIdentifier(Scope.CONVERSATION, id);
+ AtomicComponent component = EasyMock.createMock(AtomicComponent.class);
+ component.addListener(EasyMock.eq(container));
+ EasyMock.expect(component.getMaxIdleTime()).andReturn(-1L).atLeastOnce();
+ EasyMock.expect(component.getUri()).andReturn(URI.create("foo")).atLeastOnce();
+ EasyMock.replay(component);
+ container.register(component);
+ Foo foo = new Foo();
+ container.persistNew(component, id, foo, System.currentTimeMillis() + 100000);
+ assertEquals(foo, container.getInstance(component));
+ container.remove(component);
+ try {
+ container.getAssociatedInstance(component);
+ fail();
+ } catch (TargetNotFoundException e) {
+ //expected
+ }
+ EasyMock.verify(component);
+ }
+
+ public void testRecreateAfterRemoveInMemory() throws Exception {
+ String id = UUID.randomUUID().toString();
+ context.setIdentifier(Scope.CONVERSATION, id);
+ AtomicComponent component = EasyMock.createMock(AtomicComponent.class);
+ component.addListener(EasyMock.eq(container));
+ EasyMock.expect(component.getMaxAge()).andReturn(600000L).atLeastOnce();
+ component.init(EasyMock.isA(Object.class));
+ EasyMock.expect(component.getMaxIdleTime()).andReturn(-1L).atLeastOnce();
+ EasyMock.expect(component.createInstance()).andReturn(new Foo());
+ EasyMock.replay(component);
+ container.register(component);
+ Foo foo = new Foo();
+ container.persistNew(component, id, foo, System.currentTimeMillis() + 100000);
+ assertEquals(foo, container.getInstance(component));
+ container.remove(component);
+ Foo foo2 = (Foo) container.getInstance(component);
+ assertNotNull(foo2);
+ assertNotSame(foo, foo2);
+ EasyMock.verify(component);
+ }
+
+ public void testGetPersistedInstance() throws Exception {
+ String id = UUID.randomUUID().toString();
+ String id2 = UUID.randomUUID().toString();
+ context.setIdentifier(Scope.CONVERSATION, id);
+ AtomicComponent component = EasyMock.createMock(AtomicComponent.class);
+ EasyMock.expect(component.getUri()).andReturn(URI.create("foo")).atLeastOnce();
+ EasyMock.expect(component.getMaxIdleTime()).andReturn(-1L).atLeastOnce();
+ component.addListener(EasyMock.eq(container));
+ EasyMock.replay(component);
+ container.register(component);
+ Foo foo = new Foo();
+ container.persistNew(component, id, foo, System.currentTimeMillis() + 100000);
+ assertEquals(foo, container.getAssociatedInstance(component));
+ assertEquals(foo, container.getAssociatedInstance(component));
+ context.setIdentifier(Scope.CONVERSATION, id2);
+ try {
+ container.getAssociatedInstance(component);
+ fail();
+ } catch (TargetNotFoundException e) {
+ //expected
+ }
+ EasyMock.verify(component);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ context = new WorkContextImpl();
+ StoreMonitor mock = EasyMock.createNiceMock(StoreMonitor.class);
+ EasyMock.replay(mock);
+ Store store = new MemoryStore(mock);
+ container = new ConversationalScopeContainer(store, context, null);
+ container.start();
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ context.clearIdentifier(Scope.CONVERSATION);
+ container.stop();
+ }
+
+ private class Foo {
+
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeInstanceLifecycleTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeInstanceLifecycleTestCase.java
new file mode 100644
index 0000000000..782b175b47
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeInstanceLifecycleTestCase.java
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.component.scope;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.event.RuntimeEventListener;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.services.store.StoreMonitor;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.component.WorkContextImpl;
+import org.apache.tuscany.core.services.store.memory.MemoryStore;
+import org.easymock.EasyMock;
+
+/**
+ * Lifecycle unit tests for the conversational scope container
+ *
+ * @version $Rev: 451895 $ $Date: 2006-10-02 02:58:18 -0400 (Mon, 02 Oct 2006) $
+ */
+public class ConversationalScopeInstanceLifecycleTestCase extends TestCase {
+
+ public void testInitRemove() throws Exception {
+ StoreMonitor monitor = EasyMock.createMock(StoreMonitor.class);
+ monitor.start(EasyMock.isA(String.class));
+ monitor.stop(EasyMock.isA(String.class));
+ MemoryStore store = new MemoryStore(monitor);
+ WorkContext ctx = new WorkContextImpl();
+ ConversationalScopeContainer scope = new ConversationalScopeContainer(store, ctx, null);
+ scope.start();
+
+ Foo comp = new Foo();
+ AtomicComponent component = EasyMock.createMock(AtomicComponent.class);
+ EasyMock.expect(component.createInstance()).andReturn(comp);
+ component.init(EasyMock.eq(comp));
+ EasyMock.expect(component.getMaxAge()).andReturn(1L).anyTimes();
+ component.addListener(EasyMock.isA(RuntimeEventListener.class));
+ EasyMock.replay(component);
+ scope.register(component);
+ String convID = "ConvID";
+ ctx.setIdentifier(Scope.CONVERSATION, convID);
+ assertNotNull(scope.getInstance(component));
+ // expire
+ scope.remove(component);
+ scope.stop();
+ EasyMock.verify(component);
+ scope.stop();
+ }
+
+ private class Foo {
+
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeRestartTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeRestartTestCase.java
new file mode 100644
index 0000000000..b60c097766
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeRestartTestCase.java
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.component.scope;
+
+import java.lang.reflect.Constructor;
+import java.net.URI;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.services.store.StoreMonitor;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.component.WorkContextImpl;
+import org.apache.tuscany.core.component.event.ConversationEnd;
+import org.apache.tuscany.core.component.event.ConversationStart;
+import org.apache.tuscany.core.implementation.PojoConfiguration;
+import org.apache.tuscany.core.implementation.system.component.SystemAtomicComponentImpl;
+import org.apache.tuscany.core.injection.MethodEventInvoker;
+import org.apache.tuscany.core.injection.PojoObjectFactory;
+import org.apache.tuscany.core.services.store.memory.MemoryStore;
+import org.easymock.EasyMock;
+
+/**
+ * Verifies the scope container properly disposes resources and can be restarted
+ *
+ * @version $$Rev: 471111 $$ $$Date: 2006-11-03 23:06:48 -0500 (Fri, 03 Nov 2006) $$
+ */
+public class ConversationalScopeRestartTestCase extends TestCase {
+
+ public void testRestart() throws Exception {
+ StoreMonitor monitor = EasyMock.createMock(StoreMonitor.class);
+ monitor.start(EasyMock.isA(String.class));
+ monitor.stop(EasyMock.isA(String.class));
+ MemoryStore store = new MemoryStore(monitor);
+ WorkContext ctx = new WorkContextImpl();
+ ConversationalScopeContainer scope = new ConversationalScopeContainer(store, ctx, null);
+ scope.start();
+ MethodEventInvoker<Object> initInvoker = new MethodEventInvoker<Object>(
+ ConversationalScopeRestartTestCase.InitDestroyOnce.class.getMethod("init"));
+ MethodEventInvoker<Object> destroyInvoker =
+ new MethodEventInvoker<Object>(InitDestroyOnce.class.getMethod("destroy"));
+ PojoConfiguration configuration = new PojoConfiguration();
+ configuration.setInitInvoker(initInvoker);
+ configuration.setDestroyInvoker(destroyInvoker);
+ Constructor<InitDestroyOnce> ctr = InitDestroyOnce.class.getConstructor((Class<?>[]) null);
+ configuration.setInstanceFactory(new PojoObjectFactory<InitDestroyOnce>(ctr));
+ configuration.setName(new URI("InitDestroy"));
+ AtomicComponent component = new SystemAtomicComponentImpl(configuration);
+ component.setScopeContainer(scope);
+ component.start();
+
+ String conversation = "conv";
+ ctx.setIdentifier(Scope.CONVERSATION, conversation);
+ scope.onEvent(new ConversationStart(this, conversation));
+ Object instance = component.getTargetInstance();
+ assertSame(instance, component.getTargetInstance());
+
+ scope.onEvent(new ConversationEnd(this, conversation));
+ scope.stop();
+ component.stop();
+
+ scope.start();
+ scope.onEvent(new ConversationStart(this, conversation));
+ component.start();
+ //assertNotSame(instance, context.getServiceInstance());
+ scope.onEvent(new ConversationEnd(this, conversation));
+ scope.stop();
+ component.stop();
+ }
+
+ public static class InitDestroyOnce {
+
+ private boolean initialized;
+ private boolean destroyed;
+
+ public InitDestroyOnce() {
+ }
+
+ public void init() {
+ if (!initialized) {
+ initialized = true;
+ } else {
+ fail("Scope did not clean up properly - Init called more than once");
+ }
+ }
+
+ public void destroy() {
+ if (!destroyed) {
+ destroyed = true;
+ } else {
+ fail("Scope did not clean up properly - Destroyed called more than once");
+ }
+ }
+
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/DependencyLifecycleTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/DependencyLifecycleTestCase.java
new file mode 100644
index 0000000000..ab8806929b
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/DependencyLifecycleTestCase.java
@@ -0,0 +1,170 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.component.scope;
+
+import java.util.Map;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.model.Scope;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.component.WorkContextImpl;
+import org.apache.tuscany.core.component.event.ComponentStart;
+import org.apache.tuscany.core.component.event.ComponentStop;
+import org.apache.tuscany.core.component.event.HttpSessionEnd;
+import org.apache.tuscany.core.component.event.RequestEnd;
+import org.apache.tuscany.core.component.event.RequestStart;
+import org.apache.tuscany.core.mock.component.OrderedDependentPojo;
+import org.apache.tuscany.core.mock.component.OrderedDependentPojoImpl;
+import org.apache.tuscany.core.mock.component.OrderedInitPojo;
+import org.apache.tuscany.core.mock.component.OrderedInitPojoImpl;
+
+/**
+ * Tests dependencies are initalized and destroyed in the proper order (i.e. LIFO)
+ *
+ * @version $Rev$ $Date$
+ */
+public class DependencyLifecycleTestCase extends TestCase {
+
+ public void testInitDestroyOrderCompositeScope() throws Exception {
+ CompositeScopeContainer scopeCtx = new CompositeScopeContainer(null);
+ scopeCtx.start();
+ Map<String, AtomicComponent> components = MockFactory.createWiredComponents("source",
+ OrderedDependentPojoImpl.class,
+ scopeCtx,
+ "target",
+ OrderedInitPojoImpl.class,
+ scopeCtx);
+ for (AtomicComponent component : components.values()) {
+ scopeCtx.register(component);
+ }
+ AtomicComponent sourceComponent = components.get("source");
+ AtomicComponent targetComponent = components.get("target");
+ scopeCtx.register(sourceComponent);
+ scopeCtx.register(targetComponent);
+ scopeCtx.onEvent(new ComponentStart(this, null));
+ OrderedDependentPojo source = (OrderedDependentPojo) scopeCtx.getInstance(sourceComponent);
+ OrderedInitPojo target = (OrderedInitPojo) scopeCtx.getInstance(targetComponent);
+ assertNotNull(source.getPojo());
+ assertNotNull(target);
+ assertEquals(2, source.getNumberInstantiated());
+ scopeCtx.onEvent(new ComponentStop(this, null));
+ assertEquals(0, source.getNumberInstantiated());
+ scopeCtx.stop();
+ }
+
+ public void testInitDestroyOrderAfterStartCompositeScope() throws Exception {
+ CompositeScopeContainer scopeCtx = new CompositeScopeContainer(null);
+ scopeCtx.start();
+ Map<String, AtomicComponent> contexts = MockFactory.createWiredComponents("source",
+ OrderedDependentPojoImpl.class,
+ scopeCtx,
+ "target",
+ OrderedInitPojoImpl.class,
+ scopeCtx);
+ AtomicComponent sourceComponent = contexts.get("source");
+ AtomicComponent targetComponent = contexts.get("target");
+ scopeCtx.onEvent(new ComponentStart(this, null));
+ scopeCtx.register(sourceComponent);
+ scopeCtx.register(targetComponent);
+ OrderedDependentPojo source = (OrderedDependentPojo) scopeCtx.getInstance(sourceComponent);
+ OrderedInitPojo target = (OrderedInitPojo) scopeCtx.getInstance(targetComponent);
+ assertNotNull(source.getPojo());
+ assertNotNull(target);
+ assertEquals(2, source.getNumberInstantiated());
+ scopeCtx.onEvent(new ComponentStop(this, null));
+ assertEquals(0, source.getNumberInstantiated());
+ scopeCtx.stop();
+ }
+
+
+ public void testInitDestroyOrderSessionScope() throws Exception {
+ WorkContext ctx = new WorkContextImpl();
+ HttpSessionScopeContainer scopeCtx = new HttpSessionScopeContainer(ctx, null);
+ scopeCtx.start();
+ Object session = new Object();
+ Map<String, AtomicComponent> contexts = MockFactory.createWiredComponents("source",
+ OrderedDependentPojoImpl.class,
+ scopeCtx,
+ "target",
+ OrderedInitPojoImpl.class,
+ scopeCtx);
+ AtomicComponent sourceComponent = contexts.get("source");
+ AtomicComponent targetComponent = contexts.get("target");
+ scopeCtx.register(sourceComponent);
+ scopeCtx.register(targetComponent);
+ ctx.setIdentifier(Scope.SESSION, session);
+ OrderedDependentPojo source = (OrderedDependentPojo) scopeCtx.getInstance(sourceComponent);
+ assertNotNull(source.getPojo());
+ assertEquals(2, source.getNumberInstantiated());
+ scopeCtx.onEvent(new HttpSessionEnd(this, session));
+ assertEquals(0, source.getNumberInstantiated());
+ scopeCtx.stop();
+ }
+
+
+ public void testInitDestroyOrderAfterStartSessionScope() throws Exception {
+ WorkContext ctx = new WorkContextImpl();
+ HttpSessionScopeContainer scopeCtx = new HttpSessionScopeContainer(ctx, null);
+ scopeCtx.start();
+ Object session = new Object();
+ Map<String, AtomicComponent> contexts = MockFactory.createWiredComponents("source",
+ OrderedDependentPojoImpl.class,
+ scopeCtx,
+ "target",
+ OrderedInitPojoImpl.class,
+ scopeCtx);
+ AtomicComponent sourceComponent = contexts.get("source");
+ AtomicComponent targetComponent = contexts.get("target");
+ ctx.setIdentifier(Scope.SESSION, session);
+ scopeCtx.register(sourceComponent);
+ scopeCtx.register(targetComponent);
+ OrderedDependentPojo source = (OrderedDependentPojo) scopeCtx.getInstance(sourceComponent);
+ assertNotNull(source.getPojo());
+ assertEquals(2, source.getNumberInstantiated());
+ scopeCtx.onEvent(new HttpSessionEnd(this, session));
+ assertEquals(0, source.getNumberInstantiated());
+ scopeCtx.stop();
+ }
+
+ public void testInitDestroyOrderRequestScope() throws Exception {
+ WorkContext ctx = new WorkContextImpl();
+ RequestScopeContainer scopeCtx = new RequestScopeContainer(ctx, null);
+ scopeCtx.start();
+ scopeCtx.onEvent(new RequestStart(this));
+ Map<String, AtomicComponent> contexts = MockFactory.createWiredComponents("source",
+ OrderedDependentPojoImpl.class,
+ scopeCtx,
+ "target",
+ OrderedInitPojoImpl.class,
+ scopeCtx);
+ AtomicComponent sourceComponent = contexts.get("source");
+ AtomicComponent targetComponent = contexts.get("target");
+ scopeCtx.register(sourceComponent);
+ scopeCtx.register(targetComponent);
+ OrderedDependentPojo source = (OrderedDependentPojo) scopeCtx.getInstance(sourceComponent);
+ assertNotNull(source.getPojo());
+ assertEquals(2, source.getNumberInstantiated());
+ scopeCtx.onEvent(new RequestEnd(this));
+ assertEquals(0, source.getNumberInstantiated());
+ scopeCtx.stop();
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/HttpSessionScopeInitDestroyErrorTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/HttpSessionScopeInitDestroyErrorTestCase.java
new file mode 100644
index 0000000000..be05a5b15b
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/HttpSessionScopeInitDestroyErrorTestCase.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.component.scope;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.ScopeContainerMonitor;
+import org.apache.tuscany.spi.component.TargetDestructionException;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.event.RuntimeEventListener;
+import org.apache.tuscany.spi.model.Scope;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.component.WorkContextImpl;
+import org.apache.tuscany.core.component.event.HttpSessionEnd;
+import org.apache.tuscany.core.component.event.HttpSessionStart;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class HttpSessionScopeInitDestroyErrorTestCase extends TestCase {
+
+ public void testDestroyErrorMonitor() throws Exception {
+ ScopeContainerMonitor monitor;
+ monitor = EasyMock.createMock(ScopeContainerMonitor.class);
+ monitor.destructionError(EasyMock.isA(TargetDestructionException.class));
+ EasyMock.replay(monitor);
+ WorkContext workContext = new WorkContextImpl();
+ HttpSessionScopeContainer scope = new HttpSessionScopeContainer(workContext, monitor);
+ scope.start();
+ AtomicComponent component = EasyMock.createMock(AtomicComponent.class);
+ component.addListener(EasyMock.isA(RuntimeEventListener.class));
+ EasyMock.expect(component.createInstance()).andReturn(new Object());
+ EasyMock.expect(component.isEagerInit()).andReturn(true);
+ component.init(EasyMock.isA(Object.class));
+ component.destroy(EasyMock.isA(Object.class));
+ EasyMock.expectLastCall().andThrow(new TargetDestructionException("", ""));
+ EasyMock.replay(component);
+ scope.register(component);
+ Object id = new Object();
+ scope.onEvent(new HttpSessionStart(this, id));
+ workContext.setIdentifier(Scope.SESSION, id);
+ scope.getInstance(component);
+ scope.onEvent(new HttpSessionEnd(this, id));
+ EasyMock.verify(monitor);
+ }
+
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/HttpSessionScopeInstanceLifecycleTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/HttpSessionScopeInstanceLifecycleTestCase.java
new file mode 100644
index 0000000000..29d6d54450
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/HttpSessionScopeInstanceLifecycleTestCase.java
@@ -0,0 +1,136 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.component.scope;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.TargetException;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.event.RuntimeEventListener;
+import org.apache.tuscany.spi.model.Scope;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.component.WorkContextImpl;
+import org.apache.tuscany.core.component.event.HttpSessionEnd;
+import org.apache.tuscany.core.component.event.HttpSessionStart;
+import org.apache.tuscany.core.mock.component.OrderedInitPojo;
+import org.apache.tuscany.core.mock.component.OrderedInitPojoImpl;
+import org.easymock.EasyMock;
+import org.easymock.IAnswer;
+
+/**
+ * Lifecycle unit tests for the composite scope container
+ *
+ * @version $Rev$ $Date$
+ */
+public class HttpSessionScopeInstanceLifecycleTestCase extends TestCase {
+
+ public void testInitDestroy() throws Exception {
+ WorkContext ctx = new WorkContextImpl();
+ HttpSessionScopeContainer scope = new HttpSessionScopeContainer(ctx, null);
+ scope.start();
+ Foo comp = new Foo();
+ AtomicComponent component = EasyMock.createMock(AtomicComponent.class);
+ EasyMock.expect(component.createInstance()).andReturn(comp);
+ component.addListener(EasyMock.isA(RuntimeEventListener.class));
+ component.init(EasyMock.eq(comp));
+ component.destroy(EasyMock.eq(comp));
+ EasyMock.replay(component);
+ scope.register(component);
+ Object session = new Object();
+ ctx.setIdentifier(Scope.SESSION, session);
+ scope.onEvent(new HttpSessionStart(this, session));
+ assertNotNull(scope.getInstance(component));
+ // expire
+ scope.onEvent(new HttpSessionEnd(this, session));
+ scope.stop();
+ EasyMock.verify(component);
+ scope.stop();
+ }
+
+ public void testDestroyOrder() throws Exception {
+ WorkContext ctx = new WorkContextImpl();
+ HttpSessionScopeContainer scope = new HttpSessionScopeContainer(ctx, null);
+ scope.start();
+
+ AtomicComponent oneComponent = createComponent();
+ scope.register(oneComponent);
+ AtomicComponent twoComponent = createComponent();
+ scope.register(twoComponent);
+ AtomicComponent threeComponent = createComponent();
+ scope.register(threeComponent);
+
+ Object session = new Object();
+ ctx.setIdentifier(Scope.SESSION, session);
+ scope.onEvent(new HttpSessionStart(this, session));
+ OrderedInitPojo one = (OrderedInitPojo) scope.getInstance(oneComponent);
+ assertNotNull(one);
+ assertEquals(1, one.getNumberInstantiated());
+ assertEquals(1, one.getInitOrder());
+
+ OrderedInitPojo two = (OrderedInitPojo) scope.getInstance(twoComponent);
+ assertNotNull(two);
+ assertEquals(2, two.getNumberInstantiated());
+ assertEquals(2, two.getInitOrder());
+
+ OrderedInitPojo three = (OrderedInitPojo) scope.getInstance(threeComponent);
+ assertNotNull(three);
+ assertEquals(3, three.getNumberInstantiated());
+ assertEquals(3, three.getInitOrder());
+
+ scope.onEvent(new HttpSessionEnd(this, session));
+ assertEquals(0, one.getNumberInstantiated());
+ scope.stop();
+ EasyMock.verify(oneComponent);
+ EasyMock.verify(twoComponent);
+ EasyMock.verify(threeComponent);
+ }
+
+ @SuppressWarnings("unchecked")
+ private AtomicComponent createComponent() throws TargetException {
+ AtomicComponent component = EasyMock.createMock(AtomicComponent.class);
+ EasyMock.expect(component.createInstance()).andStubAnswer(new IAnswer() {
+ public Object answer() throws Throwable {
+ return new OrderedInitPojoImpl();
+ }
+ });
+ component.addListener(EasyMock.isA(RuntimeEventListener.class));
+ component.init(EasyMock.isA(OrderedInitPojoImpl.class));
+ EasyMock.expectLastCall().andAnswer(new IAnswer() {
+ public Object answer() throws Throwable {
+ OrderedInitPojoImpl pojo = (OrderedInitPojoImpl) EasyMock.getCurrentArguments()[0];
+ pojo.init();
+ return null;
+ }
+ });
+ component.destroy(EasyMock.isA(OrderedInitPojoImpl.class));
+ EasyMock.expectLastCall().andAnswer(new IAnswer() {
+ public Object answer() throws Throwable {
+ OrderedInitPojoImpl pojo = (OrderedInitPojoImpl) EasyMock.getCurrentArguments()[0];
+ pojo.destroy();
+ return null;
+ }
+ });
+ EasyMock.replay(component);
+ return component;
+ }
+
+ private class Foo {
+
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/HttpSessionScopeRestartTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/HttpSessionScopeRestartTestCase.java
new file mode 100644
index 0000000000..2baecf1e17
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/HttpSessionScopeRestartTestCase.java
@@ -0,0 +1,106 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.component.scope;
+
+import java.lang.reflect.Constructor;
+import java.net.URI;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.model.Scope;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.component.WorkContextImpl;
+import org.apache.tuscany.core.component.event.HttpSessionEnd;
+import org.apache.tuscany.core.component.event.HttpSessionStart;
+import org.apache.tuscany.core.implementation.PojoConfiguration;
+import org.apache.tuscany.core.implementation.system.component.SystemAtomicComponentImpl;
+import org.apache.tuscany.core.injection.MethodEventInvoker;
+import org.apache.tuscany.core.injection.PojoObjectFactory;
+
+/**
+ * Verifies the scope container properly disposes resources and canbe restarted
+ *
+ * @version $$Rev$$ $$Date$$
+ */
+public class HttpSessionScopeRestartTestCase extends TestCase {
+
+ public void testRestart() throws Exception {
+ WorkContext ctx = new WorkContextImpl();
+ HttpSessionScopeContainer scope = new HttpSessionScopeContainer(ctx, null);
+ scope.start();
+ MethodEventInvoker<Object> initInvoker = new MethodEventInvoker<Object>(
+ HttpSessionScopeRestartTestCase.InitDestroyOnce.class.getMethod("init"));
+ MethodEventInvoker<Object> destroyInvoker =
+ new MethodEventInvoker<Object>(InitDestroyOnce.class.getMethod("destroy"));
+ PojoConfiguration configuration = new PojoConfiguration();
+ configuration.setInitInvoker(initInvoker);
+ configuration.setDestroyInvoker(destroyInvoker);
+ Constructor<InitDestroyOnce> ctr = InitDestroyOnce.class.getConstructor((Class<?>[]) null);
+ configuration.setInstanceFactory(new PojoObjectFactory<InitDestroyOnce>(ctr));
+ configuration.setName(new URI("InitDestroy"));
+ AtomicComponent component = new SystemAtomicComponentImpl(configuration);
+ component.setScopeContainer(scope);
+ component.start();
+
+ Object session = new Object();
+ ctx.setIdentifier(Scope.SESSION, session);
+ scope.onEvent(new HttpSessionStart(this, session));
+ Object instance = component.getTargetInstance();
+ assertSame(instance, component.getTargetInstance());
+
+ scope.onEvent(new HttpSessionEnd(this, session));
+ scope.stop();
+ component.stop();
+
+ scope.start();
+ scope.onEvent(new HttpSessionStart(this, session));
+ component.start();
+ assertNotSame(instance, component.getTargetInstance());
+ scope.onEvent(new HttpSessionEnd(this, session));
+ scope.stop();
+ component.stop();
+ }
+
+ public static class InitDestroyOnce {
+
+ private boolean initialized;
+ private boolean destroyed;
+
+ public InitDestroyOnce() {
+ }
+
+ public void init() {
+ if (!initialized) {
+ initialized = true;
+ } else {
+ fail("Scope did not clean up properly - Init called more than once");
+ }
+ }
+
+ public void destroy() {
+ if (!destroyed) {
+ destroyed = true;
+ } else {
+ fail("Scope did not clean up properly - Destroyed called more than once");
+ }
+ }
+
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/InstanceWrapperBaseTestClass.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/InstanceWrapperBaseTestClass.java
new file mode 100644
index 0000000000..d75100d0e1
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/InstanceWrapperBaseTestClass.java
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.component.scope;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class InstanceWrapperBaseTestClass extends TestCase {
+ private static final Object INSTANCE = new Object();
+ private InstanceWrapperBase<Object> wrapper;
+
+ public void testLifecycle() throws Exception {
+ assertFalse(wrapper.isStarted());
+ try {
+ wrapper.getInstance();
+ fail();
+ } catch (AssertionError e) {
+ // expected
+ }
+ wrapper.start();
+ assertTrue(wrapper.isStarted());
+ assertSame(INSTANCE, wrapper.getInstance());
+ wrapper.stop();
+ assertFalse(wrapper.isStarted());
+ try {
+ wrapper.getInstance();
+ fail();
+ } catch (AssertionError e) {
+ // expected
+ }
+ }
+
+ public void testNullCheck() {
+ try {
+ new InstanceWrapperBase<Object>(null);
+ fail();
+ } catch (AssertionError e) {
+ // expected
+ }
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ wrapper = new InstanceWrapperBase<Object>(INSTANCE);
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/InstanceWrapperTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/InstanceWrapperTestCase.java
new file mode 100644
index 0000000000..f1fd74aeb0
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/InstanceWrapperTestCase.java
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.component.scope;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class InstanceWrapperTestCase extends TestCase {
+
+ public void testExceptionInit() throws Exception {
+ AtomicComponent component = getComponent();
+ InstanceWrapper wrapper = new InstanceWrapperImpl(component, new Object());
+ try {
+ wrapper.start();
+ fail();
+ } catch (SomeException e) {
+ // expected
+ }
+ assertFalse(wrapper.isStarted());
+ EasyMock.verify(component);
+ }
+
+ public void testNonStart() throws Exception {
+ AtomicComponent comp = EasyMock.createNiceMock(AtomicComponent.class); // class-level one has an expects
+ InstanceWrapper wrapper = new InstanceWrapperImpl(comp, new Object());
+ try {
+ wrapper.getInstance();
+ fail();
+ } catch (AssertionError e) {
+ // expected
+ }
+ }
+
+ private AtomicComponent getComponent() throws Exception {
+ // do not use setUp() since we do not need this in all testcases
+ AtomicComponent comp = EasyMock.createMock(AtomicComponent.class);
+ comp.init(EasyMock.isA(Object.class));
+ EasyMock.expectLastCall().andThrow(new SomeException());
+ EasyMock.replay(comp);
+ return comp;
+ }
+
+ private class SomeException extends RuntimeException {
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/MockFactory.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/MockFactory.java
new file mode 100644
index 0000000000..d7f78f46dd
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/MockFactory.java
@@ -0,0 +1,125 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.component.scope;
+
+import java.lang.reflect.Method;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.osoa.sca.annotations.Destroy;
+import org.osoa.sca.annotations.EagerInit;
+import org.osoa.sca.annotations.Init;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.idl.java.JavaServiceContract;
+import org.apache.tuscany.spi.wire.Wire;
+
+import org.apache.tuscany.core.implementation.PojoConfiguration;
+import org.apache.tuscany.core.implementation.system.component.SystemAtomicComponentImpl;
+import org.apache.tuscany.core.injection.MethodEventInvoker;
+import org.apache.tuscany.core.injection.PojoObjectFactory;
+import org.apache.tuscany.core.wire.WireImpl;
+
+/**
+ * @version $$Rev$$ $$Date$$
+ */
+public final class MockFactory {
+
+ private MockFactory() {
+ }
+
+ @SuppressWarnings("unchecked")
+ public static Map<String, AtomicComponent> createWiredComponents(String source,
+ Class<?> sourceClass,
+ ScopeContainer sourceScopeContainer,
+ String target,
+ Class<?> targetClass,
+ ScopeContainer targetScopeContainer)
+ throws NoSuchMethodException, URISyntaxException {
+
+ Map<String, AtomicComponent> components = new HashMap<String, AtomicComponent>();
+ AtomicComponent targetComponent = createAtomicComponent(target, targetScopeContainer, targetClass);
+ PojoConfiguration sourceConfig = new PojoConfiguration();
+ sourceConfig.setInstanceFactory(new PojoObjectFactory(sourceClass.getConstructor()));
+ Method[] sourceMethods = sourceClass.getMethods();
+ Class[] interfaces = targetClass.getInterfaces();
+ EagerInit eager = targetClass.getAnnotation(EagerInit.class);
+ if (eager != null) {
+ sourceConfig.setInitLevel(50);
+ }
+ Method setter = null;
+ for (Class interfaze : interfaces) {
+ for (Method method : sourceMethods) {
+ if (method.getParameterTypes().length == 1) {
+ if (interfaze.isAssignableFrom(method.getParameterTypes()[0])) {
+ setter = method;
+ }
+ }
+ if (method.getAnnotation(Init.class) != null) {
+ sourceConfig.setInitInvoker(new MethodEventInvoker<Object>(method));
+
+ } else if (method.getAnnotation(Destroy.class) != null) {
+ sourceConfig.setDestroyInvoker(new MethodEventInvoker<Object>(method));
+ }
+ }
+ }
+ if (setter == null) {
+ throw new IllegalArgumentException("No setter found on source for target");
+ }
+ sourceConfig.addReferenceSite(setter.getName(), setter);
+ sourceConfig.setName(new URI(source));
+ AtomicComponent sourceComponent = new SystemAtomicComponentImpl(sourceConfig);
+ sourceComponent.setScopeContainer(sourceScopeContainer);
+ Wire wire = new WireImpl();
+ wire.setSourceUri(URI.create("#" + setter.getName()));
+ wire.setSourceContract(new JavaServiceContract(targetClass));
+ wire.setTarget(targetComponent);
+ sourceComponent.attachWire(wire);
+ components.put(source, sourceComponent);
+ components.put(target, targetComponent);
+ return components;
+ }
+
+ @SuppressWarnings("unchecked")
+ public static AtomicComponent createAtomicComponent(String name, ScopeContainer container, Class<?> clazz)
+ throws NoSuchMethodException, URISyntaxException {
+ PojoConfiguration configuration = new PojoConfiguration();
+ configuration.setInstanceFactory(new PojoObjectFactory(clazz.getConstructor()));
+ EagerInit eager = clazz.getAnnotation(EagerInit.class);
+ if (eager != null) {
+ configuration.setInitLevel(50);
+ }
+ Method[] methods = clazz.getMethods();
+ for (Method method : methods) {
+ if (method.getAnnotation(Init.class) != null) {
+ configuration.setInitInvoker(new MethodEventInvoker<Object>(method));
+ } else if (method.getAnnotation(Destroy.class) != null) {
+ configuration.setDestroyInvoker(new MethodEventInvoker<Object>(method));
+ }
+ }
+ configuration.setName(new URI(name));
+ AtomicComponent component = new SystemAtomicComponentImpl(configuration);
+ component.setScopeContainer(container);
+ return component;
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/RequestScopeInitDestroyErrorTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/RequestScopeInitDestroyErrorTestCase.java
new file mode 100644
index 0000000000..e62392cf76
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/RequestScopeInitDestroyErrorTestCase.java
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.component.scope;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.ScopeContainerMonitor;
+import org.apache.tuscany.spi.component.TargetDestructionException;
+import org.apache.tuscany.spi.event.RuntimeEventListener;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.component.WorkContextImpl;
+import org.apache.tuscany.core.component.event.RequestEnd;
+import org.apache.tuscany.core.component.event.RequestStart;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class RequestScopeInitDestroyErrorTestCase extends TestCase {
+
+ public void testDestroyErrorMonitor() throws Exception {
+ ScopeContainerMonitor monitor;
+ monitor = EasyMock.createMock(ScopeContainerMonitor.class);
+ monitor.destructionError(EasyMock.isA(TargetDestructionException.class));
+ EasyMock.replay(monitor);
+ RequestScopeContainer scope = new RequestScopeContainer(new WorkContextImpl(), monitor);
+ scope.start();
+ AtomicComponent component = EasyMock.createMock(AtomicComponent.class);
+ component.addListener(EasyMock.isA(RuntimeEventListener.class));
+ EasyMock.expect(component.createInstance()).andReturn(new Object());
+ component.init(EasyMock.isA(Object.class));
+ component.destroy(EasyMock.isA(Object.class));
+ EasyMock.expectLastCall().andThrow(new TargetDestructionException("", ""));
+ EasyMock.replay(component);
+ scope.register(component);
+ scope.onEvent(new RequestStart(this));
+ scope.getInstance(component);
+ scope.onEvent(new RequestEnd(this));
+ EasyMock.verify(monitor);
+ }
+
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/RequestScopeInstanceLifecycleTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/RequestScopeInstanceLifecycleTestCase.java
new file mode 100644
index 0000000000..6601640c3b
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/RequestScopeInstanceLifecycleTestCase.java
@@ -0,0 +1,129 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.component.scope;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.TargetException;
+import org.apache.tuscany.spi.component.WorkContext;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.component.WorkContextImpl;
+import org.apache.tuscany.core.component.event.RequestEnd;
+import org.apache.tuscany.core.component.event.RequestStart;
+import org.apache.tuscany.core.mock.component.OrderedInitPojo;
+import org.apache.tuscany.core.mock.component.OrderedInitPojoImpl;
+import org.easymock.EasyMock;
+import org.easymock.IAnswer;
+
+/**
+ * Lifecycle unit tests for the request scope container
+ *
+ * @version $Rev$ $Date$
+ */
+public class RequestScopeInstanceLifecycleTestCase extends TestCase {
+
+ public void testInitDestroy() throws Exception {
+ WorkContext ctx = new WorkContextImpl();
+ RequestScopeContainer scope = new RequestScopeContainer(ctx, null);
+ scope.start();
+ Foo comp = new Foo();
+ AtomicComponent component = EasyMock.createMock(AtomicComponent.class);
+ EasyMock.expect(component.createInstance()).andReturn(comp);
+ component.init(EasyMock.eq(comp));
+ component.destroy(EasyMock.eq(comp));
+ EasyMock.replay(component);
+ scope.register(component);
+ scope.onEvent(new RequestStart(this));
+ assertNotNull(scope.getInstance(component));
+ // expire
+ scope.onEvent(new RequestEnd(this));
+ scope.stop();
+ EasyMock.verify(component);
+ scope.stop();
+ }
+
+ public void testDestroyOrder() throws Exception {
+ WorkContext ctx = new WorkContextImpl();
+ RequestScopeContainer scope = new RequestScopeContainer(ctx, null);
+ scope.start();
+
+ AtomicComponent oneComponent = createComponent();
+ scope.register(oneComponent);
+ AtomicComponent twoComponent = createComponent();
+ scope.register(twoComponent);
+ AtomicComponent threeComponent = createComponent();
+ scope.register(threeComponent);
+
+ scope.onEvent(new RequestStart(this));
+ OrderedInitPojo one = (OrderedInitPojo) scope.getInstance(oneComponent);
+ assertNotNull(one);
+ assertEquals(1, one.getNumberInstantiated());
+ assertEquals(1, one.getInitOrder());
+
+ OrderedInitPojo two = (OrderedInitPojo) scope.getInstance(twoComponent);
+ assertNotNull(two);
+ assertEquals(2, two.getNumberInstantiated());
+ assertEquals(2, two.getInitOrder());
+
+ OrderedInitPojo three = (OrderedInitPojo) scope.getInstance(threeComponent);
+ assertNotNull(three);
+ assertEquals(3, three.getNumberInstantiated());
+ assertEquals(3, three.getInitOrder());
+
+ scope.onEvent(new RequestEnd(this));
+ assertEquals(0, one.getNumberInstantiated());
+ scope.stop();
+ EasyMock.verify(oneComponent);
+ EasyMock.verify(twoComponent);
+ EasyMock.verify(threeComponent);
+ }
+
+ @SuppressWarnings("unchecked")
+ private AtomicComponent createComponent() throws TargetException {
+ AtomicComponent component = EasyMock.createMock(AtomicComponent.class);
+ EasyMock.expect(component.createInstance()).andStubAnswer(new IAnswer() {
+ public Object answer() throws Throwable {
+ return new OrderedInitPojoImpl();
+ }
+ });
+ component.init(EasyMock.isA(OrderedInitPojoImpl.class));
+ EasyMock.expectLastCall().andAnswer(new IAnswer() {
+ public Object answer() throws Throwable {
+ OrderedInitPojoImpl pojo = (OrderedInitPojoImpl) EasyMock.getCurrentArguments()[0];
+ pojo.init();
+ return null;
+ }
+ });
+ component.destroy(EasyMock.isA(OrderedInitPojoImpl.class));
+ EasyMock.expectLastCall().andAnswer(new IAnswer() {
+ public Object answer() throws Throwable {
+ OrderedInitPojoImpl pojo = (OrderedInitPojoImpl) EasyMock.getCurrentArguments()[0];
+ pojo.destroy();
+ return null;
+ }
+ });
+ EasyMock.replay(component);
+ return component;
+ }
+
+ private class Foo {
+
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/RequestScopeRestartTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/RequestScopeRestartTestCase.java
new file mode 100644
index 0000000000..d22c2eb538
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/RequestScopeRestartTestCase.java
@@ -0,0 +1,100 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.component.scope;
+
+import java.lang.reflect.Constructor;
+import java.net.URI;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.WorkContext;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.component.WorkContextImpl;
+import org.apache.tuscany.core.component.event.RequestEnd;
+import org.apache.tuscany.core.implementation.PojoConfiguration;
+import org.apache.tuscany.core.implementation.system.component.SystemAtomicComponentImpl;
+import org.apache.tuscany.core.injection.MethodEventInvoker;
+import org.apache.tuscany.core.injection.PojoObjectFactory;
+
+/**
+ * Verifies the scope container properly disposes resources and canbe restarted
+ *
+ * @version $$Rev$$ $$Date$$
+ */
+public class RequestScopeRestartTestCase extends TestCase {
+
+ public void testRestart() throws Exception {
+ WorkContext ctx = new WorkContextImpl();
+ RequestScopeContainer scope = new RequestScopeContainer(ctx, null);
+ scope.start();
+ MethodEventInvoker<Object> initInvoker =
+ new MethodEventInvoker<Object>(InitDestroyOnce.class.getMethod("init"));
+ MethodEventInvoker<Object> destroyInvoker =
+ new MethodEventInvoker<Object>(InitDestroyOnce.class.getMethod("destroy"));
+ PojoConfiguration configuration = new PojoConfiguration();
+ configuration.setInitInvoker(initInvoker);
+ configuration.setDestroyInvoker(destroyInvoker);
+ Constructor<InitDestroyOnce> ctr = InitDestroyOnce.class.getConstructor((Class<?>[]) null);
+ configuration.setInstanceFactory(new PojoObjectFactory<InitDestroyOnce>(ctr));
+ configuration.setName(new URI("InitDestroy"));
+ AtomicComponent component = new SystemAtomicComponentImpl(configuration);
+ component.setScopeContainer(scope);
+ component.start();
+
+ Object instance = component.getTargetInstance();
+ assertSame(instance, component.getTargetInstance());
+
+ scope.onEvent(new RequestEnd(this));
+ scope.stop();
+ component.stop();
+
+ scope.start();
+ component.start();
+ assertNotSame(instance, component.getTargetInstance());
+ scope.onEvent(new RequestEnd(this));
+ scope.stop();
+ component.stop();
+ }
+
+ public static class InitDestroyOnce {
+
+ private boolean initialized;
+ private boolean destroyed;
+
+ public InitDestroyOnce() {
+ }
+
+ public void init() {
+ if (!initialized) {
+ initialized = true;
+ } else {
+ fail("Scope did not clean up properly - Init called more than once");
+ }
+ }
+
+ public void destroy() {
+ if (!destroyed) {
+ destroyed = true;
+ } else {
+ fail("Scope did not clean up properly - Destroyed called more than once");
+ }
+ }
+
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/ScopeRegistryTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/ScopeRegistryTestCase.java
new file mode 100644
index 0000000000..e1380eb4c0
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/ScopeRegistryTestCase.java
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.component.scope;
+
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.ScopeRegistry;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.model.Scope;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.component.WorkContextImpl;
+
+/**
+ * Verifies retrieval of standard scope contexts from the default scope registry
+ *
+ * @version $$Rev$$ $$Date$$
+ */
+public class ScopeRegistryTestCase extends TestCase {
+ public void testScopeContextCreation() throws Exception {
+ WorkContext context = new WorkContextImpl();
+ ScopeRegistry scopeRegistry = new ScopeRegistryImpl();
+ scopeRegistry.registerFactory(Scope.REQUEST, new RequestScopeObjectFactory(context, null));
+ HttpSessionScopeObjectFactory sessionFactory = new HttpSessionScopeObjectFactory(scopeRegistry, context, null);
+ scopeRegistry.registerFactory(Scope.SESSION, sessionFactory);
+ scopeRegistry.registerFactory(Scope.CONVERSATION,
+ new ConversationalScopeObjectFactory(scopeRegistry, context, null, null));
+ ScopeContainer request = scopeRegistry.getScopeContainer(Scope.REQUEST);
+ assertTrue(request instanceof RequestScopeContainer);
+ assertSame(request, scopeRegistry.getScopeContainer(Scope.REQUEST));
+ ScopeContainer session = scopeRegistry.getScopeContainer(Scope.SESSION);
+ assertTrue(session instanceof HttpSessionScopeContainer);
+ assertSame(session, scopeRegistry.getScopeContainer(Scope.SESSION));
+ assertNotSame(request, session);
+ ScopeContainer conversation = scopeRegistry.getScopeContainer(Scope.CONVERSATION);
+ assertTrue(conversation instanceof ConversationalScopeContainer);
+ assertSame(conversation, scopeRegistry.getScopeContainer(Scope.CONVERSATION));
+ assertNotSame(session, conversation);
+ }
+
+ public void testDeregisterFactory() throws Exception {
+ WorkContext context = new WorkContextImpl();
+ ScopeRegistry scopeRegistry = new ScopeRegistryImpl();
+ RequestScopeObjectFactory factory = new RequestScopeObjectFactory(context, null);
+ scopeRegistry.registerFactory(Scope.REQUEST, factory);
+ scopeRegistry.deregisterFactory(Scope.REQUEST);
+ assertNull(scopeRegistry.getScopeContainer(Scope.REQUEST));
+ ConversationalScopeObjectFactory convFactory =
+ new ConversationalScopeObjectFactory(scopeRegistry, context, null, null);
+ scopeRegistry.registerFactory(Scope.CONVERSATION, convFactory);
+ scopeRegistry.deregisterFactory(Scope.CONVERSATION);
+ assertNull(scopeRegistry.getScopeContainer(Scope.CONVERSATION));
+ }
+
+ public void testScopeNotRegistered() throws Exception {
+ WorkContext workContext = new WorkContextImpl();
+ ScopeRegistry scopeRegistry = new ScopeRegistryImpl();
+ assertNull(scopeRegistry.getScopeContainer(Scope.REQUEST));
+ assertNull(scopeRegistry.getScopeContainer(Scope.SESSION));
+ assertNull(scopeRegistry.getScopeContainer(Scope.CONVERSATION));
+ assertNull(scopeRegistry.getScopeContainer(Scope.STATELESS));
+ }
+
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/StatelessScopeContainerTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/StatelessScopeContainerTestCase.java
new file mode 100644
index 0000000000..89cd9b51d7
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/StatelessScopeContainerTestCase.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.component.scope;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class StatelessScopeContainerTestCase extends TestCase {
+
+ public void testBadStopWithoutStart() throws Exception {
+ StatelessScopeContainer container = new StatelessScopeContainer(null, null);
+ try {
+ container.stop();
+ fail();
+ } catch (IllegalStateException e) {
+ //expected
+ }
+ }
+
+ public void testBadDoubleStart() throws Exception {
+ StatelessScopeContainer container = new StatelessScopeContainer(null, null);
+ try {
+ container.start();
+ container.start();
+ fail();
+ } catch (IllegalStateException e) {
+ //expected
+ }
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/StatelessScopeObjectFactoryTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/StatelessScopeObjectFactoryTestCase.java
new file mode 100644
index 0000000000..0902b9d78c
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/StatelessScopeObjectFactoryTestCase.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.component.scope;
+
+import org.apache.tuscany.spi.component.ScopeRegistry;
+import org.apache.tuscany.spi.model.Scope;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class StatelessScopeObjectFactoryTestCase extends TestCase {
+
+ public void testCreation() {
+ ScopeRegistry registry = EasyMock.createMock(ScopeRegistry.class);
+ registry.registerFactory(EasyMock.isA(Scope.class), EasyMock.isA(StatelessScopeObjectFactory.class));
+ assertNotNull(new StatelessScopeObjectFactory(registry, null, null).getInstance());
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/WorkContextTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/WorkContextTestCase.java
new file mode 100644
index 0000000000..c67b61a78f
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/component/scope/WorkContextTestCase.java
@@ -0,0 +1,212 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.component.scope;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.component.WorkContext;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.component.WorkContextImpl;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class WorkContextTestCase extends TestCase {
+
+ public void testRemoteComponent() throws Exception {
+ WorkContext ctx = new WorkContextImpl();
+ Component component = EasyMock.createNiceMock(Component.class);
+ Component component2 = EasyMock.createNiceMock(Component.class);
+ ctx.setRemoteComponent(component);
+ assertEquals(component, ctx.getRemoteComponent());
+ ctx.setRemoteComponent(component2);
+ assertEquals(component2, ctx.getRemoteComponent());
+ }
+
+ public void testNonSetRemoteComponent() throws Exception {
+ WorkContext ctx = new WorkContextImpl();
+ assertNull(ctx.getRemoteComponent());
+ }
+
+ public void testSetCurrentAtomicComponent() throws Exception {
+ WorkContext ctx = new WorkContextImpl();
+ AtomicComponent component = EasyMock.createNiceMock(AtomicComponent.class);
+ AtomicComponent component2 = EasyMock.createNiceMock(AtomicComponent.class);
+ ctx.setCurrentAtomicComponent(component);
+ assertEquals(component, ctx.getCurrentAtomicComponent());
+ ctx.setCurrentAtomicComponent(component2);
+ assertEquals(component2, ctx.getCurrentAtomicComponent());
+ }
+
+ public void testNonSetCurrentAtomicComponent() throws Exception {
+ WorkContext ctx = new WorkContextImpl();
+ assertNull(ctx.getCurrentAtomicComponent());
+ }
+
+ public void testIndentifier() throws Exception {
+ WorkContext ctx = new WorkContextImpl();
+ Object id = new Object();
+ ctx.setIdentifier(this, id);
+ assertEquals(id, ctx.getIdentifier(this));
+ }
+
+ public void testClearIndentifier() throws Exception {
+ WorkContext ctx = new WorkContextImpl();
+ Object id = new Object();
+ ctx.setIdentifier(this, id);
+ ctx.clearIdentifier(this);
+ assertNull(ctx.getIdentifier(this));
+ }
+
+ public void testClearIndentifiers() throws Exception {
+ WorkContext ctx = new WorkContextImpl();
+ Object id = new Object();
+ Object id2 = new Object();
+ ctx.setIdentifier(id, id);
+ ctx.setIdentifier(id2, id2);
+ ctx.clearIdentifiers();
+ assertNull(ctx.getIdentifier(id));
+ assertNull(ctx.getIdentifier(id2));
+ }
+
+ public void testClearNonExistentIndentifier() throws Exception {
+ WorkContext ctx = new WorkContextImpl();
+ ctx.clearIdentifier(this);
+ }
+
+ public void testNullIndentifier() throws Exception {
+ WorkContext ctx = new WorkContextImpl();
+ Object id = new Object();
+ ctx.setIdentifier(this, id);
+ ctx.clearIdentifier(null);
+ assertEquals(id, ctx.getIdentifier(this));
+ }
+
+ public void testNoIndentifier() throws Exception {
+ WorkContext ctx = new WorkContextImpl();
+ assertNull(ctx.getIdentifier(this));
+ }
+
+ public void testSetGetCorrelationId() {
+ WorkContext context = new WorkContextImpl();
+ context.setCorrelationId("msg-005");
+ assertEquals(context.getCorrelationId(), "msg-005");
+ context.setCorrelationId(null);
+ assertNull(context.getCorrelationId());
+ }
+
+ public void testSetGetCorrelationIdInNewThread() throws InterruptedException {
+ WorkContext context = new WorkContextImpl();
+ context.setCorrelationId("msg-005");
+ assertEquals(context.getCorrelationId(), "msg-005");
+ context.setIdentifier("TX", "002");
+ ChildThread t = new ChildThread(context);
+ t.start();
+ t.join();
+ assertTrue(t.passed);
+ context.setCorrelationId(null);
+ assertNull(context.getCorrelationId());
+ }
+
+ public void testCurrentAtomicComponentDoesNotPropagateToChildThread() throws InterruptedException {
+ // NOTE should behaviour be to propagate?
+ WorkContext context = new WorkContextImpl();
+ context.setCurrentAtomicComponent(EasyMock.createNiceMock(AtomicComponent.class));
+ TestCurrentAtomicComponentChildThread t = new TestCurrentAtomicComponentChildThread(context);
+ t.start();
+ t.join();
+ assertTrue(t.passed);
+ context.setCurrentAtomicComponent(null);
+ assertNull(context.getCurrentAtomicComponent());
+ }
+
+ public void testCurrentRemoteComponentDoesNotPropagateToChildThread() throws InterruptedException {
+ // NOTE should behaviour be to propagate?
+ WorkContext context = new WorkContextImpl();
+ context.setRemoteComponent(EasyMock.createNiceMock(Component.class));
+ TestCurrentRemoteComponentChildThread t = new TestCurrentRemoteComponentChildThread(context);
+ t.start();
+ t.join();
+ assertTrue(t.passed);
+ context.setRemoteComponent(null);
+ assertNull(context.getRemoteComponent());
+ }
+
+ private static final class ChildThread extends Thread {
+ private WorkContext context;
+ private boolean passed = true;
+
+ private ChildThread(WorkContext context) {
+ this.context = context;
+ }
+
+ @Override
+ public void run() {
+ try {
+ assertNull(context.getCorrelationId());
+ assertEquals("002", context.getIdentifier("TX"));
+ } catch (AssertionError e) {
+ passed = false;
+ }
+ }
+
+ }
+
+ private static final class TestCurrentAtomicComponentChildThread extends Thread {
+ private WorkContext context;
+ private boolean passed = true;
+
+ private TestCurrentAtomicComponentChildThread(WorkContext context) {
+ this.context = context;
+ }
+
+ @Override
+ public void run() {
+ try {
+ assertNull(context.getCurrentAtomicComponent());
+ } catch (AssertionError e) {
+ passed = false;
+ }
+ }
+
+ }
+
+ private static final class TestCurrentRemoteComponentChildThread extends Thread {
+ private WorkContext context;
+ private boolean passed = true;
+
+ private TestCurrentRemoteComponentChildThread(WorkContext context) {
+ this.context = context;
+ }
+
+ @Override
+ public void run() {
+ try {
+ assertNull(context.getRemoteComponent());
+ } catch (AssertionError e) {
+ passed = false;
+ }
+ }
+
+ }
+
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingInterceptorTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingInterceptorTestCase.java
new file mode 100644
index 0000000000..086649ea75
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingInterceptorTestCase.java
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.core.databinding.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.databinding.Mediator;
+import org.apache.tuscany.spi.model.DataType;
+import org.apache.tuscany.spi.model.Operation;
+import static org.apache.tuscany.spi.model.Operation.NO_CONVERSATION;
+import org.apache.tuscany.spi.wire.Interceptor;
+import org.apache.tuscany.spi.wire.Message;
+import org.apache.tuscany.spi.wire.Wire;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.replay;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class DataBindingInterceptorTestCase extends TestCase {
+
+ @SuppressWarnings("unchecked")
+ public final void testInvoke() {
+ DataType<Class> type1 = new DataType<Class>("xml:string", String.class, String.class);
+ List<DataType<Class>> types1 = new ArrayList<DataType<Class>>();
+ types1.add(type1);
+ DataType<List<DataType<Class>>> inputType1 =
+ new DataType<List<DataType<Class>>>("xml:string", Object[].class, types1);
+
+ DataType<Class> type2 = new DataType<Class>("foo", Foo.class, Foo.class);
+ List<DataType<Class>> types2 = new ArrayList<DataType<Class>>();
+ types2.add(type2);
+ DataType<List<DataType<Class>>> inputType2 =
+ new DataType<List<DataType<Class>>>("foo", Object[].class, types2);
+
+ Operation<Class> operation1 =
+ new Operation<Class>("call", inputType1, type1, null, false, "xml:string", NO_CONVERSATION);
+ Operation<Class> operation2 =
+ new Operation<Class>("call", inputType2, type2, null, false, "org.w3c.dom.Node", NO_CONVERSATION);
+
+ DataType<DataType> outputType1 =
+ new DataType<DataType>("idl:output", Object.class, operation1.getOutputType());
+ DataType<DataType> outputType2 =
+ new DataType<DataType>("idl:output", Object.class, operation2.getOutputType());
+
+ Wire outboundWire = EasyMock.createMock(Wire.class);
+ Component composite = EasyMock.createMock(Component.class);
+ Component component = EasyMock.createMock(Component.class);
+ EasyMock.replay(outboundWire, composite, component);
+
+ DataBindingInteceptor interceptor = new DataBindingInteceptor(outboundWire, operation1, operation2);
+ Mediator mediator = createMock(Mediator.class);
+ Object[] source = new Object[]{"<foo>bar</foo>"};
+ Foo foo = new Foo();
+ foo.bar = "bar";
+ Object[] target = new Object[]{foo};
+ expect(mediator.mediate(EasyMock.same(source),
+ EasyMock.same(inputType1),
+ EasyMock.same(inputType2),
+ EasyMock.isA(Map.class))).andReturn(target);
+ // expect(mediator.mediate(target[0], type2,
+ // type1)).andReturn(source[0]);
+ expect(mediator.mediate(EasyMock.same(target[0]),
+ EasyMock.eq(outputType2),
+ EasyMock.eq(outputType1),
+ EasyMock.isA(Map.class))).andReturn(source[0]);
+ replay(mediator);
+ interceptor.setMediator(mediator);
+ Message msg = createMock(Message.class);
+ msg.setBody(EasyMock.anyObject());
+ expectLastCall().anyTimes();
+ expect(msg.getBody()).andReturn(source).once().andReturn(target[0]).once().andReturn(source[0]);
+ expect(msg.isFault()).andReturn(false).once();
+ replay(msg);
+ Interceptor next = createMock(Interceptor.class);
+ expect(next.invoke(msg)).andReturn(msg);
+ replay(next);
+ interceptor.setNext(next);
+ interceptor.invoke(msg);
+ String result = (String) msg.getBody();
+ Assert.assertEquals(source[0], result);
+ EasyMock.verify(mediator, msg, next);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ private static class Foo {
+ private String bar;
+
+ public String getBar() {
+ return bar;
+ }
+
+ public void setBar(String bar) {
+ this.bar = bar;
+ }
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingJavaInterfaceProcessorTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingJavaInterfaceProcessorTestCase.java
new file mode 100644
index 0000000000..91702ac091
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingJavaInterfaceProcessorTestCase.java
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.core.databinding.impl;
+
+import static org.apache.tuscany.spi.model.Operation.NO_CONVERSATION;
+
+import java.lang.reflect.Type;
+import java.util.HashMap;
+import java.util.Map;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.tuscany.api.annotation.DataContext;
+import org.apache.tuscany.api.annotation.DataType;
+import org.apache.tuscany.spi.idl.InvalidServiceContractException;
+import org.apache.tuscany.spi.idl.java.JavaServiceContract;
+import org.apache.tuscany.spi.model.Operation;
+import org.osoa.sca.annotations.Remotable;
+import org.w3c.dom.Node;
+
+/**
+ *
+ */
+public class DataBindingJavaInterfaceProcessorTestCase extends TestCase {
+
+ /**
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ /**
+ * @throws InvalidServiceContractException
+ */
+ public final void testVisitInterface() throws InvalidServiceContractException {
+ DataBindingJavaInterfaceProcessor processor = new DataBindingJavaInterfaceProcessor();
+ JavaServiceContract contract = new JavaServiceContract(MockInterface.class);
+ Map<String, Operation<Type>> operations = new HashMap<String, Operation<Type>>();
+ Operation<Type> operation = new Operation<Type>("call", null, null, null, false, null, NO_CONVERSATION);
+ Operation<Type> operation1 = new Operation<Type>("call1", null, null, null, false, null, NO_CONVERSATION);
+ operations.put("call", operation);
+ operations.put("call1", operation1);
+ contract.setOperations(operations);
+ processor.visitInterface(MockInterface.class, null, contract);
+ Assert.assertEquals("org.w3c.dom.Node", contract.getDataBinding());
+ Assert.assertEquals("element", (String)contract.getMetaData().get("nodeType"));
+ Assert.assertEquals("org.w3c.dom.Node", contract.getOperations().get("call").getDataBinding());
+ Assert.assertEquals("xml:string", contract.getOperations().get("call1").getDataBinding());
+ }
+
+ @DataType(name = "org.w3c.dom.Node", context = {@DataContext(key = "nodeType", value = "element")})
+ @Remotable
+ public static interface MockInterface {
+ Node call(Node msg);
+
+ @DataType(name = "xml:string")
+ String call1(String msg);
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingLoaderTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingLoaderTestCase.java
new file mode 100644
index 0000000000..6941e10a0c
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingLoaderTestCase.java
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.core.databinding.impl;
+
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.tuscany.spi.loader.InvalidValueException;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.model.DataType;
+import org.apache.tuscany.spi.model.ModelObject;
+import org.easymock.EasyMock;
+
+/**
+ * Testcase for DataBindingLoader
+ */
+public class DataBindingLoaderTestCase extends TestCase {
+ private XMLStreamReader reader;
+
+ /**
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ public final void testLoad() throws LoaderException, XMLStreamException {
+ reader = EasyMock.createMock(XMLStreamReader.class);
+ // EasyMock.expect(reader.getEventType()).andReturn(XMLStreamConstants.START_ELEMENT);
+ EasyMock.expect(reader.hasNext()).andReturn(true).anyTimes();
+ EasyMock.expect(reader.getName()).andReturn(DataTypeLoader.DATA_BINDING);
+ EasyMock.expect(reader.getAttributeValue(null, "name")).andReturn("ABC");
+ EasyMock.expect(reader.next()).andReturn(XMLStreamConstants.END_ELEMENT);
+ EasyMock.replay(reader);
+
+ ModelObject mo = new DataTypeLoader(null).load(null, reader, null);
+ Assert.assertTrue(mo instanceof DataType);
+ Assert.assertEquals("ABC", ((DataType<?>)mo).getDataBinding());
+ EasyMock.verify(reader);
+
+ EasyMock.reset(reader);
+
+ // EasyMock.expect(reader.getEventType()).andReturn(XMLStreamConstants.START_ELEMENT);
+ EasyMock.expect(reader.hasNext()).andReturn(true).anyTimes();
+ EasyMock.expect(reader.getName()).andReturn(DataTypeLoader.DATA_BINDING);
+ EasyMock.expect(reader.getAttributeValue(null, "name")).andReturn(null);
+ EasyMock.expect(reader.next()).andReturn(XMLStreamConstants.END_ELEMENT);
+ EasyMock.replay(reader);
+ try {
+ mo = new DataTypeLoader(null).load(null, reader, null);
+ Assert.fail("InvalidValueException should have been thrown");
+ } catch (InvalidValueException e) {
+ Assert.assertTrue(true);
+ }
+ EasyMock.verify(reader);
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingRegistryImplTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingRegistryImplTestCase.java
new file mode 100644
index 0000000000..75eafe8380
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingRegistryImplTestCase.java
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.databinding.impl;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+
+import javax.xml.stream.XMLStreamReader;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.tuscany.spi.databinding.DataBinding;
+import org.apache.tuscany.spi.databinding.DataBindingRegistry;
+import org.apache.tuscany.spi.model.DataType;
+import org.easymock.EasyMock;
+import org.xml.sax.ContentHandler;
+
+/**
+ *
+ */
+public class DataBindingRegistryImplTestCase extends TestCase {
+ private DataBindingRegistry registry;
+
+ /**
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ registry = new DataBindingRegistryImpl();
+ }
+
+ public void testRegistry() {
+ DataBinding db1 = createMock(DataBinding.class);
+ expect(db1.getName()).andReturn(ContentHandler.class.getName()).anyTimes();
+ DataType<Class> dataType1 = new DataType<Class>(ContentHandler.class, ContentHandler.class);
+ expect(db1.introspect(ContentHandler.class)).andReturn(dataType1);
+ expect(db1.introspect((Class)EasyMock.anyObject())).andReturn(null).anyTimes();
+ replay(db1);
+
+ registry.register(db1);
+
+ DataBinding db2 = createMock(DataBinding.class);
+ expect(db2.getName()).andReturn(XMLStreamReader.class.getName()).anyTimes();
+ DataType<Class> dataType2 = new DataType<Class>(XMLStreamReader.class, XMLStreamReader.class);
+ expect(db2.introspect(XMLStreamReader.class)).andReturn(dataType2);
+ expect(db2.introspect((Class)EasyMock.anyObject())).andReturn(null).anyTimes();
+ replay(db2);
+
+ registry.register(db2);
+
+ String name = db1.getName();
+ DataBinding db3 = registry.getDataBinding(name);
+ Assert.assertTrue(db1 == db3);
+
+ DataType<?> dt = registry.introspectType(ContentHandler.class);
+ Assert.assertEquals(dataType1, dt);
+ Assert.assertTrue(dt.getDataBinding().equalsIgnoreCase(name));
+
+ registry.unregister(name);
+ DataBinding db4 = registry.getDataBinding(name);
+ Assert.assertNull(db4);
+
+
+ dt = registry.introspectType(ContentHandler.class);
+ Assert.assertNotNull(dt);
+ Assert.assertEquals("java.lang.Object", dt.getDataBinding());
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingTestCase.java
new file mode 100644
index 0000000000..de5c537274
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingTestCase.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.databinding.impl;
+
+import java.lang.reflect.Method;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.tuscany.api.annotation.DataContext;
+import org.apache.tuscany.api.annotation.DataType;
+
+public class DataBindingTestCase extends TestCase {
+ @SuppressWarnings("unused")
+ public void testDataType() throws Exception {
+ Class<Test> testClass = Test.class;
+ DataType d = testClass.getAnnotation(DataType.class);
+ Assert.assertEquals(d.name(), "sdo");
+ Assert.assertEquals(d.context().length, 0);
+
+ Method method = testClass.getMethod("test", new Class[] {Object.class});
+ DataType d2 = method.getAnnotation(DataType.class);
+ Assert.assertEquals(d2.name(), "jaxb");
+ Assert.assertEquals(d2.context()[0].key(), "contextPath");
+ Assert.assertEquals(d2.context()[0].value(), "com.example.ipo.jaxb");
+ }
+
+ @DataType(name = "sdo")
+ private static interface Test {
+ @DataType(name = "jaxb", context = {@DataContext(key = "contextPath", value = "com.example.ipo.jaxb")})
+ Object test(Object object);
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingWirePostProcessorOptimizationTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingWirePostProcessorOptimizationTestCase.java
new file mode 100644
index 0000000000..de46eb0542
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingWirePostProcessorOptimizationTestCase.java
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.databinding.impl;
+
+import java.lang.reflect.Type;
+import java.net.URI;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.tuscany.spi.databinding.Mediator;
+import org.apache.tuscany.spi.idl.java.JavaServiceContract;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.Wire;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * Verifies that data binding interceptor is not added to invocation chains when the data binding types are not set on
+ * service contracts
+ *
+ * @version $Rev$ $Date$
+ */
+public class DataBindingWirePostProcessorOptimizationTestCase extends TestCase {
+ private DataBindingWirePostProcessor processor;
+ private InvocationChain outboundChain;
+ private InvocationChain callbackChain;
+ private Wire wire;
+
+ public void testNoInterceptorInterposed() {
+ processor.process(wire);
+ EasyMock.verify(outboundChain);
+ EasyMock.verify(callbackChain);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ Mediator mediator = new MediatorImpl();
+ processor = new DataBindingWirePostProcessor(mediator);
+
+ ServiceContract<Type> contract = new JavaServiceContract(null);
+ Operation<Type> operation = new Operation<Type>("test", null, null, null);
+ operation.setServiceContract(contract);
+ Map<String, Operation<Type>> operations = new HashMap<String, Operation<Type>>();
+ operations.put("test", operation);
+ contract.setOperations(operations);
+ contract.setCallbackOperations(operations);
+
+ outboundChain = EasyMock.createMock(InvocationChain.class);
+ EasyMock.replay(outboundChain);
+ Map<Operation<?>, InvocationChain> outboundChains = new HashMap<Operation<?>, InvocationChain>();
+ outboundChains.put(operation, outboundChain);
+
+ callbackChain = EasyMock.createMock(InvocationChain.class);
+ EasyMock.replay(callbackChain);
+ Map<Operation<?>, InvocationChain> callbackChains = new HashMap<Operation<?>, InvocationChain>();
+ callbackChains.put(operation, callbackChain);
+
+ wire = EasyMock.createMock(Wire.class);
+ EasyMock.expect(wire.getInvocationChains()).andReturn(outboundChains);
+ EasyMock.expect(wire.getSourceContract()).andReturn(contract).anyTimes();
+ EasyMock.expect(wire.getTargetContract()).andReturn(contract).anyTimes();
+ EasyMock.expect(wire.getCallbackInvocationChains()).andReturn(callbackChains).anyTimes();
+ URI uri = URI.create("foo");
+ EasyMock.expect(wire.getSourceUri()).andReturn(uri).anyTimes();
+
+ EasyMock.replay(wire);
+
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingWirePostProcessorTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingWirePostProcessorTestCase.java
new file mode 100644
index 0000000000..ccc522c0cb
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingWirePostProcessorTestCase.java
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.core.databinding.impl;
+
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.databinding.Mediator;
+import org.apache.tuscany.spi.idl.java.JavaServiceContract;
+import org.apache.tuscany.spi.model.DataType;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.wire.Interceptor;
+import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.Wire;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class DataBindingWirePostProcessorTestCase extends TestCase {
+ private DataBindingWirePostProcessor processor;
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ Mediator mediator = new MediatorImpl();
+ this.processor = new DataBindingWirePostProcessor(mediator);
+ }
+
+ public void testProcess1() {
+ Wire outboundWire = createMock(Wire.class);
+
+ Component component = createMock(Component.class);
+ Component composite = createMock(Component.class);
+
+ Map<Operation<?>, InvocationChain> outboundChains =
+ new HashMap<Operation<?>, InvocationChain>();
+ DataType<Type> type1 = new DataType<Type>(String.class, String.class);
+ List<DataType<Type>> types = new ArrayList<DataType<Type>>();
+ types.add(type1);
+ DataType<List<DataType<Type>>> inputType1 = new DataType<List<DataType<Type>>>(Object[].class, types);
+ DataType<Type> outputType1 = new DataType<Type>(String.class, String.class);
+ Operation<Type> op1 = new Operation<Type>("test", inputType1, outputType1, null);
+ ServiceContract<Type> outboundContract = new JavaServiceContract(null);
+ outboundContract.setDataBinding(String.class.getName());
+ op1.setServiceContract(outboundContract);
+ Map<String, Operation<Type>> outboundOperations = new HashMap<String, Operation<Type>>();
+ outboundOperations.put("test", op1);
+
+ outboundContract.setOperations(outboundOperations);
+ InvocationChain outboundChain = createMock(InvocationChain.class);
+ outboundChains.put(op1, outboundChain);
+ expect(outboundWire.getInvocationChains()).andReturn(outboundChains);
+ outboundChain.addInterceptor(EasyMock.anyInt(), (Interceptor) EasyMock.anyObject());
+
+
+ ServiceContract<Type> contract = new JavaServiceContract();
+ Map<String, Operation<Type>> operations = Collections.emptyMap();
+ contract.setCallbackOperations(operations);
+ expect(outboundWire.getSourceContract()).andReturn(outboundContract);
+ expect(outboundWire.getTargetContract()).andReturn(outboundContract);
+
+ EasyMock.replay(composite, component, outboundWire, outboundChain);
+
+ processor.process(outboundWire);
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/impl/DirectedGraphTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/impl/DirectedGraphTestCase.java
new file mode 100755
index 0000000000..70244df8e2
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/impl/DirectedGraphTestCase.java
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.databinding.impl;
+
+import java.util.List;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.tuscany.core.databinding.impl.DirectedGraph.Edge;
+import org.apache.tuscany.core.databinding.impl.DirectedGraph.Vertex;
+
+public class DirectedGraphTestCase extends TestCase {
+ private DirectedGraph<String, Object> graph;
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ graph = new DirectedGraph<String, Object>();
+ graph.addEdge("a", "b", null, 3);
+ graph.addEdge("b", "c", null, 1);
+ graph.addEdge("a", "c", null, 8);
+ graph.addEdge("a", "d", null, 3);
+ graph.addEdge("b", "d", null, 2);
+ graph.addEdge("c", "b", null, 1);
+ graph.addEdge("c", "d", null, 2);
+ graph.addEdge("d", "b", null, 1);
+ graph.addEdge("a", "e", null, 8);
+ graph.addEdge("c", "c", null, 2);
+ }
+
+ public void testGraph() {
+ // System.out.println(graph);
+
+ Vertex vertex = graph.getVertex("a");
+ Assert.assertNotNull(vertex);
+ Assert.assertEquals(vertex.getValue(), "a");
+
+ Assert.assertNull(graph.getVertex("1"));
+
+ Edge edge = graph.getEdge("a", "b");
+ Assert.assertNotNull(edge);
+ Assert.assertEquals(edge.getWeight(), 3);
+
+ edge = graph.getEdge("b", "a");
+ Assert.assertNull(edge);
+
+ DirectedGraph<String, Object>.Path path = graph.getShortestPath("a", "c");
+
+ List<DirectedGraph<String, Object>.Edge> edges = path.getEdges();
+ Assert.assertEquals(edges.size(), 2);
+ Assert.assertEquals(edges.get(0), graph.getEdge("a", "b"));
+ Assert.assertEquals(edges.get(1), graph.getEdge("b", "c"));
+
+ Assert.assertEquals(path.getWeight(), 4);
+
+ DirectedGraph<String, Object>.Path path2 = graph.getShortestPath("b", "e");
+ Assert.assertNull(path2);
+
+ DirectedGraph<String, Object>.Path path3 = graph.getShortestPath("a", "a");
+ Assert.assertTrue(path3.getWeight() == 0 && path3.getEdges().isEmpty());
+
+ DirectedGraph<String, Object>.Path path4 = graph.getShortestPath("c", "c");
+ Assert.assertTrue(path4.getWeight() == 2 && path4.getEdges().size() == 1);
+
+ // System.out.println(path);
+
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/impl/IDLTransformerTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/impl/IDLTransformerTestCase.java
new file mode 100644
index 0000000000..079e97a275
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/impl/IDLTransformerTestCase.java
@@ -0,0 +1,220 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.databinding.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.core.databinding.javabeans.DOMNode2JavaBeanTransformer;
+import org.apache.tuscany.core.databinding.javabeans.JavaBean2DOMNodeTransformer;
+import org.apache.tuscany.core.databinding.xml.DOMDataBinding;
+import org.apache.tuscany.core.databinding.xml.Node2String;
+import org.apache.tuscany.core.databinding.xml.String2Node;
+import org.apache.tuscany.spi.databinding.DataBindingRegistry;
+import org.apache.tuscany.spi.databinding.TransformationContext;
+import org.apache.tuscany.spi.databinding.extension.DOMHelper;
+import org.apache.tuscany.spi.databinding.extension.SimpleTypeMapperExtension;
+import org.apache.tuscany.spi.model.ElementInfo;
+import org.apache.tuscany.spi.model.TypeInfo;
+import org.apache.tuscany.spi.model.DataType;
+import org.apache.tuscany.spi.model.WrapperInfo;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+public class IDLTransformerTestCase extends TestCase {
+ private static final String IPO_XML =
+ "<?xml version=\"1.0\"?>" + "<order1"
+ + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""
+ + " xmlns:ipo=\"http://www.example.com/IPO\""
+ + " xsi:schemaLocation=\"http://www.example.com/IPO ipo.xsd\""
+ + " orderDate=\"1999-12-01\">"
+ + " <shipTo exportCode=\"1\" xsi:type=\"ipo:UKAddress\">"
+ + " <name>Helen Zoe</name>"
+ + " <street>47 Eden Street</street>"
+ + " <city>Cambridge</city>"
+ + " <postcode>CB1 1JR</postcode>"
+ + " </shipTo>"
+ + " <billTo xsi:type=\"ipo:USAddress\">"
+ + " <name>Robert Smith</name>"
+ + " <street>8 Oak Avenue</street>"
+ + " <city>Old Town</city>"
+ + " <state>PA</state>"
+ + " <zip>95819</zip>"
+ + " </billTo>"
+ + " <items>"
+ + " <item partNum=\"833-AA\">"
+ + " <productName>Lapis necklace</productName>"
+ + " <quantity>1</quantity>"
+ + " <USPrice>99.95</USPrice>"
+ + " <ipo:comment>Want this for the holidays</ipo:comment>"
+ + " <shipDate>1999-12-05</shipDate>"
+ + " </item>"
+ + " </items>"
+ + "</order1>";
+
+ private static final String URI_ORDER_XSD = "http://example.com/order.xsd";
+
+ /**
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ public void testTransform() throws Exception {
+ List<DataType<QName>> types0 = new ArrayList<DataType<QName>>();
+ DataType<QName> wrapperType =
+ new DataType<QName>(null, Object.class, new QName(URI_ORDER_XSD, "checkOrderStatus"));
+ types0.add(wrapperType);
+ DataType<List<DataType<QName>>> inputType0 =
+ new DataType<List<DataType<QName>>>("idl:input", Object[].class, types0);
+
+ List<DataType<QName>> types1 = new ArrayList<DataType<QName>>();
+ DataType<QName> customerIdType =
+ new DataType<QName>(null, Object.class, new QName(URI_ORDER_XSD, "customerId"));
+ DataType<QName> orderType =
+ new DataType<QName>(null, Object.class, new QName(URI_ORDER_XSD, "order"));
+ DataType<QName> flagType = new DataType<QName>(null, Object.class, new QName(URI_ORDER_XSD, "flag"));
+ types1.add(customerIdType);
+ types1.add(orderType);
+ types1.add(flagType);
+ DataType<List<DataType<QName>>> inputType =
+ new DataType<List<DataType<QName>>>("idl:input", Object[].class, types1);
+
+ DataType<QName> statusType =
+ new DataType<QName>(null, Object.class, new QName(URI_ORDER_XSD, "status"));
+ DataType<QName> responseType =
+ new DataType<QName>(null, Object.class, new QName(URI_ORDER_XSD, "checkOrderStatusResponse"));
+
+ org.apache.tuscany.spi.model.Operation<QName> op =
+ new org.apache.tuscany.spi.model.Operation<QName>("checkOrderStatus", inputType0, responseType,
+ null);
+ op.setDataBinding(DOMDataBinding.NAME);
+
+ inputType0.setOperation(op);
+ op.setWrapperStyle(true);
+ ElementInfo inputElement =
+ new ElementInfo(new QName(URI_ORDER_XSD, "checkOrderStatus"), new TypeInfo(null, false, null));
+ wrapperType.setMetadata(ElementInfo.class.getName(), inputElement);
+
+ ElementInfo customerId =
+ new ElementInfo(new QName("", "customerId"), SimpleTypeMapperExtension.XSD_SIMPLE_TYPES
+ .get("string"));
+ ElementInfo order =
+ new ElementInfo(new QName("", "order"), new TypeInfo(new QName(URI_ORDER_XSD), false, null));
+ ElementInfo flag =
+ new ElementInfo(new QName("", "flag"), SimpleTypeMapperExtension.XSD_SIMPLE_TYPES.get("int"));
+
+ customerIdType.setMetadata(ElementInfo.class.getName(), customerId);
+ orderType.setMetadata(ElementInfo.class.getName(), order);
+ flagType.setMetadata(ElementInfo.class.getName(), flag);
+
+ customerIdType.setOperation(op);
+ orderType.setOperation(op);
+ flagType.setOperation(op);
+
+ List<ElementInfo> inputElements = new ArrayList<ElementInfo>();
+ inputElements.add(customerId);
+ inputElements.add(order);
+ inputElements.add(flag);
+
+ ElementInfo statusElement =
+ new ElementInfo(new QName("", "status"), SimpleTypeMapperExtension.XSD_SIMPLE_TYPES.get("string"));
+
+ statusType.setMetadata(ElementInfo.class.getName(), statusElement);
+ statusType.setOperation(op);
+
+ List<ElementInfo> outputElements = new ArrayList<ElementInfo>();
+ outputElements.add(statusElement);
+
+ ElementInfo outputElement =
+ new ElementInfo(new QName(URI_ORDER_XSD, "checkOrderStatusResponse"), new TypeInfo(null, false,
+ null));
+
+ responseType.setMetadata(ElementInfo.class.getName(), inputElement);
+ responseType.setOperation(op);
+
+ WrapperInfo wrapperInfo =
+ new WrapperInfo(inputElement, outputElement, inputElements, outputElements, inputType, statusType);
+ op.setWrapper(wrapperInfo);
+ op.setDataBinding(DOMDataBinding.NAME);
+
+ MediatorImpl m = new MediatorImpl();
+ TransformerRegistryImpl tr = new TransformerRegistryImpl();
+ tr.registerTransformer(new String2Node());
+ tr.registerTransformer(new Node2String());
+ tr.registerTransformer(new DOMNode2JavaBeanTransformer());
+ tr.registerTransformer(new JavaBean2DOMNodeTransformer());
+ m.setTransformerRegistry(tr);
+ DataBindingRegistry dataBindingRegistry = new DataBindingRegistryImpl();
+ dataBindingRegistry.register(new DOMDataBinding());
+ m.setDataBindingRegistry(dataBindingRegistry);
+
+ Object[] source = new Object[] {"cust001", IPO_XML, Integer.valueOf(1)};
+ Input2InputTransformer t = new Input2InputTransformer();
+ t.setDataBindingRegistry(dataBindingRegistry);
+ t.setMediator(m);
+
+ TransformationContext context = new TransformationContextImpl();
+ List<DataType<Class>> types = new ArrayList<DataType<Class>>();
+ types.add(new DataType<Class>(Object.class.getName(), String.class, String.class));
+ types.add(new DataType<Class>("java.lang.String", String.class, String.class));
+ types.add(new DataType<Class>(Object.class.getName(), int.class, int.class));
+ DataType<List<DataType<Class>>> inputType1 =
+ new DataType<List<DataType<Class>>>("idl:input", Object[].class, types);
+ context.setSourceDataType(inputType1);
+ context.setTargetDataType(op.getInputType());
+ Object[] results = t.transform(source, context);
+ assertEquals(1, results.length);
+ assertTrue(results[0] instanceof Element);
+ Element element = (Element)results[0];
+ assertEquals("http://example.com/order.xsd", element.getNamespaceURI());
+ assertEquals("checkOrderStatus", element.getLocalName());
+
+ TransformationContext context1 = new TransformationContextImpl();
+ DataType<DataType> sourceType =
+ new DataType<DataType>("idl:output", Object.class, op.getOutputType());
+ sourceType.setOperation(op.getOutputType().getOperation());
+
+ context1.setSourceDataType(sourceType);
+ DataType<DataType> targetType =
+ new DataType<DataType>("idl:output", Object.class,
+ new DataType<Class>("java.lang.Object", String.class, String.class));
+ context1.setTargetDataType(targetType);
+
+ Document factory = DOMHelper.newDocument();
+ Element responseElement =
+ factory.createElementNS("http://example.com/order.wsdl", "p:checkOrderStatusResponse");
+ Element status = factory.createElement("status");
+ responseElement.appendChild(status);
+ status.appendChild(factory.createTextNode("shipped"));
+ Output2OutputTransformer t2 = new Output2OutputTransformer();
+ t2.setMediator(m);
+ t2.setDataBindingRegistry(dataBindingRegistry);
+ Object st = t2.transform(responseElement, context1);
+ assertEquals("shipped", st);
+
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/impl/MediatorImplTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/impl/MediatorImplTestCase.java
new file mode 100644
index 0000000000..3cb7f243a9
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/impl/MediatorImplTestCase.java
@@ -0,0 +1,118 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.databinding.impl;
+
+import java.io.StringWriter;
+import java.io.Writer;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.tuscany.core.databinding.xml.Node2String;
+import org.apache.tuscany.core.databinding.xml.Node2Writer;
+import org.apache.tuscany.core.databinding.xml.SAX2DOMPipe;
+import org.apache.tuscany.core.databinding.xml.String2SAX;
+import org.apache.tuscany.spi.databinding.DataBindingRegistry;
+import org.apache.tuscany.spi.databinding.TransformationContext;
+import org.apache.tuscany.spi.databinding.TransformerRegistry;
+import org.apache.tuscany.spi.model.DataType;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+/**
+ * Test case for MediatorImpl
+ */
+public class MediatorImplTestCase extends TestCase {
+ private static final String IPO_XML =
+ "<?xml version=\"1.0\"?>" + "<ipo:purchaseOrder"
+ + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""
+ + " xmlns:ipo=\"http://www.example.com/IPO\""
+ + " xsi:schemaLocation=\"http://www.example.com/IPO ipo.xsd\""
+ + " orderDate=\"1999-12-01\">"
+ + " <shipTo exportCode=\"1\" xsi:type=\"ipo:UKAddress\">"
+ + " <name>Helen Zoe</name>"
+ + " <street>47 Eden Street</street>"
+ + " <city>Cambridge</city>"
+ + " <postcode>CB1 1JR</postcode>"
+ + " </shipTo>"
+ + " <billTo xsi:type=\"ipo:USAddress\">"
+ + " <name>Robert Smith</name>"
+ + " <street>8 Oak Avenue</street>"
+ + " <city>Old Town</city>"
+ + "<state>PA</state>"
+ + " <zip>95819</zip>"
+ + " </billTo>"
+ + " <items>"
+ + " <item partNum=\"833-AA\">"
+ + " <productName>Lapis necklace</productName>"
+ + " <quantity>1</quantity>"
+ + "<USPrice>99.95</USPrice>"
+ + " <ipo:comment>Want this for the holidays</ipo:comment>"
+ + " <shipDate>1999-12-05</shipDate>"
+ + " </item>"
+ + " </items>"
+ + "</ipo:purchaseOrder>";
+
+ private MediatorImpl mediator;
+
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ TransformerRegistry registry = new TransformerRegistryImpl();
+ registry.registerTransformer(new String2SAX());
+ registry.registerTransformer(new SAX2DOMPipe());
+ registry.registerTransformer(new Node2String());
+ registry.registerTransformer(new Node2Writer());
+
+ mediator = new MediatorImpl();
+ mediator.setTransformerRegistry(registry);
+
+ DataBindingRegistry dataBindingRegistry = new DataBindingRegistryImpl();
+ mediator.setDataBindingRegistry(dataBindingRegistry);
+ }
+
+ private TransformationContext createTransformationContext(Class sourceType, Class targetType) {
+ TransformationContext context = new TransformationContextImpl();
+ DataType sourceDataType = new DataType<Class>(sourceType, sourceType);
+ DataType targetDataType = new DataType<Class>(targetType, targetType);
+ context.setSourceDataType(sourceDataType);
+ context.setTargetDataType(targetDataType);
+ return context;
+ }
+
+ public void testTransform1() {
+ TransformationContext context = createTransformationContext(String.class, Node.class);
+ Object node =
+ mediator.mediate(IPO_XML, context.getSourceDataType(), context.getTargetDataType(), null);
+ Assert.assertTrue(node instanceof Document);
+ Element root = ((Document)node).getDocumentElement();
+ Assert.assertEquals(root.getNamespaceURI(), "http://www.example.com/IPO");
+ Assert.assertEquals(root.getLocalName(), "purchaseOrder");
+ }
+
+ public void testTransform2() {
+ TransformationContext context = createTransformationContext(String.class, Writer.class);
+ Writer writer = new StringWriter();
+ mediator.mediate(IPO_XML, writer, context.getSourceDataType(), context.getTargetDataType(), null);
+ String str = writer.toString();
+ Assert.assertTrue(str != null && str.indexOf("<shipDate>1999-12-05</shipDate>") != -1);
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/impl/PassByValueInterceptorTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/impl/PassByValueInterceptorTestCase.java
new file mode 100644
index 0000000000..571f5ae7ab
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/impl/PassByValueInterceptorTestCase.java
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.core.databinding.impl;
+
+import java.io.Serializable;
+
+import junit.framework.TestCase;
+
+/**
+ * Test case for ByValueInterceptor
+ */
+public class PassByValueInterceptorTestCase extends TestCase {
+ private MySerialiable serialiable = new MySerialiable();
+ private String str = "ABC";
+ private Integer i = new Integer(1);
+ private String[] array = new String[] {"1", "2"};
+ private Object[] values;
+
+ /**
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ values = new Object[] {serialiable, str, i, serialiable, array};
+ }
+
+ private static class MySerialiable implements Serializable {
+ private static final long serialVersionUID = 7827201707529055310L;
+ private final String name = "Serializable";
+ private final int age = 100;
+
+ public int getAge() {
+ return age;
+ }
+
+ public String getName() {
+ return name;
+ }
+ }
+
+ public void testCopy() {
+ Object[] copy = new PassByValueInterceptor().copy(values);
+ assertTrue(copy[0] instanceof MySerialiable);
+ MySerialiable copied = (MySerialiable)copy[0];
+ assertNotSame(serialiable, copy[0]);
+ assertEquals(serialiable.getName(), copied.getName());
+ assertEquals(serialiable.getAge(), copied.getAge());
+ assertSame(copy[1], str);
+ assertSame(copy[2], i);
+ assertSame(copy[0], copy[3]);
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/impl/PassByValueWirePostProcessorTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/impl/PassByValueWirePostProcessorTestCase.java
new file mode 100644
index 0000000000..0cbd8a1014
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/impl/PassByValueWirePostProcessorTestCase.java
@@ -0,0 +1,174 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.core.databinding.impl;
+
+import java.net.URI;
+import java.util.List;
+
+import org.apache.tuscany.spi.ObjectCreationException;
+import org.apache.tuscany.spi.component.TargetResolutionException;
+import org.apache.tuscany.spi.databinding.DataBindingRegistry;
+import org.apache.tuscany.spi.extension.AtomicComponentExtension;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+import org.apache.tuscany.spi.wire.Wire;
+
+import junit.framework.TestCase;
+import static org.easymock.EasyMock.createMock;
+
+/**
+ * Testcase for testing if the PassByValueWireProcessor adds the PassByValueInterceptor to the invocation chains and
+ * also ensure that the outbound and inbound chain of interceptors are linked after this insertion
+ *
+ * @version $Rev$ $Date$
+ */
+public class PassByValueWirePostProcessorTestCase extends TestCase {
+ private PassByValueWirePostProcessor processor;
+
+ public void testProcessInclusionOfInterceptor() {
+//
+// InboundWire inboundWire = createMock(InboundWire.class);
+// OutboundWire outboundWire = createMock(OutboundWire.class);
+//
+// ServiceContract<Type> serviceContract = new JavaServiceContract(null);
+// serviceContract.setRemotable(true);
+// Map<Operation<?>, InboundInvocationChain> inChainsMap =
+// new Hashtable<Operation<?>, InboundInvocationChain>();
+//
+// Operation<Type> operation1 = new Operation<Type>("testMethod", null, null, null);
+// operation1.setServiceContract(serviceContract);
+// InboundInvocationChainImpl inChain = new InboundInvocationChainImpl(operation1);
+// inChainsMap.put(operation1, inChain);
+//
+// AtomicComponentExtension componentExtn = new FooComponent();
+//
+// Map<Operation<?>, OutboundInvocationChain> outChainsMap =
+// new Hashtable<Operation<?>, OutboundInvocationChain>();
+// OutboundInvocationChainImpl outChain = new OutboundInvocationChainImpl(operation1);
+// outChainsMap.put(operation1, outChain);
+//
+// expect(inboundWire.getSourceContract()).andReturn(serviceContract);
+// expect(inboundWire.getInboundInvocationChains()).andReturn(inChainsMap);
+// expect(outboundWire.getSourceContract()).andReturn(serviceContract).times(2);
+// expect(outboundWire.getOutboundInvocationChains()).andReturn(outChainsMap).times(2);
+//
+// Interceptor inInterceptor = createMock(Interceptor.class);
+// Interceptor outInterceptor = createMock(Interceptor.class);
+// inChain.addInterceptor(0, inInterceptor);
+// outChain.addInterceptor(0, outInterceptor);
+// //outChain.addInterceptor(new SynchronousBridgingInterceptor(inChain.getHeadInterceptor()));
+//
+// EasyMock.replay(inboundWire, outboundWire);
+// processor.process(componentExtn, outboundWire, componentExtn, inboundWire);
+//
+// assertEquals(true, inChain.getHeadInterceptor() instanceof PassByValueInterceptor);
+// assertEquals(true,
+// outChain.getTailInterceptor().getNext() instanceof PassByValueInterceptor);
+// assertEquals(true, outChain.getTailInterceptor().getNext().equals(
+// inChain.getHeadInterceptor()));
+//
+ }
+
+ public void testProcessExclusionOfInterceptorWhenAllowsPassByReference() {
+// Wire inboundWire = createMock(Wire.class);
+// Wire outboundWire = createMock(Wire.class);
+//
+// ServiceContract<Type> serviceContract = new JavaServiceContract(null);
+// serviceContract.setRemotable(true);
+// Map<Operation<?>, InvocationChain> inChainsMap =
+// new Hashtable<Operation<?>, InvocationChain>();
+//
+// Operation<?> operation1 = new Operation<Type>("testMethod", null, null, null);
+// InvocationChainImpl inChain = new InvocationChainImpl(operation1);
+// inChainsMap.put(operation1, inChain);
+//
+// AtomicComponentExtension componentExtn = new FooComponent();
+// componentExtn.setAllowsPassByReference(true);
+//
+//
+// Map<Operation<?>, InvocationChain> outChainsMap =
+// new Hashtable<Operation<?>, InvocationChain>();
+// InvocationChainImpl outChain = new InvocationChainImpl(operation1);
+// outChainsMap.put(operation1, outChain);
+//
+// expect(inboundWire.getSourceContract()).andReturn(serviceContract);
+// expect(inboundWire.getInvocationChains()).andReturn(inChainsMap);
+// expect(outboundWire.getSourceContract()).andReturn(serviceContract).times(2);
+// expect(outboundWire.getInvocationChains()).andReturn(outChainsMap).times(2);
+//
+// Interceptor inInterceptor = createMock(Interceptor.class);
+// Interceptor outInterceptor = createMock(Interceptor.class);
+// inChain.addInterceptor(0, inInterceptor);
+// outChain.addInterceptor(0, outInterceptor);
+// //outChain.addInterceptor(new SynchronousBridgingInterceptor(inChain.getHeadInterceptor()));
+//
+// EasyMock.replay(inboundWire, outboundWire);
+// processor.process(componentExtn, outboundWire, componentExtn, inboundWire);
+//
+// assertEquals(false, inChain.getHeadInterceptor() instanceof PassByValueInterceptor);
+// assertEquals(false,
+// outChain.getTailInterceptor().getNext() instanceof PassByValueInterceptor);
+// assertEquals(true, outChain.getTailInterceptor().getNext().equals(
+// inChain.getHeadInterceptor()));
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ this.processor = new PassByValueWirePostProcessor();
+ DataBindingRegistry dataBindingRegistry = createMock(DataBindingRegistry.class);
+ processor.setDataBindingRegistry(dataBindingRegistry);
+ }
+
+ private class FooComponent extends AtomicComponentExtension {
+
+ public FooComponent() {
+ super(URI.create("foo"), null, null, 0, -1, -1);
+ }
+
+ public List<Wire> getWires(String name) {
+ return null;
+ }
+
+ public void attachCallbackWire(Wire wire) {
+
+ }
+
+ public void attachWire(Wire wire) {
+
+ }
+
+ public void attachWires(List<Wire> wires) {
+
+ }
+
+ public Object createInstance() throws ObjectCreationException {
+ return null;
+ }
+
+ public Object getTargetInstance() throws TargetResolutionException {
+ return null;
+ }
+
+ public TargetInvoker createTargetInvoker(String targetName, Operation operation) {
+ return null;
+ }
+
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/impl/TransformerRegistryImplTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/impl/TransformerRegistryImplTestCase.java
new file mode 100644
index 0000000000..6250efd897
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/impl/TransformerRegistryImplTestCase.java
@@ -0,0 +1,106 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.core.databinding.impl;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+
+import java.util.List;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.tuscany.spi.databinding.Transformer;
+import org.apache.tuscany.spi.databinding.TransformerRegistry;
+
+/**
+ *
+ */
+public class TransformerRegistryImplTestCase extends TestCase {
+ private TransformerRegistry registry;
+
+ /**
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ registry = new TransformerRegistryImpl();
+ }
+
+ public void testRegisterTransformer1() {
+ Transformer transformer = createMock(Transformer.class);
+ registry.registerTransformer("a", "b", 10, transformer);
+ Transformer t = registry.getTransformer("a", "b");
+ Assert.assertSame(t, transformer);
+ }
+
+ public void testRegisterTransformerTransformer() {
+ Transformer transformer = createMock(Transformer.class);
+ expect(transformer.getSourceDataBinding()).andReturn("a");
+ expect(transformer.getTargetDataBinding()).andReturn("b");
+ expect(transformer.getWeight()).andReturn(10);
+ replay(transformer);
+ registry.registerTransformer(transformer);
+ Transformer t = registry.getTransformer("a", "b");
+ Assert.assertSame(t, transformer);
+ }
+
+ public void testUnregisterTransformer() {
+ Transformer transformer = createMock(Transformer.class);
+ registry.registerTransformer("a", "b", 10, transformer);
+ boolean result = registry.unregisterTransformer("a", "b");
+ Assert.assertTrue(result);
+ Transformer t = registry.getTransformer("a", "b");
+ Assert.assertNull(t);
+ }
+
+ public void testGetTransformerChain() {
+ Transformer t1 = createMock(Transformer.class);
+ expect(t1.getSourceDataBinding()).andReturn("a");
+ expect(t1.getTargetDataBinding()).andReturn("b");
+ expect(t1.getWeight()).andReturn(10);
+ replay(t1);
+ Transformer t2 = createMock(Transformer.class);
+ expect(t2.getSourceDataBinding()).andReturn("b");
+ expect(t2.getTargetDataBinding()).andReturn("c");
+ expect(t2.getWeight()).andReturn(20);
+ replay(t2);
+
+ Transformer t3 = createMock(Transformer.class);
+ expect(t3.getSourceDataBinding()).andReturn("a");
+ expect(t3.getTargetDataBinding()).andReturn("c");
+ expect(t3.getWeight()).andReturn(120);
+ replay(t3);
+
+ registry.registerTransformer(t1);
+ registry.registerTransformer(t2);
+ registry.registerTransformer(t3);
+
+ List<Transformer> l1 = registry.getTransformerChain("a", "b");
+ Assert.assertTrue(l1.size() == 1 && l1.get(0) == t1);
+ List<Transformer> l2 = registry.getTransformerChain("a", "c");
+ Assert.assertTrue(l2.size() == 2 && l2.get(0) == t1 && l2.get(1) == t2);
+ List<Transformer> l3 = registry.getTransformerChain("a", "d");
+ Assert.assertNull(l3);
+
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/javabeans/DOMNode2JavaBeanTransformerTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/javabeans/DOMNode2JavaBeanTransformerTestCase.java
new file mode 100644
index 0000000000..842051782b
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/javabeans/DOMNode2JavaBeanTransformerTestCase.java
@@ -0,0 +1,178 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.core.databinding.javabeans;
+
+import java.io.StringReader;
+import java.io.StringWriter;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.xml.sax.InputSource;
+
+import org.apache.tuscany.spi.databinding.TransformationContext;
+import org.apache.tuscany.spi.databinding.extension.DOMHelper;
+import org.apache.tuscany.spi.model.ElementInfo;
+import org.apache.tuscany.spi.model.TypeInfo;
+import org.apache.tuscany.spi.model.DataType;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * Testcase to test the XMLTypeMapperExtension which is the back bone for all transformations supported by the JavaBeans
+ * Databinding.
+ *
+ * @version $Rev$ $Date$
+ */
+public class DOMNode2JavaBeanTransformerTestCase extends TestCase {
+ private DOMNode2JavaBeanTransformer dom2JavaTransformer = new DOMNode2JavaBeanTransformer();
+
+ public void testFieldSettings() throws Exception {
+ String samplePropertyXML =
+ "<property name=\"prop2\" >" + "<integerNumber>27</integerNumber>"
+ + "<floatNumber>79.34</floatNumber>"
+ + "<doubleNumber>184.52</doubleNumber>" + "<innerProperty>"
+ + "<integerNumber>54</integerNumber>" + "<floatNumber>158.68</floatNumber>"
+ + "<doubleNumber>369.04</doubleNumber>" + "</innerProperty>"
+ + "<stringArray>TestString_1</stringArray>"
+ + "<stringArray>TestString_2</stringArray>" + "<boolArray>true</boolArray>"
+ + "<boolArray>false</boolArray>" + "</property>";
+
+ DocumentBuilder builder = DOMHelper.newDocumentBuilder();
+ InputSource inputSource = new InputSource(new StringReader(samplePropertyXML));
+ Node samplePropertyNode = builder.parse(inputSource);
+ TypeInfo typeInfo = new TypeInfo(null, false, null);
+
+ TransformationContext context = EasyMock.createMock(TransformationContext.class);
+ DataType<Class> targetDataType = new DataType<Class>(null, SamplePropertyBean.class);
+ EasyMock.expect(context.getTargetDataType()).andReturn(targetDataType).anyTimes();
+
+ DataType<Class> sourceDataType = new DataType<Class>(null, null);
+ ElementInfo eleInfo = new ElementInfo(null, typeInfo);
+ sourceDataType.setMetadata(ElementInfo.class.getName(), eleInfo);
+ EasyMock.expect(context.getSourceDataType()).andReturn(sourceDataType).anyTimes();
+ EasyMock.replay(context);
+
+ Object javaObject =
+ dom2JavaTransformer.transform(((Document) samplePropertyNode).getDocumentElement(), context);
+
+ assertTrue(javaObject instanceof SamplePropertyBean);
+ SamplePropertyBean samplePropBean = (SamplePropertyBean) javaObject;
+ assertEquals(samplePropBean.getIntegerNumber(), 27);
+ assertEquals((float) 79.34, samplePropBean.getFloatNumber());
+ assertEquals(samplePropBean.getInnerProperty().getDoubleNumber(), 369.04);
+
+ assertEquals(samplePropBean.getStringArray()[0], "TestString_1");
+ assertEquals(samplePropBean.boolArray[0], true);
+
+ /** testing for object to node * */
+ javax.xml.transform.Transformer transformer =
+ TransformerFactory.newInstance().newTransformer();
+ JavaBean2DOMNodeTransformer java2DomTransformer = new JavaBean2DOMNodeTransformer();
+ Node aNode = java2DomTransformer.transform(javaObject, context);
+ StringWriter sw = new StringWriter();
+ transformer.transform(new DOMSource(aNode), new StreamResult(sw));
+ String nodeString = sw.toString();
+ //System.out.println(nodeString);
+
+ // testing the case when field and getter method do not have public access
+ assertTrue(nodeString.indexOf("<doubleNumber>184.52</doubleNumber>") == -1);
+ // test the case for fields that are of array type
+ assertTrue(nodeString.indexOf("<stringArray>TestString_1</stringArray>"
+ + "<stringArray>TestString_2</stringArray>") != -1);
+ // testing the case for non-public field with public getter method
+ assertTrue(nodeString.indexOf("<integerNumber>27</integerNumber>") != -1);
+ // test the case for public field that is a another java bean .i.e. embeded javabean
+ int startIndex = nodeString.indexOf("<innerProperty>");
+ int endIndex = nodeString.indexOf("</innerProperty>");
+ String fragment = nodeString.substring(startIndex, endIndex);
+ assertTrue(fragment.indexOf("<integerNumber>54</integerNumber>") != -1);
+
+ // System.out.println(sw.toString());
+
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ private static class SamplePropertyBean {
+ public boolean[] boolArray;
+ private float floatNumber = 50;
+ private SamplePropertyBean innerProperty;
+ private double doubleNumber = 75;
+ private int integerNumber = 25;
+ private String[] stringArray;
+
+ public SamplePropertyBean() {
+
+ }
+
+ double getDoubleNumber() {
+ return doubleNumber;
+ }
+
+ public void setDoubleNumber(double doubleNumber) {
+ this.doubleNumber = doubleNumber;
+ }
+
+ public float getFloatNumber() {
+ return floatNumber;
+ }
+
+ public void setFloatNumber(float floatNumber) {
+ this.floatNumber = floatNumber;
+ }
+
+ public int getIntegerNumber() {
+ return integerNumber;
+ }
+
+ public void setIntegerNumber(int integerNumber) {
+ this.integerNumber = integerNumber;
+ }
+
+ public SamplePropertyBean getInnerProperty() {
+ return innerProperty;
+ }
+
+ public void setInnerProperty(SamplePropertyBean prop) {
+ this.innerProperty = prop;
+ }
+
+ public String toString() {
+ return Double.toString(integerNumber + floatNumber + doubleNumber) + " & "
+ + ((innerProperty == null) ? "" : innerProperty.toString());
+ }
+
+ public String[] getStringArray() {
+ return stringArray;
+ }
+
+ public void setStringArray(String[] stringArray) {
+ this.stringArray = stringArray;
+ }
+
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/javabeans/JavaBean2DOMNodeTransformerTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/javabeans/JavaBean2DOMNodeTransformerTestCase.java
new file mode 100644
index 0000000000..839c7429b1
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/javabeans/JavaBean2DOMNodeTransformerTestCase.java
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.core.databinding.javabeans;
+
+import java.io.StringWriter;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.w3c.dom.Node;
+
+import org.apache.tuscany.spi.databinding.TransformationContext;
+import org.apache.tuscany.spi.model.DataType;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * Testcase to test the XMLTypeMapperExtension which is the back bone for all transformations supported by the JavaBeans
+ * Databinding.
+ *
+ * @version $Rev$ $Date$
+ */
+public class JavaBean2DOMNodeTransformerTestCase extends TestCase {
+ private JavaBean2DOMNodeTransformer aTransformer = new JavaBean2DOMNodeTransformer();
+
+ /**
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ public void testTranformation() throws Exception {
+ TransformationContext context = EasyMock.createMock(TransformationContext.class);
+ DataType<Class> dataType = new DataType<Class>(null, SamplePropertyBean.class);
+ EasyMock.expect(context.getTargetDataType()).andReturn(dataType).anyTimes();
+ EasyMock.replay(context);
+
+ javax.xml.transform.Transformer transformer =
+ TransformerFactory.newInstance().newTransformer();
+ Object data = new int[]{10, 20, 30, 40};
+ Node aNode = aTransformer.transform(data, context);
+ StringWriter sw = new StringWriter();
+ transformer.transform(new DOMSource(aNode), new StreamResult(sw));
+
+ assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><int_collection><int>10</int><int>20</int>"
+ + "<int>30</int><int>40</int></int_collection>",
+ sw.toString());
+ }
+
+ public static class SamplePropertyBean {
+ private float floatNumber = 50;
+ private SamplePropertyBean innerProperty;
+ private double doubleNumber = 75;
+ private int integerNumber = 25;
+ private String[] stringArray;
+
+ public SamplePropertyBean() {
+
+ }
+
+ double getDoubleNumber() {
+ return doubleNumber;
+ }
+
+ public void setDoubleNumber(double doubleNumber) {
+ this.doubleNumber = doubleNumber;
+ }
+
+ public float getFloatNumber() {
+ return floatNumber;
+ }
+
+ public void setFloatNumber(float floatNumber) {
+ this.floatNumber = floatNumber;
+ }
+
+ public int getIntegerNumber() {
+ return integerNumber;
+ }
+
+ public void setIntegerNumber(int integerNumber) {
+ this.integerNumber = integerNumber;
+ }
+
+ public SamplePropertyBean getInnerProperty() {
+ return innerProperty;
+ }
+
+ public void setInnerProperty(SamplePropertyBean prop) {
+ this.innerProperty = prop;
+ }
+
+ public String toString() {
+ return Double.toString(integerNumber + floatNumber + doubleNumber) + " & "
+ + ((innerProperty == null) ? "" : innerProperty.toString());
+ }
+
+ public String[] getStringArray() {
+ return stringArray;
+ }
+
+ public void setStringArray(String[] stringArray) {
+ this.stringArray = stringArray;
+ }
+
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/xml/DOM2StAXTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/xml/DOM2StAXTestCase.java
new file mode 100644
index 0000000000..942b2d67e9
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/xml/DOM2StAXTestCase.java
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.databinding.xml;
+
+import javax.xml.stream.XMLStreamReader;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.w3c.dom.Node;
+
+public class DOM2StAXTestCase extends TestCase {
+ private static final String IPO_XML =
+ "<?xml version=\"1.0\"?>" + "<ipo:purchaseOrder"
+ + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""
+ + " xmlns:ipo=\"http://www.example.com/IPO\""
+ + " xsi:schemaLocation=\"http://www.example.com/IPO ipo.xsd\""
+ + " orderDate=\"1999-12-01\">"
+ + " <shipTo exportCode=\"1\" xsi:type=\"ipo:UKAddress\">"
+ + " <name>Helen Zoe</name>"
+ + " <street>47 Eden Street</street>"
+ + " <city>Cambridge</city>"
+ + " <postcode>CB1 1JR</postcode>"
+ + " </shipTo>"
+ + " <billTo xsi:type=\"ipo:USAddress\">"
+ + " <name>Robert Smith</name>"
+ + " <street>8 Oak Avenue</street>"
+ + " <city>Old Town</city>"
+ + " <state>PA</state>"
+ + " <zip>95819</zip>"
+ + " </billTo>"
+ + " <items>"
+ + " <item partNum=\"833-AA\">"
+ + " <productName>Lapis necklace</productName>"
+ + " <quantity>1</quantity>"
+ + " <USPrice>99.95</USPrice>"
+ + " <ipo:comment>Want this for the holidays</ipo:comment>"
+ + " <shipDate>1999-12-05</shipDate>"
+ + " </item>"
+ + " </items>"
+ + "</ipo:purchaseOrder>";
+
+ /**
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ public void testTransformation() {
+ String2Node t1 = new String2Node();
+ Node node = t1.transform(IPO_XML, null);
+ Node2XMLStreamReader t2 = new Node2XMLStreamReader();
+ XMLStreamReader reader = t2.transform(node, null);
+ XMLStreamReader2String t3 = new XMLStreamReader2String();
+ String xml = t3.transform(reader, null);
+ Assert.assertTrue(xml != null && xml.indexOf("<shipDate>1999-12-05</shipDate>") != -1);
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/xml/DataPipeTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/xml/DataPipeTestCase.java
new file mode 100644
index 0000000000..d4eaf9b2a9
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/xml/DataPipeTestCase.java
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.core.databinding.xml;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.Reader;
+import java.io.Writer;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.tuscany.core.databinding.impl.PipedTransformer;
+import org.apache.tuscany.spi.databinding.extension.DOMHelper;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+/**
+ * Test case for DataPipe
+ */
+public class DataPipeTestCase extends TestCase {
+
+ public final void testStreamPipe() throws IOException {
+ byte[] bytes = new byte[] {1, 2, 3};
+ StreamDataPipe pipe = new StreamDataPipe();
+ Assert.assertSame(OutputStream.class, pipe.getSourceType());
+ Assert.assertSame(InputStream.class, pipe.getTargetType());
+ OutputStream os = pipe.getSink();
+ os.write(bytes);
+ byte[] newBytes = new byte[16];
+ int count = pipe.getResult().read(newBytes);
+ Assert.assertEquals(3, count);
+ for (int i = 0; i < bytes.length; i++) {
+ Assert.assertEquals(bytes[i], newBytes[i]);
+ }
+ }
+
+ public final void testWriter2ReaderPipe() throws IOException {
+ String str = "ABC";
+ Writer2ReaderDataPipe pipe = new Writer2ReaderDataPipe();
+ Assert.assertSame(Writer.class, pipe.getSourceType());
+ Assert.assertSame(Reader.class, pipe.getTargetType());
+ pipe.getSink().write(str);
+ char[] buf = new char[16];
+ int count = pipe.getResult().read(buf);
+ Assert.assertEquals(3, count);
+ for (int i = 0; i < str.length(); i++) {
+ Assert.assertEquals(str.charAt(i), buf[i]);
+ }
+ }
+
+ public final void testPiped() throws Exception {
+ Node2Writer node2Writer = new Node2Writer();
+ Writer2ReaderDataPipe pipe = new Writer2ReaderDataPipe();
+ PipedTransformer<Node, Writer, Reader> transformer =
+ new PipedTransformer<Node, Writer, Reader>(node2Writer, pipe);
+ Document document = DOMHelper.newDocument();
+ Element element = document.createElementNS("http://ns1", "root");
+ document.appendChild(element);
+ Reader reader = transformer.transform(document, null);
+ Assert.assertEquals(transformer.getWeight(), node2Writer.getWeight() + pipe.getWeight());
+ Assert.assertEquals(transformer.getSourceDataBinding(), node2Writer.getSourceDataBinding());
+ Assert.assertEquals(transformer.getTargetDataBinding(), pipe.getTargetDataBinding());
+ char[] buf = new char[120];
+ int count = reader.read(buf);
+ String xml = new String(buf, 0, count);
+ Assert.assertTrue(xml.contains("<root xmlns=\"http://ns1\"/>"));
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/xml/Node2StringTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/xml/Node2StringTestCase.java
new file mode 100755
index 0000000000..9b9aa3b893
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/xml/Node2StringTestCase.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.databinding.xml;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.spi.databinding.extension.DOMHelper;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+public class Node2StringTestCase extends TestCase {
+ public void testTransformation() throws Exception {
+ Document document = DOMHelper.newDocument();
+ Element element = document.createElementNS("http://ns1", "test");
+ document.appendChild(element);
+
+ new Node2String().transform(document, null);
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/xml/PushTransformationTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/xml/PushTransformationTestCase.java
new file mode 100644
index 0000000000..a2318b2faa
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/xml/PushTransformationTestCase.java
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.databinding.xml;
+
+import javax.xml.stream.XMLStreamReader;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.tuscany.core.databinding.impl.PipedTransformer;
+import org.w3c.dom.Node;
+import org.xml.sax.ContentHandler;
+
+public class PushTransformationTestCase extends TestCase {
+ private static final String IPO_XML =
+ "<?xml version=\"1.0\"?>" + "<ipo:purchaseOrder"
+ + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""
+ + " xmlns:ipo=\"http://www.example.com/IPO\""
+ + " xsi:schemaLocation=\"http://www.example.com/IPO ipo.xsd\""
+ + " orderDate=\"1999-12-01\">"
+ + " <shipTo exportCode=\"1\" xsi:type=\"ipo:UKAddress\">"
+ + " <name>Helen Zoe</name>"
+ + " <street>47 Eden Street</street>"
+ + " <city>Cambridge</city>"
+ + " <postcode>CB1 1JR</postcode>"
+ + " </shipTo>"
+ + " <billTo xsi:type=\"ipo:USAddress\">"
+ + " <name>Robert Smith</name>"
+ + " <street>8 Oak Avenue</street>"
+ + " <city>Old Town</city>"
+ + " <state>PA</state>"
+ + " <zip>95819</zip>"
+ + " </billTo>"
+ + " <items>"
+ + " <item partNum=\"833-AA\">"
+ + " <productName>Lapis necklace</productName>"
+ + " <quantity>1</quantity>"
+ + " <USPrice>99.95</USPrice>"
+ + " <ipo:comment>Want this for the holidays</ipo:comment>"
+ + " <shipDate>1999-12-05</shipDate>"
+ + " </item>"
+ + " </items>"
+ + "</ipo:purchaseOrder>";
+
+ /**
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ public void testTransformation() {
+ String2XMLStreamReader t1 = new String2XMLStreamReader();
+ XMLStreamReader reader = t1.transform(IPO_XML, null);
+ XMLStreamReader2SAX t2 = new XMLStreamReader2SAX();
+ PipedTransformer<XMLStreamReader, ContentHandler, Node> t3 =
+ new PipedTransformer<XMLStreamReader, ContentHandler, Node>(t2, new SAX2DOMPipe());
+ Node node = t3.transform(reader, null);
+ Assert.assertNotNull(node);
+ Node2String t4 = new Node2String();
+ String xml = t4.transform(node, null);
+ Assert.assertTrue(xml != null && xml.indexOf("<shipDate>1999-12-05</shipDate>") != -1);
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/xml/StAXHelperTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/xml/StAXHelperTestCase.java
new file mode 100644
index 0000000000..7d18e83ac6
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/xml/StAXHelperTestCase.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.core.databinding.xml;
+
+import javax.xml.stream.XMLStreamReader;
+
+import junit.framework.TestCase;
+
+/**
+ * Test Case for StAXHelper
+ */
+public class StAXHelperTestCase extends TestCase {
+ private static final String XML =
+ "<a:foo xmlns:a='http://a' name='foo'><bar name='bar'>" + "<doo a:name='doo' xmlns:a='http://doo'/>"
+ + "</bar></a:foo>";
+
+ /**
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ public void testHelper() throws Exception {
+ XMLStreamReader reader = StAXHelper.createXMLStreamReader(XML);
+ String xml = StAXHelper.save(reader);
+ reader = StAXHelper.createXMLStreamReader(xml);
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/xml/TraxTransformerTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/xml/TraxTransformerTestCase.java
new file mode 100644
index 0000000000..7e9494d423
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/databinding/xml/TraxTransformerTestCase.java
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.core.databinding.xml;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.net.URL;
+
+import junit.framework.TestCase;
+
+import org.w3c.dom.Node;
+import org.xml.sax.Attributes;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
+
+/**
+ *
+ */
+public class TraxTransformerTestCase extends TestCase {
+ private URL url;
+
+ /**
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ url = getClass().getResource("foo.xml");
+ }
+
+ public void testTransformDOM() throws IOException {
+ InputStream is = url.openStream();
+ InputStream2Node t1 = new InputStream2Node();
+ Node node = t1.transform(is, null);
+ is.close();
+ Writer writer = new StringWriter();
+ Node2Writer t2 = new Node2Writer();
+ t2.transform(node, writer, null);
+ String str = writer.toString();
+ StringReader reader = new StringReader(str);
+ Reader2Node t3 = new Reader2Node();
+ node = t3.transform(reader, null);
+ ByteArrayOutputStream os = new ByteArrayOutputStream();
+ Node2OutputStream t4 = new Node2OutputStream();
+ t4.transform(node, os, null);
+ InputSource inputSource = new InputSource(new ByteArrayInputStream(os.toByteArray()));
+ InputSource2Node t5 = new InputSource2Node();
+ node = t5.transform(inputSource, null);
+ }
+
+ public void testTransformSAX() throws IOException {
+ MyContentHandler handler = new MyContentHandler();
+ InputStream is = url.openStream();
+ InputStream2SAX t1 = new InputStream2SAX();
+ t1.transform(is, handler, null);
+ is.close();
+
+ String xml = "<foo xmlns=\"http://foo\">bar</foo>";
+
+ InputSource inputSource = new InputSource(new StringReader(xml));
+ InputSource2SAX t2 = new InputSource2SAX();
+ MyContentHandler handler2 = new MyContentHandler();
+ t2.transform(inputSource, handler2, null);
+
+ }
+
+ private static class MyContentHandler extends DefaultHandler {
+
+ @Override
+ public void startElement(String namespaceURI, String localName, String qName, Attributes atts)
+ throws SAXException {
+ super.startElement(namespaceURI, localName, qName, atts);
+ }
+
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/deployer/BootstrapDeployerTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/deployer/BootstrapDeployerTestCase.java
new file mode 100644
index 0000000000..0cb29ac377
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/deployer/BootstrapDeployerTestCase.java
@@ -0,0 +1,170 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.deployer;
+
+import java.net.URI;
+import java.net.URL;
+import java.util.Collection;
+import java.util.Map;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.spi.builder.Connector;
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.idl.java.JavaInterfaceProcessorRegistry;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.model.BindingDefinition;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.ComponentType;
+import org.apache.tuscany.spi.model.CompositeComponentType;
+import org.apache.tuscany.spi.model.Implementation;
+import org.apache.tuscany.spi.model.Include;
+import org.apache.tuscany.spi.model.Property;
+import org.apache.tuscany.spi.model.PropertyValue;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.bootstrap.Bootstrapper;
+import org.apache.tuscany.core.bootstrap.DefaultBootstrapper;
+import org.apache.tuscany.core.builder.ConnectorImpl;
+import org.apache.tuscany.core.component.ComponentManager;
+import org.apache.tuscany.core.component.ComponentManagerImpl;
+import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
+import org.apache.tuscany.core.implementation.system.model.SystemCompositeImplementation;
+import org.apache.tuscany.core.mock.component.BasicInterface;
+import org.apache.tuscany.core.monitor.NullMonitorFactory;
+import org.apache.tuscany.core.resolver.DefaultAutowireResolver;
+import org.easymock.EasyMock;
+import static org.easymock.EasyMock.createNiceMock;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+
+/**
+ * Verifies the default boostrap deployer
+ *
+ * @version $Rev$ $Date$
+ */
+public class BootstrapDeployerTestCase extends TestCase {
+ private DeployerImpl deployer;
+ private DeploymentContext deploymentContext;
+ private ComponentDefinition<SystemCompositeImplementation> componentDefinition;
+ private SystemCompositeImplementation implementation;
+ private URI componentId;
+
+ @SuppressWarnings("unchecked")
+ public void testBoot1Load() throws LoaderException {
+ Component parent = createNiceMock(Component.class);
+ URI uri = URI.create("sca://parent");
+ EasyMock.expect(parent.getUri()).andReturn(uri).atLeastOnce();
+ EasyMock.replay(parent);
+ URL scdl = BootstrapDeployerTestCase.class.getResource("boot1.scdl");
+ implementation.setScdlLocation(scdl);
+ deployer.load(parent, componentDefinition, deploymentContext);
+ CompositeComponentType<ServiceDefinition, ReferenceDefinition, Property<?>> composite =
+ implementation.getComponentType();
+ assertNotNull(composite);
+ assertEquals(new QName("http://example.com", "boot1"), composite.getName());
+
+ // check parse of <service>
+ Map<String, ServiceDefinition> services = composite.getDeclaredServices();
+ assertEquals(1, services.size()); // included doesn't count
+ services = composite.getServices();
+ assertEquals(2, services.size()); // included counts
+ ServiceDefinition serviceDefinition = services.get("service");
+ assertNotNull(serviceDefinition);
+ assertEquals(componentId.resolve("#service"), serviceDefinition.getUri());
+ assertEquals(BasicInterface.class, serviceDefinition.getServiceContract().getInterfaceClass());
+ Collection<BindingDefinition> bindings = serviceDefinition.getBindings();
+ assertTrue(bindings.isEmpty());
+
+ // check parse of <component>
+ Map<String, ComponentDefinition<? extends Implementation<?>>> components = composite.getDeclaredComponents();
+ assertEquals(1, components.size()); // included doesn't count
+ components = composite.getComponents();
+ assertEquals(2, components.size()); // included counts
+ ComponentDefinition<? extends Implementation<?>> component = components.get("component");
+ assertNotNull(component);
+ PropertyValue<?> propVal = component.getPropertyValues().get("publicProperty");
+ assertEquals("propval", propVal.getValueFactory().getInstance());
+
+ // check introspection of implementation
+ ComponentType<?, ?, ?> componentType = component.getImplementation().getComponentType();
+ assertNotNull(componentType); // details checked in SystemComponentTypeLoaderTestCase
+
+ // check included component
+ Map<String, Include> includes = composite.getIncludes();
+ assertEquals(1, includes.size());
+ Include include = includes.get("boot1-include");
+ assertNotNull(include);
+ CompositeComponentType included = include.getIncluded();
+ assertNotNull(included);
+ assertEquals(1, included.getComponents().size());
+ }
+
+ public void testBoot1Deployment() throws Exception {
+ URL scdl = BootstrapDeployerTestCase.class.getResource("boot1.scdl");
+ implementation.setScdlLocation(scdl);
+ Component parent = EasyMock.createMock(Component.class);
+ replay(parent);
+ // load the boot1 file using the bootstrap deployer
+ componentDefinition.setUri(URI.create("sca://parent/simple"));
+ Collection<Component> components = deployer.deploy(parent, componentDefinition);
+ assertFalse(components.isEmpty());
+ verify(parent);
+ }
+
+ public void testBoot2Deployment() throws Exception {
+ URL scdl = BootstrapDeployerTestCase.class.getResource("boot2.scdl");
+ implementation.setScdlLocation(scdl);
+ Component parent = createNiceMock(Component.class);
+ replay(parent);
+ // load the boot2 file using the bootstrap deployer
+ componentDefinition.setUri(URI.create("newDeployer"));
+ Collection<Component> components = deployer.deploy(parent, componentDefinition);
+ assertFalse(components.isEmpty());
+ verify(parent);
+ for (Component component : components) {
+ component.start();
+ }
+ }
+
+ @SuppressWarnings({"unchecked"})
+ protected void setUp() throws Exception {
+ super.setUp();
+ componentId = URI.create("sca://localhost/parent");
+ XMLInputFactory xmlFactory = XMLInputFactory.newInstance();
+ DefaultAutowireResolver resolver = new DefaultAutowireResolver();
+ ComponentManager manager = new ComponentManagerImpl(null, resolver);
+ Connector connector = new ConnectorImpl(manager);
+ JavaInterfaceProcessorRegistry registry = new JavaInterfaceProcessorRegistryImpl();
+ ServiceContract contract = registry.introspect(ComponentManager.class);
+ manager.registerJavaObject(URI.create("ComponentManager"), contract, manager);
+ NullMonitorFactory monitorFactory = new NullMonitorFactory();
+ Bootstrapper bootstrapper =
+ new DefaultBootstrapper(monitorFactory, xmlFactory, manager, resolver, connector);
+ deployer = (DeployerImpl) bootstrapper.createDeployer();
+ deploymentContext = new RootDeploymentContext(null, null, componentId, xmlFactory, null, false);
+ implementation = new SystemCompositeImplementation();
+ implementation.setClassLoader(getClass().getClassLoader());
+ componentDefinition = new ComponentDefinition<SystemCompositeImplementation>(implementation);
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/idl/java/ConversationalIntrospectionTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/idl/java/ConversationalIntrospectionTestCase.java
new file mode 100644
index 0000000000..07888bbc69
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/idl/java/ConversationalIntrospectionTestCase.java
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.idl.java;
+
+import org.osoa.sca.annotations.Conversational;
+import org.osoa.sca.annotations.EndsConversation;
+
+import org.apache.tuscany.spi.idl.InvalidConversationalOperationException;
+import org.apache.tuscany.spi.idl.java.JavaServiceContract;
+import org.apache.tuscany.spi.model.Operation;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ConversationalIntrospectionTestCase extends TestCase {
+ private JavaInterfaceProcessorRegistryImpl registry = new JavaInterfaceProcessorRegistryImpl();
+
+ public void testServiceContractConversationalInformationIntrospection() throws Exception {
+ JavaServiceContract contract = registry.introspect(Foo.class);
+ assertTrue(contract.isConversational());
+ int seq = contract.getOperations().get("operation").getConversationSequence();
+ assertEquals(Operation.CONVERSATION_CONTINUE, seq);
+ seq = contract.getOperations().get("endOperation").getConversationSequence();
+ assertEquals(Operation.CONVERSATION_END, seq);
+ }
+
+ public void testBadServiceContract() throws Exception {
+ try {
+ registry.introspect(BadFoo.class);
+ fail();
+ } catch (InvalidConversationalOperationException e) {
+ //expected
+ }
+ }
+
+ public void testNonConversationalInformationIntrospection() throws Exception {
+ JavaServiceContract contract = registry.introspect(NonConversationalFoo.class);
+ assertFalse(contract.isConversational());
+ int seq = contract.getOperations().get("operation").getConversationSequence();
+ assertEquals(Operation.NO_CONVERSATION, seq);
+ }
+
+ @Conversational
+ private interface Foo {
+ void operation();
+
+ @EndsConversation
+ void endOperation();
+ }
+
+ private interface BadFoo {
+ void operation();
+
+ @EndsConversation
+ void endOperation();
+ }
+
+ private interface NonConversationalFoo {
+ void operation();
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/idl/java/JavaInterfaceProcessorRegistryImplTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/idl/java/JavaInterfaceProcessorRegistryImplTestCase.java
new file mode 100644
index 0000000000..e3a7deb10a
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/idl/java/JavaInterfaceProcessorRegistryImplTestCase.java
@@ -0,0 +1,100 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.idl.java;
+
+import java.lang.reflect.Type;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.tuscany.spi.idl.InvalidServiceContractException;
+import org.apache.tuscany.spi.idl.java.JavaInterfaceProcessor;
+import org.apache.tuscany.spi.idl.java.JavaServiceContract;
+import org.apache.tuscany.spi.model.DataType;
+import org.apache.tuscany.spi.model.Operation;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.util.JavaIntrospectionHelper;
+import org.easymock.EasyMock;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.eq;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.isA;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class JavaInterfaceProcessorRegistryImplTestCase extends TestCase {
+ private JavaInterfaceProcessorRegistryImpl impl;
+
+ public void testSimpleInterface() throws InvalidServiceContractException {
+ JavaServiceContract contract = impl.introspect(Simple.class);
+ // TODO spec to clairfy interface name
+ assertEquals(JavaIntrospectionHelper.getBaseName(Simple.class), contract.getInterfaceName());
+ assertEquals(Simple.class, contract.getInterfaceClass());
+ Map<String, Operation<Type>> operations = contract.getOperations();
+ assertEquals(1, operations.size());
+ Operation<Type> baseInt = operations.get("baseInt");
+ assertNotNull(baseInt);
+
+ DataType<Type> returnType = baseInt.getOutputType();
+ assertEquals(Integer.TYPE, returnType.getPhysical());
+ assertEquals(Integer.TYPE, returnType.getLogical());
+
+ List<DataType<Type>> parameterTypes = baseInt.getInputType().getLogical();
+ assertEquals(1, parameterTypes.size());
+ DataType<Type> arg0 = parameterTypes.get(0);
+ assertEquals(Integer.TYPE, arg0.getPhysical());
+ assertEquals(Integer.TYPE, arg0.getLogical());
+
+ List<DataType<Type>> faultTypes = baseInt.getFaultTypes();
+ assertEquals(1, faultTypes.size());
+ DataType<Type> fault0 = faultTypes.get(0);
+ assertEquals(IllegalArgumentException.class, fault0.getPhysical());
+ assertEquals(IllegalArgumentException.class, fault0.getLogical());
+ }
+
+ public void testUnregister() throws Exception {
+ JavaInterfaceProcessor processor = createMock(JavaInterfaceProcessor.class);
+ processor.visitInterface(eq(Base.class), EasyMock.same((Class)null), isA(JavaServiceContract.class));
+ expectLastCall().once();
+ replay(processor);
+ impl.registerProcessor(processor);
+ impl.introspect(Base.class);
+ impl.unregisterProcessor(processor);
+ impl.introspect(Base.class);
+ verify(processor);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ impl = new JavaInterfaceProcessorRegistryImpl();
+
+ }
+
+ private static interface Base {
+ int baseInt(int param) throws IllegalArgumentException;
+ }
+
+ private static interface Simple extends Base {
+
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/IntrospectionRegistryTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/IntrospectionRegistryTestCase.java
new file mode 100644
index 0000000000..622e8e479a
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/IntrospectionRegistryTestCase.java
@@ -0,0 +1,123 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.implementation.java.ImplementationProcessor;
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.implementation.IntrospectionRegistryImpl.Monitor;
+import org.apache.tuscany.core.monitor.NullMonitorFactory;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class IntrospectionRegistryTestCase extends TestCase {
+
+ private Monitor monitor;
+
+ public void testRegister() throws Exception {
+ IntrospectionRegistryImpl registry = new IntrospectionRegistryImpl(monitor);
+ ImplementationProcessor processor = EasyMock.createNiceMock(ImplementationProcessor.class);
+ registry.registerProcessor(processor);
+ }
+
+ public void testUnegister() throws Exception {
+ IntrospectionRegistryImpl registry = new IntrospectionRegistryImpl(monitor);
+ ImplementationProcessor processor = EasyMock.createNiceMock(ImplementationProcessor.class);
+ registry.registerProcessor(processor);
+ registry.unregisterProcessor(processor);
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testWalk() throws Exception {
+ IntrospectionRegistryImpl registry = new IntrospectionRegistryImpl(monitor);
+ ImplementationProcessor processor = EasyMock.createMock(ImplementationProcessor.class);
+ processor.visitClass(
+ EasyMock.eq(Bar.class),
+ EasyMock.isA(PojoComponentType.class),
+ EasyMock.isA(DeploymentContext.class));
+ processor.visitConstructor(
+ EasyMock.isA(Constructor.class),
+ EasyMock.isA(PojoComponentType.class),
+ EasyMock.isA(DeploymentContext.class));
+ processor.visitMethod(
+ EasyMock.isA(Method.class),
+ EasyMock.isA(PojoComponentType.class),
+ EasyMock.isA(DeploymentContext.class));
+ processor.visitField(
+ EasyMock.isA(Field.class),
+ EasyMock.isA(PojoComponentType.class),
+ EasyMock.isA(DeploymentContext.class));
+ processor.visitSuperClass(
+ EasyMock.isA(Class.class),
+ EasyMock.isA(PojoComponentType.class),
+ EasyMock.isA(DeploymentContext.class));
+ processor.visitEnd(
+ EasyMock.isA(Class.class),
+ EasyMock.isA(PojoComponentType.class),
+ EasyMock.isA(DeploymentContext.class));
+
+ // mock.expects(once()).method("visitClass");
+// mock.expects(once()).method("visitMethod");
+// mock.expects(once()).method("visitField");
+// mock.expects(once()).method("visitConstructor");
+// mock.expects(once()).method("visitSuperClass");
+// mock.expects(once()).method("visitEnd");
+ EasyMock.replay(processor);
+ registry.registerProcessor(processor);
+ registry.introspect(
+ Bar.class,
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(),
+ EasyMock.createNiceMock(DeploymentContext.class));
+ EasyMock.verify(processor);
+ }
+
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ monitor = new NullMonitorFactory().getMonitor(Monitor.class);
+ }
+
+ private class Baz {
+
+ }
+
+ private class Bar extends Baz {
+
+ protected String bar;
+
+ public Bar() {
+ }
+
+ public void bar() {
+ }
+
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/PhysicalComponentTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/PhysicalComponentTestCase.java
new file mode 100644
index 0000000000..f3bdf5e332
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/PhysicalComponentTestCase.java
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation;
+
+import junit.framework.TestCase;
+import org.osoa.sca.annotations.Destroy;
+import org.osoa.sca.annotations.Init;
+
+import org.apache.tuscany.core.component.InstanceFactory;
+import org.apache.tuscany.core.component.scope.InstanceWrapper;
+import org.apache.tuscany.core.component.scope.InstanceWrapperBase;
+import org.apache.tuscany.spi.component.TargetDestructionException;
+import org.apache.tuscany.spi.component.TargetInitializationException;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class PhysicalComponentTestCase extends TestCase {
+ public void testSomething() {
+
+ }
+
+ /**
+ * This is the class supplied by the user.
+ */
+ public static class UserImplementation {
+ @Init
+ void init() {
+ }
+
+ @Destroy
+ void destroy() {
+ }
+ }
+
+ /**
+ * This is the generated wrapper class.
+ */
+ public static class UserWrapper extends InstanceWrapperBase<UserImplementation> {
+ public UserWrapper(UserImplementation instance) {
+ super(instance);
+ }
+
+ public void start() throws TargetInitializationException {
+ instance.init();
+ super.start();
+ }
+
+ public void stop() throws TargetDestructionException {
+ super.stop();
+ instance.destroy();
+ }
+ }
+
+ /**
+ * This is the generated factory class.
+ */
+ public static class UserFactory implements InstanceFactory<UserImplementation> {
+ public InstanceWrapper<UserImplementation> newInstance() {
+ UserImplementation instance = new UserImplementation();
+ return new UserWrapper(instance);
+ }
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/PojoAtomicComponentTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/PojoAtomicComponentTestCase.java
new file mode 100644
index 0000000000..ccb2c88767
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/PojoAtomicComponentTestCase.java
@@ -0,0 +1,193 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation;
+
+import java.net.URI;
+
+import org.apache.tuscany.spi.ObjectFactory;
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.TargetInvokerCreationException;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+import org.apache.tuscany.spi.wire.Wire;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.injection.EventInvoker;
+import org.apache.tuscany.core.injection.PojoObjectFactory;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class PojoAtomicComponentTestCase extends TestCase {
+ private PojoConfiguration config;
+
+ @SuppressWarnings({"unchecked"})
+ public void testDestroy() throws Exception {
+ EventInvoker<Object> invoker = EasyMock.createMock(EventInvoker.class);
+ invoker.invokeEvent(EasyMock.notNull());
+ EasyMock.replay(invoker);
+ config.setDestroyInvoker(invoker);
+ AtomicComponent component = new TestAtomicComponent(config);
+ assertTrue(component.isDestroyable());
+ component.destroy(new Object());
+ EasyMock.verify(invoker);
+ }
+
+ @SuppressWarnings({"unchecked"})
+ public void testNoCallbackWires() throws Exception {
+ ScopeContainer container = EasyMock.createMock(ScopeContainer.class);
+ EasyMock.expect(container.getScope()).andReturn(Scope.CONVERSATION);
+ container.register(EasyMock.isA(AtomicComponent.class));
+ EasyMock.replay(container);
+ config.addCallbackSite("callback", Foo.class.getMethod("setCallback", Object.class));
+ AtomicComponent component = new TestAtomicComponent(config);
+ component.setScopeContainer(container);
+ component.start();
+ EasyMock.verify(container);
+ }
+
+ @SuppressWarnings({"unchecked"})
+ public void testInit() throws Exception {
+ EventInvoker<Object> invoker = EasyMock.createMock(EventInvoker.class);
+ invoker.invokeEvent(EasyMock.notNull());
+ EasyMock.replay(invoker);
+ config.setInitInvoker(invoker);
+ AtomicComponent component = new TestAtomicComponent(config);
+ component.init(new Object());
+ EasyMock.verify(invoker);
+ }
+
+ public void testOptimizable() throws Exception {
+ TestAtomicComponent component = new TestAtomicComponent(config);
+ assertTrue(component.isOptimizable());
+ }
+
+ @SuppressWarnings({"unchecked"})
+ public void testDestroyableButOptimizable() throws Exception {
+ EventInvoker<Object> invoker = EasyMock.createMock(EventInvoker.class);
+ invoker.invokeEvent(EasyMock.notNull());
+ EasyMock.replay(invoker);
+ config.setDestroyInvoker(invoker);
+ TestAtomicComponent component = new TestAtomicComponent(config);
+ assertTrue(component.isOptimizable());
+ }
+
+ @SuppressWarnings({"unchecked"})
+ public void testStatelessOptimizable() throws Exception {
+ TestAtomicComponent component = new TestAtomicComponent(config, Scope.STATELESS);
+ assertTrue(component.isOptimizable());
+ }
+
+ @SuppressWarnings({"unchecked"})
+ public void testNotOptimizable() throws Exception {
+ EventInvoker<Object> invoker = EasyMock.createMock(EventInvoker.class);
+ invoker.invokeEvent(EasyMock.notNull());
+ EasyMock.replay(invoker);
+ config.setDestroyInvoker(invoker);
+ TestAtomicComponent component = new TestAtomicComponent(config, Scope.STATELESS);
+ assertFalse(component.isOptimizable());
+ }
+
+ public void testPropertyAccess() {
+ String value = "Foo!";
+ ObjectFactory objectFactory = EasyMock.createMock(ObjectFactory.class);
+ EasyMock.expect(objectFactory.getInstance()).andReturn(value);
+ EasyMock.replay(objectFactory);
+
+ TestAtomicComponent component = new TestAtomicComponent(config);
+ component.addPropertyFactory("foo", objectFactory);
+ assertSame(value, component.getProperty(String.class, "foo"));
+ }
+
+ public void testServiceLookup() {
+ URI uri = URI.create("#service");
+ FooService foo = EasyMock.createMock(FooService.class);
+ Wire wire = EasyMock.createMock(Wire.class);
+ EasyMock.expect(wire.getSourceUri()).andReturn(uri).atLeastOnce();
+ EasyMock.replay(wire);
+ ObjectFactory factory = EasyMock.createMock(ObjectFactory.class);
+ EasyMock.expect(factory.getInstance()).andReturn(foo);
+ EasyMock.replay(factory);
+ TestAtomicComponent component = new TestAtomicComponent(config, Scope.COMPOSITE, factory);
+ component.attachWire(wire);
+ assertSame(foo, component.getService(FooService.class, "service"));
+ EasyMock.verify(wire);
+ EasyMock.verify(factory);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ PojoObjectFactory<Foo> factory = new PojoObjectFactory<Foo>(Foo.class.getConstructor());
+
+ config = new PojoConfiguration();
+ config.setInstanceFactory(factory);
+ config.setName(URI.create("foo"));
+ }
+
+ private class TestAtomicComponent extends PojoAtomicComponent {
+ private final ObjectFactory factory;
+ private final Scope scope;
+
+ public TestAtomicComponent(PojoConfiguration configuration) {
+ this(configuration, Scope.COMPOSITE, null);
+ }
+
+ public TestAtomicComponent(PojoConfiguration configuration, Scope scope) {
+ this(configuration, scope, null);
+ }
+
+ public TestAtomicComponent(PojoConfiguration configuration, Scope scope, ObjectFactory factory) {
+ super(configuration);
+ this.scope = scope;
+ this.factory = factory;
+ }
+
+ public Scope getScope() {
+ return scope;
+ }
+
+ @SuppressWarnings({"unchecked"})
+ protected <B> ObjectFactory<B> createWireFactory(Class<B> interfaze, Wire wire) {
+ return factory;
+ }
+
+ public TargetInvoker createTargetInvoker(String targetName, Operation operation)
+ throws TargetInvokerCreationException {
+ return null;
+ }
+ }
+
+ private static class Foo {
+ public Foo() {
+ }
+
+ public void setCallback(Object callback) {
+
+ }
+ }
+
+ public static interface FooService {
+ }
+
+}
+
+
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeBuilderTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeBuilderTestCase.java
new file mode 100644
index 0000000000..96808add34
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeBuilderTestCase.java
@@ -0,0 +1,199 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.composite;
+
+import java.net.URI;
+import java.util.Map;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.component.ScopeContainerMonitor;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.idl.java.JavaInterfaceProcessorRegistry;
+import org.apache.tuscany.spi.idl.java.JavaServiceContract;
+import org.apache.tuscany.spi.implementation.java.ConstructorDefinition;
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.CompositeComponentType;
+import org.apache.tuscany.spi.model.CompositeImplementation;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.ReferenceTarget;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.binding.local.LocalBindingBuilder;
+import org.apache.tuscany.core.binding.local.LocalBindingDefinition;
+import org.apache.tuscany.core.builder.BuilderRegistryImpl;
+import org.apache.tuscany.core.component.scope.CompositeScopeContainer;
+import org.apache.tuscany.core.deployer.RootDeploymentContext;
+import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
+import org.apache.tuscany.core.implementation.java.JavaComponentBuilder;
+import org.apache.tuscany.core.implementation.java.JavaImplementation;
+import org.apache.tuscany.core.mock.component.OtherTarget;
+import org.apache.tuscany.core.mock.component.Source;
+import org.apache.tuscany.core.mock.component.SourceImpl;
+import org.apache.tuscany.core.mock.component.Target;
+import org.apache.tuscany.core.mock.component.TargetImpl;
+import org.easymock.EasyMock;
+
+/**
+ * @version $$Rev$$ $$Date$$
+ */
+public class CompositeBuilderTestCase extends TestCase {
+ private static final URI TOP_COMPONENT = URI.create("Top");
+ private static final URI SOURCE_COMPONENT = URI.create("Top/Parent/SourceComponent");
+ private static final URI TARGET_COMPONENT = URI.create("Top/Parent/TargetComponent");
+ private static final URI INNER_SOURCE_COMPONENT = URI.create("Top/Parent/SourceComponent/InnerSourceComponent");
+
+ private DeploymentContext deploymentContext;
+
+ @SuppressWarnings("unchecked")
+ public void testBuild() throws Exception {
+ CompositeBuilder builder = new CompositeBuilder();
+ BuilderRegistryImpl builderRegistry = new BuilderRegistryImpl(null);
+ JavaComponentBuilder jBuilder = new JavaComponentBuilder();
+ builderRegistry.register(JavaImplementation.class, jBuilder);
+ builderRegistry.register(CompositeImplementation.class, builder);
+ builderRegistry.register(LocalBindingDefinition.class, new LocalBindingBuilder());
+ builder.setBuilderRegistry(builderRegistry);
+
+ Component component =
+ builder.build(createTopComponentDef(), deploymentContext);
+ Map<URI, Component> components = deploymentContext.getComponents();
+ Component sourceComponent = components.get(SOURCE_COMPONENT);
+ assertNotNull(sourceComponent.getService("InnerSourceService"));
+ AtomicComponent innerSourceComponent = (AtomicComponent) components.get(INNER_SOURCE_COMPONENT);
+ assertNotNull(innerSourceComponent);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ ScopeContainerMonitor monitor = EasyMock.createNiceMock(ScopeContainerMonitor.class);
+ CompositeScopeContainer container = new CompositeScopeContainer(monitor);
+ container.start();
+ deploymentContext = new RootDeploymentContext(null, null, TOP_COMPONENT, null, container, false);
+ }
+
+ private ComponentDefinition createTopComponentDef() throws Exception {
+ CompositeComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> outerType =
+ new CompositeComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ outerType.add(createSourceComponentDef());
+ outerType.add(createTargetComponentDef());
+
+ CompositeImplementation outerImpl = new CompositeImplementation();
+ outerImpl.setComponentType(outerType);
+
+ ComponentDefinition def = new ComponentDefinition<CompositeImplementation>(outerImpl);
+ def.setUri(TOP_COMPONENT);
+ return def;
+ }
+
+ private ComponentDefinition<CompositeImplementation> createSourceComponentDef() throws Exception {
+
+ CompositeComponentType<ServiceDefinition, ReferenceDefinition, JavaMappedProperty<?>> innerType =
+ new CompositeComponentType<ServiceDefinition, ReferenceDefinition, JavaMappedProperty<?>>();
+ innerType.add(createInnerSourceComponentDef());
+ ReferenceDefinition reference = new ReferenceDefinition();
+ reference.setUri(URI.create("#TargetComponentRef"));
+ JavaInterfaceProcessorRegistry registry = new JavaInterfaceProcessorRegistryImpl();
+ JavaServiceContract targetContract = registry.introspect(Target.class);
+ reference.setServiceContract(targetContract);
+ innerType.add(reference);
+ ServiceDefinition service = new ServiceDefinition();
+ service.setUri(URI.create("#InnerSourceService"));
+ JavaServiceContract sourceContract = registry.introspect(Source.class);
+ service.setServiceContract(sourceContract);
+ service.setTarget(INNER_SOURCE_COMPONENT);
+ innerType.add(service);
+
+ CompositeImplementation innerImpl = new CompositeImplementation();
+ innerImpl.setComponentType(innerType);
+
+ ComponentDefinition<CompositeImplementation> sourceComponentDefinition =
+ new ComponentDefinition<CompositeImplementation>(SOURCE_COMPONENT, innerImpl);
+ ReferenceTarget refTarget = new ReferenceTarget();
+ refTarget.setReferenceName(URI.create("#TargetComponentRef"));
+ refTarget.addTarget(TARGET_COMPONENT);
+ sourceComponentDefinition.add(refTarget);
+
+ return sourceComponentDefinition;
+ }
+
+ private ComponentDefinition<JavaImplementation> createInnerSourceComponentDef() throws Exception {
+
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> sourceType =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ sourceType.setImplementationScope(Scope.COMPOSITE);
+ JavaMappedReference reference = new JavaMappedReference();
+ reference.setUri(URI.create("#targetReference"));
+ JavaInterfaceProcessorRegistry registry = new JavaInterfaceProcessorRegistryImpl();
+ ServiceContract<?> targetContract = registry.introspect(Target.class);
+ targetContract.setCallbackClass(OtherTarget.class);
+ targetContract.setCallbackName("OtherTarget");
+ reference.setServiceContract(targetContract);
+ reference.setMember(SourceImpl.class.getMethod("setTarget", Target.class));
+ sourceType.add(reference);
+
+ ServiceContract<?> sourceContract = registry.introspect(Source.class);
+
+ JavaMappedService sourceServiceDefinition = new JavaMappedService();
+ sourceServiceDefinition.setUri(URI.create("#Source"));
+ sourceServiceDefinition.setServiceContract(sourceContract);
+
+ sourceType.add(sourceServiceDefinition);
+ sourceType.setConstructorDefinition(new ConstructorDefinition<SourceImpl>(SourceImpl.class.getConstructor()));
+ JavaImplementation sourceImpl = new JavaImplementation(SourceImpl.class, sourceType);
+ ComponentDefinition<JavaImplementation> innerSourceComponentDefinition =
+ new ComponentDefinition<JavaImplementation>(INNER_SOURCE_COMPONENT, sourceImpl);
+ ReferenceTarget refTarget = new ReferenceTarget();
+ refTarget.setReferenceName(URI.create("#targetReference"));
+ refTarget.addTarget(new URI("#TargetComponentRef"));
+ innerSourceComponentDefinition.add(refTarget);
+
+ return innerSourceComponentDefinition;
+ }
+
+ private ComponentDefinition<JavaImplementation> createTargetComponentDef() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> targetType =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ targetType.setImplementationScope(Scope.COMPOSITE);
+
+ JavaInterfaceProcessorRegistry registry = new JavaInterfaceProcessorRegistryImpl();
+ ServiceContract<?> targetContract = registry.introspect(Target.class);
+ targetContract.setCallbackClass(OtherTarget.class);
+ targetContract.setCallbackName("OtherTarget");
+
+ JavaMappedService serviceDefinition = new JavaMappedService();
+ serviceDefinition.setUri(URI.create("Target"));
+ serviceDefinition.setServiceContract(targetContract);
+ serviceDefinition.setCallbackReferenceName("otherTarget");
+
+ targetType.add(serviceDefinition);
+ targetType.setConstructorDefinition(new ConstructorDefinition<TargetImpl>(TargetImpl.class.getConstructor()));
+ JavaImplementation targetImpl = new JavaImplementation(TargetImpl.class, targetType);
+ //URI uri = URI.create("TargetComponent");
+ return new ComponentDefinition<JavaImplementation>(TARGET_COMPONENT, targetImpl);
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeComponentImplTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeComponentImplTestCase.java
new file mode 100644
index 0000000000..a5574c7f78
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeComponentImplTestCase.java
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.composite;
+
+import java.net.URI;
+
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.component.Reference;
+import org.apache.tuscany.spi.component.Service;
+import org.apache.tuscany.spi.event.Event;
+import org.apache.tuscany.spi.event.RuntimeEventListener;
+import org.apache.tuscany.spi.model.Scope;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.eq;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.replay;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class CompositeComponentImplTestCase extends TestCase {
+
+ public void testGetScope() {
+ Component composite = new CompositeComponentImpl(URI.create("parent"));
+ Assert.assertEquals(Scope.SYSTEM, composite.getScope());
+ }
+
+ public void testRegisterService() throws Exception {
+ Component composite = new CompositeComponentImpl(URI.create("parent"));
+ Service service = new ServiceImpl(URI.create("foo#service"), null);
+ composite.register(service);
+ assertNotNull(composite.getService("service"));
+ }
+
+ public void testRegisterReference() throws Exception {
+ Component composite = new CompositeComponentImpl(URI.create("parent"));
+ Reference reference = new ReferenceImpl(URI.create("foo#reference"), null);
+ composite.register(reference);
+ assertNotNull(composite.getReference("reference"));
+ }
+
+ public void testOnEvent() {
+ CompositeComponentImpl composite = new CompositeComponentImpl(URI.create("parent"));
+ Event event = new Event() {
+ public Object getSource() {
+ return null;
+ }
+ };
+ RuntimeEventListener listener = createMock(RuntimeEventListener.class);
+ listener.onEvent(eq(event));
+ expectLastCall();
+ replay(listener);
+ composite.addListener(listener);
+ composite.start();
+ composite.onEvent(event);
+ EasyMock.verify(listener);
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeLoaderTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeLoaderTestCase.java
new file mode 100644
index 0000000000..84c5825e82
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeLoaderTestCase.java
@@ -0,0 +1,201 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.composite;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamReader;
+
+import static org.osoa.sca.Constants.SCA_NS;
+
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.model.CompositeComponentType;
+import org.apache.tuscany.spi.model.ModelObject;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.deployer.RootDeploymentContext;
+import org.easymock.EasyMock;
+import org.easymock.IAnswer;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class CompositeLoaderTestCase extends TestCase {
+ public static final QName COMPOSITE = new QName(SCA_NS, "composite");
+ private CompositeLoader loader;
+ private QName name;
+
+ public void testLoadNameAndDefaultAutowire() throws Exception {
+ XMLStreamReader reader = EasyMock.createMock(XMLStreamReader.class);
+ EasyMock.expect(reader.getAttributeValue(null, "name")).andReturn(name.getLocalPart());
+ EasyMock.expect(reader.getAttributeValue(null, "targetNamespace")).andReturn(name.getNamespaceURI());
+ EasyMock.expect(reader.getAttributeValue(null, "autowire")).andReturn(null);
+ EasyMock.expect(reader.next()).andReturn(XMLStreamConstants.END_ELEMENT);
+ EasyMock.expect(reader.getName()).andReturn(COMPOSITE);
+ EasyMock.replay(reader);
+ CompositeComponentType<?, ?, ?> type = loader.load(null, reader, null);
+ assertEquals(name, type.getName());
+ assertFalse(type.isAutowire());
+ EasyMock.verify(reader);
+ }
+
+ public void testAutowire() throws Exception {
+ XMLStreamReader reader = EasyMock.createMock(XMLStreamReader.class);
+ EasyMock.expect(reader.getAttributeValue(null, "name")).andReturn(name.getLocalPart());
+ EasyMock.expect(reader.getAttributeValue(null, "targetNamespace")).andReturn(name.getNamespaceURI());
+ EasyMock.expect(reader.getAttributeValue(null, "autowire")).andReturn("true");
+ EasyMock.expect(reader.next()).andReturn(XMLStreamConstants.END_ELEMENT);
+ EasyMock.expect(reader.getName()).andReturn(COMPOSITE);
+ EasyMock.replay(reader);
+ CompositeComponentType<?, ?, ?> type = loader.load(null, reader, null);
+ assertTrue(type.isAutowire());
+ EasyMock.verify(reader);
+ }
+
+ /**
+ * Tests autowire enabled is propagated when children are loaded
+ */
+ public void testAutowireContextEnabledPropagation() throws Exception {
+ LoaderRegistry registry = EasyMock.createMock(LoaderRegistry.class);
+ registry.load(EasyMock.isA(ModelObject.class),
+ EasyMock.isA(XMLStreamReader.class),
+ EasyMock.isA(DeploymentContext.class));
+ EasyMock.expectLastCall().andStubAnswer(new IAnswer<Object>() {
+ public Object answer() throws Throwable {
+ DeploymentContext context = (DeploymentContext) EasyMock.getCurrentArguments()[2];
+ assertTrue("autowire not propagated", context.isAutowire());
+ return null;
+ }
+ });
+ EasyMock.replay(registry);
+ DeploymentContext context = new RootDeploymentContext(null, null, null, null, null, true);
+ XMLStreamReader reader = EasyMock.createMock(XMLStreamReader.class);
+ EasyMock.expect(reader.getAttributeValue(null, "name")).andReturn(name.getLocalPart());
+ EasyMock.expect(reader.getAttributeValue(null, "targetNamespace")).andReturn(name.getNamespaceURI());
+ EasyMock.expect(reader.getAttributeValue(null, "autowire")).andReturn("true");
+ EasyMock.expect(reader.next()).andReturn(XMLStreamConstants.START_ELEMENT);
+ EasyMock.expect(reader.next()).andReturn(XMLStreamConstants.END_ELEMENT);
+ EasyMock.expect(reader.next()).andReturn(XMLStreamConstants.END_ELEMENT);
+ EasyMock.expect(reader.getName()).andReturn(COMPOSITE);
+ EasyMock.replay(reader);
+ loader.load(null, reader, context);
+ assertTrue(context.isAutowire());
+ }
+
+ /**
+ * Tests autowire enabled is propagated when children are loaded and composite is set to use inherited autowire
+ * settings
+ */
+ public void testAutowireContextEnabledInheritedPropagation() throws Exception {
+ LoaderRegistry registry = EasyMock.createMock(LoaderRegistry.class);
+ registry.load(EasyMock.isA(ModelObject.class),
+ EasyMock.isA(XMLStreamReader.class),
+ EasyMock.isA(DeploymentContext.class));
+ EasyMock.expectLastCall().andStubAnswer(new IAnswer<Object>() {
+ public Object answer() throws Throwable {
+ DeploymentContext context = (DeploymentContext) EasyMock.getCurrentArguments()[2];
+ assertTrue("autowire not propagated", context.isAutowire());
+ return null;
+ }
+ });
+ EasyMock.replay(registry);
+ DeploymentContext context = new RootDeploymentContext(null, null, null, null, null, true);
+ XMLStreamReader reader = EasyMock.createMock(XMLStreamReader.class);
+ EasyMock.expect(reader.getAttributeValue(null, "name")).andReturn(name.getLocalPart());
+ EasyMock.expect(reader.getAttributeValue(null, "targetNamespace")).andReturn(name.getNamespaceURI());
+ EasyMock.expect(reader.getAttributeValue(null, "autowire")).andReturn(null);
+ EasyMock.expect(reader.next()).andReturn(XMLStreamConstants.START_ELEMENT);
+ EasyMock.expect(reader.next()).andReturn(XMLStreamConstants.END_ELEMENT);
+ EasyMock.expect(reader.next()).andReturn(XMLStreamConstants.END_ELEMENT);
+ EasyMock.expect(reader.getName()).andReturn(COMPOSITE);
+ EasyMock.replay(reader);
+ loader.load(null, reader, context);
+ assertTrue(context.isAutowire());
+ }
+
+ /**
+ * Tests autowire false is propagated when children are loaded and composite inherits autowire settings
+ */
+ public void testAutowireFalseContextPropagation() throws Exception {
+ LoaderRegistry registry = EasyMock.createMock(LoaderRegistry.class);
+ registry.load(EasyMock.isA(ModelObject.class),
+ EasyMock.isA(XMLStreamReader.class),
+ EasyMock.isA(DeploymentContext.class));
+ EasyMock.expectLastCall().andStubAnswer(new IAnswer<Object>() {
+ public Object answer() throws Throwable {
+ DeploymentContext context = (DeploymentContext) EasyMock.getCurrentArguments()[2];
+ assertFalse("autowire not propagated", context.isAutowire());
+ return null;
+ }
+ });
+ EasyMock.replay(registry);
+ DeploymentContext context = new RootDeploymentContext(null, null, null, null, null, false);
+ XMLStreamReader reader = EasyMock.createMock(XMLStreamReader.class);
+ EasyMock.expect(reader.getAttributeValue(null, "name")).andReturn(name.getLocalPart());
+ EasyMock.expect(reader.getAttributeValue(null, "targetNamespace")).andReturn(name.getNamespaceURI());
+ EasyMock.expect(reader.getAttributeValue(null, "autowire")).andReturn(null);
+ EasyMock.expect(reader.next()).andReturn(XMLStreamConstants.START_ELEMENT);
+ EasyMock.expect(reader.next()).andReturn(XMLStreamConstants.END_ELEMENT);
+ EasyMock.expect(reader.next()).andReturn(XMLStreamConstants.END_ELEMENT);
+ EasyMock.expect(reader.getName()).andReturn(COMPOSITE);
+ EasyMock.replay(reader);
+ loader.load(null, reader, context);
+ assertFalse(context.isAutowire());
+ }
+
+ /**
+ * Tests autowire false is propagated when children are loaded and composite autowire is set to false
+ */
+ public void testAutowireCompositeFalsePropagation() throws Exception {
+ LoaderRegistry registry = EasyMock.createMock(LoaderRegistry.class);
+ registry.load(EasyMock.isA(ModelObject.class),
+ EasyMock.isA(XMLStreamReader.class),
+ EasyMock.isA(DeploymentContext.class));
+ EasyMock.expectLastCall().andStubAnswer(new IAnswer<Object>() {
+ public Object answer() throws Throwable {
+ DeploymentContext context = (DeploymentContext) EasyMock.getCurrentArguments()[2];
+ assertFalse("autowire not propagated", context.isAutowire());
+ return null;
+ }
+ });
+ EasyMock.replay(registry);
+ DeploymentContext context = new RootDeploymentContext(null, null, null, null, null, true);
+ XMLStreamReader reader = EasyMock.createMock(XMLStreamReader.class);
+ EasyMock.expect(reader.getAttributeValue(null, "name")).andReturn(name.getLocalPart());
+ EasyMock.expect(reader.getAttributeValue(null, "targetNamespace")).andReturn(name.getNamespaceURI());
+ EasyMock.expect(reader.getAttributeValue(null, "autowire")).andReturn("false");
+ EasyMock.expect(reader.next()).andReturn(XMLStreamConstants.START_ELEMENT);
+ EasyMock.expect(reader.next()).andReturn(XMLStreamConstants.END_ELEMENT);
+ EasyMock.expect(reader.next()).andReturn(XMLStreamConstants.END_ELEMENT);
+ EasyMock.expect(reader.getName()).andReturn(COMPOSITE);
+ EasyMock.replay(reader);
+ loader.load(null, reader, context);
+ assertTrue(context.isAutowire());
+ }
+
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ LoaderRegistry registry = EasyMock.createNiceMock(LoaderRegistry.class);
+ EasyMock.replay(registry);
+ loader = new CompositeLoader(registry, null);
+ name = new QName("http://example.com", "composite");
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeLoaderWireResolutionTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeLoaderWireResolutionTestCase.java
new file mode 100644
index 0000000000..47574c02b6
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeLoaderWireResolutionTestCase.java
@@ -0,0 +1,230 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.core.implementation.composite;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.loader.InvalidWireException;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.CompositeComponentType;
+import org.apache.tuscany.spi.model.Property;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+import org.apache.tuscany.spi.model.WireDefinition;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.implementation.java.JavaImplementation;
+
+/**
+ * This class tests the wire resolution function of the composite loader
+ *
+ * @version $Rev$ $Date$
+ */
+public class CompositeLoaderWireResolutionTestCase extends TestCase {
+ private CompositeComponentType<ServiceDefinition, ReferenceDefinition, Property<?>> componentType;
+ private CompositeLoader compositeLoader = new CompositeLoader(null, null);
+
+ public void testCompositeSvc2CompositeReferenceWire() throws Exception {
+ WireDefinition wireDefn = new WireDefinition();
+ wireDefn.setSource(new URI("compositeService1"));
+ wireDefn.setTarget(new URI("compositeReference"));
+ componentType.add(wireDefn);
+ compositeLoader.resolveWires(componentType);
+ }
+
+ public void testCompositeSvc2ComponentValid() throws Exception {
+ //undefined source and targets
+ WireDefinition wireDefn = new WireDefinition();
+ wireDefn.setSource(new URI("compositeService1"));
+ wireDefn.setTarget(new URI("Component1"));
+ componentType.add(wireDefn);
+ compositeLoader.resolveWires(componentType);
+ }
+
+ public void testCompositeSvc2ComponentQualifiedValid() throws Exception {
+ //undefined source and targets
+ WireDefinition wireDefn = new WireDefinition();
+ wireDefn.setSource(new URI("compositeService1"));
+ wireDefn.setTarget(new URI("Component2#pojoSvc3"));
+ componentType.add(wireDefn);
+ compositeLoader.resolveWires(componentType);
+ }
+
+ public void testCompositeSvc2ComponentQualifiedInvalid() throws URISyntaxException {
+ //undefined source and targets
+ WireDefinition wireDefn = new WireDefinition();
+ wireDefn.setSource(new URI("compositeService1"));
+ wireDefn.setTarget(new URI("Component2#pojoSvc5"));
+ componentType.add(wireDefn);
+ try {
+ compositeLoader.resolveWires(componentType);
+ fail();
+ } catch (InvalidWireException e) {
+ // expected
+ }
+ }
+
+ public void testCompositeSvc2ComponentUnQualifiedInvalid() throws URISyntaxException {
+ //undefined source and targets
+ WireDefinition wireDefn = new WireDefinition();
+ wireDefn.setSource(new URI("compositeService1"));
+ wireDefn.setTarget(new URI("Component2"));
+ componentType.add(wireDefn);
+ try {
+ compositeLoader.resolveWires(componentType);
+ fail();
+ } catch (InvalidWireException e) {
+ // expected
+ }
+ }
+
+ public void testComponent2CompositeReferenceValid() throws Exception {
+ //undefined source and targets
+ WireDefinition wireDefn = new WireDefinition();
+ wireDefn.setSource(new URI("Component1#pojoRef1"));
+ wireDefn.setTarget(new URI("compositeReference"));
+ componentType.add(wireDefn);
+ compositeLoader.resolveWires(componentType);
+ }
+
+ public void testComponent2CompositeReferenceQualifiedValid() throws Exception {
+ //undefined source and targets
+ WireDefinition wireDefn = new WireDefinition();
+ wireDefn.setSource(new URI("Component2#pojoRef3"));
+ wireDefn.setTarget(new URI("compositeReference"));
+ componentType.add(wireDefn);
+ compositeLoader.resolveWires(componentType);
+ }
+
+ public void testComponent2CompositeReferenceUnQualifiedInvalid() throws URISyntaxException {
+ //undefined source and targets
+ WireDefinition wireDefn = new WireDefinition();
+ wireDefn.setSource(new URI("Component2"));
+ wireDefn.setTarget(new URI("compositeReference"));
+ componentType.add(wireDefn);
+
+ try {
+ compositeLoader.resolveWires(componentType);
+ fail();
+ } catch (InvalidWireException e) {
+ // expected
+ }
+ }
+
+ public void testComponent2ComponentQualifedValid() throws Exception {
+ WireDefinition wireDefn = new WireDefinition();
+ wireDefn.setSource(new URI("Component1#pojoRef1"));
+ wireDefn.setTarget(new URI("Component2#pojoSvc3"));
+ componentType.add(wireDefn);
+ compositeLoader.resolveWires(componentType);
+ }
+
+ public void testComponent2ComponentUnQualifedInvalid() throws URISyntaxException {
+ //undefined source and targets
+ WireDefinition wireDefn = new WireDefinition();
+ wireDefn.setSource(new URI("Component1"));
+ wireDefn.setTarget(new URI("Component2"));
+ componentType.add(wireDefn);
+ try {
+ compositeLoader.resolveWires(componentType);
+ fail();
+ } catch (InvalidWireException e) {
+ // expected
+ }
+ }
+
+ public void testInvalidWireDefinitions() throws URISyntaxException {
+ //undefined source and targets
+ WireDefinition wireDefn = new WireDefinition();
+ wireDefn.setSource(new URI("undefinedSource"));
+ wireDefn.setTarget(new URI("compositeReference"));
+ componentType.add(wireDefn);
+
+ try {
+ compositeLoader.resolveWires(componentType);
+ fail();
+ } catch (InvalidWireException e) {
+ // expected
+ }
+
+ try {
+ wireDefn.setSource(new URI("compositeService1"));
+ wireDefn.setTarget(new URI("undefinedTarget"));
+ componentType.add(wireDefn);
+ compositeLoader.resolveWires(componentType);
+ fail();
+ } catch (InvalidWireException e) {
+ // expected
+ }
+ }
+
+ public void setUp() throws Exception {
+ componentType = new CompositeComponentType<ServiceDefinition, ReferenceDefinition, Property<?>>();
+
+ //add a service to the composite
+ ServiceDefinition serviceDefn = new ServiceDefinition(URI.create("#compositeService1"), null, true);
+ ServiceDefinition boundSvcDefn = new ServiceDefinition(URI.create("#boundSvc"), null, true, null);
+ ServiceDefinition boundSvcDefnWithTarget =
+ new ServiceDefinition(URI.create("#boundSvcWithTarget"), null, true);
+ boundSvcDefnWithTarget.setTarget(new URI("orgTarget"));
+ componentType.add(serviceDefn);
+ componentType.add(boundSvcDefn);
+ componentType.add(boundSvcDefnWithTarget);
+
+ ReferenceDefinition compositeReference = new ReferenceDefinition(URI.create("#compositeReference"), null);
+ componentType.add(compositeReference);
+
+ PojoComponentType<ServiceDefinition, ReferenceDefinition, Property<?>> pojoComponentType1 =
+ new PojoComponentType<ServiceDefinition, ReferenceDefinition, Property<?>>();
+ ServiceDefinition pojoSvc1 = new ServiceDefinition(URI.create("#pojoSvc1"), null, false);
+ pojoComponentType1.add(pojoSvc1);
+ ReferenceDefinition pojoRef1 = new ReferenceDefinition(URI.create("#pojoRef1"), null);
+ pojoComponentType1.add(pojoRef1);
+ JavaImplementation pojoImpl1 = new JavaImplementation(null, pojoComponentType1);
+
+ URI uri = URI.create("Component1");
+ ComponentDefinition<JavaImplementation> component1 =
+ new ComponentDefinition<JavaImplementation>(uri, pojoImpl1);
+ componentType.add(component1);
+
+ PojoComponentType<ServiceDefinition, ReferenceDefinition, Property<?>> pojoComponentType2 =
+ new PojoComponentType<ServiceDefinition, ReferenceDefinition, Property<?>>();
+ ServiceDefinition pojoSvc2 = new ServiceDefinition(URI.create("#pojoSvc2"), null, false);
+ pojoComponentType2.add(pojoSvc2);
+ ServiceDefinition pojoSvc3 = new ServiceDefinition(URI.create("#pojoSvc3"), null, false);
+ pojoComponentType2.add(pojoSvc3);
+ ReferenceDefinition pojoRef2 = new ReferenceDefinition(URI.create("#pojoRef2"), null);
+ pojoComponentType2.add(pojoRef2);
+ ReferenceDefinition pojoRef3 = new ReferenceDefinition(URI.create("#pojoRef3"), null);
+ pojoComponentType2.add(pojoRef3);
+ JavaImplementation pojoImpl2 = new JavaImplementation(null, pojoComponentType2);
+
+ URI uri2 = URI.create("Component2");
+ ComponentDefinition<JavaImplementation> component2 =
+ new ComponentDefinition<JavaImplementation>(uri2, pojoImpl2);
+ componentType.add(component2);
+ }
+
+
+
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/composite/DuplicateRegistrationTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/composite/DuplicateRegistrationTestCase.java
new file mode 100644
index 0000000000..c3394c1043
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/composite/DuplicateRegistrationTestCase.java
@@ -0,0 +1,120 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.composite;
+
+import java.net.URI;
+
+import org.apache.tuscany.spi.component.DuplicateNameException;
+import org.apache.tuscany.spi.component.Service;
+import org.apache.tuscany.spi.component.Reference;
+import org.apache.tuscany.spi.component.Component;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * Verfies children with the same name cannot be registered in the same composite
+ *
+ * @version $Rev$ $Date$
+ */
+public class DuplicateRegistrationTestCase extends TestCase {
+
+ public void testDuplicateServiceRegistration() throws Exception {
+ Component parent = new CompositeComponentImpl(URI.create("parent"));
+ parent.start();
+
+ Service service1 = EasyMock.createMock(Service.class);
+ EasyMock.expect(service1.getUri()).andReturn(URI.create("#service")).atLeastOnce();
+ service1.stop();
+ EasyMock.replay(service1);
+
+ Service service2 = EasyMock.createMock(Service.class);
+ EasyMock.expect(service2.getUri()).andReturn(URI.create("#service")).atLeastOnce();
+ service2.stop();
+ EasyMock.replay(service2);
+
+ parent.register(service2);
+ try {
+ parent.register(service1);
+ fail();
+ } catch (DuplicateNameException e) {
+ // ok
+ }
+ parent.stop();
+ }
+
+ public void testDuplicateReferenceRegistration() throws Exception {
+ Component parent = new CompositeComponentImpl(URI.create("parent"));
+ parent.start();
+
+ Reference reference1 = EasyMock.createMock(Reference.class);
+ EasyMock.expect(reference1.getUri()).andReturn(URI.create("#reference")).atLeastOnce();
+ reference1.stop();
+ EasyMock.replay(reference1);
+
+ Reference reference2 = EasyMock.createMock(Reference.class);
+ EasyMock.expect(reference2.getUri()).andReturn(URI.create("#reference")).atLeastOnce();
+ reference2.stop();
+ EasyMock.replay(reference2);
+
+ parent.register(reference2);
+ try {
+ parent.register(reference1);
+ fail();
+ } catch (DuplicateNameException e) {
+ // ok
+ }
+ parent.stop();
+
+ }
+
+ public void testDuplicateServiceReferenceRegistration() throws Exception {
+ Component parent = new CompositeComponentImpl(URI.create("parent"));
+ parent.start();
+
+ Service service1 = EasyMock.createMock(Service.class);
+ EasyMock.expect(service1.getUri()).andReturn(URI.create("#child")).atLeastOnce();
+ service1.stop();
+ EasyMock.replay(service1);
+
+ Reference service2 = EasyMock.createMock(Reference.class);
+ EasyMock.expect(service2.getUri()).andReturn(URI.create("#child")).atLeastOnce();
+ service2.stop();
+ EasyMock.replay(service2);
+
+ parent.register(service2);
+ try {
+ parent.register(service1);
+ fail();
+ } catch (DuplicateNameException e) {
+ // ok
+ }
+ parent.stop();
+
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/composite/ImplementationCompositeLoaderTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/composite/ImplementationCompositeLoaderTestCase.java
new file mode 100644
index 0000000000..f0207a168a
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/composite/ImplementationCompositeLoaderTestCase.java
@@ -0,0 +1,194 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.composite;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import javax.xml.namespace.QName;
+import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import static org.osoa.sca.Constants.SCA_NS;
+
+import org.apache.tuscany.spi.deployer.CompositeClassLoader;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.model.CompositeImplementation;
+import org.apache.tuscany.spi.services.artifact.Artifact;
+import org.apache.tuscany.spi.services.artifact.ArtifactRepository;
+
+import junit.framework.TestCase;
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.reportMatcher;
+import static org.easymock.EasyMock.verify;
+import org.easymock.IArgumentMatcher;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ImplementationCompositeLoaderTestCase extends TestCase {
+ private static final QName IMPLEMENTATION_COMPOSITE = new QName(SCA_NS, "implementation.composite");
+
+ private ClassLoader cl;
+ private ImplementationCompositeLoader loader;
+ private XMLStreamReader reader;
+ private DeploymentContext context;
+ private ArtifactRepository artifactRepository;
+
+ public void testName() throws LoaderException, XMLStreamException, MalformedURLException {
+ String name = "foo";
+ expect(reader.getName()).andReturn(IMPLEMENTATION_COMPOSITE);
+ expect(reader.getAttributeValue(null, "name")).andReturn(name);
+ expect(reader.getAttributeValue(null, "group")).andReturn(null);
+ expect(reader.getAttributeValue(null, "version")).andReturn(null);
+ expect(reader.getAttributeValue(null, "scdlLocation")).andReturn(null);
+ expect(reader.getAttributeValue(null, "jarLocation")).andReturn(null);
+ expect(reader.next()).andReturn(END_ELEMENT);
+ replay(reader);
+
+ replay(context);
+ replay(artifactRepository);
+
+ CompositeImplementation impl = loader.load(null, reader, context);
+ verify(reader);
+ verify(context);
+ verify(artifactRepository);
+ assertEquals(name, impl.getName());
+ assertNull(impl.getScdlLocation());
+ assertNull(impl.getClassLoader());
+ }
+
+ public void testWithArtifact() throws LoaderException, XMLStreamException, MalformedURLException {
+ String name = "foo";
+ expect(reader.getName()).andReturn(IMPLEMENTATION_COMPOSITE);
+ expect(reader.getAttributeValue(null, "name")).andReturn(name);
+ expect(reader.getAttributeValue(null, "group")).andReturn("com.example");
+ expect(reader.getAttributeValue(null, "version")).andReturn("1.0");
+ expect(reader.getAttributeValue(null, "scdlLocation")).andReturn(null);
+ expect(reader.getAttributeValue(null, "jarLocation")).andReturn(null);
+ expect(reader.next()).andReturn(END_ELEMENT);
+ replay(reader);
+
+ expect(context.getClassLoader()).andReturn(cl);
+ replay(context);
+ URL url = new URL("http://www.example.com/sca/base.jar");
+ artifactRepository.resolve(artifactMatcher(url, "com.example", name, "1.0"));
+ replay(artifactRepository);
+
+ CompositeImplementation impl = loader.load(null, reader, context);
+ verify(reader);
+ verify(context);
+ verify(artifactRepository);
+ assertEquals(name, impl.getName());
+ assertEquals(new URL("jar:http://www.example.com/sca/base.jar!/META-INF/sca/default.scdl"),
+ impl.getScdlLocation());
+ assertTrue(impl.getClassLoader() instanceof CompositeClassLoader);
+ }
+
+ public void testWithScdlLocation() throws LoaderException, XMLStreamException, MalformedURLException {
+ String name = "foo";
+ expect(reader.getName()).andReturn(IMPLEMENTATION_COMPOSITE);
+ expect(reader.getAttributeValue(null, "name")).andReturn(name);
+ expect(reader.getAttributeValue(null, "group")).andReturn(null);
+ expect(reader.getAttributeValue(null, "version")).andReturn(null);
+ expect(reader.getAttributeValue(null, "scdlLocation")).andReturn("bar.scdl");
+ expect(reader.getAttributeValue(null, "jarLocation")).andReturn(null);
+ expect(reader.next()).andReturn(END_ELEMENT);
+ replay(reader);
+
+ expect(context.getScdlLocation()).andReturn(new URL("http://www.example.com/sca/base.scdl"));
+ expect(context.getClassLoader()).andReturn(cl);
+ replay(context);
+ replay(artifactRepository);
+
+ CompositeImplementation impl = loader.load(null, reader, context);
+ verify(reader);
+ verify(context);
+ verify(artifactRepository);
+ assertEquals(name, impl.getName());
+ assertEquals(new URL("http://www.example.com/sca/bar.scdl"), impl.getScdlLocation());
+ assertSame(cl, impl.getClassLoader());
+ }
+
+ public void testWithJarLocation() throws LoaderException, XMLStreamException, MalformedURLException {
+ String name = "foo";
+ expect(reader.getName()).andReturn(IMPLEMENTATION_COMPOSITE);
+ expect(reader.getAttributeValue(null, "name")).andReturn(name);
+ expect(reader.getAttributeValue(null, "group")).andReturn(null);
+ expect(reader.getAttributeValue(null, "version")).andReturn(null);
+ expect(reader.getAttributeValue(null, "scdlLocation")).andReturn(null);
+ expect(reader.getAttributeValue(null, "jarLocation")).andReturn("bar.jar");
+ expect(reader.next()).andReturn(END_ELEMENT);
+ replay(reader);
+
+ expect(context.getScdlLocation()).andReturn(new URL("http://www.example.com/sca/base.scdl"));
+ expect(context.getClassLoader()).andReturn(cl);
+ replay(context);
+ replay(artifactRepository);
+
+ CompositeImplementation impl = loader.load(null, reader, context);
+ verify(reader);
+ verify(context);
+ verify(artifactRepository);
+ assertEquals(name, impl.getName());
+ assertEquals(new URL("jar:http://www.example.com/sca/bar.jar!/META-INF/sca/default.scdl"),
+ impl.getScdlLocation());
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ artifactRepository = createMock(ArtifactRepository.class);
+ reader = createMock(XMLStreamReader.class);
+ context = createMock(DeploymentContext.class);
+ cl = getClass().getClassLoader();
+ loader = new ImplementationCompositeLoader(null, artifactRepository);
+ }
+
+ protected static Artifact artifactMatcher(final URL url,
+ final String group,
+ final String name,
+ final String version) {
+ reportMatcher(new IArgumentMatcher() {
+
+ public boolean matches(Object object) {
+ if (!(object instanceof Artifact)) {
+ return false;
+ }
+
+ Artifact artifact = (Artifact) object;
+ boolean match = group.equals(artifact.getGroup())
+ && name.equals(artifact.getName())
+ && version.equals(artifact.getVersion())
+ && "jar".equals(artifact.getType());
+ if (match) {
+ artifact.setUrl(url);
+ }
+ return match;
+ }
+
+ public void appendTo(StringBuffer stringBuffer) {
+ stringBuffer.append(group).append(':').append(name).append(':').append(version);
+ }
+ });
+ return null;
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/composite/ManagedRequestContextTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/composite/ManagedRequestContextTestCase.java
new file mode 100644
index 0000000000..12299e762b
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/composite/ManagedRequestContextTestCase.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.composite;
+
+import org.osoa.sca.RequestContext;
+
+import org.apache.tuscany.spi.component.WorkContext;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ManagedRequestContextTestCase extends TestCase {
+
+ public void testGetServiceName() {
+ WorkContext workContext = EasyMock.createMock(WorkContext.class);
+ EasyMock.expect(workContext.getCurrentServiceName()).andReturn("foo");
+ EasyMock.replay(workContext);
+ RequestContext context = new ManagedRequestContext(workContext);
+ assertEquals("foo", context.getServiceName());
+ EasyMock.verify(workContext);
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/composite/ReferenceImplTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/composite/ReferenceImplTestCase.java
new file mode 100644
index 0000000000..34d37469a7
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/composite/ReferenceImplTestCase.java
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.composite;
+
+import java.net.URI;
+
+import org.apache.tuscany.spi.component.Reference;
+import org.apache.tuscany.spi.component.ReferenceBinding;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ReferenceImplTestCase extends TestCase {
+
+ public void testStart() {
+ ReferenceBinding binding = EasyMock.createMock(ReferenceBinding.class);
+ binding.start();
+ EasyMock.replay(binding);
+ Reference reference = new ReferenceImpl(URI.create("ref"), null);
+ reference.addReferenceBinding(binding);
+ reference.start();
+ EasyMock.verify(binding);
+
+ }
+
+ public void testStop() {
+ ReferenceBinding binding = EasyMock.createMock(ReferenceBinding.class);
+ binding.stop();
+ EasyMock.replay(binding);
+ Reference reference = new ReferenceImpl(URI.create("ref"), null);
+ reference.addReferenceBinding(binding);
+ reference.stop();
+ EasyMock.verify(binding);
+
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/composite/ServiceImplTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/composite/ServiceImplTestCase.java
new file mode 100644
index 0000000000..bb8ed020e0
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/composite/ServiceImplTestCase.java
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.composite;
+
+import java.net.URI;
+
+import org.apache.tuscany.spi.component.Service;
+import org.apache.tuscany.spi.component.ServiceBinding;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ServiceImplTestCase extends TestCase {
+
+ public void testStart() {
+ ServiceBinding binding = EasyMock.createMock(ServiceBinding.class);
+ binding.start();
+ EasyMock.replay(binding);
+ Service service = new ServiceImpl(URI.create("foo#bar"), null, null);
+ service.addServiceBinding(binding);
+ service.start();
+ EasyMock.verify(binding);
+
+ }
+
+ public void testStop() {
+ ServiceBinding binding = EasyMock.createMock(ServiceBinding.class);
+ binding.stop();
+ EasyMock.replay(binding);
+ Service service = new ServiceImpl(URI.create("foo#bar"), null, null);
+ service.addServiceBinding(binding);
+ service.stop();
+ EasyMock.verify(binding);
+
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/composite/SystemComponentBuilderTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/composite/SystemComponentBuilderTestCase.java
new file mode 100644
index 0000000000..7ee6583df7
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/composite/SystemComponentBuilderTestCase.java
@@ -0,0 +1,182 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.composite;
+
+import java.lang.reflect.Method;
+import java.net.URI;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.implementation.java.ConstructorDefinition;
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.PropertyValue;
+import org.apache.tuscany.spi.model.Scope;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.component.event.ComponentStart;
+import org.apache.tuscany.core.component.event.ComponentStop;
+import org.apache.tuscany.core.component.scope.CompositeScopeContainer;
+import org.apache.tuscany.core.implementation.system.builder.SystemComponentBuilder;
+import org.apache.tuscany.core.implementation.system.model.SystemImplementation;
+import org.apache.tuscany.core.injection.SingletonObjectFactory;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class SystemComponentBuilderTestCase extends TestCase {
+ Component parent;
+ DeploymentContext deploymentContext;
+ SystemComponentBuilder builder = new SystemComponentBuilder();
+ CompositeScopeContainer container;
+
+ /**
+ * Verifies lifecycle callbacks are made
+ */
+ public void testLifecycleBuild() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ type.setInitLevel(50);
+ Method initMethod = FooImpl.class.getMethod("init");
+ initMethod.setAccessible(true);
+ type.setInitMethod(initMethod);
+ Method destroyMethod = FooImpl.class.getMethod("destroy");
+ destroyMethod.setAccessible(true);
+ type.setDestroyMethod(destroyMethod);
+ type.setImplementationScope(Scope.COMPOSITE);
+ ConstructorDefinition<FooImpl> ctorDef = new ConstructorDefinition<FooImpl>(FooImpl.class.getConstructor());
+ type.setConstructorDefinition(ctorDef);
+ SystemImplementation impl = new SystemImplementation();
+ impl.setComponentType(type);
+ impl.setImplementationClass(FooImpl.class);
+ ComponentDefinition<SystemImplementation> definition = new ComponentDefinition<SystemImplementation>(impl);
+ definition.setUri(URI.create("component"));
+ AtomicComponent component = builder.build(definition, deploymentContext);
+ component.setScopeContainer(container);
+ component.start();
+ container.onEvent(new ComponentStart(this, null));
+ FooImpl foo = (FooImpl) component.getTargetInstance();
+ assertTrue(foo.initialized);
+ container.onEvent(new ComponentStop(this, null));
+ assertTrue(foo.destroyed);
+ }
+
+ /**
+ * Verifies properties are built properly
+ */
+ public void testPropertyBuild() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ type.setInitLevel(50);
+ Method initMethod = FooImpl.class.getMethod("init");
+ initMethod.setAccessible(true);
+ type.setInitMethod(initMethod);
+ Method destroyMethod = FooImpl.class.getMethod("destroy");
+ destroyMethod.setAccessible(true);
+ type.setDestroyMethod(destroyMethod);
+ type.setImplementationScope(Scope.COMPOSITE);
+ JavaMappedProperty mappedProp = new JavaMappedProperty();
+ mappedProp.setName("prop");
+ Method propMethod = FooImpl.class.getMethod("setProp", String.class);
+ propMethod.setAccessible(true);
+ mappedProp.setMember(propMethod);
+ type.add(mappedProp);
+ ConstructorDefinition<FooImpl> ctorDef = new ConstructorDefinition<FooImpl>(FooImpl.class.getConstructor());
+ type.setConstructorDefinition(ctorDef);
+ SystemImplementation impl = new SystemImplementation();
+ impl.setComponentType(type);
+ impl.setImplementationClass(FooImpl.class);
+ ComponentDefinition<SystemImplementation> definition = new ComponentDefinition<SystemImplementation>(impl);
+ definition.setUri(URI.create("component"));
+ PropertyValue<String> propVal = new PropertyValue<String>();
+ propVal.setName("prop");
+ propVal.setValueFactory(new SingletonObjectFactory<String>("value"));
+ definition.add(propVal);
+ AtomicComponent component = builder.build(definition, deploymentContext);
+ component.setScopeContainer(container);
+ component.start();
+ FooImpl foo = (FooImpl) component.getTargetInstance();
+ assertEquals("value", foo.prop);
+ container.onEvent(new ComponentStop(this, null));
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ parent = EasyMock.createNiceMock(Component.class);
+ container = new CompositeScopeContainer(null);
+ container.start();
+ deploymentContext = EasyMock.createMock(DeploymentContext.class);
+ EasyMock.expect(deploymentContext.getCompositeScope()).andReturn(container).atLeastOnce();
+ EasyMock.replay(deploymentContext);
+ }
+
+ private static interface Foo {
+
+ }
+
+ private static class FooImpl implements Foo {
+ private boolean initialized;
+ private boolean destroyed;
+ private String prop;
+ private Foo ref;
+
+ public FooImpl() {
+ }
+
+ public void init() {
+ if (initialized) {
+ fail();
+ }
+ initialized = true;
+ }
+
+ public void destroy() {
+ if (destroyed) {
+ fail();
+ }
+ destroyed = true;
+ }
+
+ public boolean isInitialized() {
+ return initialized;
+ }
+
+ public String getProp() {
+ return prop;
+ }
+
+ public void setProp(String prop) {
+ this.prop = prop;
+ }
+
+ public Foo getRef() {
+ return ref;
+ }
+
+ public void setRef(Foo ref) {
+ this.ref = ref;
+ }
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaAtomicComponentMetadataInjectionTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaAtomicComponentMetadataInjectionTestCase.java
new file mode 100644
index 0000000000..5186119345
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaAtomicComponentMetadataInjectionTestCase.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.java;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests SCA metadata such as <code>@ComponentName</code> and <code>@SCAObject</code> are handled properly
+ *
+ * @version $Rev$ $Date$
+ */
+public class JavaAtomicComponentMetadataInjectionTestCase extends TestCase {
+
+ public void testComponentNameSet() throws Exception {
+ // TODO implement
+ }
+
+ public void testCompositeContextSet() throws Exception {
+ // TODO implement
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaAtomicComponentNegativeMetadataTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaAtomicComponentNegativeMetadataTestCase.java
new file mode 100644
index 0000000000..dfd62c8c53
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaAtomicComponentNegativeMetadataTestCase.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.java;
+
+import junit.framework.TestCase;
+
+
+/**
+ * Performs rudimentary negative testing by using malformed metadata on a POJO
+ *
+ * @version $Rev $Date
+ */
+public class JavaAtomicComponentNegativeMetadataTestCase 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 {
+ // TODO implement
+ }
+
+ /**
+ * Tests that a pojo with <code>@Context</code> specified on a non-CompositeContext 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 {
+ // TODO implement
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaBuilderPropertyTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaBuilderPropertyTestCase.java
new file mode 100644
index 0000000000..5788526942
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaBuilderPropertyTestCase.java
@@ -0,0 +1,139 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.java;
+
+import java.net.URI;
+
+import org.apache.tuscany.spi.ObjectFactory;
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.ScopeRegistry;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.implementation.java.ConstructorDefinition;
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.PropertyValue;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.injection.SingletonObjectFactory;
+import org.easymock.EasyMock;
+
+/**
+ * Verifies that the java component builder handles configured properties correctly
+ *
+ * @version $Rev$ $Date$
+ */
+public class JavaBuilderPropertyTestCase extends TestCase {
+ private DeploymentContext deploymentContext;
+ private Component parent;
+ private ScopeRegistry registry;
+
+ @SuppressWarnings("unchecked")
+ public void testPropertyHandling() throws Exception {
+ JavaComponentBuilder builder = new JavaComponentBuilder();
+ builder.setScopeRegistry(registry);
+ PojoComponentType<ServiceDefinition, ReferenceDefinition, JavaMappedProperty<?>> type =
+ new PojoComponentType<ServiceDefinition, ReferenceDefinition, JavaMappedProperty<?>>();
+ JavaMappedProperty<String> property = new JavaMappedProperty<String>();
+ property.setName("test");
+ property.setDefaultValueFactory(new SingletonObjectFactory<String>("foo"));
+ property.setMember(JavaBuilderPropertyTestCase.Foo.class.getMethod("setTest", String.class));
+ type.add(property);
+ type.setConstructorDefinition(new ConstructorDefinition<Foo>(Foo.class.getConstructor((Class[]) null)));
+ type.setImplementationScope(Scope.STATELESS);
+ JavaImplementation impl = new JavaImplementation(Foo.class, type);
+ ComponentDefinition<JavaImplementation> definition = new ComponentDefinition<JavaImplementation>(impl);
+ definition.setUri(URI.create("component"));
+ PropertyValue propertyValue = new PropertyValue(property.getName(), property.getDefaultValueFactory());
+ definition.getPropertyValues().put(property.getName(), propertyValue);
+ AtomicComponent component = builder.build(definition, deploymentContext);
+ JavaBuilderPropertyTestCase.Foo foo = (JavaBuilderPropertyTestCase.Foo) component.createInstance();
+ assertEquals("foo", foo.getTest());
+ }
+
+ public void testIntPropertyHandling() throws Exception {
+ JavaComponentBuilder builder = new JavaComponentBuilder();
+ builder.setScopeRegistry(registry);
+ PojoComponentType<ServiceDefinition, ReferenceDefinition, JavaMappedProperty<?>> type =
+ new PojoComponentType<ServiceDefinition, ReferenceDefinition, JavaMappedProperty<?>>();
+ JavaMappedProperty<Integer> property = new JavaMappedProperty<Integer>();
+ property.setName("test");
+ property.setDefaultValueFactory(new SingletonObjectFactory<Integer>(1));
+ property.setMember(JavaBuilderPropertyTestCase.FooInt.class.getMethod("setTest", Integer.TYPE));
+ type.add(property);
+ type.setConstructorDefinition(new ConstructorDefinition<FooInt>(FooInt.class.getConstructor((Class[]) null)));
+ type.setImplementationScope(Scope.STATELESS);
+ JavaImplementation impl = new JavaImplementation(Foo.class, type);
+ ComponentDefinition<JavaImplementation> definition = new ComponentDefinition<JavaImplementation>(impl);
+ definition.setUri(URI.create("component"));
+ ObjectFactory<Integer> defaultValueFactory = property.getDefaultValueFactory();
+ PropertyValue<Integer> propertyValue = new PropertyValue<Integer>(property.getName(), defaultValueFactory);
+ definition.getPropertyValues().put(property.getName(), propertyValue);
+ AtomicComponent component = builder.build(definition, deploymentContext);
+ FooInt foo = (FooInt) component.createInstance();
+ assertEquals(1, foo.getTest());
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ deploymentContext = EasyMock.createMock(DeploymentContext.class);
+ EasyMock.replay(deploymentContext);
+ parent = EasyMock.createNiceMock(Component.class);
+ ScopeContainer mockContainer = EasyMock.createNiceMock(ScopeContainer.class);
+ EasyMock.replay(mockContainer);
+ registry = EasyMock.createMock(ScopeRegistry.class);
+ EasyMock.expect(registry.getScopeContainer(EasyMock.isA(Scope.class))).andReturn(mockContainer);
+ EasyMock.replay(registry);
+ }
+
+ private static class Foo {
+ private String test;
+
+ public Foo() {
+ }
+
+ public String getTest() {
+ return test;
+ }
+
+ public void setTest(String test) {
+ this.test = test;
+ }
+ }
+
+ private static class FooInt {
+ private int test;
+
+ public FooInt() {
+ }
+
+ public int getTest() {
+ return test;
+ }
+
+ public void setTest(int test) {
+ this.test = test;
+ }
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderConversationIDTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderConversationIDTestCase.java
new file mode 100644
index 0000000000..0993db0afc
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderConversationIDTestCase.java
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.java;
+
+import java.lang.reflect.Field;
+import java.net.URI;
+
+import org.osoa.sca.annotations.ConversationID;
+
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.ScopeRegistry;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.implementation.java.ConstructorDefinition;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.Scope;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.component.WorkContextImpl;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev: 473859 $ $Date: 2006-11-11 22:31:55 -0500 (Sat, 11 Nov 2006) $
+ */
+public class JavaComponentBuilderConversationIDTestCase extends TestCase {
+
+ @SuppressWarnings("unchecked")
+ public void testResourceInjection() throws Exception {
+ ScopeContainer container = EasyMock.createNiceMock(ScopeContainer.class);
+ ScopeRegistry registry = EasyMock.createMock(ScopeRegistry.class);
+ EasyMock.expect(registry.getScopeContainer(Scope.STATELESS)).andReturn(container);
+ EasyMock.replay(registry);
+ JavaComponentBuilder builder = new JavaComponentBuilder();
+ builder.setScopeRegistry(registry);
+ WorkContext workContext = new WorkContextImpl();
+ workContext.setIdentifier(Scope.CONVERSATION, "convID");
+ builder.setWorkContext(workContext);
+
+ ConstructorDefinition<Foo> ctorDef = new ConstructorDefinition<Foo>(Foo.class.getConstructor());
+ PojoComponentType type = new PojoComponentType();
+ Field field = Foo.class.getDeclaredField("conversationID");
+ type.setConversationIDMember(field);
+ type.setImplementationScope(Scope.STATELESS);
+ type.setConstructorDefinition(ctorDef);
+
+ JavaImplementation impl = new JavaImplementation(Foo.class, type);
+ URI uri = URI.create("foo");
+ ComponentDefinition<JavaImplementation> definition = new ComponentDefinition<JavaImplementation>(uri, impl);
+ JavaAtomicComponent component = (JavaAtomicComponent) builder.build(definition, null);
+ Foo foo = (Foo) component.createInstance();
+ assertEquals("convID", foo.conversationID);
+ }
+
+ private static class Foo {
+
+ @ConversationID
+ protected String conversationID;
+
+ public Foo() {
+ }
+
+ }
+}
+
+
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderMetadataTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderMetadataTestCase.java
new file mode 100644
index 0000000000..16d8518cfe
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderMetadataTestCase.java
@@ -0,0 +1,132 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.java;
+
+import java.lang.reflect.Constructor;
+import java.net.URI;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.idl.java.JavaServiceContract;
+import org.apache.tuscany.spi.implementation.java.ConstructorDefinition;
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.model.ServiceContract;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.implementation.composite.CompositeComponentImpl;
+import org.apache.tuscany.core.mock.component.Source;
+import org.apache.tuscany.core.mock.component.SourceImpl;
+import org.apache.tuscany.core.mock.component.Target;
+import org.easymock.EasyMock;
+
+/**
+ * Verifies component type metadata is properly applied to the component
+ *
+ * @version $$Rev$$ $$Date$$
+ */
+public class JavaComponentBuilderMetadataTestCase extends TestCase {
+ private DeploymentContext deploymentContext;
+ private Constructor<SourceImpl> constructor;
+ private Component parent;
+ private PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type;
+ private ComponentDefinition<JavaImplementation> definition;
+ private ScopeContainer scopeContainer;
+
+ public void testInitLevel() throws Exception {
+ type.setInitLevel(1);
+ JavaComponentBuilder builder = new JavaComponentBuilder();
+ JavaAtomicComponent component = (JavaAtomicComponent) builder.build(definition, deploymentContext);
+ assertEquals(1, component.getInitLevel());
+ }
+
+ public void testMaxAge() throws Exception {
+ type.setMaxAge(100);
+ JavaComponentBuilder builder = new JavaComponentBuilder();
+ JavaAtomicComponent component = (JavaAtomicComponent) builder.build(definition, deploymentContext);
+ assertEquals(100, component.getMaxAge());
+ }
+
+ public void testMaxIdleTime() throws Exception {
+ type.setMaxIdleTime(100);
+ JavaComponentBuilder builder = new JavaComponentBuilder();
+ JavaAtomicComponent component = (JavaAtomicComponent) builder.build(definition, deploymentContext);
+ assertEquals(100, component.getMaxIdleTime());
+ }
+
+ public void testNoMaxAgeNoMaxIdleTime() throws Exception {
+ JavaComponentBuilder builder = new JavaComponentBuilder();
+ JavaAtomicComponent component = (JavaAtomicComponent) builder.build(definition, deploymentContext);
+ assertEquals(-1, component.getMaxAge());
+ assertEquals(-1, component.getMaxIdleTime());
+ }
+
+ public void testScope() throws Exception {
+ JavaComponentBuilder builder = new JavaComponentBuilder();
+ JavaAtomicComponent component = (JavaAtomicComponent) builder.build(definition, deploymentContext);
+ component.setScopeContainer(scopeContainer);
+ assertEquals(Scope.COMPOSITE, component.getScope());
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ parent = new CompositeComponentImpl(URI.create("parent"));
+ constructor = SourceImpl.class.getConstructor((Class[]) null);
+ createDeploymentContext();
+ createComponentDefinitionAndType();
+ }
+
+
+ private void createDeploymentContext() {
+ scopeContainer = EasyMock.createMock(ScopeContainer.class);
+ scopeContainer.start();
+ scopeContainer.stop();
+ scopeContainer.register(EasyMock.isA(AtomicComponent.class));
+ EasyMock.expectLastCall().atLeastOnce();
+ EasyMock.expect(scopeContainer.getScope()).andReturn(Scope.COMPOSITE).atLeastOnce();
+ EasyMock.replay(scopeContainer);
+ deploymentContext = EasyMock.createMock(DeploymentContext.class);
+ EasyMock.replay(deploymentContext);
+ }
+
+ private void createComponentDefinitionAndType() throws Exception {
+ type = new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ type.setImplementationScope(Scope.COMPOSITE);
+ JavaMappedReference reference = new JavaMappedReference();
+ reference.setUri(URI.create("#target"));
+ reference.setMember(SourceImpl.class.getMethod("setTarget", Target.class));
+ type.add(reference);
+ ServiceContract<?> contract = new JavaServiceContract(Source.class);
+ JavaMappedService serviceDefinition = new JavaMappedService();
+ serviceDefinition.setUri(URI.create("component#Source"));
+ serviceDefinition.setServiceContract(contract);
+ type.add(serviceDefinition);
+ type.setConstructorDefinition(new ConstructorDefinition<SourceImpl>(constructor));
+ JavaImplementation sourceImpl = new JavaImplementation(SourceImpl.class, type);
+ definition = new ComponentDefinition<JavaImplementation>(sourceImpl);
+ definition.setUri(URI.create("component"));
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderReferenceTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderReferenceTestCase.java
new file mode 100644
index 0000000000..3021ccb4c6
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderReferenceTestCase.java
@@ -0,0 +1,145 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.java;
+
+import java.lang.reflect.Constructor;
+import java.net.URI;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.idl.java.JavaServiceContract;
+import org.apache.tuscany.spi.implementation.java.ConstructorDefinition;
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.Wire;
+import org.apache.tuscany.spi.wire.ProxyService;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.implementation.composite.CompositeComponentImpl;
+import org.apache.tuscany.core.mock.component.Source;
+import org.apache.tuscany.core.mock.component.SourceImpl;
+import org.apache.tuscany.core.mock.component.Target;
+import org.apache.tuscany.core.wire.jdk.JDKProxyService;
+import org.easymock.EasyMock;
+import org.easymock.IAnswer;
+
+/**
+ * @version $$Rev$$ $$Date$$
+ */
+public class JavaComponentBuilderReferenceTestCase extends TestCase {
+ private DeploymentContext deploymentContext;
+ private ProxyService proxyService;
+ private Constructor<SourceImpl> constructor;
+ private Component parent;
+ private Wire wire;
+ private ScopeContainer scopeContainer;
+
+ public void testBuildReference() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> sourceType =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ sourceType.setImplementationScope(Scope.COMPOSITE);
+ JavaMappedReference reference = new JavaMappedReference();
+ reference.setUri(URI.create("#target"));
+ reference.setMember(SourceImpl.class.getMethod("setTarget", Target.class));
+ sourceType.add(reference);
+ ServiceContract<?> contract = new JavaServiceContract(Source.class);
+ JavaMappedService serviceDefinition = new JavaMappedService();
+ serviceDefinition.setUri(URI.create("#Source"));
+ serviceDefinition.setServiceContract(contract);
+ sourceType.add(serviceDefinition);
+ sourceType.setConstructorDefinition(new ConstructorDefinition<SourceImpl>(constructor));
+ JavaImplementation sourceImpl = new JavaImplementation(SourceImpl.class, sourceType);
+ ComponentDefinition<JavaImplementation> definition = new ComponentDefinition<JavaImplementation>(sourceImpl);
+ definition.setUri(URI.create("component"));
+ JavaComponentBuilder builder = new JavaComponentBuilder();
+ builder.setProxyService(proxyService);
+ JavaAtomicComponent component = (JavaAtomicComponent) builder.build(definition, deploymentContext);
+ component.setScopeContainer(scopeContainer);
+ component.attachWire(wire);
+ deploymentContext.getCompositeScope().start();
+ component.start();
+
+ Source source = (Source) component.getTargetInstance();
+ assertNotNull(source.getTarget());
+ component.stop();
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ proxyService = new JDKProxyService();
+ parent = new CompositeComponentImpl(URI.create("parent"));
+ constructor = SourceImpl.class.getConstructor((Class[]) null);
+ createDeploymentContext();
+ createWire();
+ }
+
+
+ private void createDeploymentContext() throws Exception {
+ scopeContainer = EasyMock.createMock(ScopeContainer.class);
+ scopeContainer.start();
+ scopeContainer.stop();
+ scopeContainer.register(EasyMock.isA(AtomicComponent.class));
+ EasyMock.expectLastCall().atLeastOnce();
+ EasyMock.expect(scopeContainer.getScope()).andReturn(Scope.COMPOSITE).atLeastOnce();
+ scopeContainer.getInstance(EasyMock.isA(AtomicComponent.class));
+ EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
+ private Map<AtomicComponent, Object> cache = new HashMap<AtomicComponent, Object>();
+
+ public Object answer() throws Throwable {
+ AtomicComponent component = (AtomicComponent) EasyMock.getCurrentArguments()[0];
+ Object instance = cache.get(component);
+ if (instance == null) {
+ instance = component.createInstance();
+ cache.put(component, instance);
+ }
+ return instance;
+ }
+ }).anyTimes();
+ EasyMock.replay(scopeContainer);
+ deploymentContext = EasyMock.createMock(DeploymentContext.class);
+ EasyMock.expect(deploymentContext.getCompositeScope()).andReturn(scopeContainer).atLeastOnce();
+ EasyMock.replay(deploymentContext);
+ }
+
+ private void createWire() {
+ Map<Operation<?>, InvocationChain> chains = Collections.emptyMap();
+ wire = EasyMock.createMock(Wire.class);
+ EasyMock.expect(wire.getSourceUri()).andReturn(URI.create("#target")).atLeastOnce();
+ EasyMock.expect(wire.getInvocationChains()).andReturn(chains).atLeastOnce();
+ EasyMock.expect(wire.isOptimizable()).andReturn(false);
+ JavaServiceContract targetContract = new JavaServiceContract(Target.class);
+ targetContract.setConversational(false);
+ EasyMock.expect(wire.getSourceContract()).andReturn(targetContract).atLeastOnce();
+ EasyMock.replay(wire);
+
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderResourceTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderResourceTestCase.java
new file mode 100644
index 0000000000..abfbbe108d
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderResourceTestCase.java
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.java;
+
+import java.net.URI;
+
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.ScopeRegistry;
+import org.apache.tuscany.spi.host.ResourceHost;
+import org.apache.tuscany.spi.implementation.java.ConstructorDefinition;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.implementation.java.Resource;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.wire.Wire;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class JavaComponentBuilderResourceTestCase extends TestCase {
+
+ @SuppressWarnings("unchecked")
+ public void testResourceInjection() throws Exception {
+ ScopeContainer container = EasyMock.createNiceMock(ScopeContainer.class);
+ ScopeRegistry registry = EasyMock.createMock(ScopeRegistry.class);
+ EasyMock.expect(registry.getScopeContainer(Scope.STATELESS)).andReturn(container);
+ EasyMock.replay(registry);
+ ResourceHost host = EasyMock.createMock(ResourceHost.class);
+ EasyMock.expect(host.resolveResource(EasyMock.eq(String.class))).andReturn("result");
+ EasyMock.replay(host);
+ JavaComponentBuilder builder = new JavaComponentBuilder();
+ builder.setHost(host);
+ builder.setScopeRegistry(registry);
+ ConstructorDefinition<Foo> ctorDef = new ConstructorDefinition<Foo>(Foo.class.getConstructor());
+ PojoComponentType type = new PojoComponentType();
+ Resource resource = new Resource("resource", String.class, Foo.class.getDeclaredField("resource"));
+ type.add(resource);
+ type.setImplementationScope(Scope.STATELESS);
+ type.setConstructorDefinition(ctorDef);
+ JavaImplementation impl = new JavaImplementation(Foo.class, type);
+ URI uri = URI.create("foo");
+ ComponentDefinition<JavaImplementation> definition = new ComponentDefinition<JavaImplementation>(uri, impl);
+ Wire resourceWire = EasyMock.createMock(Wire.class);
+ EasyMock.expect(resourceWire.getTargetInstance()).andReturn("result");
+ EasyMock.replay(resourceWire);
+
+ JavaAtomicComponent component = (JavaAtomicComponent) builder.build(definition, null);
+ Foo foo = (Foo) component.createInstance();
+ assertEquals("result", foo.resource);
+ }
+
+ private static class Foo {
+
+ protected String resource;
+
+ public Foo() {
+ }
+
+ }
+}
+
+
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentTypeLoaderTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentTypeLoaderTestCase.java
new file mode 100644
index 0000000000..92e8946d6f
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentTypeLoaderTestCase.java
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.java;
+
+import java.net.URL;
+
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.implementation.java.IntrospectionRegistry;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+import org.easymock.IAnswer;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class JavaComponentTypeLoaderTestCase extends TestCase {
+
+ @SuppressWarnings("unchecked")
+ public void testPojoComponentTypeCreatedForIntrospection() throws Exception {
+ IntrospectionRegistry registry = EasyMock.createMock(IntrospectionRegistry.class);
+ registry.introspect(
+ (Class) EasyMock.isNull(),
+ EasyMock.isA(PojoComponentType.class),
+ (DeploymentContext) EasyMock.isNull());
+ EasyMock.expectLastCall().andStubAnswer(new IAnswer() {
+ public Object answer() throws Throwable {
+ return EasyMock.getCurrentArguments()[2];
+ }
+ });
+ EasyMock.replay(registry);
+ JavaComponentTypeLoader loader = new JavaComponentTypeLoader(null, registry);
+ loader.loadByIntrospection(new JavaImplementation(), null);
+ EasyMock.verify(registry);
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testPojoComponentTypeCreatedForSideFileLoadAndReturned() throws Exception {
+ LoaderRegistry registry = EasyMock.createMock(LoaderRegistry.class);
+ registry.load(
+ EasyMock.isA(PojoComponentType.class),
+ (URL) EasyMock.isNull(),
+ EasyMock.eq(PojoComponentType.class),
+ (DeploymentContext) EasyMock.isNull());
+ EasyMock.expectLastCall().andStubAnswer(new IAnswer() {
+ public Object answer() throws Throwable {
+ return EasyMock.getCurrentArguments()[0];
+ }
+ });
+ EasyMock.replay(registry);
+ JavaComponentTypeLoader loader = new JavaComponentTypeLoader(registry, null);
+ assertEquals(PojoComponentType.class, loader.loadFromSidefile(null, null).getClass());
+ EasyMock.verify(registry);
+ }
+
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaReferenceWireTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaReferenceWireTestCase.java
new file mode 100644
index 0000000000..fdf293db9b
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaReferenceWireTestCase.java
@@ -0,0 +1,155 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.java;
+
+import java.lang.reflect.Constructor;
+import java.net.URI;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.TargetException;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.Wire;
+import org.apache.tuscany.spi.wire.ProxyService;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.implementation.PojoConfiguration;
+import org.apache.tuscany.core.injection.PojoObjectFactory;
+import org.easymock.EasyMock;
+import org.easymock.IAnswer;
+
+/**
+ * Validates wiring from a Java atomic context
+ *
+ * @version $$Rev$$ $$Date$$
+ */
+public class JavaReferenceWireTestCase extends TestCase {
+
+ @SuppressWarnings({"unchecked"})
+ public void testReferenceSet() throws Exception {
+ ScopeContainer scope = createMock();
+ scope.start();
+ final Target target = new TargetImpl();
+ PojoConfiguration configuration = new PojoConfiguration();
+ configuration.addReferenceSite("target", SourceImpl.class.getMethod("setTarget", Target.class));
+ Constructor<SourceImpl> ctr = SourceImpl.class.getConstructor();
+ configuration.setInstanceFactory(new PojoObjectFactory<SourceImpl>(ctr));
+ Wire wire = EasyMock.createMock(Wire.class);
+ wire.getInvocationChains();
+ EasyMock.expectLastCall().andReturn(new HashMap<Operation<?>, InvocationChain>()).atLeastOnce();
+ URI uri = URI.create("#target");
+ EasyMock.expect(wire.getSourceUri()).andReturn(uri).atLeastOnce();
+ EasyMock.expect(wire.isOptimizable()).andReturn(false);
+ EasyMock.replay(wire);
+ ProxyService service = EasyMock.createMock(ProxyService.class);
+ EasyMock.expect(service.createProxy(EasyMock.eq(Target.class), EasyMock.eq(wire), EasyMock.isA(Map.class)))
+ .andAnswer(new IAnswer<Target>() {
+ public Target answer() throws Throwable {
+ Wire wire = (Wire) EasyMock.getCurrentArguments()[1];
+ wire.getInvocationChains();
+ return target;
+ }
+
+ }).atLeastOnce();
+ EasyMock.replay(service);
+ configuration.setProxyService(service);
+ configuration.setName(new URI("source"));
+ JavaAtomicComponent component = new JavaAtomicComponent(configuration);
+ component.setScopeContainer(scope);
+ component.attachWire(wire);
+ component.start();
+ Source source = (Source) component.getTargetInstance();
+ assertSame(target, source.getTarget());
+ scope.stop();
+ EasyMock.verify(wire);
+ EasyMock.verify(scope);
+ EasyMock.verify(service);
+ }
+
+ private ScopeContainer createMock() throws TargetException {
+ ScopeContainer scope = EasyMock.createMock(ScopeContainer.class);
+ scope.start();
+ scope.stop();
+ scope.register(EasyMock.isA(AtomicComponent.class));
+ EasyMock.expectLastCall().atLeastOnce();
+ EasyMock.expect(scope.getScope()).andReturn(Scope.COMPOSITE).atLeastOnce();
+ scope.getInstance(EasyMock.isA(AtomicComponent.class));
+ EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
+ private Map<AtomicComponent, Object> cache = new HashMap<AtomicComponent, Object>();
+
+ public Object answer() throws Throwable {
+ AtomicComponent component = (AtomicComponent) EasyMock.getCurrentArguments()[0];
+ Object instance = cache.get(component);
+ if (instance == null) {
+ instance = component.createInstance();
+ cache.put(component, instance);
+ }
+ return instance;
+ }
+ }).anyTimes();
+ EasyMock.replay(scope);
+ return scope;
+ }
+
+ private interface Source {
+ Target getTarget();
+ }
+
+ private static class SourceImpl implements Source {
+ private Target target;
+
+ public SourceImpl() {
+ }
+
+ public Target getTarget() {
+ return target;
+ }
+
+ public void setTarget(Target target) {
+ this.target = target;
+ }
+ }
+
+ private interface Target {
+
+ String getString();
+
+ void setString(String val);
+ }
+
+ private static class TargetImpl implements Target {
+ private String string;
+
+ public TargetImpl() {
+ }
+
+ public String getString() {
+ return string;
+ }
+
+ public void setString(String string) {
+ this.string = string;
+ }
+
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerBasicInvocationTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerBasicInvocationTestCase.java
new file mode 100644
index 0000000000..6ab6d7dbeb
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerBasicInvocationTestCase.java
@@ -0,0 +1,188 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.java;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.extension.ExecutionMonitor;
+import org.apache.tuscany.spi.model.Scope;
+import static org.apache.tuscany.spi.wire.TargetInvoker.NONE;
+import org.apache.tuscany.spi.wire.Wire;
+
+import junit.framework.TestCase;
+import org.easymock.classextension.EasyMock;
+
+public class JavaTargetInvokerBasicInvocationTestCase extends TestCase {
+ private Method echoMethod;
+ private Method arrayMethod;
+ private Method nullParamMethod;
+ private Method primitiveMethod;
+ private Method checkedMethod;
+ private Method runtimeMethod;
+ private Wire wire;
+ private WorkContext context;
+ private ExecutionMonitor monitor;
+
+ public JavaTargetInvokerBasicInvocationTestCase(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", Integer.TYPE);
+ checkedMethod = TestBean.class.getDeclaredMethod("checkedException", (Class[]) null);
+ runtimeMethod = TestBean.class.getDeclaredMethod("runtimeException", (Class[]) null);
+ wire = EasyMock.createNiceMock(Wire.class);
+ context = EasyMock.createNiceMock(WorkContext.class);
+ monitor = EasyMock.createNiceMock(ExecutionMonitor.class);
+ assertNotNull(echoMethod);
+ assertNotNull(checkedMethod);
+ assertNotNull(runtimeMethod);
+ }
+
+ public void testObjectInvoke() throws Throwable {
+ TestBean bean = new TestBean();
+ JavaAtomicComponent component = EasyMock.createMock(JavaAtomicComponent.class);
+ EasyMock.expect(component.getTargetInstance()).andReturn(bean);
+ EasyMock.expect(component.getScope()).andReturn(Scope.COMPOSITE);
+ EasyMock.replay(component);
+ JavaTargetInvoker invoker = new JavaTargetInvoker(echoMethod, component, context);
+ Object ret = invoker.invokeTarget("foo", NONE);
+ assertEquals("foo", ret);
+ }
+
+ public void testArrayInvoke() throws Throwable {
+ TestBean bean = new TestBean();
+ JavaAtomicComponent component = EasyMock.createMock(JavaAtomicComponent.class);
+ EasyMock.expect(component.getTargetInstance()).andReturn(bean);
+ EasyMock.expect(component.getScope()).andReturn(Scope.COMPOSITE);
+ EasyMock.replay(component);
+ JavaTargetInvoker invoker = new JavaTargetInvoker(arrayMethod, component, context);
+
+ String[] args = new String[]{"foo", "bar"};
+ Object ret = invoker.invokeTarget(new Object[]{args}, NONE);
+ String[] retA = (String[]) ret;
+ assertNotNull(retA);
+ assertEquals(2, retA.length);
+ assertEquals("foo", retA[0]);
+ assertEquals("bar", retA[1]);
+ }
+
+ public void testNullInvoke() throws Throwable {
+ TestBean bean = new TestBean();
+ JavaAtomicComponent component = EasyMock.createMock(JavaAtomicComponent.class);
+ EasyMock.expect(component.getTargetInstance()).andReturn(bean);
+ EasyMock.expect(component.getScope()).andReturn(Scope.COMPOSITE);
+ EasyMock.replay(component);
+ JavaTargetInvoker invoker = new JavaTargetInvoker(nullParamMethod, component, context);
+ Object ret = invoker.invokeTarget(null, NONE);
+ String retS = (String) ret;
+ assertEquals("foo", retS);
+ }
+
+ public void testPrimitiveInvoke() throws Throwable {
+ TestBean bean = new TestBean();
+ JavaAtomicComponent component = EasyMock.createMock(JavaAtomicComponent.class);
+ EasyMock.expect(component.getTargetInstance()).andReturn(bean);
+ EasyMock.expect(component.getScope()).andReturn(Scope.COMPOSITE);
+ EasyMock.replay(component);
+ JavaTargetInvoker invoker = new JavaTargetInvoker(primitiveMethod, component, context);
+ Object ret = invoker.invokeTarget(new Integer[]{1}, NONE);
+ Integer retI = (Integer) ret;
+ assertEquals(1, retI.intValue());
+ }
+
+ public void testInvokeCheckedException() throws Throwable {
+ TestBean bean = new TestBean();
+ JavaAtomicComponent component = EasyMock.createMock(JavaAtomicComponent.class);
+ EasyMock.expect(component.getTargetInstance()).andReturn(bean);
+ EasyMock.expect(component.getScope()).andReturn(Scope.COMPOSITE);
+ EasyMock.replay(component);
+ JavaTargetInvoker invoker = new JavaTargetInvoker(checkedMethod, component, context);
+ try {
+ invoker.invokeTarget(null, NONE);
+ } catch (InvocationTargetException e) {
+ if (e.getCause() != null && TestException.class.equals(e.getCause().getClass())) {
+ return;
+ }
+ } catch (Throwable e) {
+ //ok
+ }
+ fail(TestException.class.getName() + " should have been thrown");
+ }
+
+ public void testInvokeRuntimeException() throws Throwable {
+ TestBean bean = new TestBean();
+ JavaAtomicComponent component = EasyMock.createMock(JavaAtomicComponent.class);
+ EasyMock.expect(component.getTargetInstance()).andReturn(bean);
+ EasyMock.expect(component.getScope()).andReturn(Scope.COMPOSITE);
+ EasyMock.replay(component);
+ JavaTargetInvoker invoker = new JavaTargetInvoker(runtimeMethod, component, context);
+ try {
+ invoker.invokeTarget(null, NONE);
+ } 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 {
+ assertEquals("foo", msg);
+ return msg;
+ }
+
+ public String[] arrayEcho(String[] msg) throws Exception {
+ assertNotNull(msg);
+ assertEquals(2, msg.length);
+ assertEquals("foo", msg[0]);
+ 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/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerMediationTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerMediationTestCase.java
new file mode 100644
index 0000000000..096c7f9aba
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerMediationTestCase.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.java;
+
+import java.lang.reflect.Method;
+
+import static org.apache.tuscany.spi.wire.TargetInvoker.NONE;
+import org.apache.tuscany.spi.model.Scope;
+
+import junit.framework.TestCase;
+import org.easymock.classextension.EasyMock;
+
+/**
+ * Tests invoking on a different interface from the one actually implemented by the target
+ *
+ * @version $Rev$ $Date$
+ */
+public class JavaTargetInvokerMediationTestCase extends TestCase {
+
+ private Method hello;
+
+ public void setUp() throws Exception {
+ hello = Hello.class.getMethod("hello", String.class);
+ }
+
+ public void testMediation() throws Exception {
+ Target target = EasyMock.createMock(Target.class);
+ EasyMock.expect(target.hello("foo")).andReturn("foo");
+ EasyMock.replay(target);
+ JavaAtomicComponent component = EasyMock.createMock(JavaAtomicComponent.class);
+ EasyMock.expect(component.getTargetInstance()).andReturn(target);
+ EasyMock.expect(component.getScope()).andReturn(Scope.COMPOSITE);
+ EasyMock.replay(component);
+ JavaTargetInvoker invoker = new JavaTargetInvoker(hello, component, null, null);
+ assertEquals("foo", invoker.invokeTarget("foo", NONE));
+ }
+
+ public interface Hello {
+ String hello(String message) throws Exception;
+ }
+
+ private interface Target {
+ String hello(String message);
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerNonBlockingInvocationTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerNonBlockingInvocationTestCase.java
new file mode 100644
index 0000000000..4f5d2a1ff3
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerNonBlockingInvocationTestCase.java
@@ -0,0 +1,225 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.java;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.extension.ExecutionMonitor;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.wire.Message;
+import org.apache.tuscany.spi.wire.MessageImpl;
+import static org.apache.tuscany.spi.wire.TargetInvoker.NONE;
+
+import junit.framework.TestCase;
+import org.easymock.classextension.EasyMock;
+
+/**
+ * Verifies dispatching invocations to a Java implementation instance
+ *
+ * @version $Rev$ $Date$
+ */
+public class JavaTargetInvokerNonBlockingInvocationTestCase extends TestCase {
+
+ private Method echoMethod;
+ private Method arrayMethod;
+ private Method nullParamMethod;
+ private Method primitiveMethod;
+ private Method checkedMethod;
+ private Method runtimeMethod;
+ private WorkContext context;
+ private ExecutionMonitor monitor;
+
+ public JavaTargetInvokerNonBlockingInvocationTestCase(String arg0) {
+ super(arg0);
+ }
+
+ public void testInvoke() throws Exception {
+ AsyncTarget target = EasyMock.createMock(AsyncTarget.class);
+ target.invoke();
+ EasyMock.expectLastCall().once();
+ EasyMock.replay(target);
+ JavaAtomicComponent component = EasyMock.createMock(JavaAtomicComponent.class);
+ EasyMock.expect(component.getTargetInstance()).andReturn(target);
+ EasyMock.expect(component.getScope()).andReturn(Scope.COMPOSITE);
+ EasyMock.replay(component);
+ ExecutionMonitor monitor = EasyMock.createMock(ExecutionMonitor.class);
+ EasyMock.replay(monitor);
+
+ Message msg = new MessageImpl();
+ Object id = new Object();
+ msg.setMessageId(id);
+
+ WorkContext context = EasyMock.createMock(WorkContext.class);
+ context.setCorrelationId(id);
+ EasyMock.replay(context);
+ Method method = AsyncTarget.class.getMethod("invoke");
+ method.setAccessible(true);
+ JavaTargetInvoker invoker = new JavaTargetInvoker(method, component, context);
+ invoker.invoke(msg);
+ EasyMock.verify(target);
+ EasyMock.verify(component);
+ }
+
+ 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", Integer.TYPE);
+ checkedMethod = TestBean.class.getDeclaredMethod("checkedException", (Class[]) null);
+ runtimeMethod = TestBean.class.getDeclaredMethod("runtimeException", (Class[]) null);
+ context = EasyMock.createNiceMock(WorkContext.class);
+ monitor = EasyMock.createNiceMock(ExecutionMonitor.class);
+ assertNotNull(echoMethod);
+ assertNotNull(checkedMethod);
+ assertNotNull(runtimeMethod);
+ }
+
+ public void testObjectInvoke() throws Throwable {
+ TestBean bean = new TestBean();
+ JavaAtomicComponent component = EasyMock.createMock(JavaAtomicComponent.class);
+ EasyMock.expect(component.getTargetInstance()).andReturn(bean);
+ EasyMock.expect(component.getScope()).andReturn(Scope.COMPOSITE);
+ EasyMock.replay(component);
+ JavaTargetInvoker invoker = new JavaTargetInvoker(echoMethod, component, context);
+ Object ret = invoker.invokeTarget("foo", NONE);
+ assertEquals("foo", ret);
+ }
+
+ public void testArrayInvoke() throws Throwable {
+ TestBean bean = new TestBean();
+ JavaAtomicComponent component = EasyMock.createMock(JavaAtomicComponent.class);
+ EasyMock.expect(component.getTargetInstance()).andReturn(bean);
+ EasyMock.expect(component.getScope()).andReturn(Scope.COMPOSITE);
+ EasyMock.replay(component);
+ JavaTargetInvoker invoker = new JavaTargetInvoker(arrayMethod, component, context);
+
+ String[] args = new String[]{"foo", "bar"};
+ Object ret = invoker.invokeTarget(new Object[]{args}, NONE);
+ String[] retA = (String[]) ret;
+ assertNotNull(retA);
+ assertEquals(2, retA.length);
+ assertEquals("foo", retA[0]);
+ assertEquals("bar", retA[1]);
+ }
+
+ public void testNullInvoke() throws Throwable {
+ TestBean bean = new TestBean();
+ JavaAtomicComponent component = EasyMock.createMock(JavaAtomicComponent.class);
+ EasyMock.expect(component.getTargetInstance()).andReturn(bean);
+ EasyMock.expect(component.getScope()).andReturn(Scope.COMPOSITE);
+ EasyMock.replay(component);
+ JavaTargetInvoker invoker = new JavaTargetInvoker(nullParamMethod, component, context);
+ Object ret = invoker.invokeTarget(null, NONE);
+ String retS = (String) ret;
+ assertEquals("foo", retS);
+ }
+
+ public void testPrimitiveInvoke() throws Throwable {
+ TestBean bean = new TestBean();
+ JavaAtomicComponent component = EasyMock.createMock(JavaAtomicComponent.class);
+ EasyMock.expect(component.getTargetInstance()).andReturn(bean);
+ EasyMock.expect(component.getScope()).andReturn(Scope.COMPOSITE);
+ EasyMock.replay(component);
+ JavaTargetInvoker invoker = new JavaTargetInvoker(primitiveMethod, component, context);
+ Object ret = invoker.invokeTarget(new Integer[]{1}, NONE);
+ Integer retI = (Integer) ret;
+ assertEquals(1, retI.intValue());
+ }
+
+ public void testInvokeCheckedException() throws Throwable {
+ TestBean bean = new TestBean();
+ JavaAtomicComponent component = EasyMock.createMock(JavaAtomicComponent.class);
+ EasyMock.expect(component.getTargetInstance()).andReturn(bean);
+ EasyMock.expect(component.getScope()).andReturn(Scope.COMPOSITE);
+ EasyMock.replay(component);
+ JavaTargetInvoker invoker = new JavaTargetInvoker(checkedMethod, component, context);
+ try {
+ invoker.invokeTarget(null, NONE);
+ } catch (InvocationTargetException e) {
+ if (e.getCause() != null && TestException.class.equals(e.getCause().getClass())) {
+ return;
+ }
+ } catch (Throwable e) {
+ //ok
+ }
+ fail(TestException.class.getName() + " should have been thrown");
+ }
+
+ public void testInvokeRuntimeException() throws Throwable {
+ TestBean bean = new TestBean();
+ JavaAtomicComponent component = EasyMock.createMock(JavaAtomicComponent.class);
+ EasyMock.expect(component.getTargetInstance()).andReturn(bean);
+ EasyMock.expect(component.getScope()).andReturn(Scope.COMPOSITE);
+ EasyMock.replay(component);
+ JavaTargetInvoker invoker = new JavaTargetInvoker(runtimeMethod, component, context);
+ try {
+ invoker.invokeTarget(null, NONE);
+ } 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 {
+ assertEquals("foo", msg);
+ return msg;
+ }
+
+ public String[] arrayEcho(String[] msg) throws Exception {
+ assertNotNull(msg);
+ assertEquals(2, msg.length);
+ assertEquals("foo", msg[0]);
+ 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 {
+ }
+
+ public interface AsyncTarget {
+ void invoke();
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerSequenceTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerSequenceTestCase.java
new file mode 100644
index 0000000000..5edddeb94d
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerSequenceTestCase.java
@@ -0,0 +1,117 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.java;
+
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.wire.Message;
+import org.apache.tuscany.spi.wire.MessageImpl;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+
+import junit.framework.TestCase;
+import org.easymock.classextension.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class JavaTargetInvokerSequenceTestCase extends TestCase {
+
+ /**
+ * Verifies an invocation marked as non-conversational has an existing or new instance returned
+ */
+ public void testNoSequence() throws Exception {
+ Foo foo = EasyMock.createMock(Foo.class);
+ foo.invoke();
+ EasyMock.replay(foo);
+ JavaAtomicComponent component = EasyMock.createMock(JavaAtomicComponent.class);
+ EasyMock.expect(component.getTargetInstance()).andReturn(foo);
+ EasyMock.expect(component.getScope()).andReturn(Scope.CONVERSATION);
+ EasyMock.replay(component);
+ JavaTargetInvoker invoker = new JavaTargetInvoker(Foo.class.getMethod("invoke"), component, null, null);
+ Message msg = new MessageImpl();
+ msg.setConversationSequence(TargetInvoker.NONE);
+ invoker.invoke(msg);
+ EasyMock.verify(foo);
+ EasyMock.verify(component);
+ }
+
+ /**
+ * Verifies that an invocation marked as starting a conversation has a new instance returned
+ */
+ public void testStartSequence() throws Exception {
+ Foo foo = EasyMock.createMock(Foo.class);
+ foo.invoke();
+ EasyMock.replay(foo);
+ JavaAtomicComponent component = EasyMock.createMock(JavaAtomicComponent.class);
+ EasyMock.expect(component.getTargetInstance()).andReturn(foo);
+ EasyMock.expect(component.getScope()).andReturn(Scope.CONVERSATION);
+ EasyMock.replay(component);
+ JavaTargetInvoker invoker = new JavaTargetInvoker(Foo.class.getMethod("invoke"), component, null, null);
+ Message msg = new MessageImpl();
+ msg.setConversationSequence(TargetInvoker.START);
+ invoker.invoke(msg);
+ EasyMock.verify(foo);
+ EasyMock.verify(component);
+ }
+
+ /**
+ * Verifies that an invocation marked as continuing a conversation has an associated instance returned
+ */
+ public void testContinueSequence() throws Exception {
+ Foo foo = EasyMock.createMock(Foo.class);
+ foo.invoke();
+ EasyMock.replay(foo);
+ JavaAtomicComponent component = EasyMock.createMock(JavaAtomicComponent.class);
+ EasyMock.expect(component.getAssociatedTargetInstance()).andReturn(foo);
+ EasyMock.expect(component.getScope()).andReturn(Scope.CONVERSATION);
+ EasyMock.replay(component);
+ JavaTargetInvoker invoker = new JavaTargetInvoker(Foo.class.getMethod("invoke"), component, null, null);
+ Message msg = new MessageImpl();
+ msg.setConversationSequence(TargetInvoker.CONTINUE);
+ invoker.invoke(msg);
+ EasyMock.verify(foo);
+ EasyMock.verify(component);
+ }
+
+ /**
+ * Verifies that an invocation marked as ending a conversation has an associated instance returned and it is removed
+ * following the dispatch to the instance
+ */
+ public void testEndSequence() throws Exception {
+ Foo foo = EasyMock.createMock(Foo.class);
+ foo.invoke();
+ EasyMock.replay(foo);
+ JavaAtomicComponent component = EasyMock.createMock(JavaAtomicComponent.class);
+ EasyMock.expect(component.getAssociatedTargetInstance()).andReturn(foo);
+ EasyMock.expect(component.getScope()).andReturn(Scope.CONVERSATION);
+ component.removeInstance();
+ component.destroy(EasyMock.eq(foo));
+ EasyMock.replay(component);
+ JavaTargetInvoker invoker = new JavaTargetInvoker(Foo.class.getMethod("invoke"), component, null, null);
+ Message msg = new MessageImpl();
+ msg.setConversationSequence(TargetInvoker.END);
+ invoker.invoke(msg);
+ EasyMock.verify(foo);
+ EasyMock.verify(component);
+ }
+
+
+ private interface Foo {
+ void invoke();
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerStatelessDestroyTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerStatelessDestroyTestCase.java
new file mode 100644
index 0000000000..fc53337d54
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerStatelessDestroyTestCase.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.java;
+
+import java.lang.reflect.Method;
+
+import org.apache.tuscany.spi.model.Scope;
+
+import junit.framework.TestCase;
+import org.easymock.classextension.EasyMock;
+
+public class JavaTargetInvokerStatelessDestroyTestCase extends TestCase {
+
+ public JavaTargetInvokerStatelessDestroyTestCase(String arg0) {
+ super(arg0);
+ }
+
+ public void testDestroy() throws Exception {
+ Method echoMethod = Echo.class.getDeclaredMethod("echo", String.class);
+ JavaAtomicComponent component = EasyMock.createMock(JavaAtomicComponent.class);
+ EasyMock.expect(component.getTargetInstance()).andReturn(new JavaTargetInvokerStatelessDestroyTestCase.Echo());
+ EasyMock.expect(component.getScope()).andReturn(Scope.STATELESS);
+ component.destroy(EasyMock.isA(Echo.class));
+ EasyMock.replay(component);
+ JavaTargetInvoker invoker = new JavaTargetInvoker(echoMethod, component, null, null);
+ invoker.setCacheable(false);
+ assertEquals("foo", invoker.invokeTarget("foo", JavaTargetInvoker.NONE));
+ EasyMock.verify(component);
+ }
+
+ public static class Echo {
+ public String echo(String message) throws Exception {
+ return message;
+ }
+
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerTestCase.java
new file mode 100644
index 0000000000..246e023eaa
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerTestCase.java
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.java;
+
+import java.lang.reflect.Method;
+
+import org.apache.tuscany.spi.model.Scope;
+
+import junit.framework.TestCase;
+import org.easymock.classextension.EasyMock;
+
+public class JavaTargetInvokerTestCase extends TestCase {
+
+ public JavaTargetInvokerTestCase(String arg0) {
+ super(arg0);
+ }
+
+ public void testInvoke() throws Exception {
+ Method echoMethod = Echo.class.getDeclaredMethod("echo", String.class);
+ JavaAtomicComponent component = EasyMock.createMock(JavaAtomicComponent.class);
+ EasyMock.expect(component.getTargetInstance()).andReturn(new Echo());
+ EasyMock.expect(component.getScope()).andReturn(Scope.COMPOSITE);
+ EasyMock.replay(component);
+ JavaTargetInvoker invoker = new JavaTargetInvoker(echoMethod, component, null, null);
+ invoker.setCacheable(false);
+ assertEquals("foo", invoker.invokeTarget("foo", JavaTargetInvoker.NONE));
+ EasyMock.verify(component);
+ }
+
+ public static class Echo {
+ public String echo(String message) throws Exception {
+ return message;
+ }
+
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/java/MultiplicityTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/java/MultiplicityTestCase.java
new file mode 100644
index 0000000000..ba478c9634
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/java/MultiplicityTestCase.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.java;
+
+import junit.framework.TestCase;
+
+
+/**
+ * Tests wires that are configured with a multiplicity
+ *
+ * @version $Rev$ $Date$
+ */
+public class MultiplicityTestCase extends TestCase {
+
+ public void testMultiplicity() throws Exception {
+ // TODO implement
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/java/ResourceInjectionTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/java/ResourceInjectionTestCase.java
new file mode 100644
index 0000000000..de0ec0331e
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/java/ResourceInjectionTestCase.java
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.java;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.host.ResourceHost;
+import org.apache.tuscany.spi.wire.Wire;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.implementation.PojoConfiguration;
+import org.apache.tuscany.core.injection.PojoObjectFactory;
+import org.apache.tuscany.core.injection.ResourceObjectFactory;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ResourceInjectionTestCase extends TestCase {
+
+ public void testResourceMemberInjection() throws Exception {
+ ScopeContainer containter = EasyMock.createNiceMock(ScopeContainer.class);
+ Constructor<Foo> ctor = Foo.class.getConstructor();
+ Field field = Foo.class.getDeclaredField("resource");
+ PojoConfiguration configuration = new PojoConfiguration();
+ configuration.setName(new URI("component"));
+ configuration.setInstanceFactory(new PojoObjectFactory<Foo>(ctor));
+ configuration.addResourceSite("bar", field);
+ JavaAtomicComponent component = new JavaAtomicComponent(configuration);
+ component.setScopeContainer(containter);
+
+ Wire wire = EasyMock.createMock(Wire.class);
+ EasyMock.expect(wire.getTargetInstance()).andReturn("result");
+ EasyMock.replay(wire);
+
+ ResourceHost host = EasyMock.createMock(ResourceHost.class);
+ EasyMock.expect(host.resolveResource(EasyMock.eq(String.class))).andReturn("result");
+ EasyMock.replay(host);
+
+ ResourceObjectFactory<String> factory = new ResourceObjectFactory<String>(String.class, false, host);
+ component.addResourceFactory("bar", factory);
+
+ Foo foo = (Foo) component.createInstance();
+ assertEquals("result", foo.resource);
+ }
+
+
+ public void testResourceConstructorInjection() throws Exception {
+ ScopeContainer containter = EasyMock.createNiceMock(ScopeContainer.class);
+ Constructor<FooConstructor> ctor = FooConstructor.class.getConstructor(String.class);
+ PojoConfiguration configuration = new PojoConfiguration();
+ configuration.setName(new URI("component"));
+ configuration.setInstanceFactory(new PojoObjectFactory<FooConstructor>(ctor));
+ List<String> ctorNames = new ArrayList<String>();
+ ctorNames.add("bar");
+ configuration.setConstructorParamNames(ctorNames);
+ JavaAtomicComponent component = new JavaAtomicComponent(configuration);
+ component.setScopeContainer(containter);
+
+ Wire wire = EasyMock.createMock(Wire.class);
+ EasyMock.expect(wire.getTargetInstance()).andReturn("result");
+ EasyMock.replay(wire);
+ ResourceHost host = EasyMock.createMock(ResourceHost.class);
+ EasyMock.expect(host.resolveResource(EasyMock.eq(String.class))).andReturn("result");
+ EasyMock.replay(host);
+
+ ResourceObjectFactory<String> factory = new ResourceObjectFactory<String>(String.class, false, host);
+ component.addResourceFactory("bar", factory);
+
+ FooConstructor foo = (FooConstructor) component.createInstance();
+ assertEquals("result", foo.resource);
+ }
+
+ public static class Foo {
+ protected String resource;
+
+ public Foo() {
+ }
+
+ }
+
+ public static class FooConstructor {
+ protected String resource;
+
+ public FooConstructor(String resource) {
+ this.resource = resource;
+ }
+
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/java/integration/CallbackInvocationTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/java/integration/CallbackInvocationTestCase.java
new file mode 100644
index 0000000000..9ed9cab9b2
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/java/integration/CallbackInvocationTestCase.java
@@ -0,0 +1,347 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.java.integration;
+
+import java.lang.reflect.Method;
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import org.osoa.sca.NoRegisteredCallbackException;
+import org.osoa.sca.annotations.Callback;
+
+import org.apache.tuscany.spi.builder.Connector;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.idl.InvalidServiceContractException;
+import org.apache.tuscany.spi.idl.java.JavaInterfaceProcessorRegistry;
+import org.apache.tuscany.spi.implementation.java.ConstructorDefinition;
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.ReferenceTarget;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.services.work.WorkScheduler;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.builder.ConnectorImpl;
+import org.apache.tuscany.core.component.ComponentManager;
+import org.apache.tuscany.core.component.ComponentManagerImpl;
+import org.apache.tuscany.core.component.WorkContextImpl;
+import org.apache.tuscany.core.component.scope.CompositeScopeContainer;
+import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
+import org.apache.tuscany.core.implementation.java.JavaAtomicComponent;
+import org.apache.tuscany.core.implementation.java.JavaComponentBuilder;
+import org.apache.tuscany.core.implementation.java.JavaImplementation;
+import org.apache.tuscany.core.wire.jdk.JDKProxyService;
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.getCurrentArguments;
+import static org.easymock.EasyMock.isA;
+import static org.easymock.EasyMock.replay;
+import org.easymock.IAnswer;
+
+/**
+ * Verifies callback integration scenarios with Java components.
+ *
+ * @version $Rev$ $Date$
+ */
+public class CallbackInvocationTestCase extends TestCase {
+ private ScopeContainer container;
+ private DeploymentContext context;
+ private JavaComponentBuilder builder;
+ private WorkScheduler scheduler;
+ private WorkContext workContext;
+ private ComponentManager componentManager;
+ private Connector connector;
+
+ /**
+ * Verifies callbacks between two Java component implementations: wire creation, connection, injection of callback
+ * proxy, and invocation
+ */
+ public void testComponentToComponentCallback() throws Exception {
+ ComponentDefinition<JavaImplementation> targetDefinition = createTarget();
+ JavaAtomicComponent targetComponent = (JavaAtomicComponent) builder.build(targetDefinition, context);
+ targetComponent.setScopeContainer(container);
+ container.register(targetComponent);
+ componentManager.register(targetComponent);
+ ComponentDefinition<JavaImplementation> sourceDefinition = createSource(URI.create("fooClient"));
+ JavaAtomicComponent clientComponent = (JavaAtomicComponent) builder.build(sourceDefinition, context);
+ clientComponent.setScopeContainer(container);
+ container.register(clientComponent);
+ componentManager.register(clientComponent);
+ connector.connect(sourceDefinition);
+ targetComponent.start();
+ clientComponent.start();
+ FooClient client = (FooClient) clientComponent.getTargetInstance();
+ client.invoke();
+ assertTrue(client.invoked);
+ client.invokeMultiCallback();
+ assertTrue(client.count == 2);
+ }
+
+ /**
+ * Verifies exception is thrown when callback is not implemented
+ */
+ public void testCallbackNotRegistered() throws Exception {
+ // JFM temporarily commenting out as implementation needs to be spec compliant
+ }
+
+ /**
+ * Verifies a callback in response to an invocation from two different client components is routed back to the
+ * appropriate client.
+ */
+ public void testTwoSourceComponentToComponentCallback() throws Exception {
+ ComponentDefinition<JavaImplementation> targetDefinition = createTarget();
+ JavaAtomicComponent targetComponent =
+ (JavaAtomicComponent) builder.build(targetDefinition, context);
+ targetComponent.setScopeContainer(container);
+ container.register(targetComponent);
+ componentManager.register(targetComponent);
+
+ ComponentDefinition<JavaImplementation> sourceDefinition1 = createSource(URI.create("client1"));
+ ComponentDefinition<JavaImplementation> sourceDefinition2 = createSource(URI.create("client2"));
+ JavaAtomicComponent clientComponent1 = (JavaAtomicComponent) builder.build(sourceDefinition1, context);
+ clientComponent1.setScopeContainer(container);
+ container.register(clientComponent1);
+ componentManager.register(clientComponent1);
+ JavaAtomicComponent clientComponent2 = (JavaAtomicComponent) builder.build(sourceDefinition2, context);
+ clientComponent2.setScopeContainer(container);
+ container.register(clientComponent2);
+ componentManager.register(clientComponent2);
+
+ connector.connect(sourceDefinition1);
+ connector.connect(sourceDefinition2);
+ targetComponent.start();
+
+ FooClient client1 = (FooClient) clientComponent1.getTargetInstance();
+ client1.invoke();
+ assertTrue(client1.invoked);
+ FooClient client2 = (FooClient) clientComponent2.getTargetInstance();
+ client2.invoke();
+ assertTrue(client2.invoked);
+ }
+
+
+ private ComponentDefinition<JavaImplementation> createTarget() throws NoSuchMethodException,
+ InvalidServiceContractException {
+ ConstructorDefinition<FooImpl> ctorDef = new ConstructorDefinition<FooImpl>(FooImpl.class.getConstructor());
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ type.setConstructorDefinition(ctorDef);
+ type.setImplementationScope(Scope.COMPOSITE);
+ Method method = FooImpl.class.getMethod("setCallback", FooCallback.class);
+ JavaInterfaceProcessorRegistry registry = new JavaInterfaceProcessorRegistryImpl();
+ ServiceContract<?> contract = registry.introspect(Foo.class);
+ contract.setCallbackClass(FooCallback.class);
+ contract.setCallbackName("callback");
+ JavaMappedService mappedService = new JavaMappedService(URI.create("Foo"), contract, false, "callback", method);
+ type.getServices().put("Foo", mappedService);
+
+ JavaImplementation impl = new JavaImplementation(FooImpl.class, type);
+ impl.setComponentType(type);
+ impl.setImplementationClass(FooImpl.class);
+ return new ComponentDefinition<JavaImplementation>(URI.create("foo"), impl);
+ }
+
+ private ComponentDefinition<JavaImplementation> createSource(URI name)
+ throws NoSuchMethodException, URISyntaxException, InvalidServiceContractException {
+ ConstructorDefinition<FooClient> ctorDef =
+ new ConstructorDefinition<FooClient>(FooClient.class.getConstructor());
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ type.setConstructorDefinition(ctorDef);
+ type.setImplementationScope(Scope.COMPOSITE);
+ Method method = FooClient.class.getMethod("setFoo", Foo.class);
+ JavaInterfaceProcessorRegistry registry = new JavaInterfaceProcessorRegistryImpl();
+ ServiceContract<?> contract = registry.introspect(Foo.class);
+ contract.setCallbackClass(FooCallback.class);
+ contract.setCallbackName("callback");
+ JavaMappedReference mappedReference = new JavaMappedReference(URI.create(name + "#" + "foo"), contract, method);
+ type.getReferences().put("foo", mappedReference);
+ ReferenceTarget refTarget = new ReferenceTarget();
+ refTarget.setReferenceName(URI.create(name + "#" + "foo"));
+ refTarget.getTargets().add(new URI("foo"));
+ JavaImplementation impl = new JavaImplementation(FooClient.class, type);
+ impl.setComponentType(type);
+ impl.setImplementationClass(FooClient.class);
+ ComponentDefinition<JavaImplementation> def = new ComponentDefinition<JavaImplementation>(name, impl);
+ def.getReferenceTargets().put("foo", refTarget);
+ return def;
+ }
+
+ private ComponentDefinition<JavaImplementation> createPlainSource(URI name)
+ throws NoSuchMethodException, URISyntaxException, InvalidServiceContractException {
+ ConstructorDefinition<FooPlainClient> ctorDef =
+ new ConstructorDefinition<FooPlainClient>(FooPlainClient.class.getConstructor());
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ type.setConstructorDefinition(ctorDef);
+ type.setImplementationScope(Scope.COMPOSITE);
+ Method method = FooPlainClient.class.getMethod("setFoo", Foo.class);
+ JavaInterfaceProcessorRegistry registry = new JavaInterfaceProcessorRegistryImpl();
+ ServiceContract<?> contract = registry.introspect(Foo.class);
+ contract.setCallbackClass(FooCallback.class);
+ contract.setCallbackName("callback");
+ JavaMappedReference mappedReference = new JavaMappedReference(URI.create(name + "#" + "foo"), contract, method);
+ type.getReferences().put("foo", mappedReference);
+ ReferenceTarget refTarget = new ReferenceTarget();
+ refTarget.setReferenceName(URI.create(name + "#" + "foo"));
+ refTarget.getTargets().add(new URI("foo"));
+ JavaImplementation impl = new JavaImplementation(FooPlainClient.class, type);
+ ComponentDefinition<JavaImplementation> def = new ComponentDefinition<JavaImplementation>(name, impl);
+ def.getReferenceTargets().put("foo", refTarget);
+ return def;
+ }
+
+ @Callback(FooCallback.class)
+ public static interface Foo {
+ void call();
+
+ void callMultiCallback();
+
+ void callFromPlain();
+ }
+
+ public static class FooImpl implements Foo {
+ private FooCallback callback;
+
+ public FooImpl() {
+ }
+
+ @Callback
+ public void setCallback(FooCallback callback) {
+ this.callback = callback;
+ }
+
+ public void call() {
+ callback.callback();
+ }
+
+ public void callMultiCallback() {
+ callback.multiCallback();
+ callback.multiCallback();
+ }
+
+ public void callFromPlain() {
+ try {
+ callback.callback();
+ fail();
+ } catch (NoRegisteredCallbackException e) {
+ // expected
+ } catch (Throwable e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ public static class FooClient implements FooCallback {
+
+ private Foo foo;
+ private boolean invoked;
+ private int count;
+
+ public FooClient() {
+ }
+
+ public void setFoo(Foo foo) {
+ this.foo = foo;
+ }
+
+ public void callback() {
+ if (invoked) {
+ fail();
+ }
+ invoked = true;
+ }
+
+ public void multiCallback() {
+ count++;
+ }
+
+ public void invoke() {
+ foo.call();
+ }
+
+ public void invokeMultiCallback() {
+ foo.callMultiCallback();
+ }
+ }
+
+ public interface FooCallback {
+ void callback();
+
+ void multiCallback();
+ }
+
+ public static class FooPlainClient /* implements FooCallback */ { // do NOT implement the callback
+
+ private Foo foo;
+
+ public FooPlainClient() {
+ }
+
+ public void setFoo(Foo foo) {
+ this.foo = foo;
+ }
+
+ public void invoke() {
+ foo.callFromPlain();
+ }
+
+ public void callback() {
+
+ }
+
+ public void multiCallback() {
+
+ }
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ componentManager = new ComponentManagerImpl();
+ connector = new ConnectorImpl(null, componentManager, scheduler, workContext);
+ container = new CompositeScopeContainer(null);
+ container.start();
+ context = createMock(DeploymentContext.class);
+ context.getCompositeScope();
+ expectLastCall().andReturn(container).anyTimes();
+ replay(context);
+
+ scheduler = createMock(WorkScheduler.class);
+ scheduler.scheduleWork(isA(Runnable.class));
+ expectLastCall().andStubAnswer(new IAnswer<Object>() {
+ public Object answer() throws Throwable {
+ Runnable runnable = (Runnable) getCurrentArguments()[0];
+ runnable.run();
+ return null;
+ }
+ });
+ replay(scheduler);
+
+ builder = new JavaComponentBuilder();
+ workContext = new WorkContextImpl();
+ builder.setWorkContext(workContext);
+ builder.setProxyService(new JDKProxyService(workContext));
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/java/integration/WireToScopedJavaTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/java/integration/WireToScopedJavaTestCase.java
new file mode 100644
index 0000000000..d389041de7
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/java/integration/WireToScopedJavaTestCase.java
@@ -0,0 +1,212 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.java.integration;
+
+import java.net.URI;
+import java.util.concurrent.Executor;
+import java.util.concurrent.Executors;
+import java.util.concurrent.FutureTask;
+
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.component.TargetInvokerCreationException;
+import org.apache.tuscany.spi.idl.InvalidServiceContractException;
+import org.apache.tuscany.spi.idl.java.JavaInterfaceProcessorRegistry;
+import org.apache.tuscany.spi.idl.java.JavaServiceContract;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.Wire;
+import org.apache.tuscany.spi.wire.ProxyService;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.component.WorkContextImpl;
+import org.apache.tuscany.core.component.event.ComponentStart;
+import org.apache.tuscany.core.component.event.ComponentStop;
+import org.apache.tuscany.core.component.event.HttpSessionEnd;
+import org.apache.tuscany.core.component.event.HttpSessionStart;
+import org.apache.tuscany.core.component.event.RequestEnd;
+import org.apache.tuscany.core.component.event.RequestStart;
+import org.apache.tuscany.core.component.scope.CompositeScopeContainer;
+import org.apache.tuscany.core.component.scope.HttpSessionScopeContainer;
+import org.apache.tuscany.core.component.scope.RequestScopeContainer;
+import org.apache.tuscany.core.component.scope.StatelessScopeContainer;
+import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
+import org.apache.tuscany.core.implementation.PojoConfiguration;
+import org.apache.tuscany.core.implementation.java.JavaAtomicComponent;
+import org.apache.tuscany.core.injection.PojoObjectFactory;
+import org.apache.tuscany.core.mock.component.Target;
+import org.apache.tuscany.core.mock.component.TargetImpl;
+import org.apache.tuscany.core.wire.InvocationChainImpl;
+import org.apache.tuscany.core.wire.WireImpl;
+import org.apache.tuscany.core.wire.jdk.JDKProxyService;
+
+/**
+ * Validates wiring from a wire to Java atomic component by scope
+ *
+ * @version $$Rev$$ $$Date$$
+ */
+public class WireToScopedJavaTestCase extends TestCase {
+ private WorkContext workContext = new WorkContextImpl();
+ private ProxyService proxyService = new JDKProxyService(new WorkContextImpl());
+
+ public void testToStatelessScope() throws Exception {
+ StatelessScopeContainer scope = new StatelessScopeContainer(workContext, null);
+ scope.start();
+ final Wire wire = getWire(scope);
+ Target service = proxyService.createProxy(Target.class, wire);
+ assertNotNull(service);
+ service.setString("foo");
+ assertEquals(null, service.getString());
+ scope.stop();
+ }
+
+ public void testToRequestScope() throws Exception {
+ final RequestScopeContainer scope = new RequestScopeContainer(workContext, null);
+ scope.start();
+
+ scope.onEvent(new RequestStart(this));
+
+ final Wire wire = getWire(scope);
+ Target service = proxyService.createProxy(Target.class, wire);
+ assertNotNull(service);
+ service.setString("foo");
+
+ // another request
+ Executor executor = Executors.newSingleThreadExecutor();
+ FutureTask<Void> future = new FutureTask<Void>(new Runnable() {
+ public void run() {
+ scope.onEvent(new RequestStart(this));
+ Target service2 = proxyService.createProxy(Target.class, wire);
+ Target target2 = proxyService.createProxy(Target.class, wire);
+ assertEquals(null, service2.getString());
+ service2.setString("bar");
+ assertEquals("bar", service2.getString());
+ assertEquals("bar", target2.getString());
+ scope.onEvent(new RequestEnd(this));
+ }
+ }, null);
+ executor.execute(future);
+ future.get();
+
+ assertEquals("foo", service.getString());
+ scope.onEvent(new RequestEnd(this));
+ scope.stop();
+ }
+
+ public void testToSessionScope() throws Exception {
+ HttpSessionScopeContainer scope = new HttpSessionScopeContainer(workContext, null);
+ scope.start();
+ Object session1 = new Object();
+ workContext.setIdentifier(Scope.SESSION, session1);
+ scope.onEvent(new HttpSessionStart(this, session1));
+
+ final Wire wire = getWire(scope);
+ Target service = proxyService.createProxy(Target.class, wire);
+ Target target = proxyService.createProxy(Target.class, wire);
+ assertNotNull(service);
+ service.setString("foo");
+ assertEquals("foo", service.getString());
+ assertEquals("foo", target.getString());
+
+ workContext.clearIdentifier(Scope.SESSION);
+
+ //second session
+ Object session2 = new Object();
+ workContext.setIdentifier(Scope.SESSION, session2);
+ scope.onEvent(new HttpSessionStart(this, session2));
+
+ Target service2 = proxyService.createProxy(Target.class, wire);
+ assertNotNull(service2);
+ assertNull(service2.getString());
+ Target target2 = proxyService.createProxy(Target.class, wire);
+ service2.setString("bar");
+ assertEquals("bar", service2.getString());
+ assertEquals("bar", target2.getString());
+
+ scope.onEvent(new HttpSessionEnd(this, session2));
+ workContext.clearIdentifier(Scope.SESSION);
+
+ workContext.setIdentifier(Scope.SESSION, session1);
+ assertEquals("foo", service.getString());
+
+ scope.onEvent(new HttpSessionEnd(this, session1));
+
+ scope.stop();
+ }
+
+ public void testToCompositeScope() throws Exception {
+ CompositeScopeContainer scope = new CompositeScopeContainer(null);
+ scope.start();
+ scope.onEvent(new ComponentStart(this, null));
+ final Wire wire = getWire(scope);
+ Target service = proxyService.createProxy(Target.class, wire);
+ Target target = proxyService.createProxy(Target.class, wire);
+ assertNotNull(service);
+ service.setString("foo");
+ assertEquals("foo", service.getString());
+ assertEquals("foo", target.getString());
+ scope.onEvent(new ComponentStop(this, null));
+ scope.stop();
+ }
+
+ private Wire getWire(ScopeContainer scope) throws Exception {
+ PojoConfiguration configuration = new PojoConfiguration();
+ configuration.setImplementationClass(TargetImpl.class);
+ configuration.setInstanceFactory(new PojoObjectFactory<TargetImpl>(TargetImpl.class.getConstructor()));
+ configuration.setWorkContext(workContext);
+ configuration.setName(new URI("source"));
+ configuration.setName(new URI("target"));
+
+ JavaAtomicComponent target = new JavaAtomicComponent(configuration);
+ target.setScopeContainer(scope);
+
+ Wire wire = createWire("target#Target", Target.class, target);
+
+ target.start();
+ return wire;
+ }
+
+ private static <T> Wire createWire(String targetName, Class<T> interfaze, JavaAtomicComponent target)
+ throws InvalidServiceContractException, TargetInvokerCreationException {
+ Wire wire = new WireImpl();
+ JavaServiceContract contract = new JavaServiceContract(interfaze);
+ contract.setConversational(false);
+ wire.setSourceContract(contract);
+ createChains(interfaze, wire);
+ wire.setTargetUri(URI.create(targetName));
+ wire.setSourceUri(URI.create("component#ref"));
+ for (InvocationChain chain : wire.getInvocationChains().values()) {
+ chain.setTargetInvoker(target.createTargetInvoker("target", chain.getOperation()));
+ }
+ return wire;
+ }
+
+ private static void createChains(Class<?> interfaze, Wire wire)
+ throws InvalidServiceContractException {
+ JavaInterfaceProcessorRegistry registry = new JavaInterfaceProcessorRegistryImpl();
+ ServiceContract<?> contract = registry.introspect(interfaze);
+ for (Operation operation : contract.getOperations().values()) {
+ InvocationChain chain = new InvocationChainImpl(operation);
+ wire.addInvocationChain(operation, chain);
+ }
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/AllowsPassByReferenceProcessorTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/AllowsPassByReferenceProcessorTestCase.java
new file mode 100644
index 0000000000..08e5b2315c
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/AllowsPassByReferenceProcessorTestCase.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.processor;
+
+import org.osoa.sca.annotations.AllowsPassByReference;
+
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev: 452761 $ $Date: 2006-10-04 12:03:20 +0530 (Wed, 04 Oct 2006) $
+ */
+public class AllowsPassByReferenceProcessorTestCase extends TestCase {
+
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type;
+ AllowsPassByReferenceProcessor processor;
+
+ public void testClassAnnotation() throws Exception {
+// processor.visitClass(Foo.class, type, null);
+// assertEquals(true, type.isAllowsPassByReference());
+//
+// processor.visitClass(Bar.class, type, null);
+// assertEquals(false, type.isAllowsPassByReference());
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ type = new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ processor = new AllowsPassByReferenceProcessor();
+ }
+
+ @AllowsPassByReference
+ private class Foo {
+ }
+
+ //no annotation
+ private class Bar {
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorProcessorExtensibilityTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorProcessorExtensibilityTestCase.java
new file mode 100644
index 0000000000..f82d0f6f21
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorProcessorExtensibilityTestCase.java
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.processor;
+
+import java.lang.reflect.Constructor;
+
+import org.osoa.sca.annotations.Property;
+
+import org.apache.tuscany.spi.implementation.java.ConstructorDefinition;
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
+
+/**
+ * Verifies the constructor processor works when parameters are marked with custom extension annotations
+ *
+ * @version $Rev$ $Date$
+ */
+public class ConstructorProcessorExtensibilityTestCase extends TestCase {
+ private ConstructorProcessor processor =
+ new ConstructorProcessor(new ImplementationProcessorServiceImpl(new JavaInterfaceProcessorRegistryImpl()));
+
+ public void testProcessFirst() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<Foo> ctor1 = Foo.class.getConstructor(String.class, String.class);
+ processor.visitConstructor(ctor1, type, null);
+ assertEquals("foo", type.getConstructorDefinition().getInjectionNames().get(0));
+ }
+
+ /**
+ * Verifies the constructor processor can be called after another processor has evaluated the constructor and found
+ * an annotation
+ *
+ * @throws Exception
+ */
+ public void testProcessLast() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<Foo> ctor1 = Foo.class.getConstructor(String.class, String.class);
+ ConstructorDefinition<Foo> definition = new ConstructorDefinition<Foo>(ctor1);
+ definition.getInjectionNames().add("");
+ definition.getInjectionNames().add("mybar");
+ type.setConstructorDefinition(definition);
+ processor.visitConstructor(ctor1, type, null);
+ assertEquals("foo", type.getConstructorDefinition().getInjectionNames().get(0));
+ }
+
+
+ private @interface Bar {
+
+ }
+
+ private static class Foo {
+ @org.osoa.sca.annotations.Constructor
+ public Foo(@Property(name = "foo") String foo, @Bar String bar) {
+
+ }
+ }
+
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorProcessorTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorProcessorTestCase.java
new file mode 100644
index 0000000000..c6add2cae2
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorProcessorTestCase.java
@@ -0,0 +1,167 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.processor;
+
+import java.lang.reflect.Constructor;
+import java.util.Collection;
+import java.util.List;
+import java.util.Set;
+
+import org.osoa.sca.annotations.Property;
+import org.osoa.sca.annotations.Reference;
+
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.model.Multiplicity;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ConstructorProcessorTestCase extends TestCase {
+ private ConstructorProcessor processor =
+ new ConstructorProcessor(new ImplementationProcessorServiceImpl(new JavaInterfaceProcessorRegistryImpl()));
+
+ public void testDuplicateConstructor() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ try {
+ processor.visitClass(BadFoo.class, type, null);
+ fail();
+ } catch (DuplicateConstructorException e) {
+ // expected
+ }
+ }
+
+ public void testConstructorAnnotation() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<Foo> ctor1 = Foo.class.getConstructor(String.class);
+ processor.visitConstructor(ctor1, type, null);
+ assertEquals("foo", type.getConstructorDefinition().getInjectionNames().get(0));
+ }
+
+ public void testNoAnnotation() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<NoAnnotation> ctor1 = NoAnnotation.class.getConstructor();
+ processor.visitConstructor(ctor1, type, null);
+ assertNull(type.getConstructorDefinition());
+ }
+
+ public void testBadAnnotation() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<BadAnnotation> ctor1 = BadAnnotation.class.getConstructor(String.class, Foo.class);
+ try {
+ processor.visitConstructor(ctor1, type, null);
+ fail();
+ } catch (InvalidConstructorException e) {
+ // expected
+ }
+ }
+
+ public void testMixedParameters() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<Mixed> ctor1 = Mixed.class.getConstructor(String.class, String.class, String.class);
+ processor.visitConstructor(ctor1, type, null);
+ assertEquals("_ref0", type.getConstructorDefinition().getInjectionNames().get(0));
+ assertEquals("foo", type.getConstructorDefinition().getInjectionNames().get(1));
+ assertEquals("bar", type.getConstructorDefinition().getInjectionNames().get(2));
+ }
+
+ private static class BadFoo {
+
+ @org.osoa.sca.annotations.Constructor("foo")
+ public BadFoo(String foo) {
+
+ }
+
+ @org.osoa.sca.annotations.Constructor({"foo", "bar"})
+ public BadFoo(String foo, String bar) {
+
+ }
+ }
+
+ private static class Foo {
+ @org.osoa.sca.annotations.Constructor("foo")
+ public Foo(String foo) {
+
+ }
+ }
+
+ private static class NoAnnotation {
+ public NoAnnotation() {
+ }
+ }
+
+ private static class BadAnnotation {
+ @org.osoa.sca.annotations.Constructor("foo")
+ public BadAnnotation(String foo, Foo ref) {
+ }
+ }
+
+
+ public static final class Mixed {
+ @org.osoa.sca.annotations.Constructor
+ public Mixed(@Reference String param1,
+ @Property(name = "foo")String param2,
+ @Reference(name = "bar")String param3) {
+ }
+ }
+
+ public static final class Multiple {
+ @org.osoa.sca.annotations.Constructor
+ public Multiple(@Reference Collection<String> param1,
+ @Property(name = "foo")String[] param2,
+ @Reference(name = "bar", required = true)List<String> param3,
+ @Property(name = "abc")Set<String> param4,
+ @Reference(name = "xyz")String[] param5) {
+ }
+ }
+
+ public void testMultiplicity() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<Multiple> ctor1 =
+ Multiple.class.getConstructor(Collection.class, String[].class, List.class, Set.class, String[].class);
+ processor.visitConstructor(ctor1, type, null);
+ JavaMappedReference ref0 = type.getReferences().get("_ref0");
+ assertNotNull(ref0);
+ assertEquals(Multiplicity.ZERO_N, ref0.getMultiplicity());
+ JavaMappedReference ref1 = type.getReferences().get("bar");
+ assertNotNull(ref1);
+ assertEquals(Multiplicity.ONE_N, ref1.getMultiplicity());
+ JavaMappedReference ref2 = type.getReferences().get("xyz");
+ assertNotNull(ref2);
+ assertEquals(Multiplicity.ZERO_N, ref2.getMultiplicity());
+ JavaMappedProperty prop1 = type.getProperties().get("foo");
+ assertNotNull(prop1);
+ assertTrue(prop1.isMany());
+ JavaMappedProperty prop2 = type.getProperties().get("abc");
+ assertNotNull(prop2);
+ assertTrue(prop2.isMany());
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorPropertyTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorPropertyTestCase.java
new file mode 100644
index 0000000000..c3f1eec6c0
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorPropertyTestCase.java
@@ -0,0 +1,169 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.processor;
+
+import java.lang.reflect.Constructor;
+import java.util.List;
+
+import org.osoa.sca.annotations.Property;
+
+import org.apache.tuscany.spi.implementation.java.DuplicatePropertyException;
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ConstructorPropertyTestCase extends TestCase {
+
+ ConstructorProcessor processor =
+ new ConstructorProcessor(new ImplementationProcessorServiceImpl(new JavaInterfaceProcessorRegistryImpl()));
+
+ public void testProperty() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<Foo> ctor = Foo.class.getConstructor(String.class);
+ processor.visitConstructor(ctor, type, null);
+ JavaMappedProperty<?> property = type.getProperties().get("myProp");
+ assertTrue(property.isRequired());
+ assertEquals("myProp", property.getName());
+ }
+
+ public void testTwoPropertiesSameType() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<Foo> ctor = Foo.class.getConstructor(String.class, String.class);
+ processor.visitConstructor(ctor, type, null);
+ assertNotNull(type.getProperties().get("myProp1"));
+ assertNotNull(type.getProperties().get("myProp2"));
+ }
+
+ public void testDuplicateProperty() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<BadFoo> ctor = BadFoo.class.getConstructor(String.class, String.class);
+ try {
+ processor.visitConstructor(ctor, type, null);
+ fail();
+ } catch (DuplicatePropertyException e) {
+ // expected
+ }
+ }
+
+ public void testNoName() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<BadFoo> ctor = BadFoo.class.getConstructor(String.class);
+ try {
+ processor.visitConstructor(ctor, type, null);
+ fail();
+ } catch (InvalidPropertyException e) {
+ // expected
+ }
+ }
+
+ public void testNamesOnConstructor() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<Foo> ctor = Foo.class.getConstructor(Integer.class);
+ processor.visitConstructor(ctor, type, null);
+ assertNotNull(type.getProperties().get("myProp"));
+ }
+
+ public void testInvalidNumberOfNames() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<BadFoo> ctor = BadFoo.class.getConstructor(Integer.class, Integer.class);
+ try {
+ processor.visitConstructor(ctor, type, null);
+ fail();
+ } catch (InvalidPropertyException e) {
+ // expected
+ }
+ }
+
+ public void testNoMatchingNames() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<BadFoo> ctor = BadFoo.class.getConstructor(List.class, List.class);
+ try {
+ processor.visitConstructor(ctor, type, null);
+ fail();
+ } catch (InvalidConstructorException e) {
+ // expected
+ }
+ }
+
+// public void testMultiplicityRequired() throws Exception {
+ // TODO multiplicity
+// }
+
+ private static class Foo {
+
+ @org.osoa.sca.annotations.Constructor()
+ public Foo(@Property(name = "myProp", required = true)String prop) {
+
+ }
+
+ @org.osoa.sca.annotations.Constructor("myProp")
+ public Foo(@Property Integer prop) {
+
+ }
+
+ @org.osoa.sca.annotations.Constructor()
+ public Foo(@Property(name = "myProp1")String prop1, @Property(name = "myProp2")String prop2) {
+
+ }
+
+ @org.osoa.sca.annotations.Constructor()
+ public Foo(@Property List prop) {
+
+ }
+ }
+
+ private static class BadFoo {
+
+ @org.osoa.sca.annotations.Constructor()
+ public BadFoo(@Property(name = "myProp")String prop1, @Property(name = "myProp")String prop2) {
+
+ }
+
+ @org.osoa.sca.annotations.Constructor()
+ public BadFoo(@Property String prop) {
+
+ }
+
+ @org.osoa.sca.annotations.Constructor("myProp")
+ public BadFoo(@Property Integer prop, @Property Integer prop2) {
+
+ }
+
+ @org.osoa.sca.annotations.Constructor({"myRef", "myRef2"})
+ public BadFoo(@Property List ref, @Property(name = "myOtherRef")List ref2) {
+
+ }
+
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorReferenceTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorReferenceTestCase.java
new file mode 100644
index 0000000000..067a23a096
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorReferenceTestCase.java
@@ -0,0 +1,176 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.processor;
+
+import java.lang.reflect.Constructor;
+import java.util.List;
+
+import org.osoa.sca.annotations.Reference;
+
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ConstructorReferenceTestCase extends TestCase {
+ private ConstructorProcessor processor;
+
+ public void testReference() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<Foo> ctor = Foo.class.getConstructor(String.class);
+ processor.visitConstructor(ctor, type, null);
+ JavaMappedReference reference = type.getReferences().get("myRef");
+ assertTrue(reference.isRequired());
+ assertEquals("#myRef", reference.getUri().toString());
+ }
+
+ public void testTwoReferencesSameType() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<Foo> ctor = Foo.class.getConstructor(String.class, String.class);
+ processor.visitConstructor(ctor, type, null);
+ assertNotNull(type.getReferences().get("myRef1"));
+ assertNotNull(type.getReferences().get("myRef2"));
+ }
+
+ public void testDuplicateProperty() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<BadFoo> ctor = BadFoo.class.getConstructor(String.class, String.class);
+ try {
+ processor.visitConstructor(ctor, type, null);
+ fail();
+ } catch (DuplicateReferenceException e) {
+ // expected
+ }
+ }
+
+ public void testNoName() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<NoNameFoo> ctor = NoNameFoo.class.getConstructor(String.class);
+ processor.visitConstructor(ctor, type, null);
+ assertNotNull(type.getReferences().get("_ref0"));
+ }
+
+ public void testNamesOnConstructor() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<Foo> ctor = Foo.class.getConstructor(Integer.class);
+ processor.visitConstructor(ctor, type, null);
+ assertNotNull(type.getReferences().get("myRef"));
+ }
+
+ public void testInvalidNumberOfNames() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<BadFoo> ctor = BadFoo.class.getConstructor(Integer.class, Integer.class);
+ try {
+ processor.visitConstructor(ctor, type, null);
+ fail();
+ } catch (InvalidReferenceException e) {
+ // expected
+ }
+ }
+
+ public void testNoMatchingNames() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<BadFoo> ctor = BadFoo.class.getConstructor(List.class, List.class);
+ try {
+ processor.visitConstructor(ctor, type, null);
+ fail();
+ } catch (InvalidConstructorException e) {
+ // expected
+ }
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ processor =
+ new ConstructorProcessor(new ImplementationProcessorServiceImpl(new JavaInterfaceProcessorRegistryImpl()));
+ }
+
+// public void testMultiplicityRequired() throws Exception {
+ // TODO multiplicity
+// }
+
+ private static class Foo {
+
+ @org.osoa.sca.annotations.Constructor()
+ public Foo(@Reference(name = "myRef", required = true)String prop) {
+
+ }
+
+ @org.osoa.sca.annotations.Constructor()
+ public Foo(@Reference(name = "myRef1")String prop1, @Reference(name = "myRef2")String prop2) {
+
+ }
+
+ @org.osoa.sca.annotations.Constructor("myRef")
+ public Foo(@Reference Integer prop) {
+
+ }
+
+ @org.osoa.sca.annotations.Constructor()
+ public Foo(@Reference List prop) {
+
+ }
+ }
+
+ private static class NoNameFoo {
+
+ @org.osoa.sca.annotations.Constructor
+ public NoNameFoo(@Reference String prop) {
+
+ }
+ }
+
+ private static class BadFoo {
+
+ @org.osoa.sca.annotations.Constructor
+ public BadFoo(@Reference(name = "myRef")String prop1, @Reference(name = "myRef")String prop2) {
+
+ }
+
+ @org.osoa.sca.annotations.Constructor
+ public BadFoo(@Reference String prop) {
+
+ }
+
+ @org.osoa.sca.annotations.Constructor("myRef")
+ public BadFoo(@Reference Integer ref, @Reference Integer ref2) {
+
+ }
+
+ @org.osoa.sca.annotations.Constructor({"myRef", "myRef2"})
+ public BadFoo(@Reference List ref, @Reference(name = "myOtherRef")List ref2) {
+
+ }
+
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorResourceTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorResourceTestCase.java
new file mode 100644
index 0000000000..6272b5216e
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorResourceTestCase.java
@@ -0,0 +1,166 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.processor;
+
+import java.lang.reflect.Constructor;
+import java.util.List;
+
+import org.apache.tuscany.api.annotation.Resource;
+
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ConstructorResourceTestCase extends TestCase {
+
+ ConstructorProcessor processor =
+ new ConstructorProcessor(new ImplementationProcessorServiceImpl(new JavaInterfaceProcessorRegistryImpl()));
+
+ public void testResource() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<Foo> ctor = Foo.class.getConstructor(String.class);
+ processor.visitConstructor(ctor, type, null);
+ org.apache.tuscany.spi.implementation.java.Resource resource = type.getResources().get("myResource");
+ assertFalse(resource.isOptional());
+ }
+
+ public void testTwoResourcesSameType() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<Foo> ctor = Foo.class.getConstructor(String.class, String.class);
+ processor.visitConstructor(ctor, type, null);
+ assertNotNull(type.getResources().get("myResource1"));
+ assertNotNull(type.getResources().get("myResource2"));
+ }
+
+ public void testDuplicateResource() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<BadFoo> ctor = BadFoo.class.getConstructor(String.class, String.class);
+ try {
+ processor.visitConstructor(ctor, type, null);
+ fail();
+ } catch (DuplicateResourceException e) {
+ // expected
+ }
+ }
+
+ public void testNoName() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<ConstructorResourceTestCase.BadFoo> ctor =
+ ConstructorResourceTestCase.BadFoo.class.getConstructor(String.class);
+ try {
+ processor.visitConstructor(ctor, type, null);
+ fail();
+ } catch (InvalidResourceException e) {
+ // expected
+ }
+ }
+
+ public void testNamesOnConstructor() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<Foo> ctor = Foo.class.getConstructor(Integer.class);
+ processor.visitConstructor(ctor, type, null);
+ assertNotNull(type.getResources().get("myResource"));
+ }
+
+ public void testInvalidNumberOfNames() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<ConstructorResourceTestCase.BadFoo> ctor =
+ ConstructorResourceTestCase.BadFoo.class.getConstructor(Integer.class, Integer.class);
+ try {
+ processor.visitConstructor(ctor, type, null);
+ fail();
+ } catch (InvalidResourceException e) {
+ // expected
+ }
+ }
+
+ public void testNoMatchingNames() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<ConstructorResourceTestCase.BadFoo> ctor =
+ ConstructorResourceTestCase.BadFoo.class.getConstructor(List.class, List.class);
+ try {
+ processor.visitConstructor(ctor, type, null);
+ fail();
+ } catch (InvalidConstructorException e) {
+ // expected
+ }
+ }
+
+ private static class Foo {
+
+ @org.osoa.sca.annotations.Constructor
+ public Foo(@Resource(name = "myResource") String resource) {
+
+ }
+
+ @org.osoa.sca.annotations.Constructor("myResource")
+ public Foo(@Resource Integer resource) {
+
+ }
+
+ @org.osoa.sca.annotations.Constructor
+ public Foo(@Resource(name = "myResource1") String res1, @Resource(name = "myResource2") String res2) {
+
+ }
+
+ @org.osoa.sca.annotations.Constructor
+ public Foo(@Resource List res) {
+
+ }
+ }
+
+ private static class BadFoo {
+
+ @org.osoa.sca.annotations.Constructor
+ public BadFoo(@Resource(name = "myResource") String res1, @Resource(name = "myResource") String res2) {
+
+ }
+
+ @org.osoa.sca.annotations.Constructor
+ public BadFoo(@Resource String res) {
+
+ }
+
+ @org.osoa.sca.annotations.Constructor("myProp")
+ public BadFoo(@Resource Integer res, @Resource Integer res2) {
+
+ }
+
+ @org.osoa.sca.annotations.Constructor({"myRes", "myRes2"})
+ public BadFoo(@Resource List res, @Resource(name = "myOtherRes") List res2) {
+
+ }
+
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/ContextProcessorTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/ContextProcessorTestCase.java
new file mode 100644
index 0000000000..c0bf24e5fd
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/ContextProcessorTestCase.java
@@ -0,0 +1,196 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.processor;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import org.osoa.sca.ComponentContext;
+import org.osoa.sca.RequestContext;
+import org.osoa.sca.annotations.Context;
+
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ContextProcessorTestCase extends TestCase {
+ private ContextProcessor processor;
+ private Component composite;
+
+ // FIXME: resurrect to test ComponentContext injection
+/*
+ public void testCompositeContextMethod() throws Exception {
+ Method method = Foo.class.getMethod("setContext", ComponentContext.class);
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ processor.visitMethod(composite, method, type, null);
+ assertNotNull(type.getResources().get("context"));
+ }
+*/
+
+ // FIXME: resurrect to test ComponentContext injection
+/*
+ public void testCompositeContextField() throws Exception {
+ Field field = Foo.class.getDeclaredField("context");
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ processor.visitField(composite, field, type, null);
+ assertNotNull(type.getResources().get("context"));
+ }
+*/
+
+ public void testRequestContextMethod() throws Exception {
+ Method method = Foo.class.getMethod("setRequestContext", RequestContext.class);
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ processor.visitMethod(method, type, null);
+ assertNotNull(type.getResources().get("requestContext"));
+ }
+
+ public void testRequestContextField() throws Exception {
+ Field field = Foo.class.getDeclaredField("requestContext");
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ processor.visitField(field, type, null);
+ assertNotNull(type.getResources().get("requestContext"));
+ }
+
+ public void testInvalidParamType() throws Exception {
+ Method method = Foo.class.getMethod("setContext", String.class);
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ try {
+ processor.visitMethod(method, type, null);
+ fail();
+ } catch (UnknownContextTypeException e) {
+ // expected
+ }
+ }
+
+ public void testInvalidParamTypeField() throws Exception {
+ Field field = Foo.class.getDeclaredField("badContext");
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ try {
+ processor.visitField(field, type, null);
+ fail();
+ } catch (UnknownContextTypeException e) {
+ // expected
+ }
+ }
+
+
+ public void testInvalidParamNum() throws Exception {
+ Method method = Foo.class.getMethod("setContext", ComponentContext.class, String.class);
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ try {
+ processor.visitMethod(method, type, null);
+ fail();
+ } catch (IllegalContextException e) {
+ // expected
+ }
+ }
+
+ public void testInvalidNoParams() throws Exception {
+ Method method = Foo.class.getMethod("setContext");
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ try {
+ processor.visitMethod(method, type, null);
+ fail();
+ } catch (IllegalContextException e) {
+ // expected
+ }
+ }
+
+ public void testNoContext() throws Exception {
+ Method method = Foo.class.getMethod("noContext", ComponentContext.class);
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ processor.visitMethod(method, type, null);
+ assertEquals(0, type.getResources().size());
+ }
+
+ public void testNoContextField() throws Exception {
+ Field field = Foo.class.getDeclaredField("noContext");
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ processor.visitField(field, type, null);
+ assertEquals(0, type.getResources().size());
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ processor = new ContextProcessor();
+ processor.setWorkContext(EasyMock.createNiceMock(WorkContext.class));
+ composite = EasyMock.createNiceMock(Component.class);
+ }
+
+ private class Foo {
+ @Context
+ protected ComponentContext context;
+
+ @Context
+ protected Object badContext;
+
+ protected ComponentContext noContext;
+
+ @Context
+ protected RequestContext requestContext;
+
+ @Context
+ public void setContext(ComponentContext context) {
+
+ }
+
+ @Context
+ public void setContext(String context) {
+
+ }
+
+ @Context
+ public void setContext(ComponentContext context, String string) {
+
+ }
+
+ @Context
+ public void setContext() {
+
+ }
+
+ public void noContext(ComponentContext context) {
+
+ }
+
+ @Context
+ public void setRequestContext(RequestContext requestContext) {
+ this.requestContext = requestContext;
+ }
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConversationProcessorTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConversationProcessorTestCase.java
new file mode 100644
index 0000000000..45149a1327
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConversationProcessorTestCase.java
@@ -0,0 +1,152 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.processor;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import org.osoa.sca.annotations.ConversationAttributes;
+import org.osoa.sca.annotations.ConversationID;
+import org.osoa.sca.annotations.Scope;
+
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ConversationProcessorTestCase extends TestCase {
+ private ConversationProcessor processor = new ConversationProcessor();
+
+ public void testMaxIdleTime() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ processor.visitClass(FooMaxIdle.class, type, null);
+ assertEquals(10000L, type.getMaxIdleTime());
+ assertEquals(-1, type.getMaxAge());
+ }
+
+ public void testMaxAge() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ processor.visitClass(FooMaxAge.class, type, null);
+ assertEquals(10000L, type.getMaxAge());
+ assertEquals(-1, type.getMaxIdleTime());
+ }
+
+ public void testBadFooBoth() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ try {
+ processor.visitClass(BadFooBoth.class, type, null);
+ fail();
+ } catch (InvalidConversationalImplementation e) {
+ // expected
+ }
+ }
+
+ public void testImplicitScope() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ processor.visitClass(ImplicitFooScope.class, type, null);
+ assertEquals(org.apache.tuscany.spi.model.Scope.CONVERSATION, type.getImplementationScope());
+ }
+
+ public void testBadFooScope() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ try {
+ processor.visitClass(BadFooScope.class, type, null);
+ fail();
+ } catch (InvalidConversationalImplementation e) {
+ // expected
+ }
+ }
+
+ public void testJustConversation() throws Exception {
+ // TODO do we want these semantics
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ processor.visitClass(FooJustConversation.class, type, null);
+ assertEquals(org.apache.tuscany.spi.model.Scope.CONVERSATION, type.getImplementationScope());
+ assertEquals(-1, type.getMaxAge());
+ assertEquals(-1, type.getMaxIdleTime());
+ }
+
+ public void testSetConversationIDField() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Field field = FooWithConversationIDField.class.getDeclaredField("conversationID");
+ processor.visitField(field, type, null);
+ assertNotNull(type.getConversationIDMember());
+ assertEquals(field, type.getConversationIDMember());
+ }
+
+ public void testSetConversationIDMethod() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Method method = FooWithConversationIDMethod.class.getDeclaredMethods()[0];
+ processor.visitMethod(method, type, null);
+ assertNotNull(type.getConversationIDMember());
+ assertEquals(method, type.getConversationIDMember());
+ }
+
+ @Scope("CONVERSATION")
+ @ConversationAttributes(maxIdleTime = "10 seconds")
+ private class FooMaxIdle {
+ }
+
+ @Scope("CONVERSATION")
+ @ConversationAttributes(maxAge = "10 seconds")
+ private class FooMaxAge {
+ }
+
+ @Scope("CONVERSATION")
+ @ConversationAttributes(maxAge = "10 seconds", maxIdleTime = "10 seconds")
+ private class BadFooBoth {
+ }
+
+ @ConversationAttributes(maxAge = "10 seconds")
+ private class ImplicitFooScope {
+ }
+
+ @Scope("STATELESS")
+ @ConversationAttributes(maxAge = "10 seconds")
+ private class BadFooScope {
+ }
+
+ @ConversationAttributes
+ private class FooJustConversation {
+ }
+
+ private class FooWithConversationIDField {
+ @ConversationID
+ private String conversationID;
+ }
+
+ private class FooWithConversationIDMethod {
+ @ConversationID
+ void setConversationID(String conversationID) {
+ }
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConvertTimeMillisTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConvertTimeMillisTestCase.java
new file mode 100644
index 0000000000..556416a797
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConvertTimeMillisTestCase.java
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.processor;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ConvertTimeMillisTestCase extends TestCase {
+ private MockProcessor registy;
+
+ public void testConvertSeconds() throws Exception {
+ assertEquals(10000L, registy.convertTimeMillis("10 seconds"));
+ assertEquals(10000L, registy.convertTimeMillis("10 SECONDS"));
+ try {
+ registy.convertTimeMillis("10seconds");
+ fail();
+ } catch (NumberFormatException e) {
+ // expected
+ }
+ }
+
+ public void testConvertMinutes() throws Exception {
+ assertEquals(600000L, registy.convertTimeMillis("10 minutes"));
+ assertEquals(600000L, registy.convertTimeMillis("10 MINUTES"));
+ try {
+ registy.convertTimeMillis("10minutes");
+ fail();
+ } catch (NumberFormatException e) {
+ // expected
+ }
+ }
+
+ public void testConvertHours() throws Exception {
+ assertEquals(36000000L, registy.convertTimeMillis("10 hours"));
+ assertEquals(36000000L, registy.convertTimeMillis("10 HOURS"));
+ try {
+ registy.convertTimeMillis("10hours");
+ fail();
+ } catch (NumberFormatException e) {
+ // expected
+ }
+ }
+
+ public void testConvertDays() throws Exception {
+ assertEquals(864000000L, registy.convertTimeMillis("10 days"));
+ assertEquals(864000000L, registy.convertTimeMillis("10 DAYS"));
+ try {
+ registy.convertTimeMillis("10days");
+ fail();
+ } catch (NumberFormatException e) {
+ // expected
+ }
+ }
+
+ public void testConvertYears() throws Exception {
+ assertEquals(315569260000L, registy.convertTimeMillis("10 years"));
+ assertEquals(315569260000L, registy.convertTimeMillis("10 YEARS"));
+ try {
+ registy.convertTimeMillis("10years");
+ fail();
+ } catch (NumberFormatException e) {
+ // expected
+ }
+ }
+
+ public void testConvertDefault() throws Exception {
+ assertEquals(10000L, registy.convertTimeMillis("10 "));
+ assertEquals(10000L, registy.convertTimeMillis("10"));
+ }
+
+ public void testInvalid() throws Exception {
+ try {
+ registy.convertTimeMillis("foo");
+ fail();
+ } catch (NumberFormatException e) {
+ // expected
+ }
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ registy = new MockProcessor();
+ }
+
+ private class MockProcessor extends ConversationProcessor {
+
+ @Override
+ protected long convertTimeMillis(String expr) throws NumberFormatException {
+ return super.convertTimeMillis(expr);
+ }
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/DestroyProcessorTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/DestroyProcessorTestCase.java
new file mode 100644
index 0000000000..c4a4861d50
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/DestroyProcessorTestCase.java
@@ -0,0 +1,100 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.processor;
+
+import java.lang.reflect.Method;
+
+import org.osoa.sca.annotations.Destroy;
+
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class DestroyProcessorTestCase extends TestCase {
+
+ public void testDestroy() throws Exception {
+ DestroyProcessor processor = new DestroyProcessor();
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Method method = Foo.class.getMethod("destroy");
+ processor.visitMethod(method, type, null);
+ assertNotNull(type.getDestroyMethod());
+ }
+
+ public void testBadDestroy() throws Exception {
+ DestroyProcessor processor = new DestroyProcessor();
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Method method = Bar.class.getMethod("badDestroy", String.class);
+ try {
+ processor.visitMethod(method, type, null);
+ fail();
+ } catch (IllegalDestructorException e) {
+ // expected
+ }
+ }
+
+ public void testTwoDestroy() throws Exception {
+ DestroyProcessor processor = new DestroyProcessor();
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Method method = Bar.class.getMethod("destroy");
+ Method method2 = Bar.class.getMethod("destroy2");
+ processor.visitMethod(method, type, null);
+ try {
+ processor.visitMethod(method2, type, null);
+ fail();
+ } catch (DuplicateDestructorException e) {
+ // expected
+ }
+ }
+
+
+ private class Foo {
+
+ @Destroy
+ public void destroy() {
+ }
+ }
+
+
+ private class Bar {
+
+ @Destroy
+ public void destroy() {
+ }
+
+ @Destroy
+ public void destroy2() {
+ }
+
+ @Destroy
+ public void badDestroy(String foo) {
+ }
+
+
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/EagerInitProcessorTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/EagerInitProcessorTestCase.java
new file mode 100644
index 0000000000..292f44c3bd
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/EagerInitProcessorTestCase.java
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.processor;
+
+import org.osoa.sca.annotations.EagerInit;
+
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.implementation.java.ProcessingException;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class EagerInitProcessorTestCase extends TestCase {
+
+ public void testNoLevel() throws ProcessingException {
+ EagerInitProcessor processor = new EagerInitProcessor();
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ processor.visitClass(Level.class, type, null);
+ assertEquals(50, type.getInitLevel());
+ }
+
+ public void testSubclass() throws ProcessingException {
+ EagerInitProcessor processor = new EagerInitProcessor();
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ processor.visitClass(SubClass.class, type, null);
+ assertEquals(50, type.getInitLevel());
+ }
+
+ @EagerInit
+ private class Level {
+ }
+
+ private class SubClass extends Level {
+
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicAndPropertyTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicAndPropertyTestCase.java
new file mode 100644
index 0000000000..7827e47872
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicAndPropertyTestCase.java
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.processor;
+
+import java.lang.reflect.Constructor;
+
+import org.osoa.sca.annotations.Property;
+
+import org.apache.tuscany.spi.implementation.java.ConstructorDefinition;
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class HeuristicAndPropertyTestCase extends TestCase {
+
+ private PropertyProcessor propertyProcessor;
+ private HeuristicPojoProcessor heuristicProcessor;
+
+ /**
+ * Verifies the property and heuristic processors don't collide
+ */
+ @SuppressWarnings("unchecked")
+ public void testPropertyProcessorWithHeuristicProcessor() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor ctor = Foo.class.getConstructor(String.class);
+ type.setConstructorDefinition(new ConstructorDefinition(ctor));
+ propertyProcessor.visitConstructor(ctor, type, null);
+ heuristicProcessor.visitEnd(Foo.class, type, null);
+ assertEquals(1, type.getProperties().size());
+ assertNotNull(type.getProperties().get("foo"));
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ ImplementationProcessorServiceImpl service =
+ new ImplementationProcessorServiceImpl(new JavaInterfaceProcessorRegistryImpl());
+ propertyProcessor = new PropertyProcessor(service);
+ heuristicProcessor = new HeuristicPojoProcessor(service);
+ }
+
+ public static class Foo {
+ public Foo(@Property(name = "foo") String prop) {
+ }
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicConstructorTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicConstructorTestCase.java
new file mode 100644
index 0000000000..45fe6be68f
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicConstructorTestCase.java
@@ -0,0 +1,297 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.processor;
+
+import java.net.URI;
+
+import org.osoa.sca.annotations.Property;
+import org.osoa.sca.annotations.Reference;
+import org.osoa.sca.annotations.Remotable;
+
+import org.apache.tuscany.spi.idl.java.JavaServiceContract;
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.model.ServiceContract;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class HeuristicConstructorTestCase extends TestCase {
+
+ private HeuristicPojoProcessor processor =
+ new HeuristicPojoProcessor(new ImplementationProcessorServiceImpl(new JavaInterfaceProcessorRegistryImpl()));
+
+ /**
+ * Verifies a single constructor is chosen with a parameter as the type
+ */
+ public void testSingleConstructorWithParam() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ JavaMappedProperty<String> prop = new JavaMappedProperty<String>();
+ prop.setName("foo");
+ prop.setJavaType(String.class);
+ type.getProperties().put("foo", prop);
+ processor.visitEnd(Foo1.class, type, null);
+ assertNotNull(type.getConstructorDefinition().getConstructor());
+ assertEquals("foo", type.getConstructorDefinition().getInjectionNames().get(0));
+ }
+
+ /**
+ * Verifies a single constructor is chosen with a reference as the type
+ */
+ public void testSingleConstructorWithRef() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ JavaMappedReference ref = new JavaMappedReference();
+ ref.setUri(URI.create("#foo"));
+ ServiceContract contract = new JavaServiceContract(String.class);
+ ref.setServiceContract(contract);
+ type.getReferences().put("foo", ref);
+ processor.visitEnd(Foo1.class, type, null);
+ assertNotNull(type.getConstructorDefinition().getConstructor());
+ assertEquals("foo", type.getConstructorDefinition().getInjectionNames().get(0));
+ }
+
+ /**
+ * Verifies a single constructor is chosen with a property and a reference as the type
+ */
+ public void testSingleConstructorWithPropRef() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+
+ JavaMappedProperty<String> prop = new JavaMappedProperty<String>();
+ prop.setName("foo");
+ prop.setJavaType(String.class);
+ type.getProperties().put("foo", prop);
+
+ JavaMappedReference ref = new JavaMappedReference();
+ ref.setUri(URI.create("#ref"));
+ ServiceContract contract = new JavaServiceContract(Foo1.class);
+ ref.setServiceContract(contract);
+ type.getReferences().put("ref", ref);
+ processor.visitEnd(Foo2.class, type, null);
+ assertNotNull(type.getConstructorDefinition().getConstructor());
+ assertEquals(2, type.getConstructorDefinition().getInjectionNames().size());
+ }
+
+
+ public void testSingleConstructorResolvableParam() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ processor.visitEnd(Foo5.class, type, null);
+ assertEquals(String.class, type.getProperties().get("string").getJavaType());
+ }
+
+ public void testSingleConstructorResolvableRef() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ processor.visitEnd(Foo6.class, type, null);
+ assertEquals(Ref.class,
+ type.getReferences().get("heuristicconstructortestcase$ref").getServiceContract().getInterfaceClass());
+ }
+
+ public void testSingleConstructorAmbiguousRef() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ JavaMappedReference ref = new JavaMappedReference();
+ ref.setUri(URI.create("#ref"));
+ ServiceContract contract = new JavaServiceContract(Foo1.class);
+ ref.setServiceContract(contract);
+ type.getReferences().put("ref", ref);
+ JavaMappedReference ref2 = new JavaMappedReference();
+ ref2.setUri(URI.create("#ref2"));
+ ref2.setServiceContract(contract);
+ type.getReferences().put("ref2", ref2);
+ try {
+ processor.visitEnd(Foo4.class, type, null);
+ fail();
+ } catch (AmbiguousConstructorException e) {
+ // expected
+ }
+ }
+
+ public void testConstructorPropertyAnnotatedParamsOnly() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ processor.visitEnd(Foo7.class, type, null);
+ assertNotNull(type.getProperties().get("myProp"));
+ }
+
+ public void testConstructorReferenceAnnotatedParamsOnly() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ processor.visitEnd(Foo8.class, type, null);
+ assertNotNull(type.getReferences().get("myRef"));
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testDefaultConstructor() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ processor.visitEnd(Foo3.class, type, null);
+ assertNotNull(type.getConstructorDefinition().getConstructor());
+ }
+
+ public void testSameTypesButAnnotated() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ processor.visitEnd(Foo12.class, type, null);
+ assertEquals(2, type.getProperties().size());
+ assertNotNull(type.getProperties().get("prop1"));
+ assertNotNull(type.getProperties().get("prop2"));
+ }
+
+ /**
+ * Verifies processing executes with additional extension annotations
+ */
+ public void testRandomAnnotation() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ processor.visitEnd(Foo11.class, type, null);
+ assertEquals(1, type.getProperties().size());
+ assertNotNull(type.getProperties().get("prop1"));
+ }
+
+ public void testPrivateConstructor() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ try {
+ processor.visitEnd(Foo14.class, type, null);
+ fail();
+ } catch (NoConstructorException e) {
+ // expected
+ }
+ }
+
+
+ public void testMultipleConstructors() throws Exception {
+ // throw new UnsupportedOperationException("Finish heuristic multiple constructors - Foo10");
+ }
+
+
+ public static class Foo1 {
+ public Foo1(String val) {
+ }
+ }
+
+ public static class Foo2 {
+ public Foo2(String val, Foo1 ref) {
+ }
+ }
+
+ public static class Foo3 {
+ }
+
+ public static class Foo4 {
+ public Foo4(Foo1 ref) {
+ }
+ }
+
+ public static class Prop {
+
+ }
+
+ @Remotable
+ public static interface Ref {
+
+ }
+
+ public static class Foo5 {
+ public Foo5(String val) {
+ }
+ }
+
+ public static class Foo6 {
+ public Foo6(Ref ref) {
+ }
+ }
+
+ public static class Foo7 {
+ public Foo7(@Property(name = "myProp")String prop) {
+ }
+ }
+
+
+ public static class Foo8 {
+ public Foo8(@Reference(name = "myRef")String ref) {
+ }
+ }
+
+ public static class Foo9 {
+ public Foo9(@Reference(name = "myRef")String ref) {
+ }
+ }
+
+ public static class Foo10 {
+
+ public Foo10() {
+ }
+
+ public Foo10(String prop) {
+ }
+
+ public Foo10(@Property(name = "prop1")String prop1, @Property(name = "prop2")String prop2) {
+
+ }
+ }
+
+ public static class Foo11 {
+
+ public Foo11(@Property(name = "prop1")String prop, @Baz String baz) {
+ }
+ }
+
+ public static class Foo12 {
+
+ public Foo12(@Property(name = "prop1")String prop, @Property(name = "prop2")String baz) {
+ }
+ }
+
+ public @interface Baz {
+
+ }
+
+ public static class Foo13 {
+ public Foo13(@Reference String foo) {
+ }
+ }
+
+ public static final class Foo14 {
+ private Foo14() {
+ }
+ }
+
+ public static final class Foo15 {
+ public Foo15(@Reference String param1, @Reference String param2) {
+ }
+ }
+
+ public static final class Foo16 {
+ public Foo16(@Reference String param1,
+ @Property(name = "foo")String param2,
+ @Reference(name = "bar")String param3) {
+ }
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicPojoProcessorTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicPojoProcessorTestCase.java
new file mode 100644
index 0000000000..9863960c1e
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicPojoProcessorTestCase.java
@@ -0,0 +1,396 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.processor;
+
+import java.lang.reflect.Constructor;
+import java.net.URI;
+import java.util.Collection;
+import java.util.List;
+
+import org.osoa.sca.annotations.Property;
+import org.osoa.sca.annotations.Reference;
+import org.osoa.sca.annotations.Remotable;
+import org.osoa.sca.annotations.Service;
+
+import org.apache.tuscany.spi.databinding.extension.SimpleTypeMapperExtension;
+import org.apache.tuscany.spi.implementation.java.ConstructorDefinition;
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.implementation.java.ProcessingException;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
+
+/**
+ * Verfies component type information is properly introspected from an unadorned POJO according to the SCA Java Client
+ * and Implementation Model Specification
+ *
+ * @version $Rev$ $Date$
+ */
+public class HeuristicPojoProcessorTestCase extends TestCase {
+
+ private HeuristicPojoProcessor processor =
+ new HeuristicPojoProcessor(new ImplementationProcessorServiceImpl(new JavaInterfaceProcessorRegistryImpl()));
+
+ /**
+ * Verifies a single service interface is computed when only one interface is implemented
+ */
+ public void testSingleInterface() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<SingleInterfaceImpl> ctor = SingleInterfaceImpl.class.getConstructor();
+ type.setConstructorDefinition(new ConstructorDefinition<SingleInterfaceImpl>(ctor));
+ processor.visitEnd(SingleInterfaceImpl.class, type, null);
+ assertEquals(1, type.getServices().size());
+ assertEquals(PropertyInterface.class,
+ type.getServices().get(PropertyInterface.class.getSimpleName())
+ .getServiceContract().getInterfaceClass());
+ assertTrue(type.getProperties().isEmpty());
+ assertTrue(type.getReferences().isEmpty());
+ }
+
+ /**
+ * Verifies property and reference setters are computed
+ */
+ public void testPropertyReference() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<SingleInterfaceWithPropertyReferenceImpl> ctor =
+ SingleInterfaceWithPropertyReferenceImpl.class.getConstructor();
+ type.setConstructorDefinition(new ConstructorDefinition<SingleInterfaceWithPropertyReferenceImpl>(ctor));
+ processor.visitEnd(SingleInterfaceWithPropertyReferenceImpl.class, type, null);
+ assertEquals(1, type.getServices().size());
+ assertEquals(Interface1.class,
+ type.getServices().get(Interface1.class.getSimpleName())
+ .getServiceContract().getInterfaceClass());
+ assertEquals(1, type.getProperties().size());
+ assertEquals(ComplexProperty.class, type.getProperties().get("property").getJavaType());
+ assertEquals(1, type.getReferences().size());
+ assertEquals(Ref.class, type.getReferences().get("reference").getServiceContract().getInterfaceClass());
+ }
+
+ /**
+ * Verifies that a property setter is not introspected if an analogous operation is in the service interface
+ */
+ public void testPropertySetterInInterface() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<SingleInterfaceImpl> ctor = SingleInterfaceImpl.class.getConstructor();
+ type.setConstructorDefinition(new ConstructorDefinition<SingleInterfaceImpl>(ctor));
+ processor.visitEnd(SingleInterfaceImpl.class, type, null);
+ assertEquals(0, type.getProperties().size());
+ }
+
+ /**
+ * Verifies that a reference setter is not introspected if an analogous operation is in the service interface
+ */
+ public void testReferenceSetterInInterface() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<RefInterfaceImpl> ctor = RefInterfaceImpl.class.getConstructor();
+ type.setConstructorDefinition(new ConstructorDefinition<RefInterfaceImpl>(ctor));
+ processor.visitEnd(RefInterfaceImpl.class, type, null);
+ assertEquals(0, type.getReferences().size());
+ }
+
+ /**
+ * Verifies collection generic types or array types are introspected as references according to spec rules
+ */
+ public void testReferenceCollectionType() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<ReferenceCollectionImpl> ctor = ReferenceCollectionImpl.class.getConstructor();
+ type.setConstructorDefinition(new ConstructorDefinition<ReferenceCollectionImpl>(ctor));
+ processor.visitEnd(ReferenceCollectionImpl.class, type, null);
+ assertEquals(0, type.getProperties().size());
+ assertEquals(4, type.getReferences().size());
+ }
+
+ /**
+ * Verifies collection generic types or array types are introspected as properties according to spec rules
+ */
+ public void testPropertyCollectionType() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<PropertyCollectionImpl> ctor = PropertyCollectionImpl.class.getConstructor();
+ type.setConstructorDefinition(new ConstructorDefinition<PropertyCollectionImpl>(ctor));
+ processor.visitEnd(PropertyCollectionImpl.class, type, null);
+ assertEquals(0, type.getReferences().size());
+ assertEquals(4, type.getProperties().size());
+ }
+
+ /**
+ * Verifies references are calculated when the type marked with is @Remotable
+ */
+ public void testRemotableRef() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<RemotableRefImpl> ctor = RemotableRefImpl.class.getConstructor();
+ type.setConstructorDefinition(new ConstructorDefinition<RemotableRefImpl>(ctor));
+ processor.visitEnd(RemotableRefImpl.class, type, null);
+ assertEquals(2, type.getReferences().size());
+ assertEquals(0, type.getProperties().size());
+ }
+
+ public void testParentInterface() throws ProcessingException, NoSuchMethodException {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<Child> ctor = Child.class.getConstructor();
+ type.setConstructorDefinition(new ConstructorDefinition<Child>(ctor));
+ processor.visitEnd(Child.class, type, null);
+ assertTrue(type.getServices().containsKey(Interface1.class.getSimpleName()));
+ }
+
+ /**
+ * Verifies a service inteface is calculated when only props and refs are given
+ */
+ public void testExcludedPropertyAndReference() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ JavaMappedReference ref = new JavaMappedReference();
+ ref.setUri(URI.create("#reference"));
+ type.add(ref);
+ JavaMappedReference ref2 = new JavaMappedReference();
+ ref2.setUri(URI.create("#reference2"));
+ type.add(ref2);
+ JavaMappedProperty<?> prop1 = new JavaMappedProperty();
+ prop1.setName("string1");
+ type.add(prop1);
+ JavaMappedProperty<?> prop2 = new JavaMappedProperty();
+ prop2.setName("string2");
+ type.add(prop2);
+ processor.visitEnd(MockService.class, type, null);
+ assertEquals(1, type.getServices().size());
+ }
+
+ public void testProtectedRemotableRefField() throws ProcessingException, NoSuchMethodException {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<ProtectedRemotableRefFieldImpl> ctor = ProtectedRemotableRefFieldImpl.class.getConstructor();
+ type.setConstructorDefinition(new ConstructorDefinition<ProtectedRemotableRefFieldImpl>(ctor));
+ processor.visitEnd(ProtectedRemotableRefFieldImpl.class, type, null);
+ assertNotNull(type.getReferences().get("otherRef"));
+ }
+
+ public void testProtectedRemotableRefMethod() throws ProcessingException, NoSuchMethodException {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<ProtectedRemotableRefMethodImpl> ctor = ProtectedRemotableRefMethodImpl.class.getConstructor();
+ type.setConstructorDefinition(new ConstructorDefinition<ProtectedRemotableRefMethodImpl>(ctor));
+ processor.visitEnd(ProtectedRemotableRefMethodImpl.class, type, null);
+ assertNotNull(type.getReferences().get("otherRef"));
+ }
+
+ public void testSetDataTypes() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<PropertyIntTypeOnConstructor> ctor = PropertyIntTypeOnConstructor.class.getConstructor(int.class);
+ type.setConstructorDefinition(new ConstructorDefinition<PropertyIntTypeOnConstructor>(ctor));
+ processor.visitEnd(ProtectedRemotableRefMethodImpl.class, type, null);
+ org.apache.tuscany.spi.model.Property<?> foo = type.getProperties().get("foo");
+ assertEquals(int.class, foo.getJavaType());
+ assertEquals(SimpleTypeMapperExtension.XSD_INT, foo.getXmlType());
+ }
+
+ private static class PropertyIntTypeOnConstructor {
+ private int foo;
+
+ public PropertyIntTypeOnConstructor(@Property(name = "foo")int foo) {
+ this.foo = foo;
+ }
+
+ public int getFoo() {
+ return foo;
+ }
+ }
+
+ private interface PropertyInterface {
+ void setString1(String val);
+ }
+
+ private interface Interface1 {
+ }
+
+ private static class Parent implements Interface1 {
+
+ }
+
+ private static class Child extends Parent {
+ public Child() {
+ }
+
+ }
+
+ private static class SingleInterfaceImpl implements PropertyInterface {
+ public SingleInterfaceImpl() {
+ }
+
+ public void setString1(String val) {
+ }
+
+ }
+
+ private interface HeuristicServiceInterface {
+ void fooOperation(String ref);
+
+ void setInvalid1(); // No parameter
+
+ void setInvalid2(String str, int i); // More than one parameter
+
+ String setInvalid3(String str); // return should be void
+ }
+
+ public static class MockService implements PropertyInterface, RefInterface, HeuristicServiceInterface {
+
+ @Property
+ public void setString1(String val) {
+ }
+
+ @Property
+ public void setString2(String val) {
+ }
+
+ @Reference
+ public void setReference(Ref ref) {
+ }
+
+ @Reference
+ public void setReference2(Ref ref) {
+ }
+
+ public void fooOperation(String ref) {
+
+ }
+
+ public void setInvalid1() {
+ }
+
+ public void setInvalid2(String str, int i) {
+ }
+
+ public String setInvalid3(String str) {
+ return null;
+ }
+
+ }
+
+ @Service
+ private interface Ref {
+ }
+
+ private class ComplexProperty {
+ }
+
+ private interface RefInterface {
+ void setReference(Ref ref);
+ }
+
+ private static class RefInterfaceImpl implements RefInterface {
+ public RefInterfaceImpl() {
+ }
+
+ public void setReference(Ref ref) {
+ }
+ }
+
+ private static class SingleInterfaceWithPropertyReferenceImpl implements Interface1 {
+ public SingleInterfaceWithPropertyReferenceImpl() {
+ }
+
+ public void setReference(Ref ref) {
+ }
+
+ public void setProperty(ComplexProperty prop) {
+ }
+ }
+
+ private static class ReferenceCollectionImpl implements Interface1 {
+ public ReferenceCollectionImpl() {
+ }
+
+ public void setCollectionReference(Collection<Ref> ref) {
+ }
+
+ public void setNonGenericCollectionReference(Collection ref) {
+ }
+
+ public void setListReference(List<Ref> ref) {
+ }
+
+ public void setArrayReference(Ref[] ref) {
+ }
+ }
+
+ private static class PropertyCollectionImpl implements Interface1 {
+ public PropertyCollectionImpl() {
+ }
+
+ public void setCollectionProperty(Collection<ComplexProperty> prop) {
+ }
+
+ public void setCollectionProperty2(Collection<String> prop) {
+ }
+
+ public void setArrayProperty(ComplexProperty[] prop) {
+ }
+
+ public void setArrayProperty2(String[] prop) {
+ }
+ }
+
+ @Remotable
+ private interface RemotableRef {
+ }
+
+ private static class RemotableRefImpl implements Interface1 {
+ protected RemotableRef otherRef;
+
+ public RemotableRefImpl() {
+ }
+
+ public void setRef(RemotableRef ref) {
+
+ }
+ }
+
+ private static class ProtectedRemotableRefFieldImpl implements Interface1 {
+ protected RemotableRef otherRef;
+
+ public ProtectedRemotableRefFieldImpl() {
+ }
+
+ public ProtectedRemotableRefFieldImpl(RemotableRef otherRef) {
+ this.otherRef = otherRef;
+ }
+
+ }
+
+ private static class ProtectedRemotableRefMethodImpl implements Interface1 {
+ public ProtectedRemotableRefMethodImpl() {
+ }
+
+ protected void setOtherRef(RemotableRef otherRef) {
+ }
+
+ }
+
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeutisticExtensibleConstructorTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeutisticExtensibleConstructorTestCase.java
new file mode 100644
index 0000000000..ed2fea8c41
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeutisticExtensibleConstructorTestCase.java
@@ -0,0 +1,129 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.processor;
+
+import java.lang.reflect.Constructor;
+import java.util.List;
+
+import org.apache.tuscany.spi.implementation.java.ConstructorDefinition;
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
+
+/**
+ * Verifies constructors that have extensible annotation types, i.e. that have parameters marked by annotations which
+ * are themselves processed by some other implementation processor
+ *
+ * @version $Rev$ $Date$
+ */
+public class HeutisticExtensibleConstructorTestCase extends TestCase {
+
+ private HeuristicPojoProcessor processor =
+ new HeuristicPojoProcessor(new ImplementationProcessorServiceImpl(new JavaInterfaceProcessorRegistryImpl()));
+
+ /**
+ * Verifies heuristic processing can be called priot to an extension annotation processors being called.
+ */
+ public void testBarAnnotationProcessedFirst() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<Foo> ctor = Foo.class.getConstructor(String.class, String.class);
+ ConstructorDefinition<Foo> definition = new ConstructorDefinition<Foo>(ctor);
+ type.setConstructorDefinition(definition);
+ JavaMappedProperty property = new JavaMappedProperty();
+ property.setName("myBar");
+ definition.getInjectionNames().add("myBar");
+ type.getProperties().put("myBar", property);
+ processor.visitEnd(Foo.class, type, null);
+ assertEquals(2, type.getProperties().size());
+ }
+
+ /**
+ * Verifies heuristic processing can be called before an extension annotation processors is called.
+ * <p/>
+ * For example, given:
+ * <pre> Foo(@Bar String prop, @org.osoa.sca.annotations.Property(name = "foo") String prop2)</pre>
+ * <p/>
+ * Heuristic evaluation of @Property can occur prior to another implementation processor evaluating @Bar
+ *
+ * @throws Exception
+ */
+ public void testBarAnnotationProcessedLast() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ processor.visitEnd(Foo.class, type, null);
+
+ // now simulate process the bar impl
+ ConstructorDefinition<?> definition = type.getConstructorDefinition();
+ List<String> injectionNames = definition.getInjectionNames();
+ injectionNames.remove(0);
+ injectionNames.add(0, "mybar");
+ type.getProperties().put("mybar", new JavaMappedProperty<String>());
+
+ assertEquals(2, type.getProperties().size());
+ assertEquals("foo", definition.getInjectionNames().get(1));
+ }
+
+ /**
+ * Verifies heuristic processing can be called before an extension annotation processors is called with the
+ * extension parameter in a middle position. Specifically, verifies that the heuristic processor updates injection
+ * names and preserves their ordering.
+ */
+ public void testBarAnnotationProcessedFirstInMiddle() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<Foo2> ctor = Foo2.class.getConstructor(String.class, String.class, String.class);
+ ConstructorDefinition<Foo2> definition = new ConstructorDefinition<Foo2>(ctor);
+ type.setConstructorDefinition(definition);
+ // insert placeholder for first param, which would be done by a processor
+ definition.getInjectionNames().add("");
+ JavaMappedProperty property = new JavaMappedProperty();
+ property.setName("myBar");
+ definition.getInjectionNames().add("myBar");
+ type.getProperties().put("myBar", property);
+ processor.visitEnd(Foo2.class, type, null);
+ assertEquals("baz", definition.getInjectionNames().get(0));
+ assertEquals(2, type.getProperties().size());
+ assertEquals(1, type.getReferences().size());
+ }
+
+ public @interface Bar {
+
+ }
+
+ public static class Foo {
+ public Foo(@Bar String prop, @org.osoa.sca.annotations.Property(name = "foo") String prop2) {
+ }
+ }
+
+ public static class Foo2 {
+ public Foo2(@org.osoa.sca.annotations.Reference(name = "baz") String prop1,
+ @Bar String prop2,
+ @org.osoa.sca.annotations.Property(name = "foo") String prop3) {
+ }
+ }
+
+
+}
+
+
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/ImplementationProcessorServiceTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/ImplementationProcessorServiceTestCase.java
new file mode 100644
index 0000000000..9f340ccd11
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/ImplementationProcessorServiceTestCase.java
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.processor;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Constructor;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.osoa.sca.annotations.Callback;
+import org.osoa.sca.annotations.Conversational;
+import org.osoa.sca.annotations.Property;
+import org.osoa.sca.annotations.Remotable;
+
+import org.apache.tuscany.spi.databinding.extension.SimpleTypeMapperExtension;
+import org.apache.tuscany.spi.implementation.java.ImplementationProcessorService;
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.model.ServiceContract;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ImplementationProcessorServiceTestCase extends TestCase {
+
+ private ImplementationProcessorService implService =
+ new ImplementationProcessorServiceImpl(new JavaInterfaceProcessorRegistryImpl());
+
+ public void testCreateConversationalService() throws Exception {
+ JavaMappedService service = implService.createService(Foo.class);
+ assertTrue(Foo.class.equals(service.getServiceContract().getInterfaceClass()));
+ assertTrue(service.isRemotable());
+ assertTrue(service.getServiceContract().isConversational());
+ ServiceContract serviceContract = service.getServiceContract();
+ assertTrue(Bar.class.equals(serviceContract.getCallbackClass()));
+ assertTrue("ImplementationProcessorServiceTestCase$Bar".equals(serviceContract.getCallbackName()));
+ }
+
+ public void testCreateDefaultService() throws Exception {
+ JavaMappedService service = implService.createService(Baz.class);
+ assertTrue(Baz.class.equals(service.getServiceContract().getInterfaceClass()));
+ assertTrue(!service.isRemotable());
+ assertFalse(service.getServiceContract().isConversational());
+ }
+
+ public void testProcessParamProperty() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<PropertyClass> ctor = PropertyClass.class.getConstructor(int.class);
+ Annotation[] paramAnnotations = ctor.getParameterAnnotations()[0];
+ List<String> injectionNames = new ArrayList<String>();
+ String[] names = new String[]{"foo"};
+ implService.processParam(int.class,
+ ctor.getGenericParameterTypes()[0],
+ paramAnnotations,
+ names,
+ 0,
+ type,
+ injectionNames);
+ org.apache.tuscany.spi.model.Property<?> property = type.getProperties().get("foo");
+ assertEquals(int.class, property.getJavaType());
+ assertEquals(SimpleTypeMapperExtension.XSD_INT, property.getXmlType());
+ }
+
+
+ @Conversational
+ @Callback(Bar.class)
+ @Remotable
+ public interface Foo {
+
+ }
+
+ public interface Bar {
+
+ }
+
+ public interface Baz {
+
+ }
+
+ public static class PropertyClass {
+ private int foo;
+
+ public PropertyClass(@Property(name = "foo")int foo) {
+ this.foo = foo;
+ }
+
+ public int getFoo() {
+ return foo;
+ }
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/ImplementationProcessorServiceUniqueTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/ImplementationProcessorServiceUniqueTestCase.java
new file mode 100644
index 0000000000..da45ed2d46
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/ImplementationProcessorServiceUniqueTestCase.java
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.processor;
+
+import org.apache.tuscany.spi.implementation.java.ImplementationProcessorService;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ImplementationProcessorServiceUniqueTestCase extends TestCase {
+
+ private ImplementationProcessorService service =
+ new ImplementationProcessorServiceImpl(new JavaInterfaceProcessorRegistryImpl());
+
+ public void testUniquess1() throws Exception {
+ Class[] classes = new Class[2];
+ classes[0] = String.class;
+ classes[1] = Integer.class;
+ assertTrue(service.areUnique(classes));
+ }
+
+ public void testUniquess2() throws Exception {
+ Class[] classes = new Class[2];
+ classes[0] = String.class;
+ classes[1] = String.class;
+ assertFalse(service.areUnique(classes));
+ }
+
+ public void testUniquess3() throws Exception {
+ Class[] classes = new Class[1];
+ classes[0] = String.class;
+ assertTrue(service.areUnique(classes));
+ }
+
+ public void testUniquess4() throws Exception {
+ Class[] classes = new Class[3];
+ classes[0] = String.class;
+ classes[1] = Integer.class;
+ classes[2] = String.class;
+ assertFalse(service.areUnique(classes));
+ }
+
+ public void testUniquess5() throws Exception {
+ Class[] classes = new Class[0];
+ assertTrue(service.areUnique(classes));
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/InitProcessorTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/InitProcessorTestCase.java
new file mode 100644
index 0000000000..ee3a0d83d1
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/InitProcessorTestCase.java
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.processor;
+
+import java.lang.reflect.Method;
+
+import org.osoa.sca.annotations.Init;
+
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class InitProcessorTestCase extends TestCase {
+
+ public void testInit() throws Exception {
+ InitProcessor processor = new InitProcessor();
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Method method = InitProcessorTestCase.Foo.class.getMethod("init");
+ processor.visitMethod(method, type, null);
+ assertNotNull(type.getInitMethod());
+ assertEquals(0, type.getInitLevel());
+ }
+
+ public void testBadInit() throws Exception {
+ InitProcessor processor = new InitProcessor();
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Method method = InitProcessorTestCase.Bar.class.getMethod("badInit", String.class);
+ try {
+ processor.visitMethod(method, type, null);
+ fail();
+ } catch (IllegalInitException e) {
+ // expected
+ }
+ }
+
+ public void testTwoInit() throws Exception {
+ InitProcessor processor = new InitProcessor();
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Method method = InitProcessorTestCase.Bar.class.getMethod("init");
+ Method method2 = InitProcessorTestCase.Bar.class.getMethod("init2");
+ processor.visitMethod(method, type, null);
+ try {
+ processor.visitMethod(method2, type, null);
+ fail();
+ } catch (DuplicateInitException e) {
+ // expected
+ }
+ }
+
+
+ private class Foo {
+ @Init
+ public void init() {
+ }
+ }
+
+
+ private class Bar {
+ @Init
+ public void init() {
+ }
+
+ @Init
+ public void init2() {
+ }
+
+ @Init
+ public void badInit(String foo) {
+ }
+
+
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/MonitorProcessorTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/MonitorProcessorTestCase.java
new file mode 100644
index 0000000000..c3683399ca
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/MonitorProcessorTestCase.java
@@ -0,0 +1,180 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.processor;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.Map;
+
+import org.apache.tuscany.spi.implementation.java.ConstructorDefinition;
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.implementation.java.IllegalPropertyException;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.api.annotation.Monitor;
+import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
+import org.apache.tuscany.core.injection.SingletonObjectFactory;
+import org.apache.tuscany.host.MonitorFactory;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class MonitorProcessorTestCase extends TestCase {
+
+ private MonitorProcessor processor;
+ private MonitorFactory monitorFactory;
+
+ public void testSetter() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Method method = Foo.class.getMethod("setMonitor", Foo.class);
+ EasyMock.expect(monitorFactory.getMonitor(EasyMock.eq(Foo.class))).andReturn(null);
+ EasyMock.replay(monitorFactory);
+ processor.visitMethod(method, type, null);
+ Map<String, JavaMappedProperty<?>> properties = type.getProperties();
+ assertTrue(properties.get("monitor").getDefaultValueFactory() instanceof SingletonObjectFactory);
+ EasyMock.verify(monitorFactory);
+ }
+
+
+ public void testBadSetter() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Method method = BadMonitor.class.getMethod("setMonitor");
+ try {
+ processor.visitMethod(method, type, null);
+ fail();
+ } catch (IllegalPropertyException e) {
+ // expected
+ }
+ }
+
+ public void testField() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Field field = Foo.class.getDeclaredField("bar");
+ EasyMock.expect(monitorFactory.getMonitor(EasyMock.eq(Foo.class))).andReturn(null);
+ EasyMock.replay(monitorFactory);
+ processor.visitField(field, type, null);
+ Map<String, JavaMappedProperty<?>> properties = type.getProperties();
+ assertTrue(properties.get("bar").getDefaultValueFactory() instanceof SingletonObjectFactory);
+ EasyMock.verify(monitorFactory);
+ }
+
+ public void testConstructor() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<Bar> ctor = Bar.class.getConstructor(BazMonitor.class);
+ EasyMock.expect(monitorFactory.getMonitor(EasyMock.eq(BazMonitor.class))).andReturn(null);
+ EasyMock.replay(monitorFactory);
+ processor.visitConstructor(ctor, type, null);
+ Map<String, JavaMappedProperty<?>> properties = type.getProperties();
+ assertTrue(
+ properties.get(BazMonitor.class.getName()).getDefaultValueFactory() instanceof SingletonObjectFactory);
+ EasyMock.verify(monitorFactory);
+ }
+
+ /**
+ * Verifies calling the monitor processor to evaluate a constructor can be done after a property parameter is
+ * processed
+ */
+ public void testConstructorAfterProperty() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<Bar> ctor = Bar.class.getConstructor(String.class, BazMonitor.class);
+ EasyMock.expect(monitorFactory.getMonitor(EasyMock.eq(BazMonitor.class))).andReturn(null);
+ EasyMock.replay(monitorFactory);
+ ConstructorDefinition<Bar> definition = new ConstructorDefinition<Bar>(ctor);
+ JavaMappedProperty prop = new JavaMappedProperty();
+ definition.getInjectionNames().add("prop");
+ type.setConstructorDefinition(definition);
+ type.getProperties().put("prop", prop);
+ processor.visitConstructor(ctor, type, null);
+ Map<String, JavaMappedProperty<?>> properties = type.getProperties();
+ assertEquals(BazMonitor.class.getName(), definition.getInjectionNames().get(1));
+ assertEquals(2, type.getProperties().size());
+ String name = BazMonitor.class.getName();
+ assertTrue(properties.get(name).getDefaultValueFactory() instanceof SingletonObjectFactory);
+ EasyMock.verify(monitorFactory);
+ }
+
+ /**
+ * Verifies calling the monitor processor to evaluate a constructor can be done before a property parameter is
+ * processed
+ */
+ public void testConstructorBeforeProperty() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<Bar> ctor = Bar.class.getConstructor(String.class, BazMonitor.class);
+ EasyMock.expect(monitorFactory.getMonitor(EasyMock.eq(BazMonitor.class))).andReturn(null);
+ EasyMock.replay(monitorFactory);
+ processor.visitConstructor(ctor, type, null);
+ Map<String, JavaMappedProperty<?>> properties = type.getProperties();
+ ConstructorDefinition definition = type.getConstructorDefinition();
+ assertEquals(2, definition.getInjectionNames().size());
+ assertEquals(BazMonitor.class.getName(), definition.getInjectionNames().get(1));
+ String name = BazMonitor.class.getName();
+ assertTrue(properties.get(name).getDefaultValueFactory() instanceof SingletonObjectFactory);
+ EasyMock.verify(monitorFactory);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ monitorFactory = EasyMock.createMock(MonitorFactory.class);
+ JavaInterfaceProcessorRegistryImpl registry = new JavaInterfaceProcessorRegistryImpl();
+ ImplementationProcessorServiceImpl processor = new ImplementationProcessorServiceImpl(registry);
+ this.processor = new MonitorProcessor(monitorFactory, processor);
+ }
+
+ private class Foo {
+
+ @Monitor
+ protected Foo bar;
+
+ @Monitor
+ public void setMonitor(Foo foo) {
+ }
+ }
+
+
+ private class BadMonitor {
+
+ @Monitor
+ public void setMonitor() {
+ }
+ }
+
+ private interface BazMonitor {
+
+ }
+
+ private static class Bar {
+
+ public Bar(@Monitor BazMonitor monitor) {
+ }
+
+ public Bar(String prop, @Monitor BazMonitor monitor) {
+ }
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/PropertyProcessorTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/PropertyProcessorTestCase.java
new file mode 100644
index 0000000000..b91a33f6f0
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/PropertyProcessorTestCase.java
@@ -0,0 +1,208 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.processor;
+
+import java.util.Collection;
+import java.util.List;
+
+import org.osoa.sca.annotations.Property;
+
+import org.apache.tuscany.spi.implementation.java.DuplicatePropertyException;
+import org.apache.tuscany.spi.implementation.java.IllegalPropertyException;
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class PropertyProcessorTestCase extends TestCase {
+
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type;
+ PropertyProcessor processor;
+
+ public void testMethodAnnotation() throws Exception {
+ processor.visitMethod(Foo.class.getMethod("setFoo", String.class), type, null);
+ assertNotNull(type.getProperties().get("foo"));
+ }
+
+ public void testMethodRequired() throws Exception {
+ processor.visitMethod(Foo.class.getMethod("setFooRequired", String.class), type, null);
+ JavaMappedProperty prop = type.getProperties().get("fooRequired");
+ assertNotNull(prop);
+ assertTrue(prop.isRequired());
+ }
+
+ public void testMethodName() throws Exception {
+ processor.visitMethod(Foo.class.getMethod("setBarMethod", String.class), type, null);
+ assertNotNull(type.getProperties().get("bar"));
+ }
+
+ public void testFieldAnnotation() throws Exception {
+ processor.visitField(Foo.class.getDeclaredField("baz"), type, null);
+ assertNotNull(type.getProperties().get("baz"));
+ }
+
+ public void testFieldRequired() throws Exception {
+ processor.visitField(Foo.class.getDeclaredField("bazRequired"), type, null);
+ JavaMappedProperty prop = type.getProperties().get("bazRequired");
+ assertNotNull(prop);
+ assertTrue(prop.isRequired());
+ }
+
+ public void testFieldName() throws Exception {
+ processor.visitField(Foo.class.getDeclaredField("bazField"), type, null);
+ assertNotNull(type.getProperties().get("theBaz"));
+ }
+
+ public void testDuplicateFields() throws Exception {
+ processor.visitField(Bar.class.getDeclaredField("dup"), type, null);
+ try {
+ processor.visitField(Bar.class.getDeclaredField("baz"), type, null);
+ fail();
+ } catch (DuplicatePropertyException e) {
+ // expected
+ }
+ }
+
+ public void testDuplicateMethods() throws Exception {
+ processor.visitMethod(Bar.class.getMethod("dupMethod", String.class), type, null);
+ try {
+ processor.visitMethod(Bar.class.getMethod("dupSomeMethod", String.class), type, null);
+ fail();
+ } catch (DuplicatePropertyException e) {
+ // expected
+ }
+ }
+
+ public void testInvalidProperty() throws Exception {
+ try {
+ processor.visitMethod(Bar.class.getMethod("badMethod"), type, null);
+ fail();
+ } catch (IllegalPropertyException e) {
+ // expected
+ }
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ type = new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ JavaInterfaceProcessorRegistryImpl registry = new JavaInterfaceProcessorRegistryImpl();
+ processor = new PropertyProcessor(new ImplementationProcessorServiceImpl(registry));
+ }
+
+ private class Foo {
+
+ @Property
+ protected String baz;
+ @Property(required = true)
+ protected String bazRequired;
+ @Property(name = "theBaz")
+ protected String bazField;
+
+ @Property
+ public void setFoo(String string) {
+ }
+
+ @Property(required = true)
+ public void setFooRequired(String string) {
+ }
+
+ @Property(name = "bar")
+ public void setBarMethod(String string) {
+ }
+
+ }
+
+ private class Bar {
+
+ @Property
+ protected String dup;
+
+ @Property(name = "dup")
+ protected String baz;
+
+ @Property
+ public void dupMethod(String s) {
+ }
+
+ @Property(name = "dupMethod")
+ public void dupSomeMethod(String s) {
+ }
+
+ @Property
+ public void badMethod() {
+ }
+
+ }
+
+ private class Multiple {
+ @Property
+ protected List<String> refs1;
+
+ @Property
+ protected String[] refs2;
+
+ @Property
+ public void setRefs3(String[] refs) {
+ }
+
+ @Property
+ public void setRefs4(Collection<String> refs) {
+ }
+
+ }
+
+ public void testMultiplicityCollection() throws Exception {
+ processor.visitField(Multiple.class.getDeclaredField("refs1"), type, null);
+ JavaMappedProperty prop = type.getProperties().get("refs1");
+ assertNotNull(prop);
+ assertSame(String.class, prop.getJavaType());
+ assertTrue(prop.isMany());
+ }
+
+ public void testMultiplicityArray() throws Exception {
+ processor.visitField(Multiple.class.getDeclaredField("refs2"), type, null);
+ JavaMappedProperty prop = type.getProperties().get("refs2");
+ assertNotNull(prop);
+ assertSame(String.class, prop.getJavaType());
+ assertTrue(prop.isMany());
+ }
+
+ public void testMultiplicityArrayMethod() throws Exception {
+ processor.visitMethod(Multiple.class.getMethod("setRefs3", String[].class), type, null);
+ JavaMappedProperty prop = type.getProperties().get("refs3");
+ assertNotNull(prop);
+ assertSame(String.class, prop.getJavaType());
+ assertTrue(prop.isMany());
+ }
+
+ public void testMultiplicityCollectionMethod() throws Exception {
+ processor.visitMethod(Multiple.class.getMethod("setRefs4", Collection.class), type, null);
+ JavaMappedProperty prop = type.getProperties().get("refs4");
+ assertNotNull(prop);
+ assertSame(String.class, prop.getJavaType());
+ assertTrue(prop.isMany());
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/ReferenceProcessorTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/ReferenceProcessorTestCase.java
new file mode 100644
index 0000000000..7ee40f3eb2
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/ReferenceProcessorTestCase.java
@@ -0,0 +1,232 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.processor;
+
+import java.util.Collection;
+import java.util.List;
+
+import org.osoa.sca.annotations.Reference;
+
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.model.Multiplicity;
+import org.apache.tuscany.spi.model.ServiceContract;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ReferenceProcessorTestCase extends TestCase {
+
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ ReferenceProcessor processor = new ReferenceProcessor(new JavaInterfaceProcessorRegistryImpl());
+
+ public void testMethodAnnotation() throws Exception {
+ processor.visitMethod(ReferenceProcessorTestCase.Foo.class.getMethod("setFoo", Ref.class), type, null);
+ JavaMappedReference reference = type.getReferences().get("foo");
+ assertNotNull(reference);
+ ServiceContract contract = reference.getServiceContract();
+ assertEquals(Ref.class, contract.getInterfaceClass());
+ assertEquals("ReferenceProcessorTestCase$Ref", contract.getInterfaceName());
+ }
+
+ public void testMethodRequired() throws Exception {
+ processor.visitMethod(
+ ReferenceProcessorTestCase.Foo.class.getMethod("setFooRequired", Ref.class),
+ type,
+ null);
+ JavaMappedReference prop = type.getReferences().get("fooRequired");
+ assertNotNull(prop);
+ assertTrue(prop.isRequired());
+ }
+
+ public void testMethodName() throws Exception {
+ processor.visitMethod(
+ ReferenceProcessorTestCase.Foo.class.getMethod("setBarMethod", Ref.class),
+ type,
+ null);
+ assertNotNull(type.getReferences().get("bar"));
+ }
+
+ public void testFieldAnnotation() throws Exception {
+ processor.visitField(ReferenceProcessorTestCase.Foo.class.getDeclaredField("baz"), type, null);
+ JavaMappedReference reference = type.getReferences().get("baz");
+ assertNotNull(reference);
+ ServiceContract contract = reference.getServiceContract();
+ assertEquals(Ref.class, contract.getInterfaceClass());
+ assertEquals("ReferenceProcessorTestCase$Ref", contract.getInterfaceName());
+ }
+
+ public void testFieldRequired() throws Exception {
+ processor.visitField(ReferenceProcessorTestCase.Foo.class.getDeclaredField("bazRequired"), type, null);
+ JavaMappedReference prop = type.getReferences().get("bazRequired");
+ assertNotNull(prop);
+ assertTrue(prop.isRequired());
+ }
+
+ public void testFieldName() throws Exception {
+ processor.visitField(ReferenceProcessorTestCase.Foo.class.getDeclaredField("bazField"), type, null);
+ assertNotNull(type.getReferences().get("theBaz"));
+ }
+
+ public void testDuplicateFields() throws Exception {
+ processor.visitField(ReferenceProcessorTestCase.Bar.class.getDeclaredField("dup"), type, null);
+ try {
+ processor.visitField(ReferenceProcessorTestCase.Bar.class.getDeclaredField("baz"), type, null);
+ fail();
+ } catch (DuplicateReferenceException e) {
+ // expected
+ }
+ }
+
+ public void testDuplicateMethods() throws Exception {
+ processor.visitMethod(ReferenceProcessorTestCase.Bar.class.getMethod("dupMethod", Ref.class), type, null);
+ try {
+ processor.visitMethod(
+ ReferenceProcessorTestCase.Bar.class.getMethod("dupSomeMethod", Ref.class),
+ type,
+ null);
+ fail();
+ } catch (DuplicateReferenceException e) {
+ // expected
+ }
+ }
+
+ public void testInvalidProperty() throws Exception {
+ try {
+ processor.visitMethod(ReferenceProcessorTestCase.Bar.class.getMethod("badMethod"), type, null);
+ fail();
+ } catch (IllegalReferenceException e) {
+ // expected
+ }
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ type = new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ processor = new ReferenceProcessor(new JavaInterfaceProcessorRegistryImpl());
+ }
+
+ private interface Ref {
+ }
+
+ private class Foo {
+
+ @Reference
+ protected Ref baz;
+ @Reference(required = true)
+ protected Ref bazRequired;
+ @Reference(name = "theBaz")
+ protected Ref bazField;
+
+ @Reference
+ public void setFoo(Ref ref) {
+ }
+
+ @Reference(required = true)
+ public void setFooRequired(Ref ref) {
+ }
+
+ @Reference(name = "bar")
+ public void setBarMethod(Ref ref) {
+ }
+
+ }
+
+ private class Bar {
+
+ @Reference
+ protected Ref dup;
+
+ @Reference(name = "dup")
+ protected Ref baz;
+
+ @Reference
+ public void dupMethod(Ref s) {
+ }
+
+ @Reference(name = "dupMethod")
+ public void dupSomeMethod(Ref s) {
+ }
+
+ @Reference
+ public void badMethod() {
+ }
+
+ }
+
+ private class Multiple {
+ @Reference(required = true)
+ protected List<Ref> refs1;
+
+ @Reference(required = false)
+ protected Ref[] refs2;
+
+ @Reference(required = true)
+ public void setRefs3(Ref[] refs) {
+ }
+
+ @Reference(required = false)
+ public void setRefs4(Collection<Ref> refs) {
+ }
+
+ }
+
+ public void testMultiplicity1ToN() throws Exception {
+ processor.visitField(Multiple.class.getDeclaredField("refs1"), type, null);
+ JavaMappedReference prop = type.getReferences().get("refs1");
+ assertNotNull(prop);
+ assertSame(Ref.class, prop.getServiceContract().getInterfaceClass());
+ assertEquals(Multiplicity.ONE_N, prop.getMultiplicity());
+ assertTrue(prop.isRequired());
+ }
+
+ public void testMultiplicityTo0ToN() throws Exception {
+ processor.visitField(Multiple.class.getDeclaredField("refs2"), type, null);
+ JavaMappedReference prop = type.getReferences().get("refs2");
+ assertNotNull(prop);
+ assertSame(Ref.class, prop.getServiceContract().getInterfaceClass());
+ assertEquals(Multiplicity.ZERO_N, prop.getMultiplicity());
+ assertFalse(prop.isRequired());
+ }
+
+ public void testMultiplicity1ToNMethod() throws Exception {
+ processor.visitMethod(Multiple.class.getMethod("setRefs3", Ref[].class), type, null);
+ JavaMappedReference prop = type.getReferences().get("refs3");
+ assertNotNull(prop);
+ assertSame(Ref.class, prop.getServiceContract().getInterfaceClass());
+ assertEquals(Multiplicity.ONE_N, prop.getMultiplicity());
+ assertTrue(prop.isRequired());
+ }
+
+ public void testMultiplicity0ToNMethod() throws Exception {
+ processor.visitMethod(Multiple.class.getMethod("setRefs4", Collection.class), type, null);
+ JavaMappedReference prop = type.getReferences().get("refs4");
+ assertNotNull(prop);
+ assertSame(Ref.class, prop.getServiceContract().getInterfaceClass());
+ assertEquals(Multiplicity.ZERO_N, prop.getMultiplicity());
+ assertFalse(prop.isRequired());
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/ResourceProcessorTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/ResourceProcessorTestCase.java
new file mode 100644
index 0000000000..25c1a14be6
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/ResourceProcessorTestCase.java
@@ -0,0 +1,117 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.processor;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.implementation.java.Resource;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ResourceProcessorTestCase extends TestCase {
+
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type;
+ ResourceProcessor processor = new ResourceProcessor();
+
+ public void testVisitField() throws Exception {
+ Field field = Foo.class.getDeclaredField("bar");
+ processor.visitField(field, type, null);
+ Resource resource = type.getResources().get("bar");
+ assertFalse(resource.isOptional());
+ assertNull(resource.getMappedName());
+ assertEquals(field.getType(), resource.getType());
+ }
+
+ public void testVisitMethod() throws Exception {
+ Method method = Foo.class.getMethod("setBar", Bar.class);
+ processor.visitMethod(method, type, null);
+ Resource resource = type.getResources().get("bar");
+ assertFalse(resource.isOptional());
+ assertNull(resource.getMappedName());
+ assertEquals(method.getParameterTypes()[0], resource.getType());
+ }
+
+ public void testVisitNamedMethod() throws Exception {
+ Method method = Foo.class.getMethod("setBar2", Bar.class);
+ processor.visitMethod(method, type, null);
+ Resource resource = type.getResources().get("someName");
+ assertFalse(resource.isOptional());
+ assertEquals("mapped", resource.getMappedName());
+ }
+
+ public void testVisitBadMethod() throws Exception {
+ Method method = Foo.class.getMethod("setBad");
+ try {
+ processor.visitMethod(method, type, null);
+ fail();
+ } catch (IllegalResourceException e) {
+ // expected
+ }
+ }
+
+ public void testDuplicateResources() throws Exception {
+ Field field = Foo.class.getDeclaredField("bar");
+ processor.visitField(field, type, null);
+ try {
+ processor.visitField(field, type, null);
+ fail();
+ } catch (DuplicateResourceException e) {
+ //expected
+ }
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ type = new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ }
+
+ private class Foo {
+
+ @org.apache.tuscany.api.annotation.Resource
+ protected Bar bar;
+
+ @org.apache.tuscany.api.annotation.Resource(optional = true)
+ protected Bar barNotRequired;
+
+ @org.apache.tuscany.api.annotation.Resource
+ public void setBar(Bar bar) {
+ }
+
+ @org.apache.tuscany.api.annotation.Resource(name = "someName", mappedName = "mapped")
+ public void setBar2(Bar bar) {
+ }
+
+ @org.apache.tuscany.api.annotation.Resource
+ public void setBad() {
+ }
+
+ }
+
+ private interface Bar {
+
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/ScopeProcessorTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/ScopeProcessorTestCase.java
new file mode 100644
index 0000000000..f8fa73b0f5
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/ScopeProcessorTestCase.java
@@ -0,0 +1,128 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.processor;
+
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.implementation.java.ProcessingException;
+import org.apache.tuscany.spi.model.Scope;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ScopeProcessorTestCase extends TestCase {
+
+ Component parent;
+
+ public void testCompositeScope() throws ProcessingException {
+ ScopeProcessor processor = new ScopeProcessor();
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+
+ processor.visitClass(Composite.class, type, null);
+ assertEquals(Scope.COMPOSITE, type.getImplementationScope());
+ }
+
+ public void testSessionScope() throws ProcessingException {
+ ScopeProcessor processor = new ScopeProcessor();
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ processor.visitClass(Session.class, type, null);
+ assertEquals(Scope.SESSION, type.getImplementationScope());
+ }
+
+ public void testConversationalScope() throws ProcessingException {
+ ScopeProcessor processor = new ScopeProcessor();
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ processor.visitClass(Conversation.class, type, null);
+ assertEquals(Scope.CONVERSATION, type.getImplementationScope());
+ }
+
+ public void testRequestScope() throws ProcessingException {
+ ScopeProcessor processor = new ScopeProcessor();
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ processor.visitClass(Request.class, type, null);
+ assertEquals(Scope.REQUEST, type.getImplementationScope());
+ }
+
+ public void testSystemScope() throws ProcessingException {
+ ScopeProcessor processor = new ScopeProcessor();
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ processor.visitClass(System.class, type, null);
+ assertEquals(Scope.SYSTEM, type.getImplementationScope());
+ }
+
+ public void testStatelessScope() throws ProcessingException {
+ ScopeProcessor processor = new ScopeProcessor();
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ processor.visitClass(Stateless.class, type, null);
+ assertEquals(Scope.STATELESS, type.getImplementationScope());
+ }
+
+ public void testNoScope() throws ProcessingException {
+ ScopeProcessor processor = new ScopeProcessor();
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ processor.visitClass(None.class, type, null);
+ assertEquals(Scope.STATELESS, type.getImplementationScope());
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ parent = EasyMock.createNiceMock(Component.class);
+ }
+
+ @org.osoa.sca.annotations.Scope("COMPOSITE")
+ private class Composite {
+ }
+
+ @org.osoa.sca.annotations.Scope("SESSION")
+ private class Session {
+ }
+
+ @org.osoa.sca.annotations.Scope("CONVERSATION")
+ private class Conversation {
+ }
+
+ @org.osoa.sca.annotations.Scope("REQUEST")
+ private class Request {
+ }
+
+ @org.osoa.sca.annotations.Scope("SYSTEM")
+ private class System {
+ }
+
+ @org.osoa.sca.annotations.Scope("STATELESS")
+ private class Stateless {
+ }
+
+ private class None {
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/ServiceCallbackTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/ServiceCallbackTestCase.java
new file mode 100644
index 0000000000..b198bd730b
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/ServiceCallbackTestCase.java
@@ -0,0 +1,166 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.processor;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import org.osoa.sca.annotations.Callback;
+import org.osoa.sca.annotations.Service;
+
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.implementation.java.ProcessingException;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
+import org.apache.tuscany.core.idl.java.IllegalCallbackException;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ServiceCallbackTestCase extends TestCase {
+
+ ServiceProcessor processor =
+ new ServiceProcessor(new ImplementationProcessorServiceImpl(new JavaInterfaceProcessorRegistryImpl()));
+
+ public void testMethodCallbackInterface() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ processor.visitClass(FooImpl.class, type, null);
+ JavaMappedService service = type.getServices().get(Foo.class.getSimpleName());
+ assertNotNull(service);
+ Method method = FooImpl.class.getMethod("setCallback", FooCallback.class);
+ processor.visitMethod(method, type, null);
+ assertEquals(method, service.getCallbackMember());
+ }
+
+ public void testFieldCallbackInterface() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ processor.visitClass(FooImpl.class, type, null);
+ JavaMappedService service = type.getServices().get(Foo.class.getSimpleName());
+ assertNotNull(service);
+ Field field = FooImpl.class.getDeclaredField("callback");
+ processor.visitField(field, type, null);
+ assertEquals(field, service.getCallbackMember());
+ }
+
+ public void testMethodDoesNotMatchCallback() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ processor.visitClass(BadBarImpl.class, type, null);
+ Method method = BadBarImpl.class.getMethod("setWrongInterfaceCallback", String.class);
+ try {
+ processor.visitMethod(method, type, null);
+ fail();
+ } catch (IllegalCallbackReferenceException e) {
+ // expected
+ }
+ }
+
+ public void testNoParamCallback() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ processor.visitClass(BadBarImpl.class, type, null);
+ Method method = BadBarImpl.class.getMethod("setNoParamCallback");
+ try {
+ processor.visitMethod(method, type, null);
+ fail();
+ } catch (IllegalCallbackReferenceException e) {
+ // expected
+ }
+ }
+
+ public void testFieldDoesNotMatchCallback() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ processor.visitClass(BadBarImpl.class, type, null);
+ Field field = BadBarImpl.class.getDeclaredField("wrongInterfaceCallback");
+ try {
+ processor.visitField(field, type, null);
+ fail();
+ } catch (IllegalCallbackReferenceException e) {
+ // expected
+ }
+ }
+
+ public void testBadCallbackInterfaceAnnotation() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ try {
+ processor.visitClass(BadFooImpl.class, type, null);
+ fail();
+ } catch (ProcessingException e) {
+ // expected
+ assertTrue(e.getCause() instanceof IllegalCallbackException);
+ }
+ }
+
+ @Callback(FooCallback.class)
+ private interface Foo {
+
+ }
+
+ private interface FooCallback {
+
+ }
+
+ @Service(Foo.class)
+ private static class FooImpl implements Foo {
+
+ @Callback
+ protected FooCallback callback;
+
+ @Callback
+ public void setCallback(FooCallback cb) {
+
+ }
+ }
+
+ private static class BadBarImpl implements Foo {
+ @Callback
+ protected String wrongInterfaceCallback;
+
+ @Callback
+ public void setWrongInterfaceCallback(String cb) {
+
+ }
+
+ @Callback
+ public void setNoParamCallback() {
+
+ }
+
+ }
+
+ @Callback
+ private interface BadFoo {
+
+ }
+
+ @Service(BadFoo.class)
+ private static class BadFooImpl implements BadFoo {
+
+ }
+
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/ServiceProcessorTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/ServiceProcessorTestCase.java
new file mode 100644
index 0000000000..3d3ce498c9
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/processor/ServiceProcessorTestCase.java
@@ -0,0 +1,151 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.processor;
+
+import org.osoa.sca.annotations.Callback;
+import org.osoa.sca.annotations.Remotable;
+import org.osoa.sca.annotations.Service;
+
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.model.ServiceContract;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ServiceProcessorTestCase extends TestCase {
+ private ServiceProcessor processor;
+ private PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type;
+
+ public void testMultipleInterfaces() throws Exception {
+ processor.visitClass(FooMultiple.class, type, null);
+ assertEquals(2, type.getServices().size());
+ JavaMappedService service = type.getServices().get(Baz.class.getSimpleName());
+ ServiceContract contract = service.getServiceContract();
+ assertEquals(Baz.class, contract.getInterfaceClass());
+ assertEquals(Bar.class, contract.getCallbackClass());
+ assertEquals("ServiceProcessorTestCase$Bar", contract.getCallbackName());
+ assertNotNull(type.getServices().get(Bar.class.getSimpleName()));
+ }
+
+ public void testSingleInterfaces() throws Exception {
+ processor.visitClass(FooSingle.class, type, null);
+ assertEquals(1, type.getServices().size());
+ assertNotNull(type.getServices().get(Baz.class.getSimpleName()));
+ }
+
+ public void testMultipleNoService() throws Exception {
+ processor.visitClass(FooMultipleNoService.class, type, null);
+ assertEquals(0, type.getServices().size());
+ }
+
+ /**
+ * Verifies a service with a callback annotation is recognized
+ */
+ public void testMultipleWithCallbackAnnotation() throws Exception {
+ processor.visitClass(FooMultipleWithCalback.class, type, null);
+ assertEquals(1, type.getServices().size());
+ }
+
+ public void testRemotableNoService() throws Exception {
+ processor.visitClass(FooRemotableNoService.class, type, null);
+ assertEquals(1, type.getServices().size());
+ JavaMappedService service = type.getServices().get(BazRemotable.class.getSimpleName());
+ ServiceContract contract = service.getServiceContract();
+ assertEquals(BazRemotable.class, contract.getInterfaceClass());
+ }
+
+ public void testNonInterface() throws Exception {
+ try {
+ processor.visitClass(BadImpl.class, type, null);
+ fail();
+ } catch (InvalidServiceType e) {
+ //expected
+ }
+ }
+
+ public void testNoInterfaces() throws Exception {
+ try {
+ processor.visitClass(BadDefinition.class, type, null);
+ fail();
+ } catch (IllegalServiceDefinitionException e) {
+ //expected
+ }
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ JavaInterfaceProcessorRegistryImpl registry = new JavaInterfaceProcessorRegistryImpl();
+ processor = new ServiceProcessor(new ImplementationProcessorServiceImpl(registry));
+ type = new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ }
+
+ @Callback(Bar.class)
+ private interface Baz {
+ }
+
+ private interface Bar {
+ }
+
+ private interface Bar2 {
+ }
+
+ @Remotable
+ private interface BazRemotable {
+ }
+
+ @Service(interfaces = {Baz.class, Bar.class})
+ private class FooMultiple implements Baz, Bar {
+
+ }
+
+ @Service(Baz.class)
+ private class FooSingle implements Baz, Bar {
+
+ }
+
+ private class FooMultipleNoService implements Bar, Bar2 {
+
+ }
+
+ private class FooMultipleWithCalback implements Baz, Bar {
+
+ }
+
+ private class FooRemotableNoService implements BazRemotable, Bar {
+
+ }
+
+ @Service(FooSingle.class)
+ private class BadImpl extends FooSingle {
+
+ }
+
+
+ @Service()
+ private class BadDefinition extends FooSingle {
+
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/system/builder/SystemComponentBuilderResourceTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/system/builder/SystemComponentBuilderResourceTestCase.java
new file mode 100644
index 0000000000..8cfbc2c627
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/system/builder/SystemComponentBuilderResourceTestCase.java
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.system.builder;
+
+import java.lang.reflect.Field;
+import java.net.URI;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.ScopeRegistry;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.host.ResourceHost;
+import org.apache.tuscany.spi.implementation.java.ConstructorDefinition;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.implementation.java.Resource;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.Property;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+import org.apache.tuscany.spi.wire.Wire;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.implementation.system.model.SystemImplementation;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class SystemComponentBuilderResourceTestCase extends TestCase {
+
+ @SuppressWarnings("unchecked")
+ public void testResourceInjection() throws Exception {
+ ScopeContainer container = EasyMock.createNiceMock(ScopeContainer.class);
+ DeploymentContext ctx = EasyMock.createNiceMock(DeploymentContext.class);
+ ScopeRegistry registry = EasyMock.createMock(ScopeRegistry.class);
+ EasyMock.expect(registry.getScopeContainer(Scope.STATELESS)).andReturn(container);
+ EasyMock.replay(registry);
+ ResourceHost host = EasyMock.createMock(ResourceHost.class);
+ EasyMock.expect(host.resolveResource(EasyMock.eq(String.class))).andReturn("result");
+ EasyMock.replay(host);
+ SystemComponentBuilder builder = new SystemComponentBuilder();
+ builder.setScopeRegistry(registry);
+ builder.setHost(host);
+ ConstructorDefinition<Foo> ctorDef = new ConstructorDefinition<SystemComponentBuilderResourceTestCase.Foo>(
+ SystemComponentBuilderResourceTestCase.Foo.class.getConstructor());
+ PojoComponentType<ServiceDefinition, ReferenceDefinition, Property<?>> type =
+ new PojoComponentType<ServiceDefinition, ReferenceDefinition, Property<?>>();
+ Field member = Foo.class.getDeclaredField("resource");
+ Resource<String> resource = new Resource<String>("resource", String.class, member);
+ type.add(resource);
+ type.setImplementationScope(Scope.STATELESS);
+ type.setConstructorDefinition(ctorDef);
+ SystemImplementation impl = new SystemImplementation();
+ impl.setImplementationClass(SystemComponentBuilderResourceTestCase.Foo.class);
+ impl.setComponentType(type);
+ ComponentDefinition<SystemImplementation> definition =
+ new ComponentDefinition<SystemImplementation>(URI.create("foo"), impl);
+
+ Wire wire = EasyMock.createMock(Wire.class);
+ EasyMock.expect(wire.getTargetInstance()).andReturn("result");
+ EasyMock.replay(wire);
+
+ AtomicComponent component = builder.build(definition, ctx);
+ SystemComponentBuilderResourceTestCase.Foo foo =
+ (SystemComponentBuilderResourceTestCase.Foo) component.createInstance();
+ assertEquals("result", foo.resource);
+ }
+
+ private static class Foo {
+
+ protected String resource;
+
+ public Foo() {
+ }
+
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/system/component/SystemAtomicComponentTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/system/component/SystemAtomicComponentTestCase.java
new file mode 100644
index 0000000000..02fac67c2c
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/system/component/SystemAtomicComponentTestCase.java
@@ -0,0 +1,127 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.system.component;
+
+import java.net.URI;
+
+import org.apache.tuscany.spi.wire.Wire;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.implementation.PojoConfiguration;
+import org.apache.tuscany.core.injection.EventInvoker;
+import org.apache.tuscany.core.injection.MethodEventInvoker;
+import org.apache.tuscany.core.injection.PojoObjectFactory;
+import org.apache.tuscany.core.injection.SingletonObjectFactory;
+import org.easymock.EasyMock;
+
+/**
+ * Verifies a system atomic component can be started and initialized
+ *
+ * @version $$Rev$$ $$Date$$
+ */
+public class SystemAtomicComponentTestCase extends TestCase {
+
+ private EventInvoker<Object> initInvoker;
+ private EventInvoker<Object> destroyInvoker;
+
+ public void testDefaultCreationAndInit() throws Exception {
+ PojoObjectFactory<Foo> factory = new PojoObjectFactory<Foo>(Foo.class.getConstructor((Class[]) null));
+ PojoConfiguration configuration = new PojoConfiguration();
+ configuration.setInstanceFactory(factory);
+ configuration.setInitInvoker(initInvoker);
+ configuration.setName(new URI("foo"));
+ SystemAtomicComponentImpl component = new SystemAtomicComponentImpl(configuration);
+ Foo foo = (Foo) component.createInstance();
+ component.init(foo);
+ assertTrue(foo.initialized);
+ }
+
+ public void testDestroy() throws Exception {
+ PojoObjectFactory<Foo> factory = new PojoObjectFactory<Foo>(Foo.class.getConstructor((Class[]) null));
+ PojoConfiguration configuration = new PojoConfiguration();
+ configuration.setInstanceFactory(factory);
+ configuration.setDestroyInvoker(destroyInvoker);
+ configuration.setName(new URI("foo"));
+ SystemAtomicComponentImpl component = new SystemAtomicComponentImpl(configuration);
+ Foo foo = (Foo) component.createInstance();
+ component.destroy(foo);
+ assertTrue(foo.destroyed);
+ }
+
+ public void testReferenceAndPropertyConstructor() throws Exception {
+ PojoObjectFactory<Bar> factory = new PojoObjectFactory<Bar>(Bar.class.getConstructor(String.class, Foo.class));
+ PojoConfiguration configuration = new PojoConfiguration();
+ configuration.setInstanceFactory(factory);
+ configuration.setInitInvoker(initInvoker);
+ configuration.addConstructorParamName("foo");
+ configuration.addConstructorParamType(String.class);
+ configuration.addConstructorParamName("ref");
+ configuration.addConstructorParamType(Foo.class);
+ configuration.setName(new URI("foo"));
+ SystemAtomicComponentImpl component = new SystemAtomicComponentImpl(configuration);
+ component.addPropertyFactory("foo", new SingletonObjectFactory<String>("baz"));
+ Foo target = new Foo();
+ Wire wire = EasyMock.createMock(Wire.class);
+ EasyMock.expect(wire.getTargetInstance()).andReturn(target);
+ URI uri = URI.create("#ref");
+ EasyMock.expect(wire.getSourceUri()).andReturn(uri).anyTimes();
+ EasyMock.replay(wire);
+ component.attachWire(wire);
+ Bar bar = (Bar) component.createInstance();
+ assertEquals("baz", bar.foo);
+ assertEquals(target, bar.ref);
+ EasyMock.verify(wire);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ initInvoker = new MethodEventInvoker<Object>(Foo.class.getMethod("init"));
+ destroyInvoker = new MethodEventInvoker<Object>(Foo.class.getMethod("destroy"));
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ public static class Foo {
+ private boolean initialized;
+ private boolean destroyed;
+
+ public void init() {
+ initialized = true;
+ }
+
+ public void destroy() {
+ destroyed = true;
+ }
+ }
+
+ public static class Bar {
+
+ private String foo;
+ private Foo ref;
+
+ public Bar(String foo, Foo ref) {
+ this.foo = foo;
+ this.ref = ref;
+ }
+ }
+
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/system/component/SystemAtomicComponentWireInvocationTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/system/component/SystemAtomicComponentWireInvocationTestCase.java
new file mode 100644
index 0000000000..23685aaa9e
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/system/component/SystemAtomicComponentWireInvocationTestCase.java
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.system.component;
+
+import java.net.URI;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.wire.Wire;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.component.scope.CompositeScopeContainer;
+import org.apache.tuscany.core.implementation.PojoConfiguration;
+import org.apache.tuscany.core.injection.PojoObjectFactory;
+import org.apache.tuscany.core.mock.component.Source;
+import org.apache.tuscany.core.mock.component.SourceImpl;
+import org.apache.tuscany.core.mock.component.Target;
+import org.apache.tuscany.core.mock.component.TargetImpl;
+import org.easymock.EasyMock;
+
+/**
+ * Tests reference wires are injected properly into system component instances
+ *
+ * @version $$Rev$$ $$Date$$
+ */
+public class SystemAtomicComponentWireInvocationTestCase extends TestCase {
+
+ public void testWireResolution() throws Exception {
+ CompositeScopeContainer scope = new CompositeScopeContainer(null);
+ scope.start();
+ Target target = new TargetImpl();
+ PojoConfiguration configuration = new PojoConfiguration();
+ configuration.addReferenceSite("setTarget", SourceImpl.class.getMethod("setTarget", Target.class));
+ configuration.setInstanceFactory(new PojoObjectFactory<SourceImpl>(SourceImpl.class.getConstructor()));
+ configuration.setName(new URI("source"));
+ AtomicComponent component = new SystemAtomicComponentImpl(configuration);
+ component.setScopeContainer(scope);
+ Wire wire = EasyMock.createMock(Wire.class);
+ URI uri = URI.create("#setTarget");
+ EasyMock.expect(wire.getSourceUri()).andReturn(uri).atLeastOnce();
+ EasyMock.expect(wire.getTargetInstance()).andReturn(target);
+ EasyMock.replay(wire);
+ component.attachWire(wire);
+ component.start();
+ assertSame(((Source) component.getTargetInstance()).getTarget(), target);
+ EasyMock.verify(wire);
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/system/loader/SystemComponentTypeLoaderTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/system/loader/SystemComponentTypeLoaderTestCase.java
new file mode 100644
index 0000000000..9a3272cf2e
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/system/loader/SystemComponentTypeLoaderTestCase.java
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.system.loader;
+
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.implementation.java.ImplementationProcessorService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.implementation.java.ProcessingException;
+import org.apache.tuscany.spi.model.Property;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
+import org.apache.tuscany.core.implementation.IntrospectionRegistryImpl;
+import org.apache.tuscany.core.implementation.processor.ConstructorProcessor;
+import org.apache.tuscany.core.implementation.processor.DestroyProcessor;
+import org.apache.tuscany.core.implementation.processor.HeuristicPojoProcessor;
+import org.apache.tuscany.core.implementation.processor.ImplementationProcessorServiceImpl;
+import org.apache.tuscany.core.implementation.processor.InitProcessor;
+import org.apache.tuscany.core.implementation.processor.PropertyProcessor;
+import org.apache.tuscany.core.implementation.processor.ReferenceProcessor;
+import org.apache.tuscany.core.implementation.processor.ScopeProcessor;
+import org.apache.tuscany.core.implementation.processor.ServiceProcessor;
+import org.apache.tuscany.core.implementation.system.model.SystemImplementation;
+import org.apache.tuscany.core.mock.component.BasicInterface;
+import org.apache.tuscany.core.mock.component.BasicInterfaceImpl;
+import org.apache.tuscany.core.monitor.NullMonitorFactory;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class SystemComponentTypeLoaderTestCase extends TestCase {
+ private SystemComponentTypeLoader loader;
+
+ public void testIntrospectUnannotatedClass() throws ProcessingException {
+ Component parent = EasyMock.createNiceMock(Component.class);
+ SystemImplementation impl = new SystemImplementation(BasicInterfaceImpl.class);
+ PojoComponentType<?, ?, ?> componentType = loader.loadByIntrospection(impl, null);
+ ServiceDefinition service = componentType.getServices().get(BasicInterface.class.getSimpleName());
+ assertEquals(BasicInterface.class, service.getServiceContract().getInterfaceClass());
+ Property<?> property = componentType.getProperties().get("publicProperty");
+ assertEquals(String.class, property.getJavaType());
+ ReferenceDefinition referenceDefinition = componentType.getReferences().get("protectedReference");
+ assertEquals(BasicInterface.class, referenceDefinition.getServiceContract().getInterfaceClass());
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ JavaInterfaceProcessorRegistryImpl interfaceProcessorRegistry = new JavaInterfaceProcessorRegistryImpl();
+ ImplementationProcessorService service =
+ new ImplementationProcessorServiceImpl(interfaceProcessorRegistry);
+ IntrospectionRegistryImpl registry = new IntrospectionRegistryImpl();
+ registry.setMonitor(new NullMonitorFactory().getMonitor(IntrospectionRegistryImpl.Monitor.class));
+ registry.registerProcessor(new ConstructorProcessor(service));
+ registry.registerProcessor(new DestroyProcessor());
+ registry.registerProcessor(new InitProcessor());
+ registry.registerProcessor(new ScopeProcessor());
+ registry.registerProcessor(new PropertyProcessor(service));
+ registry.registerProcessor(new ReferenceProcessor(interfaceProcessorRegistry));
+ registry.registerProcessor(new ServiceProcessor(service));
+ registry.registerProcessor(new HeuristicPojoProcessor(service));
+ loader = new SystemComponentTypeLoader(registry);
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/system/loader/SystemImplementationLoaderTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/system/loader/SystemImplementationLoaderTestCase.java
new file mode 100644
index 0000000000..3dce59e42a
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/implementation/system/loader/SystemImplementationLoaderTestCase.java
@@ -0,0 +1,106 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.system.loader;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.Location;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.loader.UnrecognizedElementException;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.implementation.system.model.SystemImplementation;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class SystemImplementationLoaderTestCase extends TestCase {
+
+ public static final QName SYSTEM_IMPLEMENTATION =
+ new QName("http://tuscany.apache.org/xmlns/sca/system/2.0-alpha", "implementation.system");
+
+ public void testLoad() throws Exception {
+ LoaderRegistry registry = EasyMock.createNiceMock(LoaderRegistry.class);
+ EasyMock.replay(registry);
+ DeploymentContext context = EasyMock.createMock(DeploymentContext.class);
+ EasyMock.expect(context.getClassLoader()).andReturn(getClass().getClassLoader());
+ EasyMock.replay(context);
+ XMLStreamReader reader = EasyMock.createMock(XMLStreamReader.class);
+ EasyMock.expect(reader.getName()).andReturn(SYSTEM_IMPLEMENTATION);
+ EasyMock.expect(reader.getAttributeValue((String) EasyMock.isNull(), EasyMock.eq("class")))
+ .andReturn(getClass().getName());
+ EasyMock.expect(reader.next()).andReturn(XMLStreamConstants.END_ELEMENT);
+ EasyMock.replay(reader);
+ SystemImplementationLoader loader = new SystemImplementationLoader(registry);
+ SystemImplementation impl = loader.load(null, reader, context);
+ assertEquals(getClass(), impl.getImplementationClass());
+ EasyMock.verify(reader);
+ EasyMock.verify(context);
+ }
+
+ public void testUnrecognizedElement() throws Exception {
+ LoaderRegistry registry = EasyMock.createNiceMock(LoaderRegistry.class);
+ EasyMock.replay(registry);
+ DeploymentContext context = EasyMock.createMock(DeploymentContext.class);
+ EasyMock.expect(context.getClassLoader()).andReturn(getClass().getClassLoader());
+ EasyMock.replay(context);
+ XMLStreamReader reader = EasyMock.createMock(XMLStreamReader.class);
+ EasyMock.expect(reader.getName()).andReturn(SYSTEM_IMPLEMENTATION).atLeastOnce();
+ EasyMock.expect(reader.getAttributeValue((String) EasyMock.isNull(), EasyMock.eq("class")))
+ .andReturn(getClass().getName());
+ EasyMock.expect(reader.next()).andReturn(XMLStreamConstants.START_ELEMENT);
+ EasyMock.expect(reader.getLocation()).andReturn(new MockLocation());
+ EasyMock.replay(reader);
+ SystemImplementationLoader loader = new SystemImplementationLoader(registry);
+ try {
+ loader.load(null, reader, context);
+ fail();
+ } catch (UnrecognizedElementException e) {
+ // expected
+ }
+ }
+
+ private class MockLocation implements Location {
+
+ public int getLineNumber() {
+ return 0;
+ }
+
+ public int getColumnNumber() {
+ return 0;
+ }
+
+ public int getCharacterOffset() {
+ return 0;
+ }
+
+ public String getPublicId() {
+ return null;
+ }
+
+ public String getSystemId() {
+ return null;
+ }
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/injection/CallbackWireObjectFactoryTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/injection/CallbackWireObjectFactoryTestCase.java
new file mode 100644
index 0000000000..9032d091a3
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/injection/CallbackWireObjectFactoryTestCase.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.injection;
+
+import java.util.List;
+import java.util.ArrayList;
+
+import org.apache.tuscany.spi.wire.Wire;
+import org.apache.tuscany.spi.wire.ProxyService;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+import static org.easymock.EasyMock.createMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class CallbackWireObjectFactoryTestCase extends TestCase {
+
+ @SuppressWarnings({"unchecked"})
+ public void testCreateInstance() throws Exception {
+ ProxyService service = createMock(ProxyService.class);
+ Foo foo = new Foo() {
+ };
+ EasyMock.expect(service.createCallbackProxy(EasyMock.eq(Foo.class), EasyMock.isA(List.class))).andReturn(foo);
+ EasyMock.replay(service);
+ List<Wire> wires = new ArrayList<Wire>();
+ CallbackWireObjectFactory factory = new CallbackWireObjectFactory(Foo.class, service, wires);
+ assertEquals(foo, factory.getInstance());
+ EasyMock.verify(service);
+ }
+
+ private interface Foo {
+
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/injection/FieldInjectorTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/injection/FieldInjectorTestCase.java
new file mode 100644
index 0000000000..d31347f7e6
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/injection/FieldInjectorTestCase.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.injection;
+
+import java.lang.reflect.Field;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class FieldInjectorTestCase extends TestCase {
+
+ protected Field protectedField;
+
+ public void testIllegalAccess() throws Exception {
+ FieldInjector<Foo> injector = new FieldInjector<Foo>(protectedField, new SingletonObjectFactory<String>("foo"));
+ Foo foo = new Foo();
+ injector.inject(foo);
+ assertEquals("foo", foo.hidden);
+ }
+
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ protectedField = Foo.class.getDeclaredField("hidden");
+ }
+
+ private class Foo {
+ private String hidden;
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/injection/JNDIObjectFactoryTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/injection/JNDIObjectFactoryTestCase.java
new file mode 100644
index 0000000000..91214fd02d
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/injection/JNDIObjectFactoryTestCase.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.injection;
+
+import javax.naming.Context;
+import javax.naming.NamingException;
+
+import org.apache.tuscany.spi.ObjectCreationException;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class JNDIObjectFactoryTestCase extends TestCase {
+
+ public void testGetInstance() throws Exception {
+ Context ctx = EasyMock.createMock(Context.class);
+ EasyMock.expect(ctx.lookup(EasyMock.eq("foo"))).andReturn(new Foo());
+ EasyMock.replay(ctx);
+ JNDIObjectFactory<Foo> factory = new JNDIObjectFactory<Foo>(ctx, "foo");
+ assertTrue(factory.getInstance() instanceof Foo); // must do an instanceof b/c of type erasure
+ EasyMock.verify(ctx);
+ }
+
+ public void testGetInstanceError() throws Exception {
+ Context ctx = EasyMock.createMock(Context.class);
+ EasyMock.expect(ctx.lookup(EasyMock.eq("foo"))).andThrow(new NamingException());
+ EasyMock.replay(ctx);
+ JNDIObjectFactory<Foo> factory = new JNDIObjectFactory<Foo>(ctx, "foo");
+ try {
+ factory.getInstance();
+ fail();
+ } catch (ObjectCreationException e) {
+ //expected
+ }
+ EasyMock.verify(ctx);
+ }
+
+
+ private class Foo {
+
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/injection/MethodEventInvokerTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/injection/MethodEventInvokerTestCase.java
new file mode 100644
index 0000000000..3bb882da2d
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/injection/MethodEventInvokerTestCase.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.injection;
+
+import java.lang.reflect.Method;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class MethodEventInvokerTestCase extends TestCase {
+ private Method privateMethod;
+ private Method exceptionMethod;
+
+ public void testIllegalAccess() throws Exception {
+ MethodEventInvoker<MethodEventInvokerTestCase.Foo> injector = new MethodEventInvoker<Foo>(privateMethod);
+ try {
+ injector.invokeEvent(new Foo());
+ fail();
+ } catch (AssertionError e) {
+ // expected
+ }
+ }
+
+ public void testException() throws Exception {
+ MethodEventInvoker<MethodEventInvokerTestCase.Foo> injector = new MethodEventInvoker<Foo>(exceptionMethod);
+ try {
+ injector.invokeEvent(new Foo());
+ fail();
+ } catch (RuntimeException e) {
+ // expected
+ }
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ privateMethod = MethodEventInvokerTestCase.Foo.class.getDeclaredMethod("hidden");
+ exceptionMethod = MethodEventInvokerTestCase.Foo.class.getDeclaredMethod("exception");
+
+ }
+
+ private class Foo {
+
+ public void foo() {
+ }
+
+ private void hidden() {
+ }
+
+ public void exception() {
+ throw new RuntimeException();
+ }
+
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/injection/MethodInjectorTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/injection/MethodInjectorTestCase.java
new file mode 100644
index 0000000000..b21ba4ccfa
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/injection/MethodInjectorTestCase.java
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.injection;
+
+import java.lang.reflect.Method;
+
+import org.apache.tuscany.spi.ObjectCreationException;
+import org.apache.tuscany.spi.ObjectFactory;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class MethodInjectorTestCase extends TestCase {
+ private Method fooMethod;
+ private Method privateMethod;
+ private Method exceptionMethod;
+
+ public void testIllegalArgument() throws Exception {
+ ObjectFactory<Object> factory = new SingletonObjectFactory<Object>(new Object());
+ MethodInjector<Foo> injector = new MethodInjector<Foo>(fooMethod, factory);
+ try {
+ injector.inject(new Foo());
+ fail();
+ } catch (ObjectCreationException e) {
+ // expected
+ }
+ }
+
+ public void testException() throws Exception {
+ ObjectFactory<Object> factory = new SingletonObjectFactory<Object>("foo");
+ MethodInjector<Foo> injector = new MethodInjector<Foo>(exceptionMethod, factory);
+ try {
+ injector.inject(new Foo());
+ fail();
+ } catch (RuntimeException e) {
+ // expected
+ }
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ fooMethod = Foo.class.getMethod("foo", String.class);
+ privateMethod = Foo.class.getDeclaredMethod("hidden", String.class);
+ exceptionMethod = Foo.class.getDeclaredMethod("exception", String.class);
+
+ }
+
+ private class Foo {
+
+ public void foo(String bar) {
+ }
+
+ private void hidden(String bar) {
+ }
+
+ public void exception(String bar) {
+ throw new RuntimeException();
+ }
+
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/injection/PojoObjectFactoryTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/injection/PojoObjectFactoryTestCase.java
new file mode 100644
index 0000000000..f68f34b22f
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/injection/PojoObjectFactoryTestCase.java
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.injection;
+
+import java.lang.reflect.Constructor;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.tuscany.spi.ObjectFactory;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class PojoObjectFactoryTestCase extends TestCase {
+
+ private Constructor<Foo> ctor;
+
+ public void testConstructorInjection() throws Exception {
+ List<ObjectFactory> initializers = new ArrayList<ObjectFactory>();
+ initializers.add(new SingletonObjectFactory<String>("foo"));
+ PojoObjectFactory<Foo> factory = new PojoObjectFactory<Foo>(ctor, initializers);
+ Foo foo = factory.getInstance();
+ assertEquals("foo", foo.foo);
+ }
+
+ /**
+ * Verifies null parameters can be passed to a constructor. This is valid when a reference is optional during
+ * constructor injection
+ */
+ public void testConstructorInjectionOptionalParam() throws Exception {
+ List<ObjectFactory> initializers = new ArrayList<ObjectFactory>();
+ initializers.add(null);
+ PojoObjectFactory<Foo> factory = new PojoObjectFactory<Foo>(ctor, initializers);
+ Foo foo = factory.getInstance();
+ assertNull(foo.foo);
+ }
+
+ public void testConstructorInitializerInjection() throws Exception {
+ PojoObjectFactory<Foo> factory = new PojoObjectFactory<Foo>(ctor);
+ factory.setInitializerFactory(0, new SingletonObjectFactory<String>("foo"));
+ Foo foo = factory.getInstance();
+ assertEquals("foo", foo.foo);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ ctor = Foo.class.getConstructor(String.class);
+ }
+
+ private static class Foo {
+
+ private String foo;
+
+ public Foo(String foo) {
+ this.foo = foo;
+ }
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/injection/RequestContextObjectFactoryTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/injection/RequestContextObjectFactoryTestCase.java
new file mode 100644
index 0000000000..a1a41bbada
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/injection/RequestContextObjectFactoryTestCase.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.injection;
+
+import org.apache.tuscany.spi.component.WorkContext;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class RequestContextObjectFactoryTestCase extends TestCase {
+
+ public void testInstanceCreate() {
+ WorkContext workContext = EasyMock.createNiceMock(WorkContext.class);
+ RequestContextObjectFactory factory = new RequestContextObjectFactory(workContext);
+ assertNotNull(factory.getInstance());
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/injection/ResourceObjectFactoryTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/injection/ResourceObjectFactoryTestCase.java
new file mode 100644
index 0000000000..cf8bbc6818
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/injection/ResourceObjectFactoryTestCase.java
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.injection;
+
+import org.apache.tuscany.spi.host.ResourceHost;
+import org.apache.tuscany.spi.wire.Wire;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ResourceObjectFactoryTestCase extends TestCase {
+
+ public void testResolveFromHostByType() throws Exception {
+ ResourceHost host = EasyMock.createMock(ResourceHost.class);
+ EasyMock.expect(host.resolveResource(EasyMock.eq(String.class))).andReturn("foo");
+ EasyMock.replay(host);
+ ResourceObjectFactory<String> factory = new ResourceObjectFactory<String>(String.class, false, host);
+ assertEquals("foo", factory.getInstance());
+ EasyMock.verify(host);
+ }
+
+ public void testResolveFromHostByName() throws Exception {
+ ResourceHost host = EasyMock.createMock(ResourceHost.class);
+ EasyMock.expect(host.resolveResource(EasyMock.eq(String.class),
+ EasyMock.eq("sca://localhost/bar"))).andReturn("foo");
+ EasyMock.replay(host);
+ ResourceObjectFactory<String> factory =
+ new ResourceObjectFactory<String>(String.class, "sca://localhost/bar", false, host);
+ assertEquals("foo", factory.getInstance());
+ EasyMock.verify(host);
+ }
+
+
+ public void testResolveFromParentThenResolveFromHostNotFound() throws Exception {
+ ResourceHost host = EasyMock.createMock(ResourceHost.class);
+ EasyMock.expect(host.resolveResource(EasyMock.eq(String.class))).andReturn(null);
+ EasyMock.replay(host);
+ ResourceObjectFactory<String> factory = new ResourceObjectFactory<String>(String.class, true, host);
+ assertNull(factory.getInstance());
+ EasyMock.verify(host);
+ }
+
+ public void testResolveByTypeNotFound() throws Exception {
+ ResourceHost host = EasyMock.createMock(ResourceHost.class);
+ EasyMock.expect(host.resolveResource(EasyMock.eq(String.class))).andReturn(null);
+ EasyMock.replay(host);
+
+ Wire wire = EasyMock.createMock(Wire.class);
+ EasyMock.expect(wire.getTargetInstance()).andReturn(null);
+ EasyMock.replay(wire);
+
+ ResourceObjectFactory<String> factory = new ResourceObjectFactory<String>(String.class, false, host);
+ try {
+ factory.getInstance();
+ fail();
+ } catch (ResourceNotFoundException e) {
+ //expected
+ }
+ EasyMock.verify(host);
+ }
+
+ public void testResolveByTypeNotFoundOptional() throws Exception {
+ ResourceHost host = EasyMock.createMock(ResourceHost.class);
+ EasyMock.expect(host.resolveResource(EasyMock.eq(String.class))).andReturn(null);
+ EasyMock.replay(host);
+ ResourceObjectFactory<String> factory = new ResourceObjectFactory<String>(String.class, true, host);
+ assertNull(factory.getInstance());
+ EasyMock.verify(host);
+ }
+
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/injection/SingletonObjectFactoryTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/injection/SingletonObjectFactoryTestCase.java
new file mode 100644
index 0000000000..876e68d5b3
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/injection/SingletonObjectFactoryTestCase.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.injection;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class SingletonObjectFactoryTestCase extends TestCase {
+
+ public void testSingleton() throws Exception {
+ Object o = new Object();
+ SingletonObjectFactory<Object> factory = new SingletonObjectFactory<Object>(o);
+ assertEquals(o, factory.getInstance());
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/integration/conversation/AbstractConversationTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/integration/conversation/AbstractConversationTestCase.java
new file mode 100644
index 0000000000..95f51c1183
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/integration/conversation/AbstractConversationTestCase.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.integration.conversation;
+
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.services.store.StoreMonitor;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.component.WorkContextImpl;
+import org.apache.tuscany.core.component.scope.ConversationalScopeContainer;
+import org.apache.tuscany.core.services.store.memory.MemoryStore;
+import org.easymock.classextension.EasyMock;
+
+/**
+ * Provides helper methods for setting up a partial runtime for conversational test cases.
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class AbstractConversationTestCase extends TestCase {
+ protected ScopeContainer container;
+ protected MemoryStore store;
+ protected WorkContext workContext;
+
+ protected void createRuntime() {
+ workContext = new WorkContextImpl();
+ store = new MemoryStore(EasyMock.createNiceMock(StoreMonitor.class));
+ container = new ConversationalScopeContainer(store, workContext, null);
+ }
+
+ protected void initializeRuntime() {
+ store.init();
+ container.start();
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/integration/conversation/ConversationIdleExpireTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/integration/conversation/ConversationIdleExpireTestCase.java
new file mode 100644
index 0000000000..b42ebf2a69
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/integration/conversation/ConversationIdleExpireTestCase.java
@@ -0,0 +1,149 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.integration.conversation;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+import java.net.URI;
+
+import org.osoa.sca.annotations.Conversational;
+import org.osoa.sca.annotations.EndsConversation;
+
+import org.apache.tuscany.spi.ObjectCreationException;
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.TargetNotFoundException;
+import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.Wire;
+
+import org.apache.tuscany.core.implementation.PojoConfiguration;
+import org.apache.tuscany.core.implementation.java.JavaAtomicComponent;
+import org.apache.tuscany.core.injection.PojoObjectFactory;
+import org.apache.tuscany.core.integration.mock.MockFactory;
+import org.apache.tuscany.core.wire.jdk.JDKInvocationHandler;
+import org.easymock.classextension.EasyMock;
+
+/**
+ * Verifies conversational resources are cleaned up if the maximum idle time is exceeded
+ *
+ * @version $Rev$ $Date$
+ */
+public class ConversationIdleExpireTestCase extends AbstractConversationTestCase {
+ protected AtomicComponent target;
+ private JDKInvocationHandler handler;
+ private FooImpl targetInstance;
+ private Method operation1;
+ private Method operation2;
+ private final Object mutex = new Object();
+
+ public void testConversationExpire() throws Throwable {
+ workContext.setIdentifier(org.apache.tuscany.spi.model.Scope.CONVERSATION, "12345A");
+ // start the conversation
+ handler.invoke(operation1, null);
+ // verify the instance was persisted
+ assertEquals(targetInstance, store.readRecord(target, "12345A"));
+ synchronized (mutex) {
+ mutex.wait(100);
+ }
+ // verify the instance was expired
+ assertNull(store.readRecord(target, "12345A"));
+ // continue the conversation - should throw an error
+ try {
+ handler.invoke(operation2, null);
+ fail();
+ } catch (TargetNotFoundException e) {
+ // expected
+ }
+ }
+
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ createRuntime();
+ store.setReaperInterval(10);
+ initializeRuntime();
+
+ targetInstance = EasyMock.createMock(FooImpl.class);
+ targetInstance.operation1();
+ targetInstance.operation2();
+ targetInstance.end();
+ EasyMock.replay(targetInstance);
+ target = createTarget();
+
+ Wire wire = MockFactory.createWire("foo", Foo.class);
+ for (InvocationChain chain : wire.getInvocationChains().values()) {
+ chain.setTargetInvoker(target.createTargetInvoker("target", chain.getOperation()));
+ }
+ handler = new JDKInvocationHandler(Foo.class, wire, workContext);
+ operation1 = Foo.class.getMethod("operation1");
+ operation2 = Foo.class.getMethod("operation2");
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ container.stop();
+ store.destroy();
+ }
+
+ private JavaAtomicComponent createTarget() throws Exception {
+ PojoConfiguration configuration = new PojoConfiguration();
+ configuration.setName(new URI("target"));
+ configuration.setMaxIdleTime(50);
+ configuration.setInstanceFactory(new MockPojoFactory(FooImpl.class.getConstructor()));
+ configuration.setImplementationClass(FooImpl.class);
+ JavaAtomicComponent component = new JavaAtomicComponent(configuration);
+ component.setScopeContainer(container);
+ component.start();
+ return component;
+ }
+
+ private class MockPojoFactory extends PojoObjectFactory<FooImpl> {
+ public MockPojoFactory(Constructor<FooImpl> ctr) {
+ super(ctr);
+ }
+
+ public FooImpl getInstance() throws ObjectCreationException {
+ return targetInstance;
+ }
+ }
+
+ @Conversational
+ public static interface Foo {
+
+ void operation1();
+
+ void operation2();
+
+ @EndsConversation
+ void end();
+
+ }
+
+ public static class FooImpl implements Foo {
+
+ public void operation1() {
+ }
+
+ public void operation2() {
+ }
+
+ @EndsConversation
+ public void end() {
+ }
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/integration/conversation/ConversationMaxAgeExpireTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/integration/conversation/ConversationMaxAgeExpireTestCase.java
new file mode 100644
index 0000000000..a237687b1b
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/integration/conversation/ConversationMaxAgeExpireTestCase.java
@@ -0,0 +1,154 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.integration.conversation;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+import java.net.URI;
+
+import org.osoa.sca.annotations.Conversational;
+import org.osoa.sca.annotations.EndsConversation;
+
+import org.apache.tuscany.spi.ObjectCreationException;
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.TargetNotFoundException;
+import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.Wire;
+
+import org.apache.tuscany.core.implementation.PojoConfiguration;
+import org.apache.tuscany.core.implementation.java.JavaAtomicComponent;
+import org.apache.tuscany.core.injection.PojoObjectFactory;
+import org.apache.tuscany.core.integration.mock.MockFactory;
+import org.apache.tuscany.core.wire.jdk.JDKInvocationHandler;
+import org.easymock.classextension.EasyMock;
+
+/**
+ * Verifies conversational resources are cleaned up if the maximum age is exceeded
+ *
+ * @version $Rev$ $Date$
+ */
+public class ConversationMaxAgeExpireTestCase extends AbstractConversationTestCase {
+ protected AtomicComponent target;
+ private JDKInvocationHandler handler;
+ private FooImpl targetInstance;
+ private Method operation1;
+ private Method operation2;
+ private final Object mutex = new Object();
+
+ public void testConversationExpire() throws Throwable {
+ workContext.setIdentifier(org.apache.tuscany.spi.model.Scope.CONVERSATION, "12345A");
+ // start the conversation
+ handler.invoke(operation1, null);
+ // verify the instance was persisted
+ assertEquals(targetInstance, store.readRecord(target, "12345A"));
+ synchronized (mutex) {
+ mutex.wait(100);
+ }
+ // verify the instance was expired
+ assertNull(store.readRecord(target, "12345A"));
+ // continue the conversation - should throw an error
+ try {
+ handler.invoke(operation2, null);
+ fail();
+ } catch (TargetNotFoundException e) {
+ // expected
+ }
+ }
+
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ createRuntime();
+ store.setReaperInterval(10);
+ initializeRuntime();
+
+ targetInstance = EasyMock.createMock(FooImpl.class);
+ targetInstance.operation1();
+ targetInstance.operation2();
+ targetInstance.end();
+ EasyMock.replay(targetInstance);
+ target = createTarget();
+ // create source component mock
+ JavaAtomicComponent source = EasyMock.createMock(JavaAtomicComponent.class);
+ EasyMock.expect(source.getUri()).andReturn(URI.create("source")).atLeastOnce();
+ EasyMock.replay(source);
+
+ Wire wire = MockFactory.createWire("foo", Foo.class);
+ for (InvocationChain chain : wire.getInvocationChains().values()) {
+ chain.setTargetInvoker(target.createTargetInvoker("target", chain.getOperation()));
+ }
+ handler = new JDKInvocationHandler(Foo.class, wire, workContext);
+ operation1 = Foo.class.getMethod("operation1");
+ operation2 = Foo.class.getMethod("operation2");
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ container.stop();
+ store.destroy();
+ }
+
+ private AtomicComponent createTarget() throws Exception {
+ PojoConfiguration configuration = new PojoConfiguration();
+ configuration.setName(new URI("target"));
+ configuration.setMaxAge(50);
+ Constructor<FooImpl> ctor = FooImpl.class.getConstructor();
+ configuration.setInstanceFactory(new ConversationMaxAgeExpireTestCase.MockPojoFactory(ctor));
+ configuration.setImplementationClass(FooImpl.class);
+ JavaAtomicComponent component = new JavaAtomicComponent(configuration);
+ component.setScopeContainer(container);
+ component.start();
+ return component;
+ }
+
+ private class MockPojoFactory extends PojoObjectFactory<FooImpl> {
+ public MockPojoFactory(Constructor<FooImpl> ctr) {
+ super(ctr);
+ }
+
+ public FooImpl getInstance() throws ObjectCreationException {
+ return targetInstance;
+ }
+ }
+
+ @Conversational
+ public static interface Foo {
+
+ void operation1();
+
+ void operation2();
+
+ @EndsConversation
+ void end();
+
+ }
+
+ public static class FooImpl implements Foo {
+
+ public void operation1() {
+ }
+
+ public void operation2() {
+ }
+
+ @EndsConversation
+ public void end() {
+ }
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/integration/conversation/ConversationStartStopEndTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/integration/conversation/ConversationStartStopEndTestCase.java
new file mode 100644
index 0000000000..a7815a3cd6
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/integration/conversation/ConversationStartStopEndTestCase.java
@@ -0,0 +1,148 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.integration.conversation;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+import java.net.URI;
+
+import org.osoa.sca.annotations.Conversational;
+import org.osoa.sca.annotations.EndsConversation;
+
+import org.apache.tuscany.spi.ObjectCreationException;
+import org.apache.tuscany.spi.component.AtomicComponent;
+import static org.apache.tuscany.spi.model.Scope.CONVERSATION;
+import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.Wire;
+
+import org.apache.tuscany.core.implementation.PojoConfiguration;
+import org.apache.tuscany.core.implementation.java.JavaAtomicComponent;
+import org.apache.tuscany.core.injection.PojoObjectFactory;
+import org.apache.tuscany.core.integration.mock.MockFactory;
+import org.apache.tuscany.core.wire.jdk.JDKInvocationHandler;
+import org.easymock.classextension.EasyMock;
+
+/**
+ * Verifies start, continue and end conversation invocations are processed properly. Checks that a target instance is
+ * properly instantiated and persisted in the store. Additionally verifies that invocations are dispatched to a target
+ * instance, and that start, continue, and end operations are performed correctly. Finally, verfies that the target
+ * instance is removed from the store when the conversation ends.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ConversationStartStopEndTestCase extends AbstractConversationTestCase {
+ protected AtomicComponent target;
+ private FooImpl targetInstance;
+ private JDKInvocationHandler handler;
+ private Method operation1;
+ private Method operation2;
+ private Method endOperation;
+
+ public void testConversationStartContinueEnd() throws Throwable {
+ workContext.setIdentifier(CONVERSATION, "12345A");
+ // start the conversation
+ handler.invoke(operation1, null);
+ // verify the instance was persisted
+ assertEquals(targetInstance, store.readRecord(target, "12345A"));
+ // continue the conversation
+ handler.invoke(operation2, null);
+ // verify the instance was persisted
+ assertEquals(targetInstance, store.readRecord(target, "12345A"));
+ // end the conversation
+ handler.invoke(endOperation, null);
+ workContext.clearIdentifier(CONVERSATION);
+ EasyMock.verify(targetInstance);
+ // verify the store has removed the instance
+ assertNull(store.readRecord(target, "12345A"));
+ }
+
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ createRuntime();
+ initializeRuntime();
+ targetInstance = EasyMock.createMock(FooImpl.class);
+ targetInstance.operation1();
+ targetInstance.operation2();
+ targetInstance.end();
+ EasyMock.replay(targetInstance);
+ // create target component mock
+ target = createAtomicComponent();
+ Wire wire = MockFactory.createWire("foo", Foo.class);
+ for (InvocationChain chain : wire.getInvocationChains().values()) {
+ chain.setTargetInvoker(target.createTargetInvoker("foo", chain.getOperation()));
+ }
+ handler = new JDKInvocationHandler(Foo.class, wire, workContext);
+ operation1 = Foo.class.getMethod("operation1");
+ operation2 = Foo.class.getMethod("operation2");
+ endOperation = Foo.class.getMethod("end");
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ container.stop();
+ store.destroy();
+ }
+
+ private JavaAtomicComponent createAtomicComponent() throws Exception {
+ PojoConfiguration configuration = new PojoConfiguration();
+ configuration.setName(new URI("target"));
+ configuration.setInstanceFactory(new MockPojoFactory(FooImpl.class.getConstructor()));
+ configuration.setImplementationClass(FooImpl.class);
+ JavaAtomicComponent component = new JavaAtomicComponent(configuration);
+ component.setScopeContainer(container);
+ component.start();
+ return component;
+ }
+
+ private class MockPojoFactory extends PojoObjectFactory<FooImpl> {
+ public MockPojoFactory(Constructor<FooImpl> ctr) {
+ super(ctr);
+ }
+
+ public FooImpl getInstance() throws ObjectCreationException {
+ return targetInstance;
+ }
+ }
+
+ @Conversational
+ public static interface Foo {
+
+ void operation1();
+
+ void operation2();
+
+ @EndsConversation
+ void end();
+
+ }
+
+ public static class FooImpl implements Foo {
+
+ public void operation1() {
+ }
+
+ public void operation2() {
+ }
+
+ @EndsConversation
+ public void end() {
+ }
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/integration/implementation/IntrospectionRegistryIntegrationTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/integration/implementation/IntrospectionRegistryIntegrationTestCase.java
new file mode 100644
index 0000000000..a726609073
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/integration/implementation/IntrospectionRegistryIntegrationTestCase.java
@@ -0,0 +1,131 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.integration.implementation;
+
+import org.osoa.sca.annotations.Destroy;
+import org.osoa.sca.annotations.Init;
+import org.osoa.sca.annotations.Property;
+import org.osoa.sca.annotations.Reference;
+import org.osoa.sca.annotations.Scope;
+import org.apache.tuscany.api.annotation.Resource;
+
+import org.apache.tuscany.spi.implementation.java.ImplementationProcessorService;
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import static org.apache.tuscany.spi.model.Scope.COMPOSITE;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
+import org.apache.tuscany.core.implementation.IntrospectionRegistryImpl;
+import org.apache.tuscany.core.implementation.processor.DestroyProcessor;
+import org.apache.tuscany.core.implementation.processor.ImplementationProcessorServiceImpl;
+import org.apache.tuscany.core.implementation.processor.InitProcessor;
+import org.apache.tuscany.core.implementation.processor.PropertyProcessor;
+import org.apache.tuscany.core.implementation.processor.ReferenceProcessor;
+import org.apache.tuscany.core.implementation.processor.ResourceProcessor;
+import org.apache.tuscany.core.implementation.processor.ScopeProcessor;
+import org.apache.tuscany.core.monitor.NullMonitorFactory;
+
+/**
+ * Sanity check of the <code>IntegrationRegistry</code> to verify operation with processors
+ *
+ * @version $Rev$ $Date$
+ */
+public class IntrospectionRegistryIntegrationTestCase extends TestCase {
+
+ private IntrospectionRegistryImpl registry;
+
+ public void testSimpleComponentTypeParsing() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ registry.introspect(Foo.class, type, null);
+ assertEquals(Foo.class.getMethod("init"), type.getInitMethod());
+ assertEquals(Foo.class.getMethod("destroy"), type.getDestroyMethod());
+ assertEquals(COMPOSITE, type.getImplementationScope());
+ assertEquals(Foo.class.getMethod("setBar", String.class), type.getProperties().get("bar").getMember());
+ assertEquals(Foo.class.getMethod("setTarget", Foo.class), type.getReferences().get("target").getMember());
+ assertEquals(Foo.class.getMethod("setResource", Foo.class), type.getResources().get("resource").getMember());
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ registry = new IntrospectionRegistryImpl();
+ registry.setMonitor(new NullMonitorFactory().getMonitor(IntrospectionRegistryImpl.Monitor.class));
+ registry.registerProcessor(new DestroyProcessor());
+ registry.registerProcessor(new InitProcessor());
+ registry.registerProcessor(new ScopeProcessor());
+ JavaInterfaceProcessorRegistryImpl interfaceProcessorRegistry = new JavaInterfaceProcessorRegistryImpl();
+ ImplementationProcessorService service = new ImplementationProcessorServiceImpl(interfaceProcessorRegistry);
+ registry.registerProcessor(new PropertyProcessor(service));
+ registry.registerProcessor(new ReferenceProcessor(interfaceProcessorRegistry));
+ registry.registerProcessor(new ResourceProcessor());
+ }
+
+ @Scope("COMPOSITE")
+ private static class Foo {
+ protected Foo target;
+ protected String bar;
+ protected Foo resource;
+ private boolean initialized;
+ private boolean destroyed;
+
+
+ @Init
+ public void init() {
+ if (initialized) {
+ fail();
+ }
+ initialized = true;
+ }
+
+ @Destroy
+ public void destroy() {
+ if (destroyed) {
+ fail();
+ }
+ destroyed = true;
+ }
+
+ public Foo getTarget() {
+ return target;
+ }
+
+ @Reference
+ public void setTarget(Foo target) {
+ this.target = target;
+ }
+
+ public String getBar() {
+ return bar;
+ }
+
+ @Property
+ public void setBar(String bar) {
+ this.bar = bar;
+ }
+
+ @Resource
+ public void setResource(Foo resource) {
+ this.resource = resource;
+ }
+
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/integration/implementation/system/builder/SystemBuilderPropertyTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/integration/implementation/system/builder/SystemBuilderPropertyTestCase.java
new file mode 100644
index 0000000000..c95b26b094
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/integration/implementation/system/builder/SystemBuilderPropertyTestCase.java
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.integration.implementation.system.builder;
+
+import java.net.URI;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.implementation.java.ConstructorDefinition;
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.implementation.system.builder.SystemComponentBuilder;
+import org.apache.tuscany.core.implementation.system.model.SystemImplementation;
+import org.apache.tuscany.core.injection.SingletonObjectFactory;
+import org.easymock.EasyMock;
+
+/**
+ * Verifies that the system builder handles configured properties correctly
+ *
+ * @version $Rev$ $Date$
+ */
+public class SystemBuilderPropertyTestCase extends TestCase {
+
+ DeploymentContext deploymentContext;
+ Component parent;
+
+ @SuppressWarnings("unchecked")
+ public void testPropertyHandling() throws Exception {
+ SystemComponentBuilder builder = new SystemComponentBuilder();
+ PojoComponentType<ServiceDefinition, ReferenceDefinition, JavaMappedProperty<?>> type =
+ new PojoComponentType<ServiceDefinition, ReferenceDefinition, JavaMappedProperty<?>>();
+ type.setConstructorDefinition(new ConstructorDefinition<Foo>(Foo.class.getConstructor((Class[]) null)));
+ JavaMappedProperty<String> property = new JavaMappedProperty<String>();
+ property.setName("test");
+ property.setDefaultValueFactory(new SingletonObjectFactory<String>("foo"));
+ property.setMember(Foo.class.getMethod("setTest", String.class));
+ type.add(property);
+ SystemImplementation impl = new SystemImplementation();
+ impl.setComponentType(type);
+ impl.setImplementationClass(Foo.class);
+ ComponentDefinition<SystemImplementation> definition = new ComponentDefinition<SystemImplementation>(impl);
+ definition.setUri(URI.create("component"));
+ AtomicComponent component = builder.build(definition, deploymentContext);
+ Foo foo = (Foo) component.createInstance();
+ assertEquals("foo", foo.getTest());
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ deploymentContext = EasyMock.createMock(DeploymentContext.class);
+ parent = EasyMock.createNiceMock(Component.class);
+ }
+
+ private static class Foo {
+ private String test;
+
+ public Foo() {
+ }
+
+ public String getTest() {
+ return test;
+ }
+
+ public void setTest(String test) {
+ this.test = test;
+ }
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/integration/mock/MockFactory.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/integration/mock/MockFactory.java
new file mode 100644
index 0000000000..b98d197a20
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/integration/mock/MockFactory.java
@@ -0,0 +1,209 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.integration.mock;
+
+import java.lang.reflect.Member;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.idl.InvalidServiceContractException;
+import org.apache.tuscany.spi.idl.java.JavaInterfaceProcessorRegistry;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.wire.Interceptor;
+import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.Wire;
+import org.apache.tuscany.spi.wire.ProxyService;
+
+import org.apache.tuscany.core.component.WorkContextImpl;
+import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
+import org.apache.tuscany.core.implementation.PojoConfiguration;
+import org.apache.tuscany.core.implementation.java.JavaAtomicComponent;
+import org.apache.tuscany.core.injection.PojoObjectFactory;
+import org.apache.tuscany.core.wire.InvocationChainImpl;
+import org.apache.tuscany.core.wire.InvokerInterceptor;
+import org.apache.tuscany.core.wire.WireImpl;
+import org.apache.tuscany.core.wire.jdk.JDKProxyService;
+
+/**
+ * @version $$Rev$$ $$Date$$
+ */
+public final class MockFactory {
+
+ private static final ProxyService PROXY_SERVICE = new JDKProxyService(new WorkContextImpl());
+ private static final JavaInterfaceProcessorRegistry REGISTRY = new JavaInterfaceProcessorRegistryImpl();
+
+ private MockFactory() {
+ }
+
+ /**
+ * Wires two components together where the reference interface is the same as target service
+ */
+ public static Map<String, AtomicComponent> createWiredComponents(String sourceName,
+ Class<?> sourceClass,
+ ScopeContainer sourceScope,
+ Map<String, Member> members,
+ String targetName,
+ Class<?> targetService,
+ Class<?> targetClass,
+ ScopeContainer targetScope) throws Exception {
+ return createWiredComponents(sourceName,
+ sourceClass,
+ targetService,
+ sourceScope,
+ null,
+ members,
+ targetName,
+ targetClass,
+ targetScope
+ );
+
+ }
+
+ @SuppressWarnings("unchecked")
+ public static Map<String, AtomicComponent> createWiredComponents(String sourceName, Class<?> sourceClass,
+ Class<?> sourceReferenceClass,
+ ScopeContainer sourceScope,
+ Interceptor sourceHeadInterceptor,
+ Map<String, Member> members,
+ String targetName,
+ Class<?> targetClass,
+ ScopeContainer targetScope
+ )
+ throws Exception {
+
+ JavaAtomicComponent targetComponent =
+ createJavaComponent(targetName, targetScope, targetClass);
+ PojoConfiguration configuration = new PojoConfiguration();
+ configuration.setInstanceFactory(new PojoObjectFactory(sourceClass.getConstructor()));
+ configuration.setProxyService(PROXY_SERVICE);
+ for (Map.Entry<String, Member> entry : members.entrySet()) {
+ configuration.addReferenceSite(entry.getKey(), entry.getValue());
+ }
+ configuration.setWorkContext(new WorkContextImpl());
+ configuration.setName(new URI(sourceName));
+ JavaAtomicComponent sourceComponent = new JavaAtomicComponent(configuration);
+ sourceComponent.setScopeContainer(sourceScope);
+ Wire wire = createWire(targetName, sourceReferenceClass, sourceHeadInterceptor);
+ for (InvocationChain chain : wire.getInvocationChains().values()) {
+ chain.setTargetInvoker(targetComponent.createTargetInvoker(targetName, chain.getOperation()));
+ }
+ sourceComponent.attachWire(wire);
+ targetScope.register(targetComponent);
+ sourceScope.register(sourceComponent);
+ Map<String, AtomicComponent> components = new HashMap<String, AtomicComponent>();
+ components.put(sourceName, sourceComponent);
+ components.put(targetName, targetComponent);
+ return components;
+ }
+
+
+ /**
+ * Wires two components using a multiplicity reference
+ */
+ @SuppressWarnings("unchecked")
+ public static Map<String, AtomicComponent> createWiredMultiplicity(String sourceName, Class<?> sourceClass,
+ Class<?> sourceReferenceClass,
+ ScopeContainer sourceScope,
+ String targetName, Class<?> targetService,
+ Class<?> targetClass,
+ Map<String, Member> members,
+ ScopeContainer targetScope) throws Exception {
+ JavaAtomicComponent targetComponent =
+ createJavaComponent(targetName, targetScope, targetClass);
+ String serviceName = targetService.getName().substring(targetService.getName().lastIndexOf('.') + 1);
+ PojoConfiguration configuration = new PojoConfiguration();
+ configuration.setInstanceFactory(new PojoObjectFactory(sourceClass.getConstructor()));
+ configuration.setProxyService(PROXY_SERVICE);
+ for (Map.Entry<String, Member> entry : members.entrySet()) {
+ configuration.addReferenceSite(entry.getKey(), entry.getValue());
+ }
+ configuration.setWorkContext(new WorkContextImpl());
+ configuration.setName(new URI(sourceName));
+
+ JavaAtomicComponent sourceComponent = new JavaAtomicComponent(configuration);
+ sourceComponent.setScopeContainer(sourceScope);
+ Wire wire = createWire(targetName, sourceReferenceClass, null);
+ wire.setTargetUri(URI.create(targetName + "#" + serviceName));
+ for (InvocationChain chain : wire.getInvocationChains().values()) {
+ chain.setTargetInvoker(targetComponent.createTargetInvoker("target", chain.getOperation()));
+ }
+ List<Wire> wires = new ArrayList<Wire>();
+ wires.add(wire);
+ sourceComponent.attachWires(wires);
+ targetScope.register(targetComponent);
+ sourceScope.register(sourceComponent);
+
+ Map<String, AtomicComponent> components = new HashMap<String, AtomicComponent>();
+ components.put(sourceName, sourceComponent);
+ components.put(targetName, targetComponent);
+ return components;
+ }
+
+ public static <T> Wire createWire(String serviceName, Class<T> interfaze)
+ throws InvalidServiceContractException {
+ return createWire(serviceName, interfaze, null);
+ }
+
+ public static <T> Wire createWire(String serviceName, Class<T> interfaze, Interceptor interceptor)
+ throws InvalidServiceContractException {
+ Wire wire = new WireImpl();
+ ServiceContract<?> contract = REGISTRY.introspect(interfaze);
+ wire.setSourceContract(contract);
+ wire.setSourceUri(URI.create("#" + serviceName));
+ createChains(interfaze, interceptor, wire);
+ return wire;
+ }
+
+ @SuppressWarnings("unchecked")
+ private static <T> JavaAtomicComponent createJavaComponent(String name, ScopeContainer scope, Class<T> clazz)
+ throws NoSuchMethodException, URISyntaxException {
+ PojoConfiguration configuration = new PojoConfiguration();
+ configuration.setImplementationClass(clazz);
+ configuration.setInstanceFactory(new PojoObjectFactory(clazz.getConstructor()));
+ configuration.setProxyService(PROXY_SERVICE);
+ configuration.setWorkContext(new WorkContextImpl());
+ configuration.setName(new URI(name));
+ JavaAtomicComponent component = new JavaAtomicComponent(configuration);
+ component.setScopeContainer(scope);
+ return component;
+ }
+
+ private static void createChains(Class<?> interfaze, Interceptor interceptor, Wire wire)
+ throws InvalidServiceContractException {
+
+ ServiceContract<?> contract = REGISTRY.introspect(interfaze);
+ for (Operation<?> method : contract.getOperations().values()) {
+ InvocationChain chain = new InvocationChainImpl(method);
+ if (interceptor != null) {
+ chain.addInterceptor(interceptor);
+ }
+ // add tail interceptor
+ chain.addInterceptor(new InvokerInterceptor());
+ wire.addInvocationChain(method, chain);
+ }
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/integration/scope/ScopeReferenceTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/integration/scope/ScopeReferenceTestCase.java
new file mode 100644
index 0000000000..51d4e86260
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/integration/scope/ScopeReferenceTestCase.java
@@ -0,0 +1,785 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.integration.scope;
+
+import java.lang.reflect.Member;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.Executor;
+import java.util.concurrent.Executors;
+import java.util.concurrent.FutureTask;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.TargetException;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.model.Scope;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.component.WorkContextImpl;
+import org.apache.tuscany.core.component.event.ComponentStart;
+import org.apache.tuscany.core.component.event.ComponentStop;
+import org.apache.tuscany.core.component.event.HttpSessionEnd;
+import org.apache.tuscany.core.component.event.HttpSessionStart;
+import org.apache.tuscany.core.component.event.RequestEnd;
+import org.apache.tuscany.core.component.event.RequestStart;
+import org.apache.tuscany.core.component.scope.CompositeScopeContainer;
+import org.apache.tuscany.core.component.scope.HttpSessionScopeContainer;
+import org.apache.tuscany.core.component.scope.RequestScopeContainer;
+import org.apache.tuscany.core.component.scope.StatelessScopeContainer;
+import org.apache.tuscany.core.integration.mock.MockFactory;
+import org.apache.tuscany.core.mock.component.Source;
+import org.apache.tuscany.core.mock.component.SourceImpl;
+import org.apache.tuscany.core.mock.component.Target;
+import org.apache.tuscany.core.mock.component.TargetImpl;
+import org.apache.tuscany.core.util.JavaIntrospectionHelper;
+
+/**
+ * Tests scoping is properly handled for service references
+ *
+ * @version $Rev$ $Date$
+ */
+public class ScopeReferenceTestCase extends TestCase {
+ private Map<String, Member> members;
+
+ /**
+ * Tests a composite-to-composite scoped wire
+ */
+ public void testCompositeToComposite() throws Exception {
+ ScopeContainer scope = new CompositeScopeContainer(null);
+ scope.start();
+
+ Map<String, AtomicComponent> contexts = MockFactory.createWiredComponents("source",
+ SourceImpl.class,
+ scope, members,
+ "target",
+ Target.class,
+ TargetImpl.class,
+ scope);
+ scope.onEvent(new ComponentStart(this, null));
+ AtomicComponent sourceComponent = contexts.get("source");
+ AtomicComponent targetComponent = contexts.get("target");
+ Source source = (Source) sourceComponent.getTargetInstance();
+ Target target = (Target) targetComponent.getTargetInstance();
+ assertNull(source.getTarget().getString());
+ assertNull(target.getString());
+ target.setString("foo");
+ assertTrue(Proxy.isProxyClass(source.getTarget().getClass()));
+ assertEquals("foo", source.getTarget().getString());
+ scope.onEvent(new ComponentStop(this, null));
+ scope.stop();
+ }
+
+ /**
+ * Tests a composite-to-session scoped wire is setup properly by the runtime
+ */
+ public void testCompositeToSession() throws Exception {
+ WorkContext ctx = new WorkContextImpl();
+ ScopeContainer compositeScope = new CompositeScopeContainer(null);
+ compositeScope.start();
+ ScopeContainer sessionScope = new HttpSessionScopeContainer(ctx, null);
+ sessionScope.start();
+
+ Map<String, AtomicComponent> contexts = MockFactory.createWiredComponents("source", SourceImpl.class,
+ compositeScope, members, "target", Target.class, TargetImpl.class, sessionScope);
+ compositeScope.onEvent(new ComponentStart(this, null));
+ Object session1 = new Object();
+ ctx.setIdentifier(Scope.SESSION, session1);
+ sessionScope.onEvent(new HttpSessionStart(this, session1));
+ AtomicComponent sourceComponent = contexts.get("source");
+ AtomicComponent targetComponent = contexts.get("target");
+ Source source = (Source) sourceComponent.getTargetInstance();
+ Target target = (Target) targetComponent.getTargetInstance();
+ assertNull(source.getTarget().getString());
+ assertNull(target.getString());
+ target.setString("foo");
+ assertTrue(Proxy.isProxyClass(source.getTarget().getClass()));
+ assertEquals("foo", source.getTarget().getString());
+ ctx.clearIdentifier(Scope.SESSION);
+ sessionScope.onEvent(new HttpSessionEnd(this, session1));
+
+ //second session
+ Object session2 = new Object();
+ ctx.setIdentifier(Scope.SESSION, session2);
+ sessionScope.onEvent(new HttpSessionStart(this, session2));
+
+ Target target2 = (Target) targetComponent.getTargetInstance();
+ assertFalse("foo".equals(target2.getString()));
+
+ assertFalse("foo".equals(source.getTarget().getString()));
+ source.getTarget().setString("bar");
+ assertEquals("bar", target2.getString());
+ assertEquals("bar", source.getTarget().getString());
+ sessionScope.onEvent(new HttpSessionEnd(this, session2));
+
+ ctx.clearIdentifier(Scope.SESSION);
+ compositeScope.onEvent(new ComponentStop(this, null));
+ sessionScope.stop();
+ compositeScope.stop();
+ }
+
+ /**
+ * Tests a composite-to-request scoped wire
+ */
+ public void testCompositeToRequest() throws Exception {
+ WorkContext ctx = new WorkContextImpl();
+ ScopeContainer compositeScope = new CompositeScopeContainer(null);
+ compositeScope.start();
+ final ScopeContainer requestScope = new RequestScopeContainer(ctx, null);
+ requestScope.start();
+
+ Map<String, AtomicComponent> contexts = MockFactory.createWiredComponents("source", SourceImpl.class,
+ compositeScope, members, "target", Target.class, TargetImpl.class, requestScope);
+ compositeScope.onEvent(new ComponentStart(this, null));
+ requestScope.onEvent(new RequestStart(this));
+
+ AtomicComponent sourceComponent = contexts.get("source");
+ final AtomicComponent targetComponent = contexts.get("target");
+ final Source source = (Source) sourceComponent.getTargetInstance();
+ Target target = (Target) targetComponent.getTargetInstance();
+ assertNull(source.getTarget().getString());
+ assertNull(target.getString());
+ target.setString("foo");
+ assertTrue(Proxy.isProxyClass(source.getTarget().getClass()));
+ assertEquals("foo", source.getTarget().getString());
+
+ // spin off another request
+ Executor executor = Executors.newSingleThreadExecutor();
+ FutureTask<Void> future = new FutureTask<Void>(new Runnable() {
+ public void run() {
+ requestScope.onEvent(new RequestStart(this));
+ Target target2 = null;
+ try {
+ target2 = (Target) targetComponent.getTargetInstance();
+ } catch (TargetException e) {
+ fail(e.getMessage());
+ }
+ assertFalse("foo".equals(target2.getString()));
+ assertFalse("foo".equals(source.getTarget().getString()));
+ source.getTarget().setString("bar");
+ assertEquals("bar", target2.getString());
+ assertEquals("bar", source.getTarget().getString());
+ requestScope.onEvent(new RequestEnd(this));
+ }
+ }, null);
+ executor.execute(future);
+ future.get();
+ assertEquals("foo", source.getTarget().getString());
+ requestScope.onEvent(new RequestEnd(this));
+ compositeScope.onEvent(new ComponentStop(this, null));
+ requestScope.stop();
+ compositeScope.stop();
+ }
+
+ /**
+ * Tests a composite-to-stateless scoped wire is setup properly by the runtime
+ */
+ public void testCompositeToStateless() throws Exception {
+ WorkContext ctx = new WorkContextImpl();
+ ScopeContainer compositeScope = new CompositeScopeContainer(null);
+ compositeScope.start();
+ ScopeContainer statelessScope = new StatelessScopeContainer(ctx, null);
+ statelessScope.start();
+
+ Map<String, AtomicComponent> contexts = MockFactory.createWiredComponents("source", SourceImpl.class,
+ compositeScope, members, "target", Target.class, TargetImpl.class, statelessScope);
+ compositeScope.onEvent(new ComponentStart(this, null));
+
+ AtomicComponent sourceComponent = contexts.get("source");
+ AtomicComponent targetComponent = contexts.get("target");
+ Source source = (Source) sourceComponent.getTargetInstance();
+ Target target = (Target) targetComponent.getTargetInstance();
+ assertTrue(Proxy.isProxyClass(source.getTarget().getClass()));
+ assertNull(source.getTarget().getString());
+ assertNull(target.getString());
+ target.setString("foo");
+ assertFalse("foo".equals(source.getTarget().getString()));
+ Target target2 = (Target) targetComponent.getTargetInstance();
+ assertFalse("foo".equals(target2.getString()));
+ source.getTarget().setString("bar");
+ assertFalse("bar".equals(source.getTarget().getString()));
+ compositeScope.onEvent(new ComponentStop(this, null));
+ compositeScope.stop();
+ statelessScope.stop();
+ }
+
+
+ /**
+ * Tests a session-to-session scoped wire
+ */
+ public void testSessionToSession() throws Exception {
+ WorkContext ctx = new WorkContextImpl();
+ ScopeContainer sessionScope = new HttpSessionScopeContainer(ctx, null);
+ sessionScope.start();
+
+ Map<String, AtomicComponent> contexts = MockFactory.createWiredComponents("source", SourceImpl.class,
+ sessionScope, members, "target", Target.class, TargetImpl.class, sessionScope);
+
+ Object session1 = new Object();
+ ctx.setIdentifier(Scope.SESSION, session1);
+ sessionScope.onEvent(new HttpSessionStart(this, session1));
+ AtomicComponent sourceComponent = contexts.get("source");
+ AtomicComponent targetComponent = contexts.get("target");
+ Source source = (Source) sourceComponent.getTargetInstance();
+ Target target = (Target) targetComponent.getTargetInstance();
+ source.getTarget().setString("foo");
+ source.getTarget().setString("foo");
+ assertEquals("foo", target.getString());
+
+ ctx.clearIdentifier(Scope.SESSION);
+ sessionScope.onEvent(new HttpSessionEnd(this, session1));
+
+ //second session
+ Object session2 = new Object();
+ ctx.setIdentifier(Scope.SESSION, session2);
+ sessionScope.onEvent(new HttpSessionStart(this, session2));
+
+ Source source2 = (Source) sourceComponent.getTargetInstance();
+ assertNotNull(source2);
+ Target target2 = (Target) targetComponent.getTargetInstance();
+
+ assertNotNull(target2);
+ assertNull(target2.getString());
+ assertEquals(null, source2.getTarget().getString());
+ source2.getTarget().setString("baz");
+ assertEquals("baz", source2.getTarget().getString());
+ assertEquals("baz", target2.getString());
+ ctx.clearIdentifier(Scope.SESSION);
+ sessionScope.onEvent(new HttpSessionEnd(this, session2));
+ sessionScope.stop();
+ }
+
+
+ /**
+ * Tests a session-to-composite scoped wire
+ */
+ public void testSessionToComposite() throws Exception {
+ WorkContext ctx = new WorkContextImpl();
+ ScopeContainer compositeScope = new CompositeScopeContainer(null);
+ compositeScope.start();
+ ScopeContainer sessionScope = new HttpSessionScopeContainer(ctx, null);
+ sessionScope.start();
+
+ Map<String, AtomicComponent> contexts = MockFactory.createWiredComponents("source", SourceImpl.class,
+ sessionScope, members, "target", Target.class, TargetImpl.class, compositeScope);
+ compositeScope.onEvent(new ComponentStart(this, null));
+ Object session1 = new Object();
+ ctx.setIdentifier(Scope.SESSION, session1);
+ sessionScope.onEvent(new HttpSessionStart(this, session1));
+ AtomicComponent sourceComponent = contexts.get("source");
+ AtomicComponent targetComponent = contexts.get("target");
+ Source source = (Source) sourceComponent.getTargetInstance();
+ Target target = (Target) targetComponent.getTargetInstance();
+ assertNull(source.getTarget().getString());
+ assertNull(target.getString());
+ target.setString("foo");
+ assertTrue(Proxy.isProxyClass(source.getTarget().getClass()));
+ assertEquals("foo", source.getTarget().getString());
+ ctx.clearIdentifier(Scope.SESSION);
+ sessionScope.onEvent(new HttpSessionEnd(this, session1));
+
+ //second session
+ Object session2 = new Object();
+ ctx.setIdentifier(Scope.SESSION, session2);
+ sessionScope.onEvent(new HttpSessionStart(this, session2));
+
+ Target target2 = (Target) targetComponent.getTargetInstance();
+ Source source2 = (Source) sourceComponent.getTargetInstance();
+ assertEquals("foo", target2.getString());
+ assertEquals("foo", source2.getTarget().getString());
+ source2.getTarget().setString("baz");
+ assertEquals("baz", source2.getTarget().getString());
+ assertEquals("baz", target2.getString());
+ assertEquals("baz", target.getString());
+ ctx.clearIdentifier(Scope.SESSION);
+ sessionScope.onEvent(new HttpSessionEnd(this, session2));
+ compositeScope.stop();
+ sessionScope.stop();
+ }
+
+ /**
+ * Tests a session-to-request scoped wire is setup properly by the runtime
+ */
+ public void testSessionToRequest() throws Exception {
+ WorkContext ctx = new WorkContextImpl();
+ final ScopeContainer requestScope = new RequestScopeContainer(ctx, null);
+ requestScope.start();
+ ScopeContainer sessionScope = new HttpSessionScopeContainer(ctx, null);
+ sessionScope.start();
+
+ Map<String, AtomicComponent> contexts = MockFactory.createWiredComponents("source", SourceImpl.class,
+ sessionScope, members, "target", Target.class, TargetImpl.class, requestScope);
+ Object session1 = new Object();
+ ctx.setIdentifier(Scope.SESSION, session1);
+ sessionScope.onEvent(new HttpSessionStart(this, session1));
+ requestScope.onEvent(new RequestStart(this));
+ AtomicComponent sourceComponent = contexts.get("source");
+ final AtomicComponent targetComponent = contexts.get("target");
+ final Source source = (Source) sourceComponent.getTargetInstance();
+ Target target = (Target) targetComponent.getTargetInstance();
+ assertNull(source.getTarget().getString());
+ assertNull(target.getString());
+ target.setString("foo");
+ assertTrue(Proxy.isProxyClass(source.getTarget().getClass()));
+ assertEquals("foo", source.getTarget().getString());
+
+ // spin off another request
+ Executor executor = Executors.newSingleThreadExecutor();
+ FutureTask<Void> future = new FutureTask<Void>(new Runnable() {
+ public void run() {
+ requestScope.onEvent(new RequestStart(this));
+ Target target2 = null;
+ try {
+ target2 = (Target) targetComponent.getTargetInstance();
+ } catch (TargetException e) {
+ fail(e.getMessage());
+ }
+ assertFalse("foo".equals(target2.getString()));
+ assertFalse("foo".equals(source.getTarget().getString()));
+ source.getTarget().setString("bar");
+ assertEquals("bar", target2.getString());
+ assertEquals("bar", source.getTarget().getString());
+ requestScope.onEvent(new RequestEnd(this));
+ }
+ }, null);
+ executor.execute(future);
+ future.get();
+ assertEquals("foo", source.getTarget().getString());
+ requestScope.onEvent(new RequestEnd(this));
+ ctx.clearIdentifier(Scope.SESSION);
+ sessionScope.onEvent(new HttpSessionEnd(this, session1));
+ requestScope.stop();
+ sessionScope.stop();
+ }
+
+
+ /**
+ * Tests a session-to-stateless scoped wire is setup properly by the runtime
+ */
+ public void testSessionToStateless() throws Exception {
+ WorkContext ctx = new WorkContextImpl();
+ ScopeContainer sessionScope = new HttpSessionScopeContainer(ctx, null);
+ sessionScope.start();
+ ScopeContainer statelessScope = new StatelessScopeContainer(ctx, null);
+ statelessScope.start();
+
+ Map<String, AtomicComponent> contexts = MockFactory.createWiredComponents("source", SourceImpl.class,
+ sessionScope, members, "target", Target.class, TargetImpl.class, statelessScope);
+
+ Object session1 = new Object();
+ ctx.setIdentifier(Scope.SESSION, session1);
+ sessionScope.onEvent(new HttpSessionStart(this, session1));
+
+ AtomicComponent sourceComponent = contexts.get("source");
+ AtomicComponent targetComponent = contexts.get("target");
+ Source source = (Source) sourceComponent.getTargetInstance();
+ Target target = (Target) targetComponent.getTargetInstance();
+ assertTrue(Proxy.isProxyClass(source.getTarget().getClass()));
+ assertNull(source.getTarget().getString());
+ assertNull(target.getString());
+ target.setString("foo");
+ assertFalse("foo".equals(source.getTarget().getString()));
+ Target target2 = (Target) targetComponent.getTargetInstance();
+ assertFalse("foo".equals(target2.getString()));
+ source.getTarget().setString("bar");
+ assertFalse("bar".equals(source.getTarget().getString()));
+
+ ctx.clearIdentifier(Scope.SESSION);
+ sessionScope.onEvent(new HttpSessionEnd(this, session1));
+ sessionScope.stop();
+ statelessScope.stop();
+ }
+
+ /**
+ * Tests a request-to-request scoped wire is setup properly by the runtime
+ */
+ public void testRequestToRequest() throws Exception {
+ WorkContext ctx = new WorkContextImpl();
+ final ScopeContainer requestScope = new RequestScopeContainer(ctx, null);
+ requestScope.start();
+
+ Map<String, AtomicComponent> contexts = MockFactory.createWiredComponents("source", SourceImpl.class,
+ requestScope, members, "target", Target.class, TargetImpl.class, requestScope);
+ requestScope.onEvent(new RequestStart(this));
+
+ final AtomicComponent sourceComponent = contexts.get("source");
+ final AtomicComponent targetComponent = contexts.get("target");
+ Source source = (Source) sourceComponent.getTargetInstance();
+ Target target = (Target) targetComponent.getTargetInstance();
+ assertNull(source.getTarget().getString());
+ assertNull(target.getString());
+ target.setString("foo");
+ assertTrue(Proxy.isProxyClass(source.getTarget().getClass()));
+ assertEquals("foo", source.getTarget().getString());
+
+ // spin off another request
+ Executor executor = Executors.newSingleThreadExecutor();
+ FutureTask<Void> future = new FutureTask<Void>(new Runnable() {
+ public void run() {
+ requestScope.onEvent(new RequestStart(this));
+ Source source2 = null;
+ Target target2 = null;
+ try {
+ source2 = (Source) sourceComponent.getTargetInstance();
+ target2 = (Target) targetComponent.getTargetInstance();
+ } catch (TargetException e) {
+ fail(e.getMessage());
+ }
+ assertFalse("foo".equals(target2.getString()));
+ assertFalse("foo".equals(source2.getTarget().getString()));
+ source2.getTarget().setString("bar");
+ assertEquals("bar", target2.getString());
+ assertEquals("bar", source2.getTarget().getString());
+ requestScope.onEvent(new RequestEnd(this));
+ }
+ }, null);
+ executor.execute(future);
+ future.get();
+ requestScope.onEvent(new RequestEnd(this));
+ requestScope.stop();
+ }
+
+ /**
+ * Tests a request-to-composite scoped wire
+ */
+ public void testRequestToComposite() throws Exception {
+ WorkContext ctx = new WorkContextImpl();
+ final ScopeContainer requestScope = new RequestScopeContainer(ctx, null);
+ final ScopeContainer compositeScope = new CompositeScopeContainer(null);
+ requestScope.start();
+ compositeScope.start();
+ compositeScope.onEvent(new ComponentStart(this, null));
+
+ Map<String, AtomicComponent> contexts = MockFactory.createWiredComponents("source", SourceImpl.class,
+ requestScope, members, "target", Target.class, TargetImpl.class, compositeScope);
+ requestScope.onEvent(new RequestStart(this));
+
+ final AtomicComponent sourceComponent = contexts.get("source");
+ final AtomicComponent targetComponent = contexts.get("target");
+ Source source = (Source) sourceComponent.getTargetInstance();
+ Target target = (Target) targetComponent.getTargetInstance();
+ assertNull(source.getTarget().getString());
+ assertNull(target.getString());
+ target.setString("foo");
+ assertTrue(Proxy.isProxyClass(source.getTarget().getClass()));
+ assertEquals("foo", source.getTarget().getString());
+
+ // spin off another request
+ Executor executor = Executors.newSingleThreadExecutor();
+ FutureTask<Void> future = new FutureTask<Void>(new Runnable() {
+ public void run() {
+ requestScope.onEvent(new RequestStart(this));
+ Source source2 = null;
+ Target target2 = null;
+ try {
+ source2 = (Source) sourceComponent.getTargetInstance();
+ target2 = (Target) targetComponent.getTargetInstance();
+ } catch (TargetException e) {
+ fail(e.getMessage());
+ }
+ assertEquals("foo", target2.getString());
+ assertEquals("foo", source2.getTarget().getString());
+ source2.getTarget().setString("bar");
+ assertEquals("bar", target2.getString());
+ assertEquals("bar", source2.getTarget().getString());
+ requestScope.onEvent(new RequestEnd(this));
+ }
+ }, null);
+ executor.execute(future);
+ future.get();
+ assertEquals("bar", target.getString());
+
+ requestScope.onEvent(new RequestEnd(this));
+ requestScope.stop();
+ compositeScope.onEvent(new ComponentStop(this, null));
+ compositeScope.stop();
+ }
+
+ /**
+ * Tests a request-to-session scoped wire is setup properly by the runtime
+ */
+ public void testRequestToSession() throws Exception {
+ WorkContext ctx = new WorkContextImpl();
+ final ScopeContainer requestScope = new RequestScopeContainer(ctx, null);
+ final ScopeContainer sessionScope = new HttpSessionScopeContainer(ctx, null);
+ requestScope.start();
+ sessionScope.start();
+
+ Object session1 = new Object();
+ ctx.setIdentifier(Scope.SESSION, session1);
+ sessionScope.onEvent(new HttpSessionStart(this, session1));
+ Map<String, AtomicComponent> contexts = MockFactory.createWiredComponents("source", SourceImpl.class,
+ requestScope, members, "target", Target.class, TargetImpl.class, sessionScope);
+
+ final AtomicComponent sourceComponent = contexts.get("source");
+ final AtomicComponent targetComponent = contexts.get("target");
+ requestScope.onEvent(new RequestStart(this));
+ Source source = (Source) sourceComponent.getTargetInstance();
+ Target target = (Target) targetComponent.getTargetInstance();
+ assertNull(source.getTarget().getString());
+ assertNull(target.getString());
+ target.setString("foo");
+ assertTrue(Proxy.isProxyClass(source.getTarget().getClass()));
+ assertEquals("foo", source.getTarget().getString());
+
+ // spin off another request
+ Executor executor = Executors.newSingleThreadExecutor();
+ FutureTask<Void> future = new FutureTask<Void>(new Runnable() {
+ public void run() {
+ requestScope.onEvent(new RequestStart(this));
+ Source source2 = null;
+ Target target2 = null;
+ try {
+ source2 = (Source) sourceComponent.getTargetInstance();
+ target2 = (Target) targetComponent.getTargetInstance();
+ } catch (TargetException e) {
+ fail(e.getMessage());
+ }
+ assertEquals("foo", target2.getString());
+ assertEquals("foo", source2.getTarget().getString());
+ source2.getTarget().setString("bar");
+ assertEquals("bar", target2.getString());
+ assertEquals("bar", source2.getTarget().getString());
+ requestScope.onEvent(new RequestEnd(this));
+ }
+ }, null);
+ executor.execute(future);
+ future.get();
+ assertEquals("bar", target.getString());
+
+ requestScope.onEvent(new RequestEnd(this));
+ requestScope.stop();
+ ctx.clearIdentifier(Scope.SESSION);
+ sessionScope.onEvent(new HttpSessionEnd(this, session1));
+ sessionScope.stop();
+ }
+
+
+ /**
+ * Tests a request-to-stateless scoped wire is setup properly by the runtime
+ */
+ public void testRequestToStateless() throws Exception {
+ WorkContext ctx = new WorkContextImpl();
+ ScopeContainer requestScope = new RequestScopeContainer(ctx, null);
+ requestScope.start();
+ ScopeContainer statelessScope = new StatelessScopeContainer(ctx, null);
+ statelessScope.start();
+
+ Map<String, AtomicComponent> contexts = MockFactory.createWiredComponents("source", SourceImpl.class,
+ requestScope, members, "target", Target.class, TargetImpl.class, statelessScope);
+
+ AtomicComponent sourceComponent = contexts.get("source");
+ AtomicComponent targetComponent = contexts.get("target");
+ requestScope.onEvent(new RequestStart(this));
+ Source source = (Source) sourceComponent.getTargetInstance();
+ Target target = (Target) targetComponent.getTargetInstance();
+ assertTrue(Proxy.isProxyClass(source.getTarget().getClass()));
+ assertNull(source.getTarget().getString());
+ assertNull(target.getString());
+ target.setString("foo");
+ assertFalse("foo".equals(source.getTarget().getString()));
+ Target target2 = (Target) targetComponent.getTargetInstance();
+ assertFalse("foo".equals(target2.getString()));
+ source.getTarget().setString("bar");
+ assertFalse("bar".equals(source.getTarget().getString()));
+ requestScope.onEvent(new RequestEnd(this));
+ requestScope.stop();
+ statelessScope.stop();
+ }
+
+
+ /**
+ * Tests a stateless-to-stateless scoped wire is setup properly by the runtime
+ */
+ public void testStatelessToStateless() throws Exception {
+ WorkContext ctx = new WorkContextImpl();
+ ScopeContainer statelessScope = new StatelessScopeContainer(ctx, null);
+ statelessScope.start();
+
+ Map<String, AtomicComponent> contexts = MockFactory.createWiredComponents("source", SourceImpl.class,
+ statelessScope, members, "target", Target.class, TargetImpl.class, statelessScope);
+
+ AtomicComponent sourceComponent = contexts.get("source");
+ AtomicComponent targetComponent = contexts.get("target");
+ Source source = (Source) sourceComponent.getTargetInstance();
+ Target target = (Target) targetComponent.getTargetInstance();
+ assertTrue(Proxy.isProxyClass(source.getTarget().getClass()));
+ assertNull(source.getTarget().getString());
+ assertNull(target.getString());
+ target.setString("foo");
+ assertFalse("foo".equals(source.getTarget().getString()));
+ Target target2 = (Target) targetComponent.getTargetInstance();
+ assertFalse("foo".equals(target2.getString()));
+ source.getTarget().setString("bar");
+ assertFalse("bar".equals(source.getTarget().getString()));
+ statelessScope.stop();
+ }
+
+ /**
+ * Tests a stateless-to-request scoped wire is setup properly by the runtime
+ */
+ public void testStatelessToRequest() throws Exception {
+ WorkContext ctx = new WorkContextImpl();
+ final ScopeContainer requestScope = new RequestScopeContainer(ctx, null);
+ requestScope.start();
+ ScopeContainer statelessScope = new StatelessScopeContainer(ctx, null);
+ statelessScope.start();
+
+ Map<String, AtomicComponent> contexts = MockFactory.createWiredComponents("source", SourceImpl.class,
+ statelessScope, members, "target", Target.class, TargetImpl.class, requestScope);
+ requestScope.onEvent(new RequestStart(this));
+ AtomicComponent sourceComponent = contexts.get("source");
+ final AtomicComponent targetComponent = contexts.get("target");
+ final Source source = (Source) sourceComponent.getTargetInstance();
+ Target target = (Target) targetComponent.getTargetInstance();
+ assertNull(source.getTarget().getString());
+ assertNull(target.getString());
+ target.setString("foo");
+ assertTrue(Proxy.isProxyClass(source.getTarget().getClass()));
+ assertEquals("foo", source.getTarget().getString());
+
+ // spin off another request
+ Executor executor = Executors.newSingleThreadExecutor();
+ FutureTask<Void> future = new FutureTask<Void>(new Runnable() {
+ public void run() {
+ requestScope.onEvent(new RequestStart(this));
+ Target target2 = null;
+ try {
+ target2 = (Target) targetComponent.getTargetInstance();
+ } catch (TargetException e) {
+ fail(e.getMessage());
+ }
+ assertFalse("foo".equals(target2.getString()));
+ assertFalse("foo".equals(source.getTarget().getString()));
+ source.getTarget().setString("bar");
+ assertEquals("bar", target2.getString());
+ assertEquals("bar", source.getTarget().getString());
+ requestScope.onEvent(new RequestEnd(this));
+ }
+ }, null);
+ executor.execute(future);
+ future.get();
+ requestScope.stop();
+ statelessScope.stop();
+ }
+
+ /**
+ * Tests a stateless-to-session scoped wire is setup properly by the runtime
+ */
+ public void testStatelessToSession() throws Exception {
+ WorkContext ctx = new WorkContextImpl();
+ ScopeContainer statelessScope = new StatelessScopeContainer(ctx, null);
+ statelessScope.start();
+ ScopeContainer sessionScope = new HttpSessionScopeContainer(ctx, null);
+ sessionScope.start();
+
+ Map<String, AtomicComponent> contexts = MockFactory.createWiredComponents("source", SourceImpl.class,
+ statelessScope, members, "target", Target.class, TargetImpl.class, sessionScope);
+ Object session1 = new Object();
+ ctx.setIdentifier(Scope.SESSION, session1);
+ sessionScope.onEvent(new HttpSessionStart(this, session1));
+ AtomicComponent sourceComponent = contexts.get("source");
+ AtomicComponent targetComponent = contexts.get("target");
+ Source source = (Source) sourceComponent.getTargetInstance();
+ Target target = (Target) targetComponent.getTargetInstance();
+ assertNull(source.getTarget().getString());
+ assertNull(target.getString());
+ target.setString("foo");
+ assertTrue(Proxy.isProxyClass(source.getTarget().getClass()));
+ assertEquals("foo", source.getTarget().getString());
+ ctx.clearIdentifier(Scope.SESSION);
+ sessionScope.onEvent(new HttpSessionEnd(this, session1));
+
+ //second session
+ Object session2 = new Object();
+ ctx.setIdentifier(Scope.SESSION, session2);
+ sessionScope.onEvent(new HttpSessionStart(this, session2));
+
+ Target target2 = (Target) targetComponent.getTargetInstance();
+ assertFalse("foo".equals(target2.getString()));
+
+ assertFalse("foo".equals(source.getTarget().getString()));
+ source.getTarget().setString("bar");
+ assertEquals("bar", target2.getString());
+ assertEquals("bar", source.getTarget().getString());
+ sessionScope.onEvent(new HttpSessionEnd(this, session2));
+
+ ctx.clearIdentifier(Scope.SESSION);
+ sessionScope.stop();
+ statelessScope.stop();
+ }
+
+
+ /**
+ * Tests a stateless-to-composite scoped wire is setup properly by the runtime
+ */
+ public void testStatelessToComposite() throws Exception {
+ WorkContext ctx = new WorkContextImpl();
+ ScopeContainer statelessScope = new StatelessScopeContainer(ctx, null);
+ statelessScope.start();
+ ScopeContainer compositeScope = new CompositeScopeContainer(null);
+ compositeScope.start();
+
+ Map<String, AtomicComponent> contexts = MockFactory.createWiredComponents("source", SourceImpl.class,
+ statelessScope, members, "target", Target.class, TargetImpl.class, compositeScope);
+ compositeScope.onEvent(new ComponentStart(this, null));
+ AtomicComponent sourceComponent = contexts.get("source");
+ AtomicComponent targetComponent = contexts.get("target");
+ Source source = (Source) sourceComponent.getTargetInstance();
+ Target target = (Target) targetComponent.getTargetInstance();
+ assertNull(source.getTarget().getString());
+ assertNull(target.getString());
+ target.setString("foo");
+ assertTrue(Proxy.isProxyClass(source.getTarget().getClass()));
+ assertEquals("foo", source.getTarget().getString());
+
+ //second session
+ Object session2 = new Object();
+ ctx.setIdentifier(Scope.SESSION, session2);
+ compositeScope.onEvent(new HttpSessionStart(this, session2));
+
+ Target target2 = (Target) targetComponent.getTargetInstance();
+ assertEquals("foo", target2.getString());
+
+ assertEquals("foo", source.getTarget().getString());
+ source.getTarget().setString("bar");
+ assertEquals("bar", target2.getString());
+ assertEquals("bar", source.getTarget().getString());
+
+ compositeScope.onEvent(new ComponentStop(this, null));
+ compositeScope.stop();
+ statelessScope.stop();
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ members = new HashMap<String, Member>();
+ Method[] methods = SourceImpl.class.getMethods();
+ for (Method method : methods) {
+ if (method.getName().startsWith("set")) {
+ members.put(JavaIntrospectionHelper.toPropertyName(method.getName()), method);
+ }
+ }
+ }
+
+
+}
+
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/integration/wire/DifferentInterfaceWireTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/integration/wire/DifferentInterfaceWireTestCase.java
new file mode 100644
index 0000000000..7588e377b4
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/integration/wire/DifferentInterfaceWireTestCase.java
@@ -0,0 +1,136 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.integration.wire;
+
+import java.lang.reflect.Member;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.TargetException;
+import org.apache.tuscany.spi.model.Scope;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.integration.mock.MockFactory;
+import org.apache.tuscany.core.mock.component.OtherTarget;
+import org.apache.tuscany.core.mock.component.OtherTargetImpl;
+import org.apache.tuscany.core.mock.component.Target;
+import org.apache.tuscany.core.mock.component.SourceImpl;
+import org.apache.tuscany.core.mock.component.Source;
+import org.easymock.EasyMock;
+import org.easymock.IAnswer;
+
+
+/**
+ * Tests wires that have different interfaces on the source and target side
+ *
+ * @version $Rev$ $Date$
+ */
+public class DifferentInterfaceWireTestCase extends TestCase {
+
+ public void testDifferentInterfaceInjection() throws Exception {
+ Map<String, Member> members = new HashMap<String, Member>();
+ Method m = SourceImpl.class.getMethod("setTarget", Target.class);
+ members.put("target", m);
+ ScopeContainer scope = createMock();
+ scope.start();
+ Map<String, AtomicComponent> contexts =
+ MockFactory.createWiredComponents("source",
+ SourceImpl.class,
+ Target.class,
+ scope,
+ null,
+ members,
+ "target",
+ OtherTargetImpl.class,
+ scope
+ );
+ AtomicComponent sourceComponent = contexts.get("source");
+ Source source = (Source) sourceComponent.getTargetInstance();
+ Target target = source.getTarget();
+ assertTrue(Proxy.isProxyClass(target.getClass()));
+ assertNotNull(target);
+ scope.stop();
+ EasyMock.verify(scope);
+ }
+
+ public void testDifferentInterfaceMultiplicityInjection() throws Exception {
+ Map<String, Member> members = new HashMap<String, Member>();
+ Method m = SourceImpl.class.getMethod("setTargets", List.class);
+ members.put("target", m);
+ ScopeContainer scope = createMock();
+ scope.start();
+ Map<String, AtomicComponent> components = MockFactory.createWiredMultiplicity("source",
+ SourceImpl.class,
+ Target.class,
+ scope,
+ "target",
+ OtherTarget.class,
+ OtherTargetImpl.class,
+ members,
+ scope);
+ AtomicComponent sourceComponent = components.get("source");
+ Source source = (Source) sourceComponent.getTargetInstance();
+ List<Target> targets = source.getTargets();
+ assertEquals(1, targets.size());
+ Target target = targets.get(0);
+ target.setString("foo");
+ assertEquals("foo", target.getString());
+ assertTrue(Proxy.isProxyClass(target.getClass()));
+ scope.stop();
+ EasyMock.verify(scope);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ private ScopeContainer createMock() throws TargetException {
+ ScopeContainer scope = EasyMock.createMock(ScopeContainer.class);
+ scope.start();
+ scope.stop();
+ scope.register(EasyMock.isA(AtomicComponent.class));
+ EasyMock.expectLastCall().atLeastOnce();
+ EasyMock.expect(scope.getScope()).andReturn(Scope.COMPOSITE).atLeastOnce();
+ scope.getInstance(EasyMock.isA(AtomicComponent.class));
+ EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
+ private Map<AtomicComponent, Object> cache = new HashMap<AtomicComponent, Object>();
+
+ public Object answer() throws Throwable {
+ AtomicComponent component = (AtomicComponent) EasyMock.getCurrentArguments()[0];
+ Object instance = cache.get(component);
+ if (instance == null) {
+ instance = component.createInstance();
+ cache.put(component, instance);
+ }
+ return instance;
+ }
+ }).anyTimes();
+ EasyMock.replay(scope);
+ return scope;
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/integration/wire/ReferenceInjectionTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/integration/wire/ReferenceInjectionTestCase.java
new file mode 100644
index 0000000000..a3ac4dea65
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/integration/wire/ReferenceInjectionTestCase.java
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.integration.wire;
+
+import java.lang.reflect.Member;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.ScopeContainer;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.component.scope.CompositeScopeContainer;
+import org.apache.tuscany.core.integration.mock.MockFactory;
+import org.apache.tuscany.core.mock.component.Source;
+import org.apache.tuscany.core.mock.component.SourceImpl;
+import org.apache.tuscany.core.mock.component.Target;
+import org.apache.tuscany.core.mock.component.TargetImpl;
+
+/**
+ * @version $$Rev$$ $$Date$$
+ */
+public class ReferenceInjectionTestCase extends TestCase {
+ private Map<String, Member> members;
+
+ public void testProxiedReferenceInjection() throws Exception {
+ ScopeContainer scope = new CompositeScopeContainer(null);
+ scope.start();
+ Map<String, AtomicComponent> components = MockFactory.createWiredComponents("source",
+ SourceImpl.class,
+ scope,
+ members,
+ "target",
+ Target.class,
+ TargetImpl.class,
+ scope);
+ AtomicComponent sourceComponent = components.get("source");
+ Source source = (Source) sourceComponent.getTargetInstance();
+ Target target = source.getTarget();
+ assertTrue(Proxy.isProxyClass(target.getClass()));
+
+ assertNotNull(target);
+ scope.stop();
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ members = new HashMap<String, Member>();
+ Method m = SourceImpl.class.getMethod("setTarget", Target.class);
+ members.put("target", m);
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/integration/wire/oneway/OneWayWireToJavaInvocationTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/integration/wire/oneway/OneWayWireToJavaInvocationTestCase.java
new file mode 100644
index 0000000000..df0d3700b6
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/integration/wire/oneway/OneWayWireToJavaInvocationTestCase.java
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.integration.wire.oneway;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.Type;
+import java.util.concurrent.CountDownLatch;
+
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.extension.ExecutionMonitor;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.services.work.WorkScheduler;
+import org.apache.tuscany.spi.wire.Interceptor;
+import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.Message;
+import org.apache.tuscany.spi.wire.MessageImpl;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.component.WorkContextImpl;
+import org.apache.tuscany.core.implementation.java.JavaAtomicComponent;
+import org.apache.tuscany.core.implementation.java.JavaTargetInvoker;
+import org.apache.tuscany.core.services.work.jsr237.Jsr237WorkScheduler;
+import org.apache.tuscany.core.services.work.jsr237.workmanager.ThreadPoolWorkManager;
+import org.apache.tuscany.core.wire.InvocationChainImpl;
+import org.apache.tuscany.core.wire.InvokerInterceptor;
+import org.apache.tuscany.core.wire.NonBlockingInterceptor;
+import org.easymock.classextension.EasyMock;
+
+/**
+ * Verifies non-blocking invocations are properly made through a wire to a Java component
+ *
+ * @version $Rev$ $Date$
+ */
+public class OneWayWireToJavaInvocationTestCase extends TestCase {
+ private WorkScheduler scheduler;
+ private WorkContext context;
+ private CountDownLatch latch;
+ private InvocationChain ochain;
+ private JavaTargetInvoker invoker;
+ private JavaAtomicComponent component;
+ private AsyncTarget target;
+
+ public void testOneWay() throws Exception {
+ MessageImpl msg = new MessageImpl();
+ msg.setTargetInvoker(invoker);
+ ochain.getHeadInterceptor().invoke(msg);
+ latch.await();
+ EasyMock.verify(target);
+ EasyMock.verify(component);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ latch = new CountDownLatch(1);
+ context = new WorkContextImpl();
+ scheduler = new Jsr237WorkScheduler(new ThreadPoolWorkManager(1));
+ target = EasyMock.createMock(AsyncTarget.class);
+ target.invoke();
+ EasyMock.expectLastCall().once();
+ EasyMock.replay(target);
+ component = EasyMock.createMock(JavaAtomicComponent.class);
+ EasyMock.expect(component.getScope()).andReturn(Scope.COMPOSITE);
+ EasyMock.expect(component.getTargetInstance()).andReturn(target);
+ EasyMock.replay(component);
+ Method method = AsyncTarget.class.getMethod("invoke");
+ method.setAccessible(true);
+ ExecutionMonitor monitor = EasyMock.createNiceMock(ExecutionMonitor.class);
+ invoker = new JavaTargetInvoker(method, component, context);
+ Operation<Type> operation = new Operation<Type>("invoke", null, null, null, false, null, TargetInvoker.NONE);
+ ochain = new InvocationChainImpl(operation);
+ NonBlockingInterceptor bridgeInterceptor = new NonBlockingInterceptor(scheduler, context);
+ ochain.addInterceptor(bridgeInterceptor);
+ InvocationChain ichain = new InvocationChainImpl(operation);
+ WaitInterceptor waitInterceptor = new WaitInterceptor();
+ InvokerInterceptor invokerInterceptor = new InvokerInterceptor();
+ ichain.addInterceptor(waitInterceptor);
+ ichain.addInterceptor(invokerInterceptor);
+ bridgeInterceptor.setNext(waitInterceptor);
+ ochain.setTargetInvoker(invoker);
+ }
+
+ public interface AsyncTarget {
+ void invoke();
+ }
+
+
+ private class WaitInterceptor implements Interceptor {
+ private Interceptor next;
+
+ public Message invoke(Message msg) {
+ msg = next.invoke(msg);
+ latch.countDown();
+ return msg;
+ }
+
+ public Interceptor getNext() {
+ return next;
+ }
+
+ public void setNext(Interceptor next) {
+ this.next = next;
+ }
+
+ public boolean isOptimizable() {
+ return false;
+ }
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderNoBindingTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderNoBindingTestCase.java
new file mode 100644
index 0000000000..52136d0d72
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderNoBindingTestCase.java
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.loader;
+
+import java.net.URI;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamReader;
+
+import static org.osoa.sca.Constants.SCA_NS;
+
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.model.Implementation;
+import org.apache.tuscany.spi.model.ModelObject;
+import org.apache.tuscany.spi.model.Property;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.implementation.java.JavaImplementation;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ComponentLoaderNoBindingTestCase extends TestCase {
+ private static final QName COMPONENT = new QName(SCA_NS, "component");
+ private ComponentLoader loader;
+ private XMLStreamReader reader;
+ private ServiceDefinition service;
+ private ReferenceDefinition reference;
+ private DeploymentContext ctx;
+
+ public void testNoServiceBinding() throws Exception {
+ loader.load(null, reader, ctx);
+ assert service.getBindings().isEmpty();
+ }
+
+ public void testNoReferenceBinding() throws Exception {
+ loader.load(null, reader, ctx);
+ assert reference.getBindings().isEmpty();
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ URI componentId = URI.create("sca://localhost/parent/");
+ service = new ServiceDefinition();
+ service.setUri(URI.create("service"));
+ reference = new ReferenceDefinition();
+ reference.setUri(URI.create("#ref"));
+ PojoComponentType<ServiceDefinition, ReferenceDefinition, Property<?>> type =
+ new PojoComponentType<ServiceDefinition, ReferenceDefinition, Property<?>>();
+ type.add(service);
+ type.add(reference);
+ JavaImplementation impl = new JavaImplementation(null, type);
+ LoaderRegistry registry = EasyMock.createMock(LoaderRegistry.class);
+ EasyMock.expect(registry.load(
+ (ModelObject) EasyMock.isNull(),
+ EasyMock.isA(XMLStreamReader.class),
+ EasyMock.isA(DeploymentContext.class))).andReturn(impl);
+ registry.loadComponentType(
+ EasyMock.isA(Implementation.class),
+ EasyMock.isA(DeploymentContext.class));
+ EasyMock.replay(registry);
+ loader = new ComponentLoader(registry, null);
+ reader = EasyMock.createMock(XMLStreamReader.class);
+ EasyMock.expect(reader.getName()).andReturn(COMPONENT).atLeastOnce();
+ EasyMock.expect(reader.next()).andReturn(XMLStreamConstants.END_ELEMENT);
+ EasyMock.expect(reader.getAttributeValue(null, "name")).andReturn("foo");
+ EasyMock.expect(reader.getAttributeValue(null, "initLevel")).andReturn("0");
+ EasyMock.expect(reader.getAttributeValue((String) EasyMock.isNull(), EasyMock.eq("autowire")))
+ .andReturn(null);
+ EasyMock.expect(reader.nextTag()).andReturn(1);
+ EasyMock.replay(reader);
+ ctx = EasyMock.createMock(DeploymentContext.class);
+ EasyMock.expect(ctx.getClassLoader()).andReturn(null);
+ EasyMock.expect(ctx.isAutowire()).andReturn(false);
+ EasyMock.expect(ctx.getScdlLocation()).andReturn(null);
+ EasyMock.expect(ctx.getComponentId()).andReturn(componentId);
+ EasyMock.replay(ctx);
+
+
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderNoReferenceTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderNoReferenceTestCase.java
new file mode 100644
index 0000000000..55c51d5c12
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderNoReferenceTestCase.java
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.loader;
+
+import java.net.URI;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import static org.osoa.sca.Constants.SCA_NS;
+
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.loader.UndefinedReferenceException;
+import org.apache.tuscany.spi.model.Implementation;
+import org.apache.tuscany.spi.model.ModelObject;
+import org.apache.tuscany.spi.model.Property;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.implementation.java.JavaImplementation;
+import org.easymock.EasyMock;
+import static org.easymock.EasyMock.isNull;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ComponentLoaderNoReferenceTestCase extends TestCase {
+ private static final QName COMPONENT = new QName(SCA_NS, "component");
+ private static final QName REFERENCE = new QName(SCA_NS, "reference");
+ private static final String NAME = "testComponent";
+ private ComponentLoader loader;
+ private XMLStreamReader reader;
+ private DeploymentContext ctx;
+
+ /**
+ * Verifies an error is thrown when an attempt to configure a non-existent reference in SCDL is made
+ */
+ public void testNoReferenceOnComponentType() throws LoaderException, XMLStreamException {
+ try {
+ loader.load(null, reader, ctx);
+ fail();
+ } catch (UndefinedReferenceException e) {
+ // expected
+ }
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ URI componentId = URI.create("sca://localhost/parent/");
+ PojoComponentType<ServiceDefinition, ReferenceDefinition, Property<?>> type =
+ new PojoComponentType<ServiceDefinition, ReferenceDefinition, Property<?>>();
+ JavaImplementation impl = new JavaImplementation(null, type);
+ reader = EasyMock.createMock(XMLStreamReader.class);
+ EasyMock.expect(reader.getName()).andReturn(COMPONENT);
+ EasyMock.expect(reader.getAttributeValue((String) EasyMock.isNull(), EasyMock.isA(String.class)))
+ .andReturn(NAME);
+ EasyMock.expect(reader.getAttributeValue((String) EasyMock.isNull(), EasyMock.eq("initLevel")))
+ .andReturn(null);
+ EasyMock.expect(reader.getAttributeValue((String) EasyMock.isNull(), EasyMock.eq("autowire")))
+ .andReturn(null);
+ EasyMock.expect(reader.getAttributeValue(EasyMock.isA(String.class), EasyMock.isA(String.class)))
+ .andReturn(null);
+ EasyMock.expect(reader.nextTag()).andReturn(0);
+ EasyMock.expect(reader.next()).andReturn(XMLStreamConstants.START_ELEMENT);
+ EasyMock.expect(reader.getName()).andReturn(REFERENCE);
+ EasyMock.expect(reader.getAttributeValue((String) isNull(), EasyMock.eq("name")))
+ .andReturn("noreference");
+ EasyMock.expect(reader.getAttributeValue((String) EasyMock.isNull(), EasyMock.eq("autowire")))
+ .andReturn(null);
+ EasyMock.expect(reader.getAttributeValue(null, "target")).andReturn("text");
+
+ EasyMock.expect(reader.next()).andReturn(XMLStreamConstants.END_ELEMENT);
+ EasyMock.replay(reader);
+ LoaderRegistry mockRegistry = EasyMock.createMock(LoaderRegistry.class);
+ mockRegistry.loadComponentType(
+ EasyMock.isA(Implementation.class),
+ EasyMock.isA(DeploymentContext.class));
+ EasyMock.expect(mockRegistry.load(
+ (ModelObject) isNull(),
+ EasyMock.isA(XMLStreamReader.class),
+ EasyMock.isA(DeploymentContext.class))).andReturn(impl);
+ EasyMock.replay(mockRegistry);
+ loader = new ComponentLoader(mockRegistry, null);
+ ctx = EasyMock.createMock(DeploymentContext.class);
+ EasyMock.expect(ctx.getClassLoader()).andReturn(null);
+ EasyMock.expect(ctx.isAutowire()).andReturn(false);
+ EasyMock.expect(ctx.getScdlLocation()).andReturn(null);
+ EasyMock.expect(ctx.getComponentId()).andReturn(componentId);
+ EasyMock.replay(ctx);
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderPropertyTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderPropertyTestCase.java
new file mode 100644
index 0000000000..c6f65481b7
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderPropertyTestCase.java
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.loader;
+
+import javax.xml.stream.XMLStreamException;
+
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.loader.MissingRequiredPropertyException;
+import org.apache.tuscany.spi.loader.PropertyObjectFactory;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.Implementation;
+import org.apache.tuscany.spi.model.Property;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.implementation.java.JavaImplementation;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ComponentLoaderPropertyTestCase extends TestCase {
+
+ private TestLoader loader;
+
+ /**
+ * Verifies that an optional property not cofigured in an assembly will avoid having a PropertyValue created for it
+ * so that the runtime does not erroneously inject null values
+ */
+ public void testOptionalPropertyNotConfigured() throws LoaderException, XMLStreamException {
+ PojoComponentType<?, ?, Property<?>> type =
+ new PojoComponentType<ServiceDefinition, ReferenceDefinition, Property<?>>();
+ Property property = new Property();
+ property.setName("name");
+ type.add(property);
+ JavaImplementation impl = new JavaImplementation(null, type);
+ impl.setComponentType(type);
+ ComponentDefinition<Implementation<?>> defn = new ComponentDefinition<Implementation<?>>(impl);
+ loader.populatePropertyValues(defn);
+ assertTrue(defn.getPropertyValues().isEmpty());
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ LoaderRegistry mockRegistry = EasyMock.createMock(LoaderRegistry.class);
+ PropertyObjectFactory mockPropertyFactory = EasyMock.createMock(PropertyObjectFactory.class);
+ loader = new TestLoader(mockRegistry, mockPropertyFactory);
+ }
+
+ private class TestLoader extends ComponentLoader {
+
+ public TestLoader(LoaderRegistry registry, PropertyObjectFactory propertyFactory) {
+ super(registry, propertyFactory);
+ }
+
+ @Override
+ public void populatePropertyValues(ComponentDefinition<Implementation<?>> componentDefinition)
+ throws MissingRequiredPropertyException {
+ super.populatePropertyValues(componentDefinition);
+ }
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderRefTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderRefTestCase.java
new file mode 100644
index 0000000000..07ef7d6348
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderRefTestCase.java
@@ -0,0 +1,159 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.loader;
+
+import java.net.URI;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.Property;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.ReferenceTarget;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.implementation.java.JavaImplementation;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ComponentLoaderRefTestCase extends TestCase {
+ private ComponentLoader loader;
+ private final URI componentId = URI.create("sca://localhost/parent/");
+ private DeploymentContext context;
+
+ public void testLoadReferenceNoFragment() throws LoaderException, XMLStreamException {
+ PojoComponentType<?, MockReferenceDefinition, Property<?>> type =
+ new PojoComponentType<ServiceDefinition, MockReferenceDefinition, Property<?>>();
+ MockReferenceDefinition reference = new MockReferenceDefinition();
+ reference.setUri(URI.create("#reference"));
+ type.add(reference);
+ JavaImplementation impl = new JavaImplementation();
+ impl.setComponentType(type);
+ ComponentDefinition<?> definition = new ComponentDefinition<JavaImplementation>(impl);
+ definition.setUri(URI.create("component"));
+ XMLStreamReader reader = EasyMock.createMock(XMLStreamReader.class);
+ EasyMock.expect(reader.getAttributeValue(null, "name")).andReturn("reference");
+ EasyMock.expect(reader.getAttributeValue(null, "target")).andReturn("target");
+ EasyMock.expect(reader.getAttributeValue(null, "autowire")).andReturn(null);
+ EasyMock.replay(reader);
+ loader.loadReference(reader, definition, context);
+ ReferenceTarget target = definition.getReferenceTargets().get("reference");
+ assertEquals(1, target.getTargets().size());
+ URI uri = target.getTargets().get(0);
+ assertEquals(componentId.resolve("target"), uri);
+ assertNull(uri.getFragment());
+ EasyMock.verify(reader);
+ }
+
+ public void testLoadReferenceWithFragment() throws LoaderException, XMLStreamException {
+ PojoComponentType<?, MockReferenceDefinition, Property<?>> type =
+ new PojoComponentType<ServiceDefinition, MockReferenceDefinition, Property<?>>();
+ MockReferenceDefinition reference = new MockReferenceDefinition();
+ reference.setUri(URI.create("#reference"));
+ type.add(reference);
+ JavaImplementation impl = new JavaImplementation();
+ impl.setComponentType(type);
+ ComponentDefinition<?> definition = new ComponentDefinition<JavaImplementation>(impl);
+ definition.setUri(URI.create("component"));
+ XMLStreamReader reader = EasyMock.createMock(XMLStreamReader.class);
+ EasyMock.expect(reader.getAttributeValue(null, "name")).andReturn("reference");
+ EasyMock.expect(reader.getAttributeValue(null, "target")).andReturn("target/fragment");
+ EasyMock.expect(reader.getAttributeValue(null, "autowire")).andReturn(null);
+ EasyMock.replay(reader);
+ loader.loadReference(reader, definition, context);
+ ReferenceTarget target = definition.getReferenceTargets().get("reference");
+ assertEquals(1, target.getTargets().size());
+ URI uri = target.getTargets().get(0);
+ assertEquals(componentId.resolve("target#fragment"), uri);
+ EasyMock.verify(reader);
+ }
+
+ public void testLoadReferenceWithMultipleTargetUris() throws LoaderException, XMLStreamException {
+ PojoComponentType<?, MockReferenceDefinition, Property<?>> type =
+ new PojoComponentType<ServiceDefinition, MockReferenceDefinition, Property<?>>();
+ MockReferenceDefinition reference = new MockReferenceDefinition();
+ reference.setUri(URI.create("#reference"));
+ type.add(reference);
+ JavaImplementation impl = new JavaImplementation();
+ impl.setComponentType(type);
+ ComponentDefinition<?> definition = new ComponentDefinition<JavaImplementation>(impl);
+ definition.setUri(URI.create("component"));
+ XMLStreamReader reader = EasyMock.createMock(XMLStreamReader.class);
+ EasyMock.expect(reader.getAttributeValue(null, "name")).andReturn("reference");
+ EasyMock.expect(reader.getAttributeValue(null, "target")).andReturn("target1/fragment1 target2/fragment2");
+ EasyMock.expect(reader.getAttributeValue(null, "autowire")).andReturn(null);
+ EasyMock.replay(reader);
+ loader.loadReference(reader, definition, context);
+ ReferenceTarget target = definition.getReferenceTargets().get("reference");
+ assertEquals(2, target.getTargets().size());
+ URI uri1 = target.getTargets().get(0);
+ assertEquals(componentId.resolve("target1#fragment1"), uri1);
+ URI uri2 = target.getTargets().get(1);
+ assertEquals(componentId.resolve("target2#fragment2"), uri2);
+ EasyMock.verify(reader);
+ }
+
+ public void testLoadReferenceAutowire() throws LoaderException, XMLStreamException {
+ PojoComponentType<?, MockReferenceDefinition, Property<?>> type =
+ new PojoComponentType<ServiceDefinition, MockReferenceDefinition, Property<?>>();
+ MockReferenceDefinition reference = new MockReferenceDefinition();
+ reference.setUri(URI.create("#reference"));
+ type.add(reference);
+ JavaImplementation impl = new JavaImplementation();
+ impl.setComponentType(type);
+ ComponentDefinition<?> definition = new ComponentDefinition<JavaImplementation>(impl);
+ definition.setUri(URI.create("component"));
+ XMLStreamReader reader = EasyMock.createMock(XMLStreamReader.class);
+ EasyMock.expect(reader.getAttributeValue(null, "name")).andReturn("reference");
+ EasyMock.expect(reader.getAttributeValue(null, "target")).andReturn("target/fragment");
+ EasyMock.expect(reader.getAttributeValue(null, "autowire")).andReturn("true");
+ EasyMock.replay(reader);
+ loader.loadReference(reader, definition, context);
+ ReferenceTarget target = definition.getReferenceTargets().get("reference");
+ assertTrue(target.isAutowire());
+ EasyMock.verify(reader);
+ }
+
+
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ LoaderRegistry mockRegistry = EasyMock.createMock(LoaderRegistry.class);
+ loader = new ComponentLoader(mockRegistry, null);
+ Component parent = EasyMock.createNiceMock(Component.class);
+ EasyMock.expect(parent.getUri()).andReturn(componentId).atLeastOnce();
+ EasyMock.replay(parent);
+
+ context = EasyMock.createMock(DeploymentContext.class);
+ EasyMock.expect(context.getComponentId()).andReturn(componentId);
+ EasyMock.replay(context);
+ }
+
+ private class MockReferenceDefinition extends ReferenceDefinition {
+
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderTestCase.java
new file mode 100644
index 0000000000..f13fbe67e3
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderTestCase.java
@@ -0,0 +1,245 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.loader;
+
+import java.net.URI;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import static org.osoa.sca.Constants.SCA_NS;
+
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.loader.PropertyObjectFactory;
+import org.apache.tuscany.spi.loader.UnrecognizedElementException;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.Implementation;
+import org.apache.tuscany.spi.model.ModelObject;
+import org.apache.tuscany.spi.model.Property;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.implementation.java.JavaImplementation;
+import org.easymock.EasyMock;
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.isNull;
+import static org.easymock.EasyMock.replay;
+import org.easymock.IAnswer;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ComponentLoaderTestCase extends TestCase {
+ private static final QName COMPONENT = new QName(SCA_NS, "component");
+ private static final String COMPONENT_NAME = "sca://localhost/parent/";
+ private static final String NAME = "testComponent";
+ private JavaImplementation impl;
+
+ private XMLStreamReader mockReader;
+ private LoaderRegistry mockRegistry;
+ private PropertyObjectFactory mockPropertyFactory;
+ private ComponentLoader loader;
+ private Component parent;
+ private DeploymentContext ctx;
+ private URI componentId;
+
+ public void testEmptyComponent() throws LoaderException, XMLStreamException {
+ EasyMock.expect(mockReader.getName()).andReturn(COMPONENT).atLeastOnce();
+ EasyMock.expect(mockReader.getAttributeValue((String) EasyMock.isNull(), EasyMock.isA(String.class)))
+ .andReturn(NAME);
+ EasyMock.expect(mockReader.getAttributeValue((String) EasyMock.isNull(), EasyMock.eq("initLevel")))
+ .andReturn(null);
+ EasyMock.expect(mockReader.getAttributeValue((String) EasyMock.isNull(), EasyMock.eq("autowire")))
+ .andReturn(null);
+ EasyMock.expect(mockReader.getAttributeValue(EasyMock.isA(String.class), EasyMock.isA(String.class)))
+ .andReturn(null);
+ EasyMock.expect(mockReader.nextTag()).andReturn(0);
+ EasyMock.expect(mockReader.next()).andReturn(XMLStreamConstants.END_ELEMENT);
+ EasyMock.replay(mockReader);
+ mockRegistry.loadComponentType(
+ EasyMock.isA(Implementation.class),
+ EasyMock.isA(DeploymentContext.class));
+ EasyMock.expectLastCall().andStubAnswer(new IAnswer<Object>() {
+ @SuppressWarnings("unchecked")
+ public Object answer() throws Throwable {
+ Implementation impl = (Implementation) EasyMock.getCurrentArguments()[0];
+ impl.setComponentType(new PojoComponentType());
+ return impl;
+ }
+ });
+
+ EasyMock.expect(mockRegistry.load(
+ (ModelObject) isNull(),
+ EasyMock.eq(mockReader),
+ EasyMock.isA(DeploymentContext.class))).andReturn(impl);
+ EasyMock.replay(mockRegistry);
+ ComponentDefinition component = loader.load(null, mockReader, ctx);
+ assertEquals(COMPONENT_NAME + NAME, component.getUri().toString());
+ assertNull(component.getInitLevel());
+ }
+
+ public void testAutowire() throws LoaderException, XMLStreamException {
+ EasyMock.expect(mockReader.getName()).andReturn(COMPONENT).atLeastOnce();
+ EasyMock.expect(mockReader.getAttributeValue((String) EasyMock.isNull(), EasyMock.isA(String.class)))
+ .andReturn(NAME);
+ EasyMock.expect(mockReader.getAttributeValue((String) EasyMock.isNull(), EasyMock.eq("initLevel")))
+ .andReturn(null);
+ EasyMock.expect(mockReader.getAttributeValue((String) EasyMock.isNull(), EasyMock.eq("autowire")))
+ .andReturn("true");
+ EasyMock.expect(mockReader.nextTag()).andReturn(0);
+ EasyMock.expect(mockReader.next()).andReturn(XMLStreamConstants.END_ELEMENT);
+ EasyMock.replay(mockReader);
+
+ mockRegistry.loadComponentType(
+ EasyMock.isA(Implementation.class),
+ EasyMock.isA(DeploymentContext.class));
+
+ EasyMock.expectLastCall().andStubAnswer(new IAnswer<Object>() {
+ @SuppressWarnings("unchecked")
+ public Object answer() throws Throwable {
+ Implementation impl = (Implementation) EasyMock.getCurrentArguments()[0];
+ impl.setComponentType(new PojoComponentType());
+ return impl;
+ }
+ });
+ EasyMock.expect(mockRegistry.load(
+ (ModelObject) isNull(),
+ EasyMock.eq(mockReader),
+ EasyMock.isA(DeploymentContext.class))).andReturn(impl);
+ EasyMock.replay(mockRegistry);
+
+ ComponentDefinition component = loader.load(null, mockReader, ctx);
+
+ assertTrue(component.getAutowire());
+ }
+
+ public void testInitValue20() throws LoaderException, XMLStreamException {
+ EasyMock.expect(mockReader.getName()).andReturn(COMPONENT).atLeastOnce();
+ EasyMock.expect(mockReader.getAttributeValue((String) EasyMock.isNull(), EasyMock.isA(String.class)))
+ .andReturn(NAME);
+ EasyMock.expect(mockReader.getAttributeValue((String) EasyMock.isNull(), EasyMock.eq("initLevel")))
+ .andReturn("20");
+ EasyMock.expect(mockReader.getAttributeValue((String) EasyMock.isNull(), EasyMock.eq("autowire")))
+ .andReturn(null);
+ EasyMock.expect(mockReader.nextTag()).andReturn(0);
+ EasyMock.expect(mockReader.next()).andReturn(XMLStreamConstants.END_ELEMENT);
+ EasyMock.replay(mockReader);
+
+ mockRegistry.loadComponentType(
+ EasyMock.isA(Implementation.class),
+ EasyMock.isA(DeploymentContext.class));
+
+ EasyMock.expectLastCall().andStubAnswer(new IAnswer<Object>() {
+ @SuppressWarnings("unchecked")
+ public Object answer() throws Throwable {
+ Implementation impl = (Implementation) EasyMock.getCurrentArguments()[0];
+ impl.setComponentType(new PojoComponentType());
+ return impl;
+ }
+ });
+ EasyMock.expect(mockRegistry.load(
+ (ModelObject) isNull(),
+ EasyMock.eq(mockReader),
+ EasyMock.isA(DeploymentContext.class))).andReturn(impl);
+ EasyMock.replay(mockRegistry);
+
+ ComponentDefinition component = loader.load(null, mockReader, ctx);
+ assertEquals(COMPONENT_NAME + NAME, component.getUri().toString());
+ assertEquals(Integer.valueOf(20), component.getInitLevel());
+ }
+
+ public void testLoadPropertyWithSource() throws LoaderException, XMLStreamException {
+ PojoComponentType<?, ?, Property<?>> type =
+ new PojoComponentType<ServiceDefinition, ReferenceDefinition, Property<?>>();
+ Property property = new Property();
+ property.setName("name");
+ type.add(property);
+ JavaImplementation impl = new JavaImplementation();
+ impl.setComponentType(type);
+ ComponentDefinition<?> defn = new ComponentDefinition<JavaImplementation>(impl);
+ XMLStreamReader reader = createMock(XMLStreamReader.class);
+ expect(reader.getAttributeValue(null, "name")).andReturn("name");
+ expect(reader.getAttributeValue(null, "source")).andReturn("$source");
+ expect(reader.getAttributeValue(null, "file")).andReturn(null);
+ expect(reader.next()).andReturn(XMLStreamConstants.END_ELEMENT);
+ replay(reader);
+ loader.loadProperty(reader, defn, null);
+ assertEquals("$source", defn.getPropertyValues().get("name").getSource());
+ EasyMock.verify(reader);
+ }
+
+ public void testUnrecognizedElement() throws LoaderException, XMLStreamException {
+ EasyMock.expect(mockReader.getName()).andReturn(COMPONENT);
+ EasyMock.expect(mockReader.getAttributeValue((String) EasyMock.isNull(), EasyMock.isA(String.class)))
+ .andReturn(NAME);
+ EasyMock.expect(mockReader.getAttributeValue((String) EasyMock.isNull(), EasyMock.eq("initLevel")))
+ .andReturn(null);
+ EasyMock.expect(mockReader.getAttributeValue((String) EasyMock.isNull(), EasyMock.eq("autowire")))
+ .andReturn(null);
+ EasyMock.expect(mockReader.getAttributeValue(EasyMock.isA(String.class), EasyMock.isA(String.class)))
+ .andReturn(null);
+ EasyMock.expect(mockReader.nextTag()).andReturn(0);
+ EasyMock.expect(mockReader.next()).andReturn(XMLStreamConstants.START_ELEMENT);
+ EasyMock.expect(mockReader.getName()).andReturn(new QName("foo", "bar"));
+ EasyMock.replay(mockReader);
+ mockRegistry.loadComponentType(
+ EasyMock.isA(Implementation.class),
+ EasyMock.isA(DeploymentContext.class));
+
+ EasyMock.expect(mockRegistry.load(
+ (ModelObject) isNull(),
+ EasyMock.eq(mockReader),
+ EasyMock.isA(DeploymentContext.class))).andReturn(impl);
+ EasyMock.replay(mockRegistry);
+ try {
+ loader.load(null, mockReader, ctx);
+ fail();
+ } catch (UnrecognizedElementException e) {
+ // expected
+ }
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ componentId = URI.create(COMPONENT_NAME);
+ impl = new JavaImplementation();
+ mockReader = EasyMock.createMock(XMLStreamReader.class);
+ mockRegistry = EasyMock.createMock(LoaderRegistry.class);
+ mockPropertyFactory = EasyMock.createMock(PropertyObjectFactory.class);
+ loader = new ComponentLoader(mockRegistry, mockPropertyFactory);
+ parent = EasyMock.createNiceMock(Component.class);
+ URI uri = URI.create("foo");
+ EasyMock.expect(parent.getUri()).andReturn(uri).atLeastOnce();
+ EasyMock.replay(parent);
+
+ ctx = EasyMock.createMock(DeploymentContext.class);
+ EasyMock.expect(ctx.isAutowire()).andReturn(false);
+ EasyMock.expect(ctx.getClassLoader()).andReturn(null);
+ EasyMock.expect(ctx.getScdlLocation()).andReturn(null);
+ EasyMock.expect(ctx.getComponentId()).andReturn(componentId);
+ EasyMock.replay(ctx);
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderValidationTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderValidationTestCase.java
new file mode 100644
index 0000000000..fdfdaeaa7f
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderValidationTestCase.java
@@ -0,0 +1,169 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.loader;
+
+import java.net.URI;
+import javax.xml.stream.XMLStreamException;
+
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.loader.MissingReferenceException;
+import org.apache.tuscany.spi.loader.PropertyObjectFactory;
+import org.apache.tuscany.spi.loader.ReferenceMultiplicityViolationException;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.Implementation;
+import org.apache.tuscany.spi.model.Multiplicity;
+import org.apache.tuscany.spi.model.Property;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.ReferenceTarget;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.implementation.java.JavaImplementation;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ComponentLoaderValidationTestCase extends TestCase {
+
+ private ComponentLoaderValidationTestCase.TestLoader loader;
+
+ public void testValidation() throws LoaderException, XMLStreamException {
+ PojoComponentType<ServiceDefinition, ReferenceDefinition, Property<?>> type =
+ new PojoComponentType<ServiceDefinition, ReferenceDefinition, Property<?>>();
+ ReferenceDefinition refDefinition = new ReferenceDefinition();
+ refDefinition.setUri(URI.create("#name"));
+ type.add(refDefinition);
+ JavaImplementation impl = new JavaImplementation(null, type);
+ ComponentDefinition<Implementation<?>> defn = new ComponentDefinition<Implementation<?>>(impl);
+ ReferenceTarget target = new ReferenceTarget();
+ target.setReferenceName(URI.create("#name"));
+ defn.add(target);
+ loader.validate(defn);
+ }
+
+ public void testReferenceNotSet() throws LoaderException, XMLStreamException {
+ PojoComponentType<ServiceDefinition, ReferenceDefinition, Property<?>> type =
+ new PojoComponentType<ServiceDefinition, ReferenceDefinition, Property<?>>();
+ ReferenceDefinition refDefinition = new ReferenceDefinition();
+ refDefinition.setUri(URI.create("#name"));
+ refDefinition.setRequired(true);
+ type.add(refDefinition);
+ JavaImplementation impl = new JavaImplementation(null, type);
+ ComponentDefinition<Implementation<?>> defn = new ComponentDefinition<Implementation<?>>(impl);
+ try {
+ loader.validate(defn);
+ fail();
+ } catch (MissingReferenceException e) {
+ // expected
+ }
+ }
+
+ public void testNotRequiredReference() throws LoaderException, XMLStreamException {
+ PojoComponentType<ServiceDefinition, ReferenceDefinition, Property<?>> type =
+ new PojoComponentType<ServiceDefinition, ReferenceDefinition, Property<?>>();
+ ReferenceDefinition refDefinition = new ReferenceDefinition();
+ refDefinition.setUri(URI.create("#name"));
+ refDefinition.setRequired(false);
+ type.add(refDefinition);
+ JavaImplementation impl = new JavaImplementation(null, type);
+ ComponentDefinition<Implementation<?>> defn = new ComponentDefinition<Implementation<?>>(impl);
+ loader.validate(defn);
+ }
+
+ public void testReferenceMultiplicity() throws LoaderException, XMLStreamException {
+ PojoComponentType<ServiceDefinition, ReferenceDefinition, Property<?>> type =
+ new PojoComponentType<ServiceDefinition, ReferenceDefinition, Property<?>>();
+ ReferenceDefinition refDefinition = new ReferenceDefinition();
+ URI uri = URI.create("#r1");
+ refDefinition.setUri(uri);
+ refDefinition.setRequired(true);
+ refDefinition.setMultiplicity(Multiplicity.ONE_N);
+ type.add(refDefinition);
+ JavaImplementation impl = new JavaImplementation(null, type);
+ ComponentDefinition<Implementation<?>> defn = new ComponentDefinition<Implementation<?>>(impl);
+ ReferenceTarget target = new ReferenceTarget();
+ target.setReferenceName(uri);
+ target.addTarget(URI.create("c1"));
+ target.addTarget(URI.create("c2"));
+ defn.add(target);
+ loader.validate(defn);
+
+ refDefinition.setMultiplicity(Multiplicity.ZERO_ONE);
+ try {
+ loader.validate(defn);
+ fail();
+ } catch (ReferenceMultiplicityViolationException e) {
+ // Expected
+ }
+
+ refDefinition.setMultiplicity(Multiplicity.ZERO_N);
+ loader.validate(defn);
+
+ refDefinition.setMultiplicity(Multiplicity.ONE_ONE);
+ try {
+ loader.validate(defn);
+ fail();
+ } catch (ReferenceMultiplicityViolationException e) {
+ // Expected
+ }
+
+ target.getTargets().clear();
+ refDefinition.setMultiplicity(Multiplicity.ONE_ONE);
+ try {
+ loader.validate(defn);
+ fail();
+ } catch (ReferenceMultiplicityViolationException e) {
+ // Expected
+ }
+ refDefinition.setMultiplicity(Multiplicity.ONE_N);
+ try {
+ loader.validate(defn);
+ fail();
+ } catch (ReferenceMultiplicityViolationException e) {
+ // Expected
+ }
+ refDefinition.setMultiplicity(Multiplicity.ZERO_N);
+ loader.validate(defn);
+ refDefinition.setMultiplicity(Multiplicity.ZERO_ONE);
+ loader.validate(defn);
+
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ LoaderRegistry mockRegistry = EasyMock.createMock(LoaderRegistry.class);
+ PropertyObjectFactory mockPropertyFactory = EasyMock.createMock(PropertyObjectFactory.class);
+ loader = new ComponentLoaderValidationTestCase.TestLoader(mockRegistry, mockPropertyFactory);
+ }
+
+ private class TestLoader extends ComponentLoader {
+
+ public TestLoader(LoaderRegistry registry, PropertyObjectFactory propertyFactory) {
+ super(registry, propertyFactory);
+ }
+
+ @Override
+ protected void validate(ComponentDefinition<Implementation<?>> definition) throws LoaderException {
+ super.validate(definition);
+ }
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/loader/ComponentTypeElementLoaderTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/loader/ComponentTypeElementLoaderTestCase.java
new file mode 100644
index 0000000000..9948019b7b
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/loader/ComponentTypeElementLoaderTestCase.java
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.loader;
+
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.model.ComponentType;
+import org.apache.tuscany.spi.model.ModelObject;
+import org.apache.tuscany.spi.model.Property;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ComponentTypeElementLoaderTestCase extends TestCase {
+
+ public void testSpecializedComponentTypePassedIn() throws Exception {
+ ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>> type =
+ new ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>>();
+ ComponentTypeElementLoader loader = new ComponentTypeElementLoader(null);
+ XMLStreamReader reader = EasyMock.createMock(XMLStreamReader.class);
+ EasyMock.expect(reader.getName()).andReturn(ComponentTypeElementLoader.COMPONENT_TYPE);
+ EasyMock.expect(reader.next()).andReturn(XMLStreamConstants.END_ELEMENT);
+ EasyMock.replay(reader);
+ // verify that the exact component type instance is returned. Some StAXElementLoader implementations may chose
+ // to copy the original instance but ComponentTypeElementLoader does not since it has no knowledge of the
+ // specialized instance
+ ModelObject object = loader.load(type, reader, null);
+ assertEquals(object, type);
+ }
+
+ public void testComponentTypePassedAsContext() throws Exception {
+ ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>> type =
+ new ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>>();
+ LoaderRegistry registry = EasyMock.createMock(LoaderRegistry.class);
+ EasyMock.expect(registry.load(
+ EasyMock.isA(ComponentType.class),
+ EasyMock.isA(XMLStreamReader.class),
+ (DeploymentContext) EasyMock.isNull())).andReturn(type);
+ EasyMock.replay(registry);
+ ComponentTypeElementLoader loader = new ComponentTypeElementLoader(registry);
+ XMLStreamReader reader = EasyMock.createMock(XMLStreamReader.class);
+ EasyMock.expect(reader.getName()).andReturn(ComponentTypeElementLoader.COMPONENT_TYPE);
+ EasyMock.expect(reader.next()).andReturn(XMLStreamConstants.START_ELEMENT);
+ EasyMock.expect(reader.getName()).andReturn(new QName("foo", "foo"));
+ EasyMock.expect(reader.next()).andReturn(XMLStreamConstants.END_ELEMENT);
+ EasyMock.replay(reader);
+
+ loader.load(type, reader, null);
+ EasyMock.verify(registry);
+ }
+
+ public void testNonSpecializedComponentTypePassedIn() throws Exception {
+ ComponentTypeElementLoader loader = new ComponentTypeElementLoader(null);
+ XMLStreamReader reader = EasyMock.createMock(XMLStreamReader.class);
+ EasyMock.expect(reader.getName()).andReturn(ComponentTypeElementLoader.COMPONENT_TYPE);
+ EasyMock.expect(reader.next()).andReturn(XMLStreamConstants.END_ELEMENT);
+ EasyMock.replay(reader);
+ ModelObject object = loader.load(null, reader, null);
+ assertEquals(ComponentType.class, object.getClass());
+ }
+
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/loader/DependencyLoaderTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/loader/DependencyLoaderTestCase.java
new file mode 100644
index 0000000000..41b56d2bab
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/loader/DependencyLoaderTestCase.java
@@ -0,0 +1,124 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.loader;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.Location;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.loader.UnrecognizedElementException;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+import org.apache.tuscany.core.implementation.composite.Dependency;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class DependencyLoaderTestCase extends TestCase {
+ private static final String NS = "http://tuscany.apache.org/xmlns/sca/2.0-alpha";
+ private static final QName DEPENDENCY = new QName(NS, "dependency");
+ private static final QName GROUP = new QName(NS, "group");
+ private static final QName NAME = new QName(NS, "name");
+ private static final QName VERSION = new QName(NS, "version");
+ private static final QName CLASSIFIER = new QName(NS, "classifier");
+ private static final QName TYPE = new QName(NS, "type");
+
+ public void testLoad() throws Exception {
+ LoaderRegistry registry = EasyMock.createNiceMock(LoaderRegistry.class);
+ EasyMock.replay(registry);
+ XMLStreamReader reader = EasyMock.createMock(XMLStreamReader.class);
+ EasyMock.expect(reader.nextTag()).andReturn(XMLStreamConstants.START_ELEMENT);
+ EasyMock.expect(reader.getName()).andReturn(GROUP);
+ EasyMock.expect(reader.getElementText()).andReturn("group");
+ EasyMock.expect(reader.nextTag()).andReturn(XMLStreamConstants.START_ELEMENT);
+ EasyMock.expect(reader.getName()).andReturn(NAME);
+ EasyMock.expect(reader.getElementText()).andReturn("name");
+ EasyMock.expect(reader.nextTag()).andReturn(XMLStreamConstants.START_ELEMENT);
+ EasyMock.expect(reader.getName()).andReturn(VERSION);
+ EasyMock.expect(reader.getElementText()).andReturn("1");
+ EasyMock.expect(reader.nextTag()).andReturn(XMLStreamConstants.START_ELEMENT);
+ EasyMock.expect(reader.getName()).andReturn(CLASSIFIER);
+ EasyMock.expect(reader.getElementText()).andReturn("classifier");
+ EasyMock.expect(reader.nextTag()).andReturn(XMLStreamConstants.START_ELEMENT);
+ EasyMock.expect(reader.getName()).andReturn(TYPE);
+ EasyMock.expect(reader.getElementText()).andReturn("type");
+ EasyMock.expect(reader.nextTag()).andReturn(XMLStreamConstants.END_ELEMENT);
+ EasyMock.replay(reader);
+ DependencyLoader loader = new DependencyLoader(registry);
+ Dependency dependency = loader.load(null, reader, null);
+ assertEquals("group", dependency.getArtifact().getGroup());
+ assertEquals("name", dependency.getArtifact().getName());
+ assertEquals("1", dependency.getArtifact().getVersion());
+ assertEquals("classifier", dependency.getArtifact().getClassifier());
+ assertEquals("type", dependency.getArtifact().getType());
+ }
+
+ public void testLoaderRegister() {
+ LoaderRegistry registry = EasyMock.createMock(LoaderRegistry.class);
+ registry.registerLoader(EasyMock.eq(DEPENDENCY), EasyMock.isA(DependencyLoader.class));
+ EasyMock.replay(registry);
+ DependencyLoader loader = new DependencyLoader(registry);
+ loader.start();
+ EasyMock.verify(registry);
+ }
+
+ public void testUnrecognizedElement() throws Exception {
+ LoaderRegistry registry = EasyMock.createNiceMock(LoaderRegistry.class);
+ EasyMock.replay(registry);
+ XMLStreamReader reader = EasyMock.createMock(XMLStreamReader.class);
+ EasyMock.expect(reader.nextTag()).andReturn(XMLStreamConstants.START_ELEMENT);
+ EasyMock.expect(reader.getName()).andReturn(new QName("foo", "bar"));
+ EasyMock.expect(reader.getElementText()).andReturn("foo");
+ EasyMock.expect(reader.getLocation()).andReturn(new MockLocation());
+ EasyMock.replay(reader);
+ DependencyLoader loader = new DependencyLoader(registry);
+ try {
+ loader.load(null, reader, null);
+ fail();
+ } catch (UnrecognizedElementException e) {
+ // expected
+ }
+ }
+
+ private class MockLocation implements Location {
+
+ public int getLineNumber() {
+ return 0;
+ }
+
+ public int getColumnNumber() {
+ return 0;
+ }
+
+ public int getCharacterOffset() {
+ return 0;
+ }
+
+ public String getPublicId() {
+ return null;
+ }
+
+ public String getSystemId() {
+ return null;
+ }
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/loader/IncludeLoaderTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/loader/IncludeLoaderTestCase.java
new file mode 100644
index 0000000000..671c3a74d9
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/loader/IncludeLoaderTestCase.java
@@ -0,0 +1,176 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.loader;
+
+import java.net.URI;
+import java.net.URL;
+import javax.xml.namespace.QName;
+import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import junit.framework.TestCase;
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.eq;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.isA;
+import static org.easymock.EasyMock.isNull;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+import org.osoa.sca.Constants;
+
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.loader.MissingIncludeException;
+import org.apache.tuscany.spi.model.CompositeComponentType;
+import org.apache.tuscany.spi.model.Include;
+import org.apache.tuscany.spi.model.ModelObject;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class IncludeLoaderTestCase extends TestCase {
+ private static final QName INCLUDE = new QName(Constants.SCA_NS, "include");
+
+ private LoaderRegistry registry;
+ private IncludeLoader loader;
+ private XMLStreamReader reader;
+ private DeploymentContext context;
+ private URL base;
+ private URL includeURL;
+ private ClassLoader cl;
+ private URI componentId;
+
+ public void testNoLocation() throws LoaderException, XMLStreamException {
+ String name = "foo";
+ expect(reader.getName()).andReturn(INCLUDE);
+ expect(reader.getAttributeValue(null, "name")).andReturn(name);
+ expect(reader.getAttributeValue(null, "scdlLocation")).andReturn(null);
+ expect(reader.getAttributeValue(null, "scdlResource")).andReturn(null);
+ expect(reader.next()).andReturn(END_ELEMENT);
+
+ expect(context.getClassLoader()).andReturn(cl);
+ replay(registry, reader, context);
+
+ try {
+ loader.load(null, reader, context);
+ fail();
+ } catch (MissingIncludeException e) {
+ // OK expected
+ }
+ verify(registry, reader, context);
+ }
+
+ public void testWithAbsoluteScdlLocation() throws LoaderException, XMLStreamException {
+ String name = "foo";
+ expect(reader.getName()).andReturn(INCLUDE);
+ expect(reader.getAttributeValue(null, "name")).andReturn(name);
+ expect(reader.getAttributeValue(null, "scdlLocation")).andReturn("http://example.com/include.scdl");
+ expect(reader.getAttributeValue(null, "scdlResource")).andReturn(null);
+ expect(reader.next()).andReturn(END_ELEMENT);
+
+ expect(context.getScdlLocation()).andReturn(base);
+ expect(context.getClassLoader()).andReturn(cl);
+ expect(context.isAutowire()).andReturn(false);
+ expect(context.getComponentId()).andReturn(componentId);
+
+ expect(registry.load(
+ (ModelObject) isNull(),
+ eq(includeURL),
+ eq(CompositeComponentType.class),
+ isA(DeploymentContext.class)))
+ .andReturn(null);
+ replay(registry, reader, context);
+
+ Include include = loader.load(null, reader, context);
+ assertEquals(name, include.getName());
+ assertEquals(includeURL, include.getScdlLocation());
+ verify(registry, reader, context);
+ }
+
+ public void testWithRelativeScdlLocation() throws LoaderException, XMLStreamException {
+ String name = "foo";
+ expect(reader.getName()).andReturn(INCLUDE);
+ expect(reader.getAttributeValue(null, "name")).andReturn(name);
+ expect(reader.getAttributeValue(null, "scdlLocation")).andReturn("include.scdl");
+ expect(reader.getAttributeValue(null, "scdlResource")).andReturn(null);
+ expect(reader.next()).andReturn(END_ELEMENT);
+
+ expect(context.getScdlLocation()).andReturn(base);
+ expect(context.getClassLoader()).andReturn(cl);
+ expect(context.isAutowire()).andReturn(false);
+ expect(context.getComponentId()).andReturn(componentId);
+
+ expect(registry.load(
+ (ModelObject) isNull(),
+ eq(includeURL),
+ eq(CompositeComponentType.class),
+ isA(DeploymentContext.class)))
+ .andReturn(null);
+ replay(registry, reader, context);
+
+ Include include = loader.load(null, reader, context);
+ assertEquals(name, include.getName());
+ assertEquals(includeURL, include.getScdlLocation());
+ verify(registry, reader, context);
+ }
+
+ public void testWithScdlResource() throws LoaderException, XMLStreamException {
+ String name = "foo";
+ String resource = "org/apache/tuscany/core/loader/test-include.scdl";
+ includeURL = cl.getResource(resource);
+ assertNotNull(includeURL);
+
+ expect(reader.getName()).andReturn(INCLUDE);
+ expect(reader.getAttributeValue(null, "name")).andReturn(name);
+ expect(reader.getAttributeValue(null, "scdlLocation")).andReturn(null);
+ expect(reader.getAttributeValue(null, "scdlResource")).andReturn(resource);
+ expect(reader.next()).andReturn(END_ELEMENT);
+
+ expect(context.getClassLoader()).andReturn(cl);
+ expect(context.isAutowire()).andReturn(false);
+ expect(context.getComponentId()).andReturn(componentId);
+
+ expect(registry.load(
+ (ModelObject) isNull(),
+ eq(includeURL),
+ eq(CompositeComponentType.class),
+ isA(DeploymentContext.class)))
+ .andReturn(null);
+ replay(registry, reader, context);
+
+ Include include = loader.load(null, reader, context);
+ assertEquals(name, include.getName());
+ assertEquals(includeURL, include.getScdlLocation());
+ verify(registry, reader, context);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ registry = createMock(LoaderRegistry.class);
+ reader = createMock(XMLStreamReader.class);
+ context = createMock(DeploymentContext.class);
+ cl = getClass().getClassLoader();
+ base = new URL("http://example.com/test.scdl");
+ includeURL = new URL("http://example.com/include.scdl");
+ loader = new IncludeLoader(registry);
+ componentId = URI.create("sca://localhost/parent/");
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/loader/JNDIPropertyFactoryTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/loader/JNDIPropertyFactoryTestCase.java
new file mode 100644
index 0000000000..fb5bfd32d3
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/loader/JNDIPropertyFactoryTestCase.java
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.loader;
+
+import java.lang.reflect.Type;
+import java.util.Hashtable;
+import javax.naming.Context;
+import javax.naming.NamingException;
+import javax.naming.spi.InitialContextFactory;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import org.apache.tuscany.spi.model.PropertyValue;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.injection.JNDIObjectFactory;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class JNDIPropertyFactoryTestCase extends TestCase {
+
+ public void testCreate() throws Exception {
+ String old = System.getProperty(Context.INITIAL_CONTEXT_FACTORY);
+ try {
+ System.setProperty(Context.INITIAL_CONTEXT_FACTORY, MockInitialContextFactory.class.getName());
+ JNDIPropertyFactory factory = new JNDIPropertyFactory();
+ Element element = EasyMock.createMock(Element.class);
+ EasyMock.expect(element.getTextContent()).andReturn("foo");
+ EasyMock.replay(element);
+ Document doc = EasyMock.createMock(Document.class);
+ EasyMock.expect(doc.getDocumentElement()).andReturn(element);
+ EasyMock.replay(doc);
+ PropertyValue<?> value = new MockPropertyValue<Type>();
+ value.setValue(doc);
+ JNDIObjectFactory<?> jndiFactory = (JNDIObjectFactory<?>) factory.createObjectFactory(null, value);
+ assertEquals("bar", jndiFactory.getInstance());
+ } finally {
+ System.clearProperty(Context.INITIAL_CONTEXT_FACTORY);
+ if (old != null) {
+ System.setProperty(Context.INITIAL_CONTEXT_FACTORY, old);
+ }
+ }
+
+ }
+
+ private class MockPropertyValue<T> extends PropertyValue<T> {
+
+ }
+
+ public static class MockInitialContextFactory implements InitialContextFactory {
+ public MockInitialContextFactory() {
+ }
+
+ public Context getInitialContext(Hashtable<?, ?> environment) throws NamingException {
+ Context context = EasyMock.createMock(Context.class);
+ EasyMock.expect(context.lookup("foo")).andReturn("bar");
+ EasyMock.replay(context);
+ return context;
+ }
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/loader/LoaderExceptionFormatterTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/loader/LoaderExceptionFormatterTestCase.java
new file mode 100644
index 0000000000..49c53935dc
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/loader/LoaderExceptionFormatterTestCase.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.loader;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+import org.apache.tuscany.spi.loader.LoaderException;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+import org.apache.tuscany.host.monitor.FormatterRegistry;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class LoaderExceptionFormatterTestCase extends TestCase {
+
+ public void testLog() {
+ FormatterRegistry registry = EasyMock.createNiceMock(FormatterRegistry.class);
+ LoaderExceptionFormatter formatter = new LoaderExceptionFormatter(registry);
+ LoaderException e = new LoaderException("test");
+ StringWriter writer = new StringWriter();
+ PrintWriter pw = new PrintWriter(writer);
+ formatter.write(pw, e);
+ pw.close();
+ assertTrue(!"message".equals(writer.toString()));
+ }
+
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/loader/PolicySetLoaderTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/loader/PolicySetLoaderTestCase.java
new file mode 100644
index 0000000000..2b3acc9d92
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/loader/PolicySetLoaderTestCase.java
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.loader;
+
+import java.util.Collection;
+import java.util.Iterator;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLInputFactory;
+import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
+import javax.xml.stream.XMLStreamReader;
+
+import static org.osoa.sca.Constants.SCA_NS;
+
+import org.apache.tuscany.spi.model.IntentMap;
+import org.apache.tuscany.spi.model.PolicySet;
+import org.apache.tuscany.spi.model.Qualifier;
+
+import junit.framework.TestCase;
+
+public class PolicySetLoaderTestCase extends TestCase {
+ private static final QName POLICYSET = new QName(SCA_NS, "policySet");
+
+ public void testLoader() throws Exception {
+ PolicySetLoader loader = new PolicySetLoader(null);
+ XMLInputFactory factory = XMLInputFactory.newInstance();
+ XMLStreamReader reader = factory.createXMLStreamReader(this.getClass().getResourceAsStream("TestPolicy.scdl"));
+ while (true) {
+ int state = reader.next();
+ if (START_ELEMENT == state && reader.getName().equals(POLICYSET)) {
+ break;
+ }
+ }
+ PolicySet policySet = loader.load(null, reader, null);
+ assertNotNull(policySet);
+ assertEquals(2, policySet.getAppliedArtifacts().size());
+ assertTrue(policySet.getAppliedArtifacts().contains(new QName(SCA_NS, "binding.ws")));
+ assertTrue(policySet.getAppliedArtifacts().contains(new QName(SCA_NS, "binding.jms")));
+ Collection<IntentMap> intentMaps = policySet.getIntentMaps();
+ assertEquals(1, intentMaps.size());
+ IntentMap intentMap = intentMaps.iterator().next();
+ assertEquals("transport", intentMap.getDefaultProvideIntent());
+ assertTrue(intentMap.getProvideIntents().contains("sec.confidentiality"));
+ Collection<Qualifier> qualifiers = intentMap.getQualifiers();
+ assertEquals(2, qualifiers.size());
+ Iterator qit = qualifiers.iterator();
+ Qualifier qualifier1 = (Qualifier) qit.next();
+ assertEquals(2, qualifier1.getWsPolicyAttachments().size());
+ assertEquals("transport", qualifier1.getName());
+ Qualifier qualifier2 = (Qualifier) qit.next();
+ assertEquals("message", qualifier2.getName());
+ IntentMap messageMap = qualifier2.getIntentMap();
+ assertEquals(2, messageMap.getQualifiers().size());
+
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/loader/PropertyParsingTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/loader/PropertyParsingTestCase.java
new file mode 100644
index 0000000000..eb732d9f74
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/loader/PropertyParsingTestCase.java
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.loader;
+
+import java.io.StringReader;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class PropertyParsingTestCase extends TestCase {
+ private XMLInputFactory xmlFactory;
+ private DocumentBuilder docBuilder;
+ private Element root;
+
+ public void testComplexProperty() throws XMLStreamException {
+ String xml = "<property xmlns:foo='http://foo.com'>"
+ + "<foo:a>aValue</foo:a>"
+ + "<foo:b>InterestingURI</foo:b>"
+ + "</property>";
+
+ XMLStreamReader reader = getReader(xml);
+ PropertyUtils.loadPropertyValue(reader, root);
+ NodeList childNodes = root.getChildNodes();
+ assertEquals(2, childNodes.getLength());
+
+ Element e = (Element) childNodes.item(0);
+ assertEquals("http://foo.com", e.getNamespaceURI());
+ assertEquals("a", e.getLocalName());
+ assertEquals("aValue", e.getTextContent());
+ e = (Element) childNodes.item(1);
+ assertEquals("http://foo.com", e.getNamespaceURI());
+ assertEquals("b", e.getLocalName());
+ assertEquals("InterestingURI", e.getTextContent());
+ }
+
+ public XMLStreamReader getReader(String xml) throws XMLStreamException {
+ XMLStreamReader reader = xmlFactory.createXMLStreamReader(new StringReader(xml));
+ reader.next();
+ return reader;
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ xmlFactory = XMLInputFactory.newInstance();
+ DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
+ docBuilder = docFactory.newDocumentBuilder();
+ Document doc = docBuilder.newDocument();
+ root = doc.createElement("value");
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/loader/ReferenceLoaderTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/loader/ReferenceLoaderTestCase.java
new file mode 100644
index 0000000000..3d4bcaf195
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/loader/ReferenceLoaderTestCase.java
@@ -0,0 +1,137 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.loader;
+
+import java.net.URI;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.osoa.sca.Constants;
+
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.model.BindingDefinition;
+import org.apache.tuscany.spi.model.ComponentType;
+import org.apache.tuscany.spi.model.ModelObject;
+import org.apache.tuscany.spi.model.Property;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * Verifies loading of a reference definition from an XML-based assembly
+ *
+ * @version $Rev$ $Date$
+ */
+public class ReferenceLoaderTestCase extends TestCase {
+ private static final QName REFERENCE = new QName(Constants.SCA_NS, "reference");
+ private static final String COMPONENT_NAME = "sca://someComponent";
+ private URI componentId;
+ private ReferenceLoader loader;
+ private XMLStreamReader mockReader;
+ private LoaderRegistry mockRegistry;
+ private DeploymentContext ctx;
+
+ public void testWithNoInterface() throws LoaderException, XMLStreamException {
+ String name = "referenceDefinition";
+ EasyMock.expect(mockReader.getName()).andReturn(REFERENCE).anyTimes();
+ EasyMock.expect(mockReader.getAttributeValue(null, "name")).andReturn(name);
+ EasyMock.expect(mockReader.getAttributeValue(null, "multiplicity")).andReturn("0..1");
+ EasyMock.expect(mockReader.next()).andReturn(XMLStreamConstants.END_ELEMENT);
+ EasyMock.expect(mockReader.getName()).andReturn(REFERENCE).anyTimes();
+ EasyMock.replay(mockReader);
+ ReferenceDefinition referenceDefinition = loader.load(null, mockReader, ctx);
+ assertNotNull(referenceDefinition);
+ assertEquals(COMPONENT_NAME + "#" + name, referenceDefinition.getUri().toString());
+ }
+
+ public void testComponentTypeService() throws LoaderException, XMLStreamException {
+ String name = "reference";
+ EasyMock.expect(mockReader.getName()).andReturn(REFERENCE).anyTimes();
+ EasyMock.expect(mockReader.getAttributeValue(null, "name")).andReturn(name);
+ EasyMock.expect(mockReader.getAttributeValue(null, "multiplicity")).andReturn("0..1");
+ EasyMock.expect(mockReader.next()).andReturn(XMLStreamConstants.END_ELEMENT);
+ EasyMock.expect(mockReader.getName()).andReturn(REFERENCE).anyTimes();
+ EasyMock.replay(mockReader);
+ ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>> type =
+ new ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>>();
+ ReferenceDefinition referenceDefinition = loader.load(type, mockReader, ctx);
+ assertTrue(ReferenceDefinition.class.equals(referenceDefinition.getClass()));
+ }
+
+ public void testMultipleBindings() throws LoaderException, XMLStreamException {
+ String name = "referenceDefinition";
+ EasyMock.expect(mockReader.getName()).andReturn(REFERENCE).anyTimes();
+ EasyMock.expect(mockReader.getAttributeValue(null, "name")).andReturn(name);
+ EasyMock.expect(mockReader.getAttributeValue(null, "multiplicity")).andReturn("0..1");
+ EasyMock.expect(mockReader.next()).andReturn(XMLStreamConstants.START_ELEMENT).times(2);
+ EasyMock.expect(mockReader.next()).andReturn(XMLStreamConstants.END_ELEMENT);
+ EasyMock.expect(mockReader.getName()).andReturn(REFERENCE).anyTimes();
+ EasyMock.replay(mockReader);
+
+ BindingDefinition binding = new BindingDefinition() {
+ };
+ EasyMock.expect(mockRegistry.load(
+ (ModelObject) EasyMock.isNull(),
+ EasyMock.eq(mockReader),
+ EasyMock.isA(DeploymentContext.class)))
+ .andReturn(binding).times(2);
+ EasyMock.replay(mockRegistry);
+
+ ReferenceDefinition referenceDefinition = loader.load(null, mockReader, ctx);
+ assertEquals(2, referenceDefinition.getBindings().size());
+ }
+
+ public void testWithInterface() throws LoaderException, XMLStreamException {
+ String name = "referenceDefinition";
+ ServiceContract sc = new ServiceContract() {
+ };
+ EasyMock.expect(mockReader.getName()).andReturn(REFERENCE).anyTimes();
+ EasyMock.expect(mockReader.getAttributeValue(null, "name")).andReturn(name);
+ EasyMock.expect(mockReader.getAttributeValue(null, "multiplicity")).andReturn("0..1");
+ EasyMock.expect(mockReader.next()).andReturn(XMLStreamConstants.START_ELEMENT);
+ EasyMock.expect(mockRegistry.load(null, mockReader, ctx)).andReturn(sc);
+ EasyMock.expect(mockReader.next()).andReturn(XMLStreamConstants.END_ELEMENT);
+
+ EasyMock.replay(mockReader);
+ EasyMock.replay(mockRegistry);
+
+ ReferenceDefinition referenceDefinition = loader.load(null, mockReader, ctx);
+ assertNotNull(referenceDefinition);
+ assertEquals(COMPONENT_NAME + "#" + name, referenceDefinition.getUri().toString());
+ assertSame(sc, referenceDefinition.getServiceContract());
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ componentId = URI.create(COMPONENT_NAME);
+ mockReader = EasyMock.createStrictMock(XMLStreamReader.class);
+ mockRegistry = EasyMock.createMock(LoaderRegistry.class);
+ loader = new ReferenceLoader(mockRegistry);
+ ctx = EasyMock.createMock(DeploymentContext.class);
+ EasyMock.expect(ctx.getComponentId()).andReturn(componentId);
+ EasyMock.replay(ctx);
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/loader/ServiceLoaderPromoteTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/loader/ServiceLoaderPromoteTestCase.java
new file mode 100644
index 0000000000..335d9f5aa9
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/loader/ServiceLoaderPromoteTestCase.java
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.loader;
+
+import java.net.URI;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.osoa.sca.Constants;
+
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ServiceLoaderPromoteTestCase extends TestCase {
+ private static final QName SERVICE = new QName(Constants.SCA_NS, "service");
+ private static final String COMPONENT_NAME = "sca://domain/someComponent/";
+ private URI componentId;
+ private ServiceLoader loader;
+ private XMLStreamReader mockReader;
+ private DeploymentContext ctx;
+
+ public void testReferenceNoFragment() throws LoaderException, XMLStreamException {
+ String name = "serviceDefinition";
+ EasyMock.expect(mockReader.getName()).andReturn(SERVICE);
+ EasyMock.expect(mockReader.getAttributeValue(null, "name")).andReturn(name);
+ EasyMock.expect(mockReader.getAttributeValue(null, "promote")).andReturn("target");
+ EasyMock.expect(mockReader.next()).andReturn(XMLStreamConstants.END_ELEMENT);
+ EasyMock.expect(mockReader.getName()).andReturn(SERVICE);
+ EasyMock.replay(mockReader);
+ ServiceDefinition serviceDefinition = loader.load(null, mockReader, ctx);
+ assertNotNull(serviceDefinition);
+ assertEquals(COMPONENT_NAME + "target", serviceDefinition.getTarget().toString());
+ }
+
+ public void testReferenceWithFragment() throws LoaderException, XMLStreamException {
+ String name = "serviceDefinition";
+ EasyMock.expect(mockReader.getName()).andReturn(SERVICE);
+ EasyMock.expect(mockReader.getAttributeValue(null, "name")).andReturn(name);
+ EasyMock.expect(mockReader.getAttributeValue(null, "promote")).andReturn("target/fragment");
+ EasyMock.expect(mockReader.next()).andReturn(XMLStreamConstants.END_ELEMENT);
+ EasyMock.expect(mockReader.getName()).andReturn(SERVICE);
+ EasyMock.replay(mockReader);
+ ServiceDefinition serviceDefinition = loader.load(null, mockReader, ctx);
+ assertNotNull(serviceDefinition);
+ assertEquals(COMPONENT_NAME + "target#fragment", serviceDefinition.getTarget().toString());
+ }
+
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ mockReader = EasyMock.createStrictMock(XMLStreamReader.class);
+ LoaderRegistry mockRegistry = EasyMock.createMock(LoaderRegistry.class);
+ loader = new ServiceLoader(mockRegistry);
+
+ componentId = URI.create(COMPONENT_NAME);
+ ctx = EasyMock.createMock(DeploymentContext.class);
+ EasyMock.expect(ctx.getComponentId()).andReturn(componentId);
+ EasyMock.replay(ctx);
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/loader/ServiceLoaderTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/loader/ServiceLoaderTestCase.java
new file mode 100644
index 0000000000..b7cb8161c7
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/loader/ServiceLoaderTestCase.java
@@ -0,0 +1,161 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.loader;
+
+import java.net.URI;
+import javax.xml.namespace.QName;
+import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
+import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import static org.osoa.sca.Constants.SCA_NS;
+
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.model.BindingDefinition;
+import org.apache.tuscany.spi.model.ComponentType;
+import org.apache.tuscany.spi.model.Property;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+
+/**
+ * Verifies loading of a service definition from an XML-based assembly
+ *
+ * @version $Rev$ $Date$
+ */
+public class ServiceLoaderTestCase extends TestCase {
+ private static final QName SERVICE = new QName(SCA_NS, "service");
+ //private static final QName REFERENCE = new QName(SCA_NS, "reference");
+ private static final QName INTERFACE_JAVA = new QName(SCA_NS, "interface.java");
+ private static final String PARENT_NAME = "sca://localhost/parent/";
+ private ServiceLoader loader;
+ private DeploymentContext deploymentContext;
+ private XMLStreamReader mockReader;
+ private LoaderRegistry mockRegistry;
+ private URI componentId;
+
+ public void testWithNoInterface() throws LoaderException, XMLStreamException {
+ String name = "serviceDefinition";
+ expect(mockReader.getName()).andReturn(SERVICE).anyTimes();
+ expect(mockReader.getAttributeValue(null, "name")).andReturn(name);
+ expect(mockReader.getAttributeValue(null, "promote")).andReturn(null);
+ expect(mockReader.next()).andReturn(END_ELEMENT);
+ expect(mockReader.getName()).andReturn(SERVICE).anyTimes();
+ replay(mockReader);
+ ServiceDefinition serviceDefinition = loader.load(null, mockReader, deploymentContext);
+ assertNotNull(serviceDefinition);
+ assertEquals(PARENT_NAME + "#" + name, serviceDefinition.getUri().toString());
+ }
+
+ public void testComponentTypeService() throws LoaderException, XMLStreamException {
+ String name = "service";
+ expect(mockReader.getName()).andReturn(SERVICE).anyTimes();
+ expect(mockReader.getAttributeValue(null, "name")).andReturn(name);
+ expect(mockReader.getAttributeValue(null, "promote")).andReturn(null);
+ expect(mockReader.next()).andReturn(END_ELEMENT);
+ expect(mockReader.getName()).andReturn(SERVICE).anyTimes();
+ replay(mockReader);
+ ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>> type =
+ new ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>>();
+ ServiceDefinition serviceDefinition = loader.load(type, mockReader, deploymentContext);
+ assertTrue(ServiceDefinition.class.equals(serviceDefinition.getClass()));
+ }
+
+ public void testMultipleBindings() throws LoaderException, XMLStreamException {
+ String name = "serviceDefinition";
+ expect(mockReader.getName()).andReturn(SERVICE).anyTimes();
+ expect(mockReader.getAttributeValue(null, "name")).andReturn(name);
+ expect(mockReader.getAttributeValue(null, "promote")).andReturn("component/target");
+ expect(mockReader.next()).andReturn(START_ELEMENT);
+ expect(mockReader.next()).andReturn(START_ELEMENT);
+ expect(mockReader.next()).andReturn(END_ELEMENT);
+ expect(mockReader.getName()).andReturn(SERVICE).anyTimes();
+ replay(mockReader);
+
+ BindingDefinition binding = new BindingDefinition() {
+ };
+ expect(mockRegistry.load(null, mockReader, deploymentContext)).andReturn(binding).times(2);
+ replay(mockRegistry);
+
+ ServiceDefinition serviceDefinition = loader.load(null, mockReader, deploymentContext);
+ assertEquals(2, serviceDefinition.getBindings().size());
+ }
+
+ public void testWithInterface() throws LoaderException, XMLStreamException {
+ String name = "serviceDefinition";
+ String target = "target";
+ ServiceContract sc = new ServiceContract() {
+ };
+ expect(mockReader.getName()).andReturn(SERVICE).anyTimes();
+ expect(mockReader.getAttributeValue(null, "name")).andReturn(name);
+ expect(mockReader.getAttributeValue(null, "promote")).andReturn(target);
+ expect(mockReader.next()).andReturn(START_ELEMENT);
+ expect(mockRegistry.load(null, mockReader, deploymentContext)).andReturn(sc);
+ expect(mockReader.next()).andReturn(END_ELEMENT);
+ expect(mockReader.getName()).andReturn(SERVICE);
+
+ replay(mockReader);
+ replay(mockRegistry);
+
+ ServiceDefinition serviceDefinition = loader.load(null, mockReader, deploymentContext);
+ assertNotNull(serviceDefinition);
+ assertEquals(PARENT_NAME + "#" + name, serviceDefinition.getUri().toString());
+ assertSame(sc, serviceDefinition.getServiceContract());
+ }
+
+ public void testWithNoReference() throws LoaderException, XMLStreamException {
+ String name = "serviceDefinition";
+ ServiceContract sc = new ServiceContract() {
+ };
+ expect(mockReader.getName()).andReturn(SERVICE).anyTimes();
+ expect(mockReader.getAttributeValue(null, "name")).andReturn(name);
+ expect(mockReader.getAttributeValue(null, "promote")).andReturn(null);
+ expect(mockReader.next()).andReturn(START_ELEMENT);
+ expect(mockRegistry.load(null, mockReader, deploymentContext)).andReturn(sc);
+ expect(mockReader.next()).andReturn(END_ELEMENT);
+ expect(mockReader.getName()).andReturn(SERVICE);
+
+ replay(mockReader);
+ replay(mockRegistry);
+
+ ServiceDefinition serviceDefinition = loader.load(null, mockReader, deploymentContext);
+ assertNotNull(serviceDefinition);
+ assertEquals(PARENT_NAME + "#" + name, serviceDefinition.getUri().toString());
+ assertSame(sc, serviceDefinition.getServiceContract());
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ mockReader = EasyMock.createStrictMock(XMLStreamReader.class);
+ mockRegistry = EasyMock.createMock(LoaderRegistry.class);
+ loader = new ServiceLoader(mockRegistry);
+ componentId = URI.create(PARENT_NAME);
+ deploymentContext = EasyMock.createMock(DeploymentContext.class);
+ EasyMock.expect(deploymentContext.getComponentId()).andReturn(componentId);
+ EasyMock.replay(deploymentContext);
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/loader/StAXLoaderRegistryImplTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/loader/StAXLoaderRegistryImplTestCase.java
new file mode 100644
index 0000000000..b98051f3f8
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/loader/StAXLoaderRegistryImplTestCase.java
@@ -0,0 +1,131 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.loader;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.StAXElementLoader;
+import org.apache.tuscany.spi.loader.UnrecognizedElementException;
+import org.apache.tuscany.spi.model.ModelObject;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.deployer.RootDeploymentContext;
+import static org.easymock.EasyMock.isNull;
+import org.easymock.classextension.EasyMock;
+
+/**
+ * Verifies the default loader registry
+ *
+ * @version $Rev$ $Date$
+ */
+public class StAXLoaderRegistryImplTestCase extends TestCase {
+ private LoaderRegistryImpl registry;
+ private QName name;
+ private LoaderRegistryImpl.Monitor mockMonitor;
+ private StAXElementLoader<ModelObject> mockLoader;
+ private XMLStreamReader mockReader;
+ private DeploymentContext deploymentContext;
+ private ModelObject modelObject;
+
+ public void testLoaderRegistration() {
+ mockMonitor.registeringLoader(EasyMock.eq(name));
+ EasyMock.replay(mockMonitor);
+ registry.registerLoader(name, mockLoader);
+ EasyMock.verify(mockMonitor);
+ }
+
+ public void testLoaderUnregistration() {
+ mockMonitor.unregisteringLoader(EasyMock.eq(name));
+ EasyMock.replay(mockMonitor);
+ registry.unregisterLoader(name, (StAXElementLoader<ModelObject>) mockLoader);
+ EasyMock.verify(mockMonitor);
+ }
+
+ public void testSuccessfulDispatch() throws LoaderException, XMLStreamException {
+ EasyMock.expect(mockReader.getName()).andReturn(name);
+ EasyMock.replay(mockReader);
+ mockMonitor.registeringLoader(EasyMock.eq(name));
+ mockMonitor.elementLoad(EasyMock.eq(name));
+ EasyMock.replay(mockMonitor);
+ EasyMock.expect(mockLoader.load(
+ (ModelObject) isNull(),
+ EasyMock.eq(mockReader),
+ EasyMock.eq(deploymentContext))).andReturn(modelObject);
+ EasyMock.replay(mockLoader);
+ registry.registerLoader(name, (StAXElementLoader<ModelObject>) mockLoader);
+ Component parent = EasyMock.createNiceMock(Component.class);
+ assertSame(modelObject, registry.load(null, mockReader, deploymentContext));
+ EasyMock.verify(mockLoader);
+ EasyMock.verify(mockMonitor);
+ EasyMock.verify(mockReader);
+
+ }
+
+ public void testUnsuccessfulDispatch() throws LoaderException, XMLStreamException {
+ EasyMock.expect(mockReader.getName()).andReturn(name);
+ EasyMock.replay(mockReader);
+ mockMonitor.elementLoad(EasyMock.eq(name));
+ EasyMock.replay(mockMonitor);
+ try {
+ registry.load(null, mockReader, deploymentContext);
+ fail();
+ } catch (UnrecognizedElementException e) {
+ assertSame(name, e.getElement());
+ }
+ EasyMock.verify(mockReader);
+ EasyMock.verify(mockMonitor);
+ }
+
+ public void testPregivenModelObject() throws Exception {
+ EasyMock.expect(mockReader.getName()).andReturn(name);
+ EasyMock.replay(mockReader);
+ mockMonitor.registeringLoader(EasyMock.eq(name));
+ mockMonitor.elementLoad(EasyMock.eq(name));
+ EasyMock.replay(mockMonitor);
+ EasyMock.expect(mockLoader.load(
+ EasyMock.eq(modelObject),
+ EasyMock.eq(mockReader),
+ EasyMock.eq(deploymentContext))).andReturn(modelObject);
+ EasyMock.replay(mockLoader);
+ registry.registerLoader(name, (StAXElementLoader<ModelObject>) mockLoader);
+ Component parent = EasyMock.createNiceMock(Component.class);
+ assertSame(modelObject, registry.load(modelObject, mockReader, deploymentContext));
+ EasyMock.verify(mockLoader);
+ }
+
+ @SuppressWarnings("unchecked")
+ protected void setUp() throws Exception {
+ super.setUp();
+ name = new QName("http://mock", "test");
+ deploymentContext = new RootDeploymentContext(null, null, null, null, null, false);
+ mockMonitor = EasyMock.createMock(LoaderRegistryImpl.Monitor.class);
+ registry = new LoaderRegistryImpl(mockMonitor);
+
+ mockLoader = EasyMock.createMock(StAXElementLoader.class);
+ mockReader = EasyMock.createMock(XMLStreamReader.class);
+ modelObject = new ModelObject() {
+ };
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/loader/StringParserPropertyFactoryTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/loader/StringParserPropertyFactoryTestCase.java
new file mode 100644
index 0000000000..4445dfad2c
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/loader/StringParserPropertyFactoryTestCase.java
@@ -0,0 +1,128 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.loader;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import org.apache.tuscany.spi.ObjectFactory;
+import org.apache.tuscany.spi.model.Property;
+import org.apache.tuscany.spi.model.PropertyValue;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class StringParserPropertyFactoryTestCase extends TestCase {
+
+ private <T> PropertyValue<T> mock(String value) {
+ Document document = EasyMock.createMock(Document.class);
+ Element element = EasyMock.createMock(Element.class);
+ EasyMock.expect(document.getDocumentElement()).andReturn(element);
+ EasyMock.expect(element.getTextContent()).andReturn(value);
+ EasyMock.replay(document, element);
+ return new PropertyValue<T>(null, document);
+ }
+
+ public void testInteger() throws Exception {
+
+ StringParserPropertyFactory factory = new StringParserPropertyFactory();
+ Property<Integer> property = new Property<Integer>();
+ property.setJavaType(Integer.class);
+ PropertyValue<Integer> propertyValue = mock("1");
+ ObjectFactory<Integer> oFactory = factory.createObjectFactory(property, propertyValue);
+ assertEquals(1, oFactory.getInstance().intValue());
+ }
+
+ public void testPrimitiveInt() throws Exception {
+ StringParserPropertyFactory factory = new StringParserPropertyFactory();
+ Property<Integer> property = new Property<Integer>();
+ property.setJavaType(Integer.TYPE);
+ PropertyValue<Integer> propertyValue = mock("1");
+ ObjectFactory<Integer> oFactory = factory.createObjectFactory(property, propertyValue);
+ assertEquals(1, oFactory.getInstance().intValue());
+ }
+
+ public void testString() throws Exception {
+ StringParserPropertyFactory factory = new StringParserPropertyFactory();
+ Property<String> property = new Property<String>();
+ property.setJavaType(String.class);
+ PropertyValue<String> propertyValue = mock("1");
+ ObjectFactory<String> oFactory = factory.createObjectFactory(property, propertyValue);
+ assertEquals("1", oFactory.getInstance());
+ }
+
+ public void testByteArray() throws Exception {
+ StringParserPropertyFactory factory = new StringParserPropertyFactory();
+ Property<byte[]> property = new Property<byte[]>();
+ property.setJavaType(byte[].class);
+ PropertyValue<byte[]> propertyValue = mock("1");
+ ObjectFactory<byte[]> oFactory = factory.createObjectFactory(property, propertyValue);
+ byte[] result = oFactory.getInstance();
+ byte[] expected = "1".getBytes();
+ for (int i = 0; i < result.length; i++) {
+ byte b = result[i];
+ if (b != expected[i]) {
+ fail();
+ }
+ }
+ }
+
+ public void testBoolean() throws Exception {
+ StringParserPropertyFactory factory = new StringParserPropertyFactory();
+ Property<Boolean> property = new Property<Boolean>();
+ property.setJavaType(Boolean.class);
+ PropertyValue<Boolean> propertyValue = mock("true");
+ ObjectFactory<Boolean> oFactory = factory.createObjectFactory(property, propertyValue);
+ assertTrue(oFactory.getInstance());
+ }
+
+ public void testPrimitiveBoolean() throws Exception {
+ StringParserPropertyFactory factory = new StringParserPropertyFactory();
+ Property<Boolean> property = new Property<Boolean>();
+ property.setJavaType(Boolean.TYPE);
+ PropertyValue<Boolean> propertyValue = mock("true");
+ ObjectFactory<Boolean> oFactory = factory.createObjectFactory(property, propertyValue);
+ assertTrue(oFactory.getInstance());
+ }
+
+ public void testStringConstructor() throws Exception {
+ StringParserPropertyFactory factory = new StringParserPropertyFactory();
+ Property<Foo> property = new Property<Foo>();
+ property.setJavaType(Foo.class);
+ PropertyValue<Foo> propertyValue = mock("test");
+ ObjectFactory<Foo> oFactory = factory.createObjectFactory(property, propertyValue);
+ assertEquals("test", oFactory.getInstance().getFoo());
+ }
+
+ private static class Foo {
+ private String foo;
+
+ public Foo(String foo) {
+ this.foo = foo;
+ }
+
+ public String getFoo() {
+ return foo;
+ }
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/loader/WireLoaderTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/loader/WireLoaderTestCase.java
new file mode 100644
index 0000000000..75e455d5a8
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/loader/WireLoaderTestCase.java
@@ -0,0 +1,181 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.loader;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.Location;
+import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
+import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import static org.osoa.sca.Constants.SCA_NS;
+
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.loader.InvalidWireException;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.model.WireDefinition;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+
+/**
+ * @version $Rev: 471504 $ $Date: 2006-11-06 01:10:40 +0530 (Mon, 06 Nov 2006) $
+ */
+public class WireLoaderTestCase extends TestCase {
+ private static final QName WIRE = new QName(SCA_NS, "wire");
+ private static final QName SOURCE_URI = new QName(SCA_NS, "source.uri");
+ private static final QName TARGET_URI = new QName(SCA_NS, "target.uri");
+
+ private LoaderRegistry registry;
+ private WireLoader loader;
+ private XMLStreamReader reader;
+ private DeploymentContext context;
+ private Component composite;
+
+ public void testValidWire() throws LoaderException, XMLStreamException {
+ expect(reader.getName()).andReturn(WIRE);
+ expect(reader.next()).andReturn(START_ELEMENT);
+ expect(reader.getName()).andReturn(SOURCE_URI).times(1);
+ expect(reader.getElementText()).andReturn("source").times(1);
+ expect(reader.next()).andReturn(END_ELEMENT);
+ expect(reader.next()).andReturn(START_ELEMENT);
+ expect(reader.getName()).andReturn(TARGET_URI).times(2);
+ expect(reader.getElementText()).andReturn("target").times(1);
+ expect(reader.next()).andReturn(END_ELEMENT);
+ expect(reader.next()).andReturn(END_ELEMENT);
+ expect(reader.getName()).andReturn(WIRE).anyTimes();
+ replay(registry, reader, context);
+ WireDefinition wireDef = loader.load(null, reader, context);
+ assertNotNull(wireDef);
+ verify(registry, reader, context);
+ }
+
+ public void testInValidWireNoSourceElement() throws LoaderException, XMLStreamException {
+ expect(reader.getName()).andReturn(WIRE).times(1);
+ expect(reader.next()).andReturn(START_ELEMENT);
+ expect(reader.getName()).andReturn(TARGET_URI).times(2);
+ expect(reader.getElementText()).andReturn("target").times(1);
+ expect(reader.next()).andReturn(END_ELEMENT);
+ expect(reader.next()).andReturn(END_ELEMENT);
+ expect(reader.getName()).andReturn(WIRE).anyTimes();
+ replay(registry, reader, context);
+ try {
+ loader.load(null, reader, context);
+ fail();
+ } catch (InvalidWireException e) {
+ //expected behaviour
+ }
+ verify(registry, reader, context);
+ }
+
+ public void testInValidWireNoTargetElement() throws LoaderException, XMLStreamException {
+ expect(reader.getName()).andReturn(WIRE).times(1);
+ expect(reader.next()).andReturn(START_ELEMENT);
+ expect(reader.getName()).andReturn(SOURCE_URI).times(1);
+ expect(reader.getElementText()).andReturn("source").times(1);
+ expect(reader.next()).andReturn(END_ELEMENT);
+ expect(reader.next()).andReturn(END_ELEMENT);
+ expect(reader.getName()).andReturn(WIRE).anyTimes();
+ replay(registry, reader, context);
+ try {
+ loader.load(null, reader, context);
+ fail();
+ } catch (InvalidWireException e) {
+ //expected behaviour
+ }
+ verify(registry, reader, context);
+ }
+
+ public void testInValidWireNoSourceSpecified() throws LoaderException, XMLStreamException {
+ expect(reader.getName()).andReturn(WIRE).times(1);
+ expect(reader.next()).andReturn(START_ELEMENT);
+ expect(reader.getName()).andReturn(SOURCE_URI).times(1);
+ expect(reader.getElementText()).andReturn("").times(1);
+ replay(registry, reader, context);
+ try {
+ loader.load(null, reader, context);
+ fail();
+ } catch (InvalidWireException e) {
+ //expected behaviour
+ }
+ verify(registry, reader, context);
+ }
+
+ public void testInValidWireNoTargetSpecified() throws LoaderException, XMLStreamException {
+ expect(reader.getName()).andReturn(WIRE).times(1);
+ expect(reader.next()).andReturn(START_ELEMENT);
+ expect(reader.getName()).andReturn(SOURCE_URI).times(1);
+ expect(reader.getElementText()).andReturn("source").times(1);
+ expect(reader.next()).andReturn(END_ELEMENT);
+ expect(reader.next()).andReturn(START_ELEMENT);
+ expect(reader.getName()).andReturn(TARGET_URI).times(2);
+ expect(reader.getElementText()).andReturn("").times(1);
+ expect(reader.getName()).andReturn(WIRE).anyTimes();
+ replay(registry, reader, context);
+ try {
+ loader.load(null, reader, context);
+ fail();
+ } catch (InvalidWireException e) {
+ //expected behaviour
+ }
+ verify(registry, reader, context);
+ }
+
+ public void testWireSourceAndTargetFragments() throws LoaderException, XMLStreamException {
+ expect(reader.getName()).andReturn(WIRE);
+ expect(reader.next()).andReturn(START_ELEMENT);
+ expect(reader.getName()).andReturn(SOURCE_URI).times(1);
+ expect(reader.getElementText()).andReturn("source/reference").times(1);
+ expect(reader.next()).andReturn(END_ELEMENT);
+ expect(reader.next()).andReturn(START_ELEMENT);
+ expect(reader.getName()).andReturn(TARGET_URI).times(2);
+ expect(reader.getElementText()).andReturn("target/service").times(1);
+ expect(reader.next()).andReturn(END_ELEMENT);
+ expect(reader.next()).andReturn(END_ELEMENT);
+ expect(reader.getName()).andReturn(WIRE).anyTimes();
+ replay(registry, reader, context);
+ WireDefinition wireDef = loader.load(null, reader, context);
+ assertNotNull(wireDef);
+ assertEquals("source", wireDef.getSource().getPath());
+ assertEquals("reference", wireDef.getSource().getFragment());
+ assertEquals("target", wireDef.getTarget().getPath());
+ assertEquals("service", wireDef.getTarget().getFragment());
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ registry = createMock(LoaderRegistry.class);
+ reader = createMock(XMLStreamReader.class);
+ Location location = EasyMock.createNiceMock(Location.class);
+ EasyMock.replay(location);
+ EasyMock.expect(reader.getLocation()).andReturn(location).anyTimes();
+ context = createMock(DeploymentContext.class);
+ composite = createMock(Component.class);
+ loader = new WireLoader(registry);
+ }
+
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/marshaller/JavaPhysicalChangeSetMarshallerTest.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/marshaller/JavaPhysicalChangeSetMarshallerTest.java
new file mode 100644
index 0000000000..3c65e231d2
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/marshaller/JavaPhysicalChangeSetMarshallerTest.java
@@ -0,0 +1,154 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.marshaller;
+
+import java.io.InputStream;
+import java.util.Set;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamReader;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.core.marshaller.extensions.java.JavaPhysicalComponentDefinitionMarshaller;
+import org.apache.tuscany.core.marshaller.extensions.java.JavaPhysicalReferenceDefinitionMarshaller;
+import org.apache.tuscany.core.marshaller.extensions.java.JavaPhysicalServiceDefinitionMarshaller;
+import org.apache.tuscany.core.model.physical.java.JavaPhysicalComponentDefinition;
+import org.apache.tuscany.core.model.physical.java.JavaPhysicalReferenceDefinition;
+import org.apache.tuscany.core.model.physical.java.JavaPhysicalServiceDefinition;
+import org.apache.tuscany.spi.marshaller.ModelMarshallerRegistry;
+import org.apache.tuscany.spi.model.physical.PhysicalChangeSet;
+import org.apache.tuscany.spi.model.physical.PhysicalComponentDefinition;
+import org.apache.tuscany.spi.model.physical.PhysicalOperationDefinition;
+import org.apache.tuscany.spi.model.physical.PhysicalWireDefinition;
+
+/**
+ * Test case for Java physical change set marshaller.
+ *
+ * @version $Revision$ $Date$
+ *
+ */
+public class JavaPhysicalChangeSetMarshallerTest extends TestCase {
+
+ private ModelMarshallerRegistry registry;
+
+ public JavaPhysicalChangeSetMarshallerTest(String arg0) {
+ super(arg0);
+ }
+
+ public void setUp() {
+
+ registry = new DefaultModelMarshallerRegistry();
+
+ AbstractMarshallerExtension<?>[] marshallers = new AbstractMarshallerExtension<?>[6];
+
+ marshallers[0] = new JavaPhysicalComponentDefinitionMarshaller();
+ marshallers[1] = new JavaPhysicalServiceDefinitionMarshaller();
+ marshallers[2] = new JavaPhysicalReferenceDefinitionMarshaller();
+ marshallers[3] = new PhysicalOperationDefinitionMarshaller();
+ marshallers[4] = new PhysicalWireDefinitionMarshaller();
+ marshallers[5] = new PhysicalChangeSetMarshaller();
+
+ for (int i = 0; i < 6; i++) {
+ marshallers[i].setRegistry(registry);
+ }
+
+ }
+
+ public void testUnmarshall() throws Exception {
+
+ ClassLoader cl = getClass().getClassLoader();
+ InputStream inputStream = cl.getResourceAsStream("marshall/javaChangeSet.xml");
+ XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(inputStream);
+
+ reader.next();
+ PhysicalChangeSet changeSet = (PhysicalChangeSet)registry.unmarshall(reader);
+ assertNotNull(changeSet);
+ Set<? extends PhysicalComponentDefinition> pcds = changeSet.getComponentDefinitions();
+ assertEquals(2, pcds.size());
+ for (PhysicalComponentDefinition pcd : pcds) {
+
+ assertTrue(pcd instanceof JavaPhysicalComponentDefinition);
+ String componentId = pcd.getComponentId().toString();
+ assertTrue("cmp1".equals(componentId) || "cmp2".equals(componentId));
+
+ JavaPhysicalComponentDefinition jpcd = (JavaPhysicalComponentDefinition)pcd;
+
+ Set<JavaPhysicalReferenceDefinition> refs = jpcd.getReferences();
+ assertEquals(1, refs.size());
+ JavaPhysicalReferenceDefinition ref = refs.iterator().next();
+ if ("cmp1".equals(componentId)) {
+ assertEquals("rf1", ref.getName());
+ Set<PhysicalOperationDefinition> pods = ref.getOperations();
+ assertEquals(1, pods.size());
+ PhysicalOperationDefinition pod = pods.iterator().next();
+ assertEquals("op2", pod.getName());
+ } else {
+ assertEquals("rf2", ref.getName());
+ Set<PhysicalOperationDefinition> pods = ref.getOperations();
+ assertEquals(1, pods.size());
+ PhysicalOperationDefinition pod = pods.iterator().next();
+ assertEquals("op1", pod.getName());
+ }
+
+ Set<JavaPhysicalServiceDefinition> svs = jpcd.getServices();
+ assertEquals(1, svs.size());
+ JavaPhysicalServiceDefinition sv = svs.iterator().next();
+ if ("cmp1".equals(componentId)) {
+ assertEquals("sv1", sv.getName());
+ Set<PhysicalOperationDefinition> pods = sv.getOperations();
+ assertEquals(1, pods.size());
+ PhysicalOperationDefinition pod = pods.iterator().next();
+ assertEquals("op1", pod.getName());
+ } else {
+ assertEquals("sv2", sv.getName());
+ Set<PhysicalOperationDefinition> pods = sv.getOperations();
+ assertEquals(1, pods.size());
+ PhysicalOperationDefinition pod = pods.iterator().next();
+ assertEquals("op2", pod.getName());
+ }
+
+ }
+
+ Set<PhysicalWireDefinition> pwds = changeSet.getWireDefinitions();
+
+ assertEquals(2, changeSet.getWireDefinitions().size());
+ for (PhysicalWireDefinition pwd : pwds) {
+
+ String sourceUri = pwd.getSourceUri().toString();
+ String targetUri = pwd.getTargetUri().toString();
+
+ assertTrue(("cmp1#rf1".equals(sourceUri) && "cmp2#sv2".equals(targetUri))
+ || ("cmp2#rf2".equals(sourceUri) && "cmp1#sv1"
+ .equals(targetUri)));
+
+ Set<PhysicalOperationDefinition> pods = pwd.getOperations();
+ assertEquals(1, pods.size());
+ PhysicalOperationDefinition pod = pods.iterator().next();
+
+ if (sourceUri.equals("cmp1#rf1")) {
+ assertEquals("op2", pod.getName());
+ } else {
+ assertEquals("op1", pod.getName());
+ }
+ }
+
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/binding/MockServiceBinding.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/binding/MockServiceBinding.java
new file mode 100644
index 0000000000..5fc4f84d90
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/binding/MockServiceBinding.java
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.mock.binding;
+
+import java.net.URI;
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.spi.component.AbstractSCAObject;
+import org.apache.tuscany.spi.component.ServiceBinding;
+import org.apache.tuscany.spi.component.TargetInvokerCreationException;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+import org.apache.tuscany.spi.wire.Wire;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class MockServiceBinding extends AbstractSCAObject implements ServiceBinding {
+ private Wire wire;
+
+ public MockServiceBinding(URI uri) {
+ super(uri);
+ }
+
+ public QName getBindingType() {
+ return null;
+ }
+
+ public ServiceContract<?> getBindingServiceContract() {
+ return null;
+ }
+
+ public Wire getWire() {
+ return wire;
+ }
+
+ public void setWire(Wire wire) {
+ this.wire = wire;
+ }
+
+ public TargetInvoker createTargetInvoker(String targetName, Operation operation)
+ throws TargetInvokerCreationException {
+ return null;
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/AsyncTarget.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/AsyncTarget.java
new file mode 100644
index 0000000000..653d5d7335
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/AsyncTarget.java
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.mock.component;
+
+import org.osoa.sca.annotations.OneWay;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public interface AsyncTarget {
+ @OneWay
+ void invoke();
+
+ int getCount();
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/BadContextPojo.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/BadContextPojo.java
new file mode 100644
index 0000000000..066acc346d
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/BadContextPojo.java
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.mock.component;
+
+import org.osoa.sca.annotations.Context;
+
+public class BadContextPojo {
+
+ @Context
+ String context;
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/BadNamePojo.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/BadNamePojo.java
new file mode 100644
index 0000000000..77ec37f9e4
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/BadNamePojo.java
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.mock.component;
+
+import org.osoa.sca.annotations.ComponentName;
+
+public class BadNamePojo {
+ @ComponentName
+ private int name;
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/BasicInterface.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/BasicInterface.java
new file mode 100644
index 0000000000..b7921c248f
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/BasicInterface.java
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.mock.component;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public interface BasicInterface {
+ String returnsProperty();
+
+ BasicInterface returnsReference();
+
+ int returnsInt();
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/BasicInterfaceImpl.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/BasicInterfaceImpl.java
new file mode 100644
index 0000000000..f7d7bb38cf
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/BasicInterfaceImpl.java
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.mock.component;
+
+import org.osoa.sca.annotations.Property;
+import org.osoa.sca.annotations.Reference;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class BasicInterfaceImpl implements BasicInterface {
+
+ @Property
+ public String publicProperty;
+
+ @Reference (required = false)
+ public BasicInterface publicReference;
+
+ @Property
+ protected String protectedProperty;
+
+ @Reference (required = false)
+ protected BasicInterface protectedReference;
+
+ private String privateProperty;
+
+ private BasicInterface privateReference;
+
+ @Property
+ public void setPrivateProperty(String privateProperty) {
+ this.privateProperty = privateProperty;
+ }
+
+ @Reference (required = false)
+ public void setPrivateReference(BasicInterface privateReference) {
+ this.privateReference = privateReference;
+ }
+
+ public String returnsProperty() {
+ return privateProperty;
+ }
+
+ public BasicInterface returnsReference() {
+ return privateReference;
+ }
+
+ public int returnsInt() {
+ return 0;
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeComponent.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeComponent.java
new file mode 100644
index 0000000000..88b97216cd
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeComponent.java
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.mock.component;
+
+import org.osoa.sca.annotations.Scope;
+
+/**
+ * @version $Rev$ $Date$
+ */
+@Scope("COMPOSITE")
+public interface CompositeScopeComponent {
+
+ //public boolean isInit();
+}
+
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeComponentImpl.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeComponentImpl.java
new file mode 100644
index 0000000000..93ee1f707a
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeComponentImpl.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.mock.component;
+
+import org.osoa.sca.annotations.Scope;
+
+
+/**
+ * @version $Rev$ $Date$
+ */
+@Scope("COMPOSITE")
+public class CompositeScopeComponentImpl implements
+ CompositeScopeComponent {
+
+ private String foo;
+
+ public void setFoo(String foo) {
+ this.foo = foo;
+ }
+
+ public String getFoo() {
+ return foo;
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeDestroyOnlyComponent.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeDestroyOnlyComponent.java
new file mode 100644
index 0000000000..16ce3b5569
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeDestroyOnlyComponent.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.mock.component;
+
+import org.osoa.sca.annotations.Destroy;
+
+public class CompositeScopeDestroyOnlyComponent extends CompositeScopeComponentImpl {
+
+ boolean destroyed;
+
+ public boolean isDestroyed() {
+ return destroyed;
+ }
+
+ @Destroy
+ public void destroy() {
+ destroyed = true;
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeInitDestroyComponent.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeInitDestroyComponent.java
new file mode 100644
index 0000000000..05b938a87c
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeInitDestroyComponent.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.mock.component;
+
+import org.osoa.sca.annotations.Destroy;
+
+public class CompositeScopeInitDestroyComponent extends CompositeScopeInitOnlyComponent {
+
+ boolean destroyed;
+
+ 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/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeInitOnlyComponent.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeInitOnlyComponent.java
new file mode 100644
index 0000000000..f9f80ca15c
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeInitOnlyComponent.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.mock.component;
+
+import org.osoa.sca.annotations.Init;
+
+public class CompositeScopeInitOnlyComponent extends CompositeScopeComponentImpl {
+
+ private boolean 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;
+
+ public boolean isInitialized() {
+ return initialized;
+ }
+
+ @Init
+ public void init() {
+ if (initialized) {
+ throw new AssertionError("Init called more than once");
+ }
+ initialized = true;
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeComponent.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeComponent.java
new file mode 100644
index 0000000000..c71ac0586f
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeComponent.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.mock.component;
+
+import org.osoa.sca.annotations.Scope;
+
+/**
+ * @version $Rev: 430937 $ $Date: 2006-08-11 21:17:56 -0400 (Fri, 11 Aug 2006) $
+ */
+@Scope("CONVERSATION")
+public interface ConversationalScopeComponent {
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeComponentImpl.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeComponentImpl.java
new file mode 100644
index 0000000000..5ea7278e1f
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeComponentImpl.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.mock.component;
+
+import org.osoa.sca.annotations.Scope;
+
+/**
+ * @version $Rev: 430937 $ $Date: 2006-08-11 21:17:56 -0400 (Fri, 11 Aug 2006) $
+ */
+@Scope("CONVERSATION")
+public class ConversationalScopeComponentImpl implements ConversationalScopeComponent {
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeDestroyOnlyComponent.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeDestroyOnlyComponent.java
new file mode 100644
index 0000000000..8cea9efa49
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeDestroyOnlyComponent.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.mock.component;
+
+import org.osoa.sca.annotations.Destroy;
+import org.osoa.sca.annotations.Scope;
+
+@Scope("CONVERSATION")
+public class ConversationalScopeDestroyOnlyComponent extends ConversationalScopeComponentImpl {
+
+ boolean destroyed;
+
+ public boolean isDestroyed() {
+ return destroyed;
+ }
+
+ @Destroy
+ public void destroy() {
+ destroyed = true;
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeInitDestroyComponent.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeInitDestroyComponent.java
new file mode 100644
index 0000000000..40dbfedf2c
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeInitDestroyComponent.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.mock.component;
+
+import org.osoa.sca.annotations.Destroy;
+import org.osoa.sca.annotations.Scope;
+
+@Scope("CONVERSATION")
+public class ConversationalScopeInitDestroyComponent
+ extends ConversationalScopeInitOnlyComponent {
+
+ private boolean destroyed;
+
+ public boolean isDestroyed() {
+ return destroyed;
+ }
+
+ @Destroy
+ public void destroy() {
+ destroyed = true;
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeInitOnlyComponent.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeInitOnlyComponent.java
new file mode 100644
index 0000000000..caaa0c39e7
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeInitOnlyComponent.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.mock.component;
+
+import org.osoa.sca.annotations.Init;
+import org.osoa.sca.annotations.Scope;
+
+@Scope("CONVERSATION")
+public class ConversationalScopeInitOnlyComponent
+ extends ConversationalScopeComponentImpl {
+
+ private boolean initialized;
+
+ public boolean isInitialized() {
+ return initialized;
+ }
+
+ @Init
+ public void init() {
+ initialized = true;
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/OrderException.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/OrderException.java
new file mode 100644
index 0000000000..af257c226d
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/OrderException.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.mock.component;
+
+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/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/OrderedDependentPojo.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/OrderedDependentPojo.java
new file mode 100644
index 0000000000..2033f0eca5
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/OrderedDependentPojo.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.mock.component;
+
+/**
+ * @version $$Rev$$ $$Date$$
+ */
+public interface OrderedDependentPojo extends OrderedInitPojo {
+
+ OrderedInitPojo getPojo();
+
+ void setPojo(OrderedInitPojo pojo);
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/OrderedDependentPojoImpl.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/OrderedDependentPojoImpl.java
new file mode 100644
index 0000000000..439c3d143c
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/OrderedDependentPojoImpl.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.mock.component;
+
+/**
+ * @version $$Rev$$ $$Date$$
+ */
+public class OrderedDependentPojoImpl extends OrderedInitPojoImpl implements OrderedDependentPojo {
+
+ private OrderedInitPojo pojo;
+
+ public OrderedInitPojo getPojo() {
+ return pojo;
+ }
+
+ public void setPojo(OrderedInitPojo pojo) {
+ this.pojo = pojo;
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/OrderedEagerInitPojo.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/OrderedEagerInitPojo.java
new file mode 100644
index 0000000000..1986952747
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/OrderedEagerInitPojo.java
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.mock.component;
+
+import org.osoa.sca.annotations.Destroy;
+import org.osoa.sca.annotations.Init;
+import org.osoa.sca.annotations.Scope;
+import org.osoa.sca.annotations.EagerInit;
+
+@Scope("COMPOSITE")
+@EagerInit
+public class OrderedEagerInitPojo {
+
+ private static final 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/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/OrderedInitPojo.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/OrderedInitPojo.java
new file mode 100644
index 0000000000..0b891cfa42
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/OrderedInitPojo.java
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.mock.component;
+
+/**
+ * @version $$Rev$$ $$Date$$
+ */
+public interface OrderedInitPojo {
+ int getNumberInstantiated();
+
+ int getInitOrder();
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/OrderedInitPojoImpl.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/OrderedInitPojoImpl.java
new file mode 100644
index 0000000000..a7063f6353
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/OrderedInitPojoImpl.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.mock.component;
+
+import org.osoa.sca.annotations.Destroy;
+import org.osoa.sca.annotations.Init;
+import org.osoa.sca.annotations.Scope;
+
+@Scope("COMPOSITE")
+public class OrderedInitPojoImpl implements OrderedInitPojo {
+
+ private static final Object LOCK = new Object();
+ private static int numberInstantied;
+ private int initOrder;
+
+ public OrderedInitPojoImpl() {
+ }
+
+ @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/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/OtherTarget.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/OtherTarget.java
new file mode 100644
index 0000000000..0b897daa40
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/OtherTarget.java
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.mock.component;
+
+/**
+ * Implementations are used in wiring tests
+ *
+ * @version $Rev$ $Date$
+ */
+public interface OtherTarget {
+
+ String getString();
+
+ void setString(String val);
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/OtherTargetImpl.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/OtherTargetImpl.java
new file mode 100644
index 0000000000..a3b2bbf098
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/OtherTargetImpl.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.mock.component;
+
+/**
+ * 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/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/RequestScopeComponent.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/RequestScopeComponent.java
new file mode 100644
index 0000000000..8c7dc107ee
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/RequestScopeComponent.java
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.mock.component;
+
+import org.osoa.sca.annotations.Scope;
+
+/**
+ * @version $Rev$ $Date$
+ */
+@Scope("REQUEST")
+public interface RequestScopeComponent {
+
+}
+
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/RequestScopeDestroyOnlyComponent.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/RequestScopeDestroyOnlyComponent.java
new file mode 100644
index 0000000000..5224ceda5f
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/RequestScopeDestroyOnlyComponent.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.mock.component;
+
+import org.osoa.sca.annotations.Destroy;
+import org.osoa.sca.annotations.Scope;
+
+@Scope("REQUEST")
+public class RequestScopeDestroyOnlyComponent extends SessionScopeComponentImpl {
+
+ boolean destroyed;
+
+ public boolean isDestroyed() {
+ return destroyed;
+ }
+
+ @Destroy
+ public void destroy() {
+ destroyed = true;
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/RequestScopeInitDestroyComponent.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/RequestScopeInitDestroyComponent.java
new file mode 100644
index 0000000000..38b188a4b5
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/RequestScopeInitDestroyComponent.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.mock.component;
+
+import org.osoa.sca.annotations.Destroy;
+import org.osoa.sca.annotations.Scope;
+
+@Scope("REQUEST")
+public class RequestScopeInitDestroyComponent extends SessionScopeInitOnlyComponent {
+
+ boolean destroyed;
+
+ public boolean isDestroyed() {
+ return destroyed;
+ }
+
+ @Destroy
+ public void destroy() {
+ destroyed = true;
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/RequestScopeInitOnlyComponent.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/RequestScopeInitOnlyComponent.java
new file mode 100644
index 0000000000..707f8ab50f
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/RequestScopeInitOnlyComponent.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.mock.component;
+
+import org.osoa.sca.annotations.Init;
+import org.osoa.sca.annotations.Scope;
+
+@Scope("REQUEST")
+public class RequestScopeInitOnlyComponent extends SessionScopeComponentImpl {
+
+ private boolean initialized;
+
+ public boolean isInitialized() {
+ return initialized;
+ }
+
+ @Init
+ public void init() {
+ initialized = true;
+ }
+
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/SessionScopeComponent.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/SessionScopeComponent.java
new file mode 100644
index 0000000000..827ba804f2
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/SessionScopeComponent.java
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.mock.component;
+
+import org.osoa.sca.annotations.Scope;
+
+/**
+ * @version $Rev$ $Date$
+ */
+@Scope("SESSION")
+public interface SessionScopeComponent {
+
+}
+
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/SessionScopeComponentImpl.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/SessionScopeComponentImpl.java
new file mode 100644
index 0000000000..e547bf6113
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/SessionScopeComponentImpl.java
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.mock.component;
+
+import org.osoa.sca.annotations.Scope;
+
+/**
+ * @version $Rev$ $Date$
+ */
+@Scope("SESSION")
+public class SessionScopeComponentImpl implements
+ SessionScopeComponent {
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/SessionScopeInitDestroyComponent.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/SessionScopeInitDestroyComponent.java
new file mode 100644
index 0000000000..c11bd1bd49
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/SessionScopeInitDestroyComponent.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.mock.component;
+
+import org.osoa.sca.annotations.Destroy;
+
+public class SessionScopeInitDestroyComponent extends SessionScopeInitOnlyComponent {
+
+ private boolean destroyed;
+
+ public boolean isDestroyed() {
+ return destroyed;
+ }
+
+ @Destroy
+ public void destroy() {
+ destroyed = true;
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/SessionScopeInitOnlyComponent.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/SessionScopeInitOnlyComponent.java
new file mode 100644
index 0000000000..095cc916ec
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/SessionScopeInitOnlyComponent.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.mock.component;
+
+import org.osoa.sca.annotations.Init;
+
+public class SessionScopeInitOnlyComponent extends SessionScopeComponentImpl {
+
+ private boolean initialized;
+
+ public boolean isInitialized() {
+ return initialized;
+ }
+
+ @Init
+ public void init() {
+ initialized = true;
+ }
+
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/SimpleTarget.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/SimpleTarget.java
new file mode 100644
index 0000000000..c78ba00a7a
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/SimpleTarget.java
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.mock.component;
+
+public interface SimpleTarget {
+
+ String hello(String message) throws Exception;
+
+ String goodbye(String message) throws Exception;
+
+ String echo(String message) throws Exception;
+
+}
+
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/SimpleTargetImpl.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/SimpleTargetImpl.java
new file mode 100644
index 0000000000..634a07a401
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/SimpleTargetImpl.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.mock.component;
+
+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/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/Source.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/Source.java
new file mode 100644
index 0000000000..f7969f748b
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/Source.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.mock.component;
+
+import java.util.List;
+
+/**
+ * Implementations are used in wiring tests
+ *
+ * @version $Rev$ $Date$
+ */
+public interface Source {
+
+ Target getTarget();
+
+ List<Target> getTargets();
+
+ List<Target> getTargetsThroughField();
+
+}
+
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/SourceImpl.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/SourceImpl.java
new file mode 100644
index 0000000000..187e33b2bd
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/SourceImpl.java
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.mock.component;
+
+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;
+ private Target[] targetsArray;
+
+ 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;
+ }
+
+ public Target[] getArrayOfTargets() {
+ return targetsArray;
+ }
+
+ public void setArrayOfTargets(Target[] targets) {
+ targetsArray = targets;
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/StatelessComponent.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/StatelessComponent.java
new file mode 100644
index 0000000000..c16ac942a3
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/StatelessComponent.java
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.mock.component;
+
+import org.osoa.sca.annotations.Scope;
+
+/**
+ * @version $Rev$ $Date$
+ */
+@Scope("STATELESS")
+public interface StatelessComponent {
+
+}
+
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/StatelessComponentImpl.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/StatelessComponentImpl.java
new file mode 100644
index 0000000000..64a23c12c8
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/StatelessComponentImpl.java
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.mock.component;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class StatelessComponentImpl implements
+ StatelessComponent {
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/Target.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/Target.java
new file mode 100644
index 0000000000..778c14665d
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/Target.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.mock.component;
+
+/**
+ * Implementations are used in wiring tests
+ *
+ * @version $Rev$ $Date$
+ */
+public interface Target {
+
+ String getString();
+
+ void setString(String val);
+}
+
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/TargetImpl.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/TargetImpl.java
new file mode 100644
index 0000000000..037dd3a37c
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/component/TargetImpl.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.mock.component;
+
+/**
+ * Mock system component implementation used in wiring tests
+ *
+ * @version $Rev$ $Date$
+ */
+public class TargetImpl implements Target {
+
+ private String theString;
+
+ public String getString() {
+ return theString;
+ }
+
+ public void setString(String val) {
+ theString = val;
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/wire/MockStaticInvoker.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/wire/MockStaticInvoker.java
new file mode 100644
index 0000000000..cdd0de7a6d
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/wire/MockStaticInvoker.java
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.mock.wire;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+import org.apache.tuscany.spi.wire.Interceptor;
+import org.apache.tuscany.spi.wire.InvocationRuntimeException;
+import org.apache.tuscany.spi.wire.Message;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+
+/**
+ * Caches component instances that do not need to be resolved for every wire, e.g. an wire originating from a lesser
+ * scope intended for a target with a wider scope
+ *
+ * @version $Rev$ $Date$
+ */
+public class MockStaticInvoker implements TargetInvoker {
+
+ private Object instance;
+ private Method operation;
+ private boolean cacheable;
+
+
+ public MockStaticInvoker(Method operation, Object instance) {
+ this.operation = operation;
+ this.instance = instance;
+ }
+
+ public boolean isCacheable() {
+ return cacheable;
+ }
+
+ public void setCacheable(boolean cacheable) {
+ this.cacheable = cacheable;
+ }
+
+ public boolean isOptimizable() {
+ return isCacheable();
+ }
+
+ public Object invokeTarget(final Object payload, final short sequence) throws InvocationTargetException {
+ try {
+ if (payload != null && !payload.getClass().isArray()) {
+ return operation.invoke(instance, payload);
+ } else {
+ return operation.invoke(instance, (Object[]) payload);
+ }
+ } catch (IllegalAccessException e) {
+ throw new InvocationRuntimeException(e);
+ }
+ }
+
+ public Message invoke(Message msg) throws InvocationRuntimeException {
+ try {
+ Object resp = invokeTarget(msg.getBody(), TargetInvoker.NONE);
+ msg.setBody(resp);
+ } catch (InvocationTargetException e) {
+ msg.setBodyWithFault(e.getCause());
+ } catch (Throwable e) {
+ msg.setBodyWithFault(e);
+ }
+ return msg;
+ }
+
+ public void setNext(Interceptor next) {
+ throw new IllegalStateException("This interceptor must be the last interceptor in an interceptor chain");
+ }
+
+ public Object clone() throws CloneNotSupportedException {
+ try {
+ MockStaticInvoker invoker = (MockStaticInvoker) super.clone();
+ invoker.instance = this.instance;
+ invoker.operation = this.operation;
+ return invoker;
+ } catch (CloneNotSupportedException e) {
+ return null; // will not happen
+ }
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/wire/MockSyncInterceptor.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/wire/MockSyncInterceptor.java
new file mode 100644
index 0000000000..1fe2c027ab
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/wire/MockSyncInterceptor.java
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.mock.wire;
+
+import org.apache.tuscany.spi.wire.Interceptor;
+import org.apache.tuscany.spi.wire.Message;
+
+public class MockSyncInterceptor implements Interceptor {
+
+ private int count;
+
+ private Interceptor next;
+
+ public MockSyncInterceptor() {
+ }
+
+ public Message invoke(Message msg) {
+ ++count;
+ return next.invoke(msg);
+ }
+
+ public int getCount() {
+ return count;
+ }
+
+ public void setNext(Interceptor next) {
+ this.next = next;
+ }
+
+ public Interceptor getNext() {
+ return next;
+ }
+
+ public boolean isOptimizable() {
+ return false;
+ }
+
+}
+
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/wire/MockTargetInvoker.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/wire/MockTargetInvoker.java
new file mode 100644
index 0000000000..3fcc75bdb4
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/mock/wire/MockTargetInvoker.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.mock.wire;
+
+import org.apache.tuscany.spi.wire.InvocationRuntimeException;
+import org.apache.tuscany.spi.wire.Message;
+
+import org.apache.tuscany.core.binding.local.AbstractLocalTargetInvoker;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class MockTargetInvoker extends AbstractLocalTargetInvoker {
+ public Message invoke(Message msg) throws InvocationRuntimeException {
+ return null;
+ }
+} \ No newline at end of file
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/monitor/DefaultExceptionFormatterTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/monitor/DefaultExceptionFormatterTestCase.java
new file mode 100644
index 0000000000..437e718206
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/monitor/DefaultExceptionFormatterTestCase.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.monitor;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.api.TuscanyException;
+import org.apache.tuscany.api.TuscanyRuntimeException;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class DefaultExceptionFormatterTestCase extends TestCase {
+ private DefaultExceptionFormatter formatter = new DefaultExceptionFormatter();
+
+ public void testTuscanyExceptionFormat() throws Exception {
+ StringWriter writer = new StringWriter();
+ PrintWriter pw = new PrintWriter(writer);
+ TuscanyException e = new TuscanyException("somemessage") {
+ };
+ formatter.write(pw, e);
+ assertTrue(writer.toString().indexOf("somemessage") >= 0);
+ }
+
+ public void testTuscanyRuntimeExceptionFormat() throws Exception {
+ StringWriter writer = new StringWriter();
+ PrintWriter pw = new PrintWriter(writer);
+ TuscanyRuntimeException e = new TuscanyRuntimeException("somemessage") {
+ };
+ formatter.write(pw, e);
+ assertTrue(writer.toString().indexOf("somemessage") >= 0);
+ }
+
+ public void testNormalExceptionFormat() throws Exception {
+ StringWriter writer = new StringWriter();
+ PrintWriter pw = new PrintWriter(writer);
+ Exception e = new Exception();
+ formatter.write(pw, e); // just verify there are no errors since no formatting needs to be doen
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/monitor/JavaLoggingTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/monitor/JavaLoggingTestCase.java
new file mode 100644
index 0000000000..5fdf035c7a
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/monitor/JavaLoggingTestCase.java
@@ -0,0 +1,153 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.monitor;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+import java.util.logging.Handler;
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
+import java.util.logging.Logger;
+
+import org.apache.tuscany.api.annotation.LogLevel;
+import org.apache.tuscany.host.MonitorFactory;
+
+import junit.framework.TestCase;
+
+/**
+ * Test case for the JavaLoggingMonitorFactory.
+ *
+ * @version $Rev$ $Date$
+ */
+public class JavaLoggingTestCase extends TestCase {
+ private static final Logger LOGGER = Logger.getLogger(Monitor.class.getName());
+ private static final MockHandler HANDLER = new MockHandler();
+
+ private MonitorFactory factory;
+
+ /**
+ * Smoke test to ensure the LOGGER is working.
+ */
+ public void testLogger() {
+ LOGGER.info("test");
+ assertEquals(1, HANDLER.logs.size());
+ }
+
+ /**
+ * Test that no record is logged.
+ */
+ public void testUnloggedEvent() {
+ Monitor mon = factory.getMonitor(Monitor.class);
+ mon.eventNotToLog();
+ assertEquals(0, HANDLER.logs.size());
+ }
+
+ /**
+ * Test the correct record is written for an event with no arguments.
+ */
+ public void testEventWithNoArgs() {
+ Monitor mon = factory.getMonitor(Monitor.class);
+ mon.eventWithNoArgs();
+ assertEquals(1, HANDLER.logs.size());
+ LogRecord record = HANDLER.logs.get(0);
+ assertEquals(Level.INFO, record.getLevel());
+ assertEquals(LOGGER.getName(), record.getLoggerName());
+ assertEquals(Monitor.class.getName() + "#eventWithNoArgs", record.getMessage());
+ }
+
+ /**
+ * Test the correct record is written for an event defined by annotation.
+ */
+ public void testEventWithAnnotation() {
+ Monitor mon = factory.getMonitor(Monitor.class);
+ mon.eventWithAnnotation();
+ assertEquals(1, HANDLER.logs.size());
+ LogRecord record = HANDLER.logs.get(0);
+ assertEquals(Level.INFO, record.getLevel());
+ assertEquals(LOGGER.getName(), record.getLoggerName());
+ assertEquals(Monitor.class.getName() + "#eventWithAnnotation", record.getMessage());
+ }
+
+ /**
+ * Test the argument is logged.
+ */
+ public void testEventWithOneArg() {
+ Monitor mon = factory.getMonitor(Monitor.class);
+ mon.eventWithOneArg("ARG");
+ assertEquals(1, HANDLER.logs.size());
+ LogRecord record = HANDLER.logs.get(0);
+ assertEquals(Monitor.class.getName() + "#eventWithOneArg", record.getMessage());
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ LOGGER.setUseParentHandlers(false);
+ LOGGER.addHandler(HANDLER);
+ HANDLER.flush();
+
+ String sourceClass = Monitor.class.getName();
+ Properties levels = new Properties();
+ levels.setProperty(sourceClass + "#eventWithNoArgs", "INFO");
+ levels.setProperty(sourceClass + "#eventWithOneArg", "INFO");
+ levels.setProperty(sourceClass + "#eventWithThrowable", "WARNING");
+ factory = new JavaLoggingMonitorFactory(levels, Level.FINE, "TestMessages");
+ }
+
+ protected void tearDown() throws Exception {
+ LOGGER.removeHandler(HANDLER);
+ HANDLER.flush();
+ super.tearDown();
+ }
+
+ /**
+ * Mock log HANDLER to capture records.
+ */
+ public static class MockHandler extends Handler {
+ List<LogRecord> logs = new ArrayList<LogRecord>();
+
+ public void publish(LogRecord record) {
+ logs.add(record);
+ }
+
+ public void flush() {
+ logs.clear();
+ }
+
+ public void close() throws SecurityException {
+ }
+ }
+
+ @SuppressWarnings({"JavaDoc"})
+ public static interface Monitor {
+ void eventNotToLog();
+
+ @LogLevel("INFO")
+ void eventWithNoArgs();
+
+ @LogLevel("INFO")
+ void eventWithOneArg(String msg);
+
+ @LogLevel("WARNING")
+ void eventWithThrowable(Exception e);
+
+ @LogLevel("INFO")
+ void eventWithAnnotation();
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/policy/IntentRegistryImplTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/policy/IntentRegistryImplTestCase.java
new file mode 100644
index 0000000000..de1c91b741
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/policy/IntentRegistryImplTestCase.java
@@ -0,0 +1,152 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.policy;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import javax.xml.namespace.QName;
+
+import static org.osoa.sca.Constants.SCA_NS;
+
+import org.apache.tuscany.spi.model.Intent;
+import org.apache.tuscany.spi.model.IntentName;
+import org.apache.tuscany.spi.policy.IntentRegistry;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class IntentRegistryImplTestCase extends TestCase {
+ private static final QName WS_BINDING = new QName(SCA_NS, "binding.ws");
+ private static final QName JMS_BINDING = new QName(SCA_NS, "binding.jms");
+ private IntentRegistry intentReg;
+
+ @Override
+ protected void setUp() throws Exception {
+ intentReg = new IntentRegistryImpl();
+
+ Intent bodyintent = new Intent(new IntentName("sec.confidentiality/message/body"), "test");
+ bodyintent.addAppliedArtifacts(WS_BINDING);
+ bodyintent.addAppliedArtifacts(JMS_BINDING);
+ intentReg.register(bodyintent);
+
+ Intent headintent = new Intent(new IntentName("sec.confidentiality/message/head"), "test");
+ headintent.addAppliedArtifacts(WS_BINDING);
+ headintent.addAppliedArtifacts(JMS_BINDING);
+ intentReg.register(headintent);
+
+ Intent confidentialityintent = new Intent(new IntentName("sec.confidentiality"), "test");
+ confidentialityintent.addAppliedArtifacts(WS_BINDING);
+ confidentialityintent.addAppliedArtifacts(JMS_BINDING);
+ intentReg.register(confidentialityintent);
+
+ Intent messageintent = new Intent(new IntentName("sec.confidentiality/message"), null);
+ messageintent.addAppliedArtifacts(WS_BINDING);
+ messageintent.addAppliedArtifacts(JMS_BINDING);
+ intentReg.register(messageintent);
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ intentReg = null;
+ }
+
+// public void testGetQualifiedIntent() {
+// List<IntentName> intentNameList = new ArrayList<IntentName>();
+// intentReg.get
+// //intentReg.getConcretIntents(intentNameList, artifact)
+// }
+
+ public void testGetConcretIntents() {
+ Intent messageintent = new Intent(new IntentName("sec.confidentiality/transport"), null);
+ messageintent.addAppliedArtifacts(WS_BINDING);
+ messageintent.addAppliedArtifacts(JMS_BINDING);
+ intentReg.register(messageintent);
+
+ Intent allintent = new Intent(new IntentName("sec.confidentiality/all"), null);
+ allintent.addAppliedArtifacts(WS_BINDING);
+ allintent.addRequriedIntents(new IntentName("sec.confidentiality/message"));
+ allintent.addRequriedIntents(new IntentName("sec.confidentiality/transport"));
+
+
+ intentReg.register(allintent);
+ List<IntentName> intents = new ArrayList<IntentName>();
+ intents.add(new IntentName("sec.confidentiality/all"));
+ Collection<IntentName> concreteIntents = intentReg.inlineProfileIntent(intents, WS_BINDING);
+ assertEquals(2, concreteIntents.size());
+ assertTrue(concreteIntents.contains(new IntentName("sec.confidentiality/message")));
+ assertTrue(concreteIntents.contains(new IntentName("sec.confidentiality/transport")));
+ //fail("Not yet implemented");
+ }
+
+ public void testGetQualifiedIntents() {
+ IntentName message = new IntentName("sec.confidentiality/message");
+ Collection<IntentName> qualifiedIntents = intentReg.getQualifiedIntents(message, JMS_BINDING);
+ assertEquals(2, qualifiedIntents.size());
+ assertTrue(qualifiedIntents.contains(new IntentName("sec.confidentiality/message/body")));
+ assertTrue(qualifiedIntents.contains(new IntentName("sec.confidentiality/message/head")));
+ assertFalse(qualifiedIntents.contains(new IntentName("sec.confidentiality/message")));
+ assertFalse(qualifiedIntents.contains(new IntentName("sec.confidentiality")));
+ }
+
+ public void testIsApplicable() {
+ assertTrue(intentReg.isApplicable(new IntentName("sec.confidentiality/message"), WS_BINDING));
+ assertFalse(intentReg.isApplicable(new IntentName("sec.confidentiality/transport"), WS_BINDING));
+ assertFalse(intentReg.isApplicable(new IntentName("test.confidentiality/transport"), WS_BINDING));
+ }
+
+ public void testRegister() {
+ Intent messageintent = new Intent(new IntentName("sec.confidentiality/transport"), null);
+ messageintent.addAppliedArtifacts(WS_BINDING);
+ messageintent.addAppliedArtifacts(JMS_BINDING);
+ intentReg.register(messageintent);
+ assertTrue(intentReg.isApplicable(new IntentName("sec.confidentiality/transport"), WS_BINDING));
+ assertTrue(intentReg.isApplicable(new IntentName("sec.confidentiality/transport"), JMS_BINDING));
+
+ }
+
+ public void testIsQualifiedIntent() {
+ Intent messageintent = new Intent(new IntentName("sec.confidentiality/transport"), null);
+ messageintent.addAppliedArtifacts(WS_BINDING);
+ messageintent.addAppliedArtifacts(JMS_BINDING);
+ intentReg.register(messageintent);
+ Intent allintent = new Intent(new IntentName("sec.confidentiality/all"), null);
+ allintent.addAppliedArtifacts(WS_BINDING);
+
+ assertTrue(intentReg.isQualifiedIntent(new IntentName("sec.confidentiality/transport")));
+ assertTrue(intentReg.isQualifiedIntent(new IntentName("sec.confidentiality/message/body")));
+ assertTrue(intentReg.isQualifiedIntent(new IntentName("sec.confidentiality/message/body")));
+ assertFalse(intentReg.isQualifiedIntent(new IntentName("sec.confidentiality/message")));
+ assertFalse(intentReg.isQualifiedIntent(new IntentName("sec.confidentiality")));
+ }
+
+ public void testUnRegister() {
+ Intent messageintent = new Intent(new IntentName("sec.confidentiality/transport"), null);
+ messageintent.addAppliedArtifacts(WS_BINDING);
+ messageintent.addAppliedArtifacts(JMS_BINDING);
+ intentReg.register(messageintent);
+ intentReg.unRegister(messageintent);
+ assertFalse(intentReg.isApplicable(new IntentName("sec.confidentiality/transport"), WS_BINDING));
+ assertFalse(intentReg.isApplicable(new IntentName("sec.confidentiality/transport"), JMS_BINDING));
+
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/policy/PolicyEngineImplTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/policy/PolicyEngineImplTestCase.java
new file mode 100644
index 0000000000..f6db640e2b
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/policy/PolicyEngineImplTestCase.java
@@ -0,0 +1,140 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.policy;
+
+import java.io.InputStream;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamReader;
+
+import static org.osoa.sca.Constants.SCA_NS;
+
+import org.apache.tuscany.spi.model.Intent;
+import org.apache.tuscany.spi.model.IntentName;
+import org.apache.tuscany.spi.model.PolicyModel;
+import org.apache.tuscany.spi.model.PolicySet;
+import org.apache.tuscany.spi.policy.IntentRegistry;
+import org.apache.tuscany.spi.policy.PolicyEngine;
+import org.apache.tuscany.spi.policy.PolicySetContainer;
+import org.apache.tuscany.spi.policy.SCATypeManager;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.loader.PolicySetLoader;
+
+public class PolicyEngineImplTestCase extends TestCase {
+ private static final QName POLICYSET = new QName(SCA_NS, "policySet");
+ private static final QName WS_BINDING = new QName(SCA_NS, "binding.ws");
+ private IntentRegistry intentReg;
+ private PolicyEngine policyEngine;
+
+
+ public void testgetPolicy() throws Exception {
+ Collection<PolicyModel> policies =
+ policyEngine.getPolicy(new IntentName[]{new IntentName("sec.authentication/cert")}, null, WS_BINDING);
+ assertEquals(2, policies.size());
+ policies =
+ policyEngine.getPolicy(new IntentName[]{new IntentName("sec.authentication/basic")}, null, WS_BINDING);
+ assertEquals(1, policies.size());
+
+ //test for unqualified intent with default value on intentMap
+ policies = policyEngine.getPolicy(new IntentName[]{new IntentName("sec.authentication")}, null, WS_BINDING);
+ assertEquals(2, policies.size());
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ PolicySetLoader loader = new PolicySetLoader(null);
+ XMLInputFactory factory = XMLInputFactory.newInstance();
+ InputStream resourceAsStream = this.getClass().getResourceAsStream("PolicySet.scdl");
+ XMLStreamReader reader = factory.createXMLStreamReader(resourceAsStream);
+ PolicySetContainerImpl psc = new PolicySetContainerImpl();
+ while (true) {
+ int state = reader.next();
+ if (state == XMLStreamConstants.END_DOCUMENT) {
+ break;
+ }
+ if (XMLStreamConstants.START_ELEMENT == state && reader.getName().equals(POLICYSET)) {
+ psc.addPolicySet(loader.load(null, reader, null));
+ }
+
+ }
+ resourceAsStream.close();
+ intentReg = new IntentRegistryImpl();
+ policyEngine = new PolicyEngineImpl(intentReg, psc, new SCATypeManagerImpl());
+
+ Intent bodyintent = new Intent(new IntentName("sec.confidentiality/message/body"), "test");
+ bodyintent.addAppliedArtifacts(WS_BINDING);
+ intentReg.register(bodyintent);
+
+ Intent allintent = new Intent(new IntentName("sec.confidentiality/message/all"), "test");
+ allintent.addAppliedArtifacts(WS_BINDING);
+ intentReg.register(allintent);
+
+ Intent confidentialityintent = new Intent(new IntentName("sec.confidentiality"), "test");
+ confidentialityintent.addAppliedArtifacts(WS_BINDING);
+ intentReg.register(confidentialityintent);
+
+ Intent messageintent = new Intent(new IntentName("sec.confidentiality/message"), null);
+ messageintent.addAppliedArtifacts(WS_BINDING);
+ intentReg.register(messageintent);
+
+ Intent authintent = new Intent(new IntentName("sec.authentication"), null);
+ authintent.addAppliedArtifacts(WS_BINDING);
+ intentReg.register(authintent);
+
+ Intent certintent = new Intent(new IntentName("sec.authentication/cert"), null);
+ certintent.addAppliedArtifacts(WS_BINDING);
+ intentReg.register(certintent);
+
+ Intent basicintent = new Intent(new IntentName("sec.authentication/basic"), null);
+ basicintent.addAppliedArtifacts(WS_BINDING);
+ intentReg.register(basicintent);
+
+ }
+
+ private class PolicySetContainerImpl implements PolicySetContainer {
+
+ private Map<QName, PolicySet> sets = new HashMap<QName, PolicySet>();
+
+ public Collection<PolicySet> getAllPolicySet() {
+ return sets.values();
+ }
+
+ public PolicySet getPolicySet(QName name) {
+ return sets.get(name);
+ }
+
+ public void addPolicySet(PolicySet pset) {
+ sets.put(pset.getName(), pset);
+ }
+
+ }
+
+ private class SCATypeManagerImpl implements SCATypeManager {
+
+ public boolean isTypeOf(QName subType, QName type) {
+ return subType.equals(type);
+ }
+
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/property/PropertyHelperTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/property/PropertyHelperTestCase.java
new file mode 100644
index 0000000000..4f2e2fbf42
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/property/PropertyHelperTestCase.java
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.core.property;
+
+import java.net.URL;
+import javax.xml.namespace.NamespaceContext;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.databinding.xml.String2Node;
+import org.easymock.EasyMock;
+
+/**
+ *
+ */
+public class PropertyHelperTestCase extends TestCase {
+ private static final String IPO_XML =
+ "<?xml version=\"1.0\"?>" + "<ipo:purchaseOrder"
+ + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""
+ + " xmlns:ipo=\"http://www.example.com/IPO\""
+ + " xsi:schemaLocation=\"http://www.example.com/IPO ipo.xsd\""
+ + " orderDate=\"1999-12-01\">"
+ + " <shipTo exportCode=\"1\" xsi:type=\"ipo:UKAddress\">"
+ + " <name>Helen Zoe</name>"
+ + " <street>47 Eden Street</street>"
+ + " <city>Cambridge</city>"
+ + " <postcode>CB1 1JR</postcode>"
+ + " </shipTo>"
+ + " <billTo xsi:type=\"ipo:USAddress\">"
+ + " <name>Robert Smith</name>"
+ + " <street>8 Oak Avenue</street>"
+ + " <city>Old Town</city>"
+ + " <state>PA</state>"
+ + " <zip>95819</zip>"
+ + " </billTo>"
+ + " <items>"
+ + " <item partNum=\"833-AA\">"
+ + " <productName>Lapis necklace</productName>"
+ + " <quantity>1</quantity>"
+ + " <USPrice>99.95</USPrice>"
+ + " <ipo:comment>Want this for the holidays</ipo:comment>"
+ + " <shipDate>1999-12-05</shipDate>"
+ + " </item>"
+ + " </items>"
+ + "</ipo:purchaseOrder>";
+
+ /**
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ public void testXPath() throws Exception {
+ String2Node t = new String2Node();
+ Node node = t.transform(IPO_XML, null);
+
+ Document doc = PropertyHelper.evaluate(null, node, "/ipo:purchaseOrder/billTo");
+ assertNotNull(doc);
+
+ NamespaceContext context = EasyMock.createMock(NamespaceContext.class);
+ EasyMock.expect(context.getNamespaceURI("ipo")).andReturn("http://www.example.com/IPO").anyTimes();
+ EasyMock.replay(context);
+ doc = PropertyHelper.evaluate(context, node, "/ipo:purchaseOrder/items");
+ assertNotNull(doc);
+ doc = PropertyHelper.evaluate(context, node, "/ipo:purchaseOrder/billTo");
+ assertNotNull(doc);
+ doc = PropertyHelper.evaluate(context, node, "/");
+ assertNotNull(doc);
+ doc = PropertyHelper.evaluate(context, node, "/ipo:purchaseOrder/billTo1");
+ assertNull(doc);
+ }
+
+ public void testFile() throws Exception {
+ URL url = getClass().getResource("ipo.xml");
+ Document doc = PropertyHelper.loadFromFile(url.toExternalForm(), null);
+ assertNotNull(doc);
+
+ DeploymentContext context = EasyMock.createMock(DeploymentContext.class);
+ EasyMock.expect(context.getClassLoader()).andReturn(getClass().getClassLoader());
+ EasyMock.replay(context);
+ doc = PropertyHelper.loadFromFile("org/apache/tuscany/core/property/ipo.xml", context);
+ assertNotNull(doc);
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/property/SimplePropertyObjectFactoryTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/property/SimplePropertyObjectFactoryTestCase.java
new file mode 100644
index 0000000000..9ef1faccfe
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/property/SimplePropertyObjectFactoryTestCase.java
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.property;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import org.apache.tuscany.spi.ObjectFactory;
+import org.apache.tuscany.spi.model.Property;
+import org.apache.tuscany.spi.model.PropertyValue;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class SimplePropertyObjectFactoryTestCase extends TestCase {
+
+ private <T> PropertyValue<T> mock(String value) {
+ Document document = EasyMock.createMock(Document.class);
+ Element element = EasyMock.createMock(Element.class);
+ EasyMock.expect(document.getDocumentElement()).andReturn(element);
+ EasyMock.expect(element.getTextContent()).andReturn(value);
+ EasyMock.replay(document, element);
+ return new PropertyValue<T>(null, document);
+ }
+
+ public void testInteger() throws Exception {
+
+ PropertyObjectFactoryImpl factory = new PropertyObjectFactoryImpl();
+ Property<Integer> property = new Property<Integer>();
+ property.setJavaType(Integer.class);
+ PropertyValue<Integer> propertyValue = mock("1");
+ ObjectFactory<Integer> oFactory = factory.createObjectFactory(property, propertyValue);
+ assertEquals(1, oFactory.getInstance().intValue());
+ }
+
+ public void testPrimitiveInt() throws Exception {
+ PropertyObjectFactoryImpl factory = new PropertyObjectFactoryImpl();
+ Property<Integer> property = new Property<Integer>();
+ property.setJavaType(Integer.TYPE);
+ PropertyValue<Integer> propertyValue = mock("1");
+ ObjectFactory<Integer> oFactory = factory.createObjectFactory(property, propertyValue);
+ assertEquals(1, oFactory.getInstance().intValue());
+ }
+
+ public void testString() throws Exception {
+ PropertyObjectFactoryImpl factory = new PropertyObjectFactoryImpl();
+ Property<String> property = new Property<String>();
+ property.setJavaType(String.class);
+ PropertyValue<String> propertyValue = mock("1");
+ ObjectFactory<String> oFactory = factory.createObjectFactory(property, propertyValue);
+ assertEquals("1", oFactory.getInstance());
+ }
+
+ public void testByteArray() throws Exception {
+ PropertyObjectFactoryImpl factory = new PropertyObjectFactoryImpl();
+ Property<byte[]> property = new Property<byte[]>();
+ property.setJavaType(byte[].class);
+ PropertyValue<byte[]> propertyValue = mock("TWFu"); // BASE64 for "Man"
+ ObjectFactory<byte[]> oFactory = factory.createObjectFactory(property, propertyValue);
+ byte[] result = oFactory.getInstance();
+ byte[] expected = "Man".getBytes();
+ for (int i = 0; i < result.length; i++) {
+ byte b = result[i];
+ if (b != expected[i]) {
+ fail();
+ }
+ }
+ }
+
+ public void testBoolean() throws Exception {
+ PropertyObjectFactoryImpl factory = new PropertyObjectFactoryImpl();
+ Property<Boolean> property = new Property<Boolean>();
+ property.setJavaType(Boolean.class);
+ PropertyValue<Boolean> propertyValue = mock("true");
+ ObjectFactory<Boolean> oFactory = factory.createObjectFactory(property, propertyValue);
+ assertTrue(oFactory.getInstance());
+ }
+
+ public void testPrimitiveBoolean() throws Exception {
+ PropertyObjectFactoryImpl factory = new PropertyObjectFactoryImpl();
+ Property<Boolean> property = new Property<Boolean>();
+ property.setJavaType(Boolean.TYPE);
+ PropertyValue<Boolean> propertyValue = mock("true");
+ ObjectFactory<Boolean> oFactory = factory.createObjectFactory(property, propertyValue);
+ assertTrue(oFactory.getInstance());
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/resolver/DefaultAutowireResolverTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/resolver/DefaultAutowireResolverTestCase.java
new file mode 100644
index 0000000000..6d50489f18
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/resolver/DefaultAutowireResolverTestCase.java
@@ -0,0 +1,177 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.resolver;
+
+import java.net.URI;
+
+import org.apache.tuscany.spi.model.AtomicImplementation;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.ComponentType;
+import org.apache.tuscany.spi.model.CompositeComponentType;
+import org.apache.tuscany.spi.model.CompositeImplementation;
+import org.apache.tuscany.spi.model.Property;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.ReferenceTarget;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class DefaultAutowireResolverTestCase extends TestCase {
+ private static final URI REFERENCE_URI = URI.create("source#ref");
+ private static final URI TARGET_URI = URI.create("target#service");
+ private DefaultAutowireResolver resolver;
+
+ public void testAutowireAtomicToAtomic() throws Exception {
+ ComponentDefinition<CompositeImplementation> composite = createComposite("composite");
+ CompositeComponentType<?, ?, ?> type = composite.getImplementation().getComponentType();
+ ComponentDefinition<MockAtomicImpl> source = createSourceAtomic(Foo.class);
+ type.add(source);
+ ComponentDefinition<MockAtomicImpl> target = createTargetAtomic(Foo.class);
+ type.add(target);
+ resolver.resolve(null, composite);
+ ReferenceTarget refTarget = source.getReferenceTargets().get(REFERENCE_URI.getFragment());
+ assertEquals(TARGET_URI, refTarget.getTargets().get(0));
+ }
+
+ public void testAutowireAtomicToAtomicRequiresSuperInterface() throws Exception {
+ ComponentDefinition<CompositeImplementation> composite = createComposite("composite");
+ CompositeComponentType<?, ?, ?> type = composite.getImplementation().getComponentType();
+ ComponentDefinition<MockAtomicImpl> source = createSourceAtomic(SuperFoo.class);
+ type.add(source);
+ ComponentDefinition<MockAtomicImpl> target = createTargetAtomic(Foo.class);
+ type.add(target);
+ resolver.resolve(null, composite);
+ ReferenceTarget refTarget = source.getReferenceTargets().get(REFERENCE_URI.getFragment());
+ assertEquals(TARGET_URI, refTarget.getTargets().get(0));
+ }
+
+ public void testAutowireAtomicToAtomicRequiresSubInterface() throws Exception {
+ ComponentDefinition<CompositeImplementation> composite = createComposite("composite");
+ CompositeComponentType<?, ?, ?> type = composite.getImplementation().getComponentType();
+ ComponentDefinition<MockAtomicImpl> source = createSourceAtomic(Foo.class);
+ type.add(source);
+ ComponentDefinition<MockAtomicImpl> target = createTargetAtomic(SuperFoo.class);
+ type.add(target);
+ try {
+ resolver.resolve(null, composite);
+ fail();
+ } catch (AutowireTargetNotFoundException e) {
+ // expected
+ }
+ }
+
+ public void testAutowireAtomicToAtomicIncompatibleInterfaces() throws Exception {
+ ComponentDefinition<CompositeImplementation> composite = createComposite("composite");
+ CompositeComponentType<?, ?, ?> type = composite.getImplementation().getComponentType();
+ ComponentDefinition<MockAtomicImpl> source = createSourceAtomic(Foo.class);
+ type.add(source);
+ ComponentDefinition<MockAtomicImpl> target = createTargetAtomic(String.class);
+ type.add(target);
+ try {
+ resolver.resolve(null, composite);
+ fail();
+ } catch (AutowireTargetNotFoundException e) {
+ // expected
+ }
+ }
+
+ public void testNestedAutowireAtomicToAtomic() throws Exception {
+ ComponentDefinition<CompositeImplementation> composite = createComposite("composite");
+ CompositeComponentType<?, ?, ?> type = composite.getImplementation().getComponentType();
+ ComponentDefinition<MockAtomicImpl> source = createSourceAtomic(Foo.class);
+ type.add(source);
+ ComponentDefinition<MockAtomicImpl> target = createTargetAtomic(Foo.class);
+ type.add(target);
+ ComponentDefinition<CompositeImplementation> parent = createComposite("parent");
+ parent.getImplementation().getComponentType().add(composite);
+ resolver.resolve(null, parent);
+ ReferenceTarget refTarget = source.getReferenceTargets().get(REFERENCE_URI.getFragment());
+ assertEquals(TARGET_URI, refTarget.getTargets().get(0));
+ }
+
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ resolver = new DefaultAutowireResolver();
+ }
+
+ private ComponentDefinition<CompositeImplementation> createComposite(String uri) {
+ URI parentUri = URI.create(uri);
+ CompositeComponentType<ServiceDefinition, ReferenceDefinition, Property<?>> type =
+ new CompositeComponentType<ServiceDefinition, ReferenceDefinition, Property<?>>();
+ CompositeImplementation impl = new CompositeImplementation();
+ impl.setComponentType(type);
+ return new ComponentDefinition<CompositeImplementation>(parentUri, impl);
+ }
+
+ private ComponentDefinition<MockAtomicImpl> createSourceAtomic(Class<?> requiredInterface) {
+ URI uri = URI.create("source");
+ ServiceContract contract = new ServiceContract() {
+ };
+ contract.setInterfaceClass(requiredInterface);
+ ReferenceDefinition reference = new ReferenceDefinition(URI.create("#ref"), contract);
+ reference.setRequired(true);
+ MockComponentType type = new MockComponentType();
+ type.add(reference);
+ MockAtomicImpl impl = new MockAtomicImpl();
+ impl.setComponentType(type);
+ ComponentDefinition<MockAtomicImpl> definition = new ComponentDefinition<MockAtomicImpl>(uri, impl);
+ ReferenceTarget target = new ReferenceTarget();
+ target.setReferenceName(REFERENCE_URI);
+ target.setAutowire(true);
+ definition.add(target);
+ return definition;
+ }
+
+ private ComponentDefinition<MockAtomicImpl> createTargetAtomic(Class<?> serviceInterface) {
+ URI uri = URI.create("target");
+ ServiceDefinition service = new ServiceDefinition();
+ service.setUri(URI.create("#service"));
+ ServiceContract contract = new ServiceContract() {
+ };
+ contract.setInterfaceClass(serviceInterface);
+ service.setServiceContract(contract);
+ MockComponentType type = new MockComponentType();
+ type.add(service);
+ MockAtomicImpl impl = new MockAtomicImpl();
+ impl.setComponentType(type);
+ return new ComponentDefinition<MockAtomicImpl>(uri, impl);
+ }
+
+ private class MockAtomicImpl extends AtomicImplementation<MockComponentType> {
+
+ }
+
+ private class MockComponentType extends ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>> {
+
+ }
+
+ private interface SuperFoo {
+
+ }
+
+ private interface Foo extends SuperFoo {
+
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/services/artifact/LocalMavenRepositoryTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/services/artifact/LocalMavenRepositoryTestCase.java
new file mode 100644
index 0000000000..0efecb9302
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/services/artifact/LocalMavenRepositoryTestCase.java
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.services.artifact;
+
+import java.io.File;
+import java.io.UnsupportedEncodingException;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.spi.services.artifact.Artifact;
+
+/**
+ * This testcase assumes that there is a maven repo in the default location.
+ *
+ * @version $Rev$ $Date$
+ */
+public class LocalMavenRepositoryTestCase extends TestCase {
+ private static final String VERSION = "3.8.1";
+ private LocalMavenRepository repo;
+ private Artifact artifact;
+ private String path;
+
+ public void testPathWithNoClassifier() {
+ assertEquals(path, repo.getPath(artifact));
+ }
+
+ public void testPathWithClassifier() {
+ artifact.setClassifier("x86");
+ path = "junit/junit/" + VERSION + "/junit-" + VERSION + "-x86.jar";
+ assertEquals(path, repo.getPath(artifact));
+ }
+
+ public void testArtifactFoundInRepo() throws MalformedURLException, UnsupportedEncodingException {
+ String home = System.getProperty("user.home");
+ File file = new File(home + "/.m2/repository", path);
+ repo.resolve(artifact);
+ assertEquals(file.toURI().toURL(), artifact.getUrl());
+ }
+
+ public void testArtifactNotFoundInRepo() throws MalformedURLException {
+ artifact.setClassifier("x86");
+ repo.resolve(artifact);
+ assertNull(artifact.getUrl());
+ }
+
+ public void testNonNullURLIsUnmodified() throws MalformedURLException {
+ URL url = new URL("http://www.apache.org");
+ artifact.setUrl(url);
+ repo.resolve(artifact);
+ assertSame(url, artifact.getUrl());
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ repo = new LocalMavenRepository(".m2/repository");
+
+ artifact = new Artifact();
+ artifact.setGroup("junit");
+ artifact.setName("junit");
+ artifact.setVersion(VERSION);
+ artifact.setType("jar");
+ path = "junit/junit/" + VERSION + "/junit-" + VERSION + ".jar";
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/services/deployment/AssemblyServiceImplTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/services/deployment/AssemblyServiceImplTestCase.java
new file mode 100644
index 0000000000..357eee9f93
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/services/deployment/AssemblyServiceImplTestCase.java
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.services.deployment;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.net.URLConnection;
+import java.net.URLStreamHandler;
+
+import junit.framework.TestCase;
+import org.easymock.classextension.EasyMock;
+
+import org.apache.tuscany.host.deployment.UnsupportedContentTypeException;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class AssemblyServiceImplTestCase extends TestCase {
+ private AssemblyServiceImpl service;
+
+ public void testApplyChangesWithNullURL() {
+ try {
+ service.applyChanges(null);
+ fail();
+ } catch (IllegalArgumentException e) {
+ //ok
+ } catch (Throwable t) {
+ fail();
+ }
+ }
+
+ public void testApplyChangesWhenURLContentTypeIsNull() throws Exception {
+ final URLConnection urlConnection = EasyMock.createMock(URLConnection.class);
+ EasyMock.expect(urlConnection.getContentType()).andReturn(null);
+ EasyMock.replay(urlConnection);
+ URLStreamHandler handler = new MockURLStreamHandler(urlConnection);
+
+ URL url = new URL(null, "file:/tmp/foo.xml", handler);
+ try {
+ service.applyChanges(url);
+ } catch (UnsupportedContentTypeException e) {
+ assertNull(e.getMessage());
+ assertEquals(url.toString(), e.getIdentifier());
+ EasyMock.verify(urlConnection);
+ } catch (Throwable t) {
+ fail();
+ }
+ }
+
+ public void testApplyChangesWithNullStream() {
+ try {
+ service.applyChanges(null, "xxx/xxx");
+ fail();
+ } catch (IllegalArgumentException e) {
+ //ok
+ } catch (Throwable t) {
+ fail();
+ }
+ }
+
+ public void testApplyChangesWithNullContentType() {
+ InputStream is = EasyMock.createMock(InputStream.class);
+ EasyMock.replay(is);
+ try {
+ service.applyChanges(is, null);
+ fail();
+ } catch (IllegalArgumentException e) {
+ EasyMock.verify(is);
+ } catch (Throwable t) {
+ fail();
+ }
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ service = new AssemblyServiceImpl();
+ }
+
+ private static class MockURLStreamHandler extends URLStreamHandler {
+ private final URLConnection urlConnection;
+
+ public MockURLStreamHandler(URLConnection urlConnection) {
+ this.urlConnection = urlConnection;
+ }
+
+ protected URLConnection openConnection(URL url) throws IOException {
+ return urlConnection;
+ }
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/services/deployment/ContentTypeDescriberImplTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/services/deployment/ContentTypeDescriberImplTestCase.java
new file mode 100644
index 0000000000..f163edea6d
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/services/deployment/ContentTypeDescriberImplTestCase.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.services.deployment;
+
+import java.net.URL;
+
+import junit.framework.TestCase;
+
+public class ContentTypeDescriberImplTestCase extends TestCase {
+ private ContentTypeDescriberImpl contentTypeBuilder;
+
+ public void testResolveContentType() throws Exception {
+ URL artifactURL = getClass().getResource("test.scdl");
+ assertEquals("application/v.tuscany.scdl", contentTypeBuilder.getContentType(artifactURL, null));
+ }
+
+ public void testUnknownResolveContentType() throws Exception {
+ URL artifactURL = getClass().getResource("test.ext");
+ assertNull(contentTypeBuilder.getContentType(artifactURL, null));
+ }
+
+ public void testDefaultContentType() throws Exception {
+ URL artifactURL = getClass().getResource("test.ext");
+ assertEquals("application/v.tuscany.ext", contentTypeBuilder.getContentType(artifactURL,
+ "application/v.tuscany.ext"));
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ contentTypeBuilder = new ContentTypeDescriberImpl();
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/services/deployment/ContributionRepositoryTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/services/deployment/ContributionRepositoryTestCase.java
new file mode 100644
index 0000000000..9da0e0f015
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/services/deployment/ContributionRepositoryTestCase.java
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.core.services.deployment;
+
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URL;
+
+import junit.framework.TestCase;
+
+public class ContributionRepositoryTestCase extends TestCase {
+ protected ContributionRepositoryImpl repository;
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ // create repository (this should re-create the root directory)
+ this.repository = new ContributionRepositoryImpl("target/repository");
+
+ }
+
+ public void testStore() throws Exception {
+ String resourceLocation = "/repository/sample-calculator.jar";
+ URI contribution = getClass().getResource(resourceLocation).toURI();
+ InputStream contributionStream = getClass().getResourceAsStream(resourceLocation);
+ repository.store(contribution, contributionStream);
+
+ URL contributionURL = repository.find(contribution);
+ assertNotNull(contributionURL);
+ }
+
+ public void testRemove() throws Exception {
+ String resourceLocation = "/repository/sample-calculator.jar";
+ URI contribution = getClass().getResource(resourceLocation).toURI();
+ InputStream contributionStream = getClass().getResourceAsStream(resourceLocation);
+ repository.store(contribution, contributionStream);
+
+ repository.remove(contribution);
+ URL contributionURL = repository.find(contribution);
+ assertNull(contributionURL);
+ }
+
+ public void testList() throws Exception {
+ String resourceLocation = "/repository/sample-calculator.jar";
+ URI contribution = getClass().getResource(resourceLocation).toURI();
+ InputStream contributionStream = getClass().getResourceAsStream(resourceLocation);
+ repository.store(contribution, contributionStream);
+
+ assertEquals(1, repository.list().size());
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/services/deployment/ContributionServiceImplTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/services/deployment/ContributionServiceImplTestCase.java
new file mode 100644
index 0000000000..3f259fe0a3
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/services/deployment/ContributionServiceImplTestCase.java
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.core.services.deployment;
+
+import org.apache.tuscany.spi.deployer.ContentTypeDescriber;
+import org.apache.tuscany.spi.deployer.ContributionProcessorRegistry;
+import org.apache.tuscany.spi.deployer.ContributionRepository;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.host.deployment.ContributionService;
+
+/**
+ * This is more intended to be a integration test then a unit test. *
+ */
+public class ContributionServiceImplTestCase extends TestCase {
+ private static final String JAR_CONTRIBUTION = "/repository/sample-calculator.jar";
+ private ContributionRepository repository;
+ private ContentTypeDescriber contentTypeDescriber;
+ private ContributionProcessorRegistry registry;
+ private ContributionService contributionService;
+
+ protected void setUp() throws Exception {
+ super.setUp();
+
+// this.repository = new ContributionRepositoryImpl("target/repository");
+//
+// this.contentTypeDescriber = new ContentTypeDescriberImpl();
+//
+// this.registry = new ContributionProcessorRegistryImpl(contentTypeDescriber);
+//
+// JarContributionProcessor jarProcessor = new JarContributionProcessor();
+// jarProcessor.setContributionProcessorRegistry(this.registry);
+// this.registry.register(JarContributionProcessor.CONTENT_TYPE, jarProcessor);
+//
+// JavaContributionProcessor javaProcessor = new JavaContributionProcessor(null);
+// javaProcessor.setContributionProcessorRegistry(this.registry);
+// this.registry.register(JavaContributionProcessor.CONTENT_TYPE, javaProcessor);
+//
+//
+// contributionService = new ContributionServiceImpl(repository, registry);
+ }
+
+ public void testContributeURL() throws Exception {
+// URL contribution = getClass().getResource(JAR_CONTRIBUTION);
+//
+// URI contributionURI = contributionService.contribute(contribution);
+// assertNotNull(contributionURI);
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/services/deployment/contribution/FolderContributionProcessorTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/services/deployment/contribution/FolderContributionProcessorTestCase.java
new file mode 100644
index 0000000000..a6205e4b9b
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/services/deployment/contribution/FolderContributionProcessorTestCase.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.services.deployment.contribution;
+
+import java.io.File;
+
+import junit.framework.TestCase;
+
+public class FolderContributionProcessorTestCase extends TestCase {
+ private static final String DIRECTORY_CONTRIBUTION =
+ "//D:/DEV/Projects/Tuscany/source/java-sca-integration/samples/sca/calculator";
+
+ private File contributionRoot;
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ this.contributionRoot = new File(DIRECTORY_CONTRIBUTION);
+ }
+
+ public final void testProcessJarArtifacts() throws Exception {
+ // FolderContributionProcessor folderContribution = new FolderContributionProcessor();
+ // ContributionProcessorRegistry mockRegistry = EasyMock.createMock(ContributionProcessorRegistry.class);
+ // mockRegistry.register(FolderContributionProcessor.CONTENT_TYPE, folderContribution);
+ // EasyMock.expectLastCall().anyTimes();
+ // EasyMock.replay(mockRegistry);
+ // folderContribution.setContributionProcessorRegistry(mockRegistry);
+ // folderContribution.start();
+ // EasyMock.verify(mockRegistry);
+ //
+ // Contribution contribution = new Contribution(URI.create("sca://contributions/001"));
+ // contribution.setLocation(this.contributionRoot.toURL());
+ // folderContribution.processContent(contribution, contribution.getUri(), null);
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/services/deployment/contribution/JarContributionProcessorTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/services/deployment/contribution/JarContributionProcessorTestCase.java
new file mode 100644
index 0000000000..3762622425
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/services/deployment/contribution/JarContributionProcessorTestCase.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.services.deployment.contribution;
+
+import junit.framework.TestCase;
+
+public class JarContributionProcessorTestCase extends TestCase {
+ private static final String JAR_CONTRIBUTION = "/repository/sample-calculator.jar";
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ public final void testProcessJarArtifacts() throws Exception {
+ /*
+ JarContributionProcessor jarContribution = new JarContributionProcessor();
+ ContributionProcessorRegistry mockRegistry = EasyMock.createMock(ContributionProcessorRegistry.class);
+ mockRegistry.register(JarContributionProcessor.CONTENT_TYPE, jarContribution);
+ EasyMock.expectLastCall().once();
+ EasyMock.replay(mockRegistry);
+ jarContribution.setContributionProcessorRegistry(mockRegistry);
+ jarContribution.start();
+ EasyMock.verify(mockRegistry);
+ URL jarURL = getClass().getResource(JarContributionProcessorTestCase.JAR_CONTRIBUTION);
+ Contribution contribution = new Contribution(URI.create("sca://contributions/001"));
+ contribution.setLocation(jarURL);
+ jarContribution.processContent(contribution, contribution.getUri(), jarURL.openStream());
+ */
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/services/deployment/contribution/JavaContributionProcessorTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/services/deployment/contribution/JavaContributionProcessorTestCase.java
new file mode 100644
index 0000000000..89f9a20b6b
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/services/deployment/contribution/JavaContributionProcessorTestCase.java
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.services.deployment.contribution;
+
+import java.net.URL;
+import java.util.jar.JarEntry;
+import java.util.jar.JarInputStream;
+
+import org.apache.tuscany.spi.implementation.java.ImplementationProcessorService;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
+import org.apache.tuscany.core.implementation.IntrospectionRegistryImpl;
+import org.apache.tuscany.core.implementation.processor.DestroyProcessor;
+import org.apache.tuscany.core.implementation.processor.ImplementationProcessorServiceImpl;
+import org.apache.tuscany.core.implementation.processor.InitProcessor;
+import org.apache.tuscany.core.implementation.processor.PropertyProcessor;
+import org.apache.tuscany.core.implementation.processor.ReferenceProcessor;
+import org.apache.tuscany.core.implementation.processor.ResourceProcessor;
+import org.apache.tuscany.core.implementation.processor.ScopeProcessor;
+import org.apache.tuscany.core.monitor.NullMonitorFactory;
+
+public class JavaContributionProcessorTestCase extends TestCase {
+ private static final String JAR_CONTRIBUTION = "/repository/sample-calculator.jar";
+ private static final String JAVA_ARTIFACT_URL =
+ "jar:file://repository/sample-calculator.jar!/calculator/AddService.class";
+ private IntrospectionRegistryImpl registry;
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ registry = new IntrospectionRegistryImpl();
+ registry.setMonitor(new NullMonitorFactory().getMonitor(IntrospectionRegistryImpl.Monitor.class));
+ registry.registerProcessor(new DestroyProcessor());
+ registry.registerProcessor(new InitProcessor());
+ registry.registerProcessor(new ScopeProcessor());
+ JavaInterfaceProcessorRegistryImpl interfaceProcessorRegistry = new JavaInterfaceProcessorRegistryImpl();
+ ImplementationProcessorService service = new ImplementationProcessorServiceImpl(interfaceProcessorRegistry);
+ registry.registerProcessor(new PropertyProcessor(service));
+ registry.registerProcessor(new ReferenceProcessor(interfaceProcessorRegistry));
+ registry.registerProcessor(new ResourceProcessor());
+ }
+
+ protected URL getClassURL() throws Exception {
+ URL jarURL = getClass().getResource(JAR_CONTRIBUTION);
+ JarInputStream jar = new JarInputStream(getClass().getResourceAsStream(JAR_CONTRIBUTION));
+ URL rootURL = new URL("jar:" + jarURL.toString() + "!/");
+ URL classURL = null;
+
+ try {
+ while (true) {
+ JarEntry entry = jar.getNextJarEntry();
+ if (entry.getName().endsWith(".class")) {
+
+ classURL = new URL(rootURL, entry.getName());
+ break;
+ }
+ }
+ } finally {
+ jar.close();
+ }
+ return classURL;
+ }
+
+ public final void testProcessJarArtifacts() throws Exception {
+ //ContributionProcessor javaContributionProcessor = new JavaContributionProcessor(registry);
+
+ //URL jarURL = this.getClassURL();
+ //javaContributionProcessor.processContent(null, jarURL, jarURL.openStream());
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/services/host/DelegatingResourceHostRegistryTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/services/host/DelegatingResourceHostRegistryTestCase.java
new file mode 100644
index 0000000000..c3eb2fa1bf
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/services/host/DelegatingResourceHostRegistryTestCase.java
@@ -0,0 +1,147 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.services.host;
+
+import org.apache.tuscany.spi.host.ResourceHost;
+import org.apache.tuscany.spi.host.ResourceResolutionException;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class DelegatingResourceHostRegistryTestCase extends TestCase {
+
+ public void testResolveByType() throws Exception {
+ Object ret = new Object();
+ DelegatingResourceHostRegistry registry = new DelegatingResourceHostRegistry();
+ registry.registerResource(Object.class, ret);
+ assertEquals(ret, registry.resolveResource(Object.class));
+ }
+
+ public void testResolveByUri() throws Exception {
+ ResourceHost host = EasyMock.createMock(ResourceHost.class);
+ EasyMock.expect(host.resolveResource(String.class, "Foo://foo")).andReturn("result");
+ EasyMock.replay(host);
+ DelegatingResourceHostRegistry registry = new DelegatingResourceHostRegistry();
+ registry.registerResourceHost("Foo://", host);
+ assertEquals("result", registry.resolveResource(String.class, "Foo://foo"));
+ EasyMock.verify(host);
+ }
+
+ public void testResolveBySCAUri() throws Exception {
+ ResourceHost host = EasyMock.createMock(ResourceHost.class);
+ EasyMock.replay(host);
+ DelegatingResourceHostRegistry registry = new DelegatingResourceHostRegistry();
+ registry.registerResourceHost("Foo://", host);
+ Object ret = new Object();
+ registry.registerResource(Object.class, "foo", ret);
+ assertEquals(ret, registry.resolveResource(Object.class, "SCA://foo"));
+ EasyMock.verify(host);
+ }
+
+ public void testResolveByUriNotFound() throws Exception {
+ ResourceHost host = EasyMock.createMock(ResourceHost.class);
+ EasyMock.replay(host);
+ DelegatingResourceHostRegistry registry = new DelegatingResourceHostRegistry();
+ registry.registerResourceHost("Foo://", host);
+ try {
+ assertEquals("result", registry.resolveResource(String.class, "Bar://bar"));
+ fail();
+ } catch (ResourceResolutionException e) {
+ //expected
+ }
+ EasyMock.verify(host);
+ }
+
+ public void testUnregisterHost() throws Exception {
+ ResourceHost host = EasyMock.createMock(ResourceHost.class);
+ EasyMock.replay(host);
+ DelegatingResourceHostRegistry registry = new DelegatingResourceHostRegistry();
+ registry.registerResourceHost("Foo://", host);
+ registry.unregisterResourceHost("Foo://");
+ try {
+ registry.resolveResource(String.class, "Foo://foo");
+ fail();
+ } catch (ResourceResolutionException e) {
+ //expected
+ }
+ EasyMock.verify(host);
+ }
+
+ public void testUnregisterResource() throws Exception {
+ DelegatingResourceHostRegistry registry = new DelegatingResourceHostRegistry();
+ registry.registerResource(Object.class, new Object());
+ registry.unregisterResource(Object.class);
+ assertNull(registry.resolveResource(Object.class));
+ }
+
+ public void testUnregisterMappedResource() throws Exception {
+ DelegatingResourceHostRegistry registry = new DelegatingResourceHostRegistry();
+ registry.registerResource(Object.class, "foo", new Object());
+ registry.registerResource(Object.class, new Object());
+ registry.unregisterResource(Object.class);
+ assertNull(registry.resolveResource(Object.class));
+ assertNotNull(registry.resolveResource(Object.class, "foo"));
+ registry.unregisterResource(Object.class, "foo");
+ assertNull(registry.resolveResource(Object.class));
+ }
+
+ public void testReolvedByTypeToMappedResource() throws Exception {
+ DelegatingResourceHostRegistry registry = new DelegatingResourceHostRegistry();
+ registry.registerResource(Object.class, "foo", new Object());
+ assertNull(registry.resolveResource(Object.class));
+ }
+
+ public void testDelegatingResolveResource() throws Exception {
+ Object ret = new Object();
+ ResourceHost host = EasyMock.createMock(ResourceHost.class);
+ EasyMock.expect(host.resolveResource(Object.class)).andReturn(ret);
+ EasyMock.replay(host);
+ DelegatingResourceHostRegistry registry = new DelegatingResourceHostRegistry();
+ registry.registerResourceHost("Foo://", host);
+ assertEquals(ret, registry.resolveResource(Object.class));
+ EasyMock.verify(host);
+ }
+
+ public void testDelegatingResolveResourceByTypeandName() throws Exception {
+ Object ret = new Object();
+ ResourceHost host = EasyMock.createMock(ResourceHost.class);
+ EasyMock.expect(host.resolveResource(EasyMock.eq(Object.class), EasyMock.eq("Foo://bar"))).andReturn(ret);
+ EasyMock.replay(host);
+ DelegatingResourceHostRegistry registry = new DelegatingResourceHostRegistry();
+ registry.registerResourceHost("Foo://", host);
+ assertEquals(ret, registry.resolveResource(Object.class, "Foo://bar"));
+ EasyMock.verify(host);
+ }
+
+ public void testResolveLocalResourceFirst() throws Exception {
+ Object local = new Object();
+ ResourceHost host = EasyMock.createMock(ResourceHost.class);
+ EasyMock.replay(host);
+ DelegatingResourceHostRegistry registry = new DelegatingResourceHostRegistry();
+ registry.registerResourceHost("Foo://", host);
+ registry.registerResource(Object.class, local);
+ assertEquals(local, registry.resolveResource(Object.class));
+ EasyMock.verify(host);
+ }
+
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/services/store/memory/MemoryStoreTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/services/store/memory/MemoryStoreTestCase.java
new file mode 100644
index 0000000000..06ea7cf903
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/services/store/memory/MemoryStoreTestCase.java
@@ -0,0 +1,166 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.services.store.memory;
+
+import java.net.URI;
+import java.util.UUID;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.event.RuntimeEventListener;
+import org.apache.tuscany.spi.services.store.DuplicateRecordException;
+import org.apache.tuscany.spi.services.store.Store;
+import org.apache.tuscany.spi.services.store.StoreExpirationEvent;
+import org.apache.tuscany.spi.services.store.StoreMonitor;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+import org.easymock.IAnswer;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class MemoryStoreTestCase extends TestCase {
+ private StoreMonitor monitor;
+
+ public void testEviction() throws Exception {
+ MemoryStore store = new MemoryStore(monitor);
+ store.setReaperInterval(10);
+ store.init();
+ AtomicComponent component = EasyMock.createNiceMock(AtomicComponent.class);
+ EasyMock.replay(component);
+ String id = UUID.randomUUID().toString();
+ Object value = new Object();
+ store.insertRecord(component, id, value, 1);
+ Thread.sleep(100);
+ assertNull(store.readRecord(component, id));
+ store.destroy();
+ }
+
+ public void testNotifyOnEviction() throws Exception {
+ final CountDownLatch latch = new CountDownLatch(1);
+ RuntimeEventListener listener = EasyMock.createMock(RuntimeEventListener.class);
+ listener.onEvent(EasyMock.isA(StoreExpirationEvent.class));
+ org.easymock.classextension.EasyMock.expectLastCall().andStubAnswer(new IAnswer<Object>() {
+ public Object answer() throws Throwable {
+ latch.countDown();
+ return null;
+ }
+ });
+ EasyMock.replay(listener);
+ MemoryStore store = new MemoryStore(monitor);
+ store.addListener(listener);
+ store.setReaperInterval(10);
+ store.init();
+ AtomicComponent component = EasyMock.createNiceMock(AtomicComponent.class);
+ EasyMock.replay(component);
+ String id = UUID.randomUUID().toString();
+ Object value = new Object();
+ store.insertRecord(component, id, value, 1);
+ if (!latch.await(1000, TimeUnit.MILLISECONDS)) {
+ // failed to notify listener
+ fail();
+ }
+ EasyMock.verify(listener);
+ }
+
+ public void testNoEviction() throws Exception {
+ MemoryStore store = new MemoryStore(monitor);
+ store.setReaperInterval(10);
+ store.init();
+ AtomicComponent component = EasyMock.createNiceMock(AtomicComponent.class);
+ EasyMock.replay(component);
+ String id = UUID.randomUUID().toString();
+ Object value = new Object();
+ store.insertRecord(component, id, value, Store.NEVER);
+ Thread.sleep(100);
+ assertNotNull(store.readRecord(component, id));
+ store.destroy();
+ }
+
+ public void testInsertRecord() throws Exception {
+ MemoryStore store = new MemoryStore(monitor);
+ store.setReaperInterval(10);
+ store.init();
+ AtomicComponent component = EasyMock.createNiceMock(AtomicComponent.class);
+ EasyMock.replay(component);
+ String id = UUID.randomUUID().toString();
+ Object value = new Object();
+ store.insertRecord(component, id, value, Store.NEVER);
+ store.destroy();
+ }
+
+ public void testInsertAlreadyExists() throws Exception {
+ MemoryStore store = new MemoryStore(monitor);
+ store.setReaperInterval(10);
+ store.init();
+ AtomicComponent component = EasyMock.createMock(AtomicComponent.class);
+ EasyMock.expect(component.getUri()).andReturn(URI.create("component"));
+ EasyMock.replay(component);
+ String id = UUID.randomUUID().toString();
+ Object value = new Object();
+ store.insertRecord(component, id, value, Store.NEVER);
+ try {
+ store.insertRecord(component, id, value, Store.NEVER);
+ fail();
+ } catch (DuplicateRecordException e) {
+ //expected
+ }
+ store.destroy();
+ }
+
+ public void testUpdateRecord() throws Exception {
+ MemoryStore store = new MemoryStore(monitor);
+ store.setReaperInterval(10);
+ store.init();
+ AtomicComponent component = EasyMock.createNiceMock(AtomicComponent.class);
+ EasyMock.replay(component);
+ String id = UUID.randomUUID().toString();
+ Object value = new Object();
+ Object newValue = new Object();
+
+ store.insertRecord(component, id, value, Store.NEVER);
+ store.updateRecord(component, id, newValue, 1L);
+ assertEquals(newValue, store.readRecord(component, id));
+ store.destroy();
+ }
+
+ public void testDeleteRecord() throws Exception {
+ MemoryStore store = new MemoryStore(monitor);
+ store.setReaperInterval(10);
+ store.init();
+ AtomicComponent component = EasyMock.createNiceMock(AtomicComponent.class);
+ EasyMock.replay(component);
+ String id = UUID.randomUUID().toString();
+ Object value = new Object();
+
+ store.insertRecord(component, id, value, Store.NEVER);
+ store.removeRecord(component, id);
+ assertNull(store.readRecord(component, id));
+ store.destroy();
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ monitor = EasyMock.createNiceMock(StoreMonitor.class);
+ EasyMock.replay(monitor);
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/services/work/jsr237/Jsr237WorkSchedulerTest.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/services/work/jsr237/Jsr237WorkSchedulerTest.java
new file mode 100644
index 0000000000..1a5cb4ebe1
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/services/work/jsr237/Jsr237WorkSchedulerTest.java
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.services.work.jsr237;
+
+import org.apache.tuscany.spi.services.work.NotificationListener;
+import org.apache.tuscany.spi.services.work.WorkScheduler;
+
+import commonj.work.WorkManager;
+import junit.framework.TestCase;
+import org.apache.tuscany.core.services.work.jsr237.workmanager.ThreadPoolWorkManager;
+
+public class Jsr237WorkSchedulerTest extends TestCase {
+
+ /*
+ * Test method for 'org.apache.tuscany.core.services.work.jsr237.Jsr237WorkScheduler.scheduleWork(T) <T>'
+ */
+ public void testScheduleWorkT() {
+
+
+ WorkManager workManager = new ThreadPoolWorkManager(1);
+ WorkScheduler workScheduler = new Jsr237WorkScheduler(workManager);
+
+ workScheduler.scheduleWork(new MyRunnable(), new MyNotificationListener());
+
+ }
+
+ /*
+ * Test method for 'org.apache.tuscany.core.services.work.jsr237.Jsr237WorkScheduler.scheduleWork(T,
+ * NotificationListener<T>) <T>'
+ */
+ public void testScheduleWorkTNotificationListenerOfT() {
+
+ }
+
+ private class MyRunnable implements Runnable {
+ public void run() {
+ System.err.println("Test executed");
+ }
+ }
+
+ private class MyNotificationListener implements NotificationListener<MyRunnable> {
+
+ public void workAccepted(MyRunnable work) {
+ System.err.println("Work accepted");
+ }
+
+ public void workCompleted(MyRunnable work) {
+ System.err.println("Work completed");
+ }
+
+ public void workStarted(MyRunnable work) {
+ System.err.println("Work started");
+ }
+
+ public void workRejected(MyRunnable work) {
+ System.err.println("Work rejected");
+ }
+
+ public void workFailed(MyRunnable work, Throwable error) {
+ System.err.println("Work failed");
+ }
+
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/services/work/jsr237/Jsr237WorkSchedulerTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/services/work/jsr237/Jsr237WorkSchedulerTestCase.java
new file mode 100644
index 0000000000..3966f65683
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/services/work/jsr237/Jsr237WorkSchedulerTestCase.java
@@ -0,0 +1,100 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.services.work.jsr237;
+
+import org.apache.tuscany.spi.services.work.NotificationListener;
+import org.apache.tuscany.spi.services.work.WorkSchedulerException;
+
+import commonj.work.Work;
+import commonj.work.WorkItem;
+import commonj.work.WorkListener;
+import commonj.work.WorkManager;
+import commonj.work.WorkRejectedException;
+import junit.framework.TestCase;
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.isA;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class Jsr237WorkSchedulerTestCase extends TestCase {
+
+ public void testSchedule() throws Exception {
+ WorkItem item = createMock(WorkItem.class);
+ WorkManager mgr = createMock(WorkManager.class);
+ mgr.schedule(isA(Work.class));
+ expectLastCall().andReturn(item);
+ replay(mgr);
+ Jsr237WorkScheduler scheduler = new Jsr237WorkScheduler(mgr);
+ Work work = createMock(Work.class);
+ scheduler.scheduleWork(work);
+ verify(mgr);
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testListener() throws Exception {
+ WorkItem item = createMock(WorkItem.class);
+ WorkManager mgr = createMock(WorkManager.class);
+ mgr.schedule(isA(Work.class), isA(WorkListener.class));
+ expectLastCall().andReturn(item);
+ replay(mgr);
+ Jsr237WorkScheduler scheduler = new Jsr237WorkScheduler(mgr);
+ Work work = createMock(Work.class);
+ NotificationListener<Runnable> listener = createMock(NotificationListener.class);
+ scheduler.scheduleWork(work, listener);
+ verify(mgr);
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testWorkRejectedListener() throws Exception {
+ WorkManager mgr = createMock(WorkManager.class);
+ mgr.schedule(isA(Work.class), isA(WorkListener.class));
+ expectLastCall().andThrow(new WorkRejectedException());
+ replay(mgr);
+ Jsr237WorkScheduler scheduler = new Jsr237WorkScheduler(mgr);
+ Work work = createMock(Work.class);
+ NotificationListener<Runnable> listener = createMock(NotificationListener.class);
+ listener.workRejected(isA(Runnable.class));
+ expectLastCall();
+ replay(listener);
+ scheduler.scheduleWork(work, listener);
+ verify(mgr);
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testWorkRejectedNoListener() throws Exception {
+ WorkManager mgr = createMock(WorkManager.class);
+ mgr.schedule(isA(Work.class));
+ expectLastCall().andThrow(new WorkRejectedException());
+ replay(mgr);
+ Jsr237WorkScheduler scheduler = new Jsr237WorkScheduler(mgr);
+ Work work = createMock(Work.class);
+ try {
+ scheduler.scheduleWork(work);
+ fail();
+ } catch (WorkSchedulerException e) {
+ // expected
+ }
+ verify(mgr);
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/services/work/jsr237/workmanager/ThreadPoolWorkManagerTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/services/work/jsr237/workmanager/ThreadPoolWorkManagerTestCase.java
new file mode 100644
index 0000000000..33ecd66fdc
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/services/work/jsr237/workmanager/ThreadPoolWorkManagerTestCase.java
@@ -0,0 +1,132 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.services.work.jsr237.workmanager;
+
+import java.util.concurrent.CountDownLatch;
+
+import commonj.work.Work;
+import commonj.work.WorkEvent;
+import commonj.work.WorkListener;
+import junit.framework.TestCase;
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.createStrictMock;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.isA;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+import org.easymock.IAnswer;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ThreadPoolWorkManagerTestCase extends TestCase {
+
+ public void testSchedule() throws Exception {
+ final CountDownLatch latch = new CountDownLatch(1);
+ Work work = createMock(Work.class);
+ work.run();
+ expectLastCall().andStubAnswer(new IAnswer<Object>() {
+ public Object answer() throws Throwable {
+ latch.countDown();
+ return null;
+ }
+ });
+ replay(work);
+ ThreadPoolWorkManager mgr = new ThreadPoolWorkManager(1);
+ mgr.schedule(work);
+ latch.await();
+ verify(work);
+ }
+
+ public void testListener() throws Exception {
+ final CountDownLatch latch = new CountDownLatch(1);
+ WorkListener listener = createStrictMock(WorkListener.class);
+ listener.workAccepted(isA(WorkEvent.class));
+ listener.workStarted(isA(WorkEvent.class));
+ listener.workCompleted(isA(WorkEvent.class));
+ expectLastCall();
+ replay(listener);
+ Work work = createMock(Work.class);
+ work.run();
+ expectLastCall().andStubAnswer(new IAnswer<Object>() {
+ public Object answer() throws Throwable {
+ latch.countDown();
+ return null;
+ }
+ });
+ replay(work);
+ ThreadPoolWorkManager mgr = new ThreadPoolWorkManager(1);
+ mgr.schedule(work, listener);
+ latch.await();
+ verify(work);
+ }
+
+ public void testDelayListener() throws Exception {
+ final CountDownLatch latch = new CountDownLatch(1);
+ final CountDownLatch latch2 = new CountDownLatch(1);
+ WorkListener listener = createStrictMock(WorkListener.class);
+ listener.workAccepted(isA(WorkEvent.class));
+ listener.workStarted(isA(WorkEvent.class));
+ listener.workCompleted(isA(WorkEvent.class));
+ expectLastCall().andStubAnswer(new IAnswer<Object>() {
+ public Object answer() throws Throwable {
+ latch2.countDown();
+ return null;
+ }
+ });
+ replay(listener);
+ Work work = createMock(Work.class);
+ work.run();
+ expectLastCall().andStubAnswer(new IAnswer<Object>() {
+ public Object answer() throws Throwable {
+ latch.await();
+ return null;
+ }
+ });
+ replay(work);
+ ThreadPoolWorkManager mgr = new ThreadPoolWorkManager(1);
+ mgr.schedule(work, listener);
+ latch.countDown();
+ verify(work);
+ }
+
+ public void testErrorListener() throws Exception {
+ final CountDownLatch latch = new CountDownLatch(1);
+ WorkListener listener = createStrictMock(WorkListener.class);
+ listener.workAccepted(isA(WorkEvent.class));
+ listener.workStarted(isA(WorkEvent.class));
+ listener.workCompleted(isA(WorkEvent.class));
+ replay(listener);
+ Work work = createMock(Work.class);
+ work.run();
+ expectLastCall().andStubAnswer(new IAnswer<Object>() {
+ public Object answer() throws Throwable {
+ latch.countDown();
+ throw new RuntimeException();
+ }
+ });
+ replay(work);
+ ThreadPoolWorkManager mgr = new ThreadPoolWorkManager(1);
+ mgr.schedule(work, listener);
+ latch.await();
+ verify(work);
+ }
+
+}
+
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/util/Bean1.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/util/Bean1.java
new file mode 100644
index 0000000000..79fad549aa
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/util/Bean1.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.util;
+
+
+public class Bean1 extends SuperBean {
+
+ public static final int ALL_BEAN1_FIELDS = 6 + ALL_SUPER_FIELDS;
+ public static final int ALL_BEAN1_PUBLIC_PROTECTED_FIELDS = 5 + ALL_SUPER_PUBLIC_PROTECTED_FIELDS;
+ public static final int ALL_BEAN1_METHODS = 4 + ALL_SUPER_METHODS - 1;
+ public String field3;
+ protected String field2;
+ private String field1;
+
+ public void setMethod1(String param) {
+ }
+
+ public void setMethod1(int param) {
+ }
+
+ public void override(String param) throws Exception {
+ }
+
+
+ public void noOverride(String param) throws Exception {
+ }
+
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/util/Bean2.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/util/Bean2.java
new file mode 100644
index 0000000000..7f7f03da9e
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/util/Bean2.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.util;
+
+import java.util.List;
+
+import junit.framework.AssertionFailedError;
+
+public class Bean2 {
+
+ private List methodList;
+ private List fieldList;
+
+ public List getMethodList() {
+ return methodList;
+ }
+
+ public void setMethodList(List list) {
+ methodList = list;
+ }
+
+ public List getfieldList() {
+ return fieldList;
+ }
+
+ public void setfieldList(List list) {
+ throw new AssertionFailedError("setter inadvertantly called");
+ }
+
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/util/JavaIntrospectionHelperTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/util/JavaIntrospectionHelperTestCase.java
new file mode 100644
index 0000000000..797b147b54
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/util/JavaIntrospectionHelperTestCase.java
@@ -0,0 +1,180 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.util;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.mock.component.Target;
+
+public class JavaIntrospectionHelperTestCase extends TestCase {
+
+ private List testNoGenericsList;
+ private List<String> testList;
+ private Map<String, Bean1> testMap;
+ private Target[] testArray;
+ private String[] testStringArray;
+
+ public JavaIntrospectionHelperTestCase() {
+ super();
+ }
+
+ public JavaIntrospectionHelperTestCase(String arg0) {
+ super(arg0);
+ }
+
+ public void testBean1AllPublicProtectedFields() throws Exception {
+ Set<Field> beanFields = JavaIntrospectionHelper.getAllPublicAndProtectedFields(Bean1.class);
+ assertEquals(4, beanFields.size()); //Bean1.ALL_BEAN1_PUBLIC_PROTECTED_FIELDS
+ }
+
+ public void testGetSuperAllMethods() throws Exception {
+ Set<Method> superBeanMethods = JavaIntrospectionHelper.getAllUniquePublicProtectedMethods(SuperBean.class);
+ assertEquals(SuperBean.ALL_SUPER_METHODS, superBeanMethods.size());
+ }
+
+ public void testGetBean1AllMethods() throws Exception {
+ Set<Method> beanMethods = JavaIntrospectionHelper.getAllUniquePublicProtectedMethods(Bean1.class);
+ assertEquals(Bean1.ALL_BEAN1_METHODS, beanMethods.size());
+ }
+
+ public void testOverrideMethod() throws Exception {
+ Set<Method> beanFields = JavaIntrospectionHelper.getAllUniquePublicProtectedMethods(Bean1.class);
+ boolean invoked = false;
+ for (Method method : beanFields) {
+ if (method.getName().equals("override")) {
+ method.invoke(new Bean1(), "foo");
+ invoked = true;
+ }
+ }
+ if (!invoked) {
+ throw new Exception("Override never invoked");
+ }
+ }
+
+ public void testNoOverrideMethod() throws Exception {
+ Set<Method> beanFields = JavaIntrospectionHelper.getAllUniquePublicProtectedMethods(Bean1.class);
+ boolean found = false;
+ for (Method method : beanFields) {
+ if (method.getName().equals("noOverride") && method.getParameterTypes().length == 0) {
+ found = true;
+ }
+ }
+ if (!found) {
+ throw new Exception("No override not found");
+ }
+ }
+
+ public void testDefaultConstructor() throws Exception {
+ Constructor ctr = JavaIntrospectionHelper.getDefaultConstructor(Bean2.class);
+ assertEquals(ctr, Bean2.class.getConstructor());
+ assertTrue(Bean2.class == ctr.newInstance((Object[]) null).getClass());
+ }
+
+
+ public void testGetAllInterfaces() {
+ Set<Class> interfaces = JavaIntrospectionHelper.getAllInterfaces(Z.class);
+ assertEquals(2, interfaces.size());
+ assertTrue(interfaces.contains(W.class));
+ assertTrue(interfaces.contains(W2.class));
+ }
+
+
+ public void testGetAllInterfacesObject() {
+ Set<Class> interfaces = JavaIntrospectionHelper.getAllInterfaces(Object.class);
+ assertEquals(0, interfaces.size());
+ }
+
+ public void testGetAllInterfacesNoInterfaces() {
+ Set<Class> interfaces = JavaIntrospectionHelper.getAllInterfaces(NoInterface.class);
+ assertEquals(0, interfaces.size());
+ }
+
+ /**
+ * Tests generics introspection capabilities
+ */
+ public void testGenerics() throws Exception {
+
+ List classes = JavaIntrospectionHelper.getGenerics(getClass().getDeclaredField("testList").getGenericType());
+ assertEquals(1, classes.size());
+ assertEquals(String.class, classes.get(0));
+
+ classes =
+ JavaIntrospectionHelper.getGenerics(getClass().getDeclaredField("testNoGenericsList").getGenericType());
+ assertEquals(0, classes.size());
+
+ classes = JavaIntrospectionHelper.getGenerics(getClass().getDeclaredField("testMap").getGenericType());
+ assertEquals(2, classes.size());
+ assertEquals(String.class, classes.get(0));
+ assertEquals(Bean1.class, classes.get(1));
+
+ classes = JavaIntrospectionHelper
+ .getGenerics(getClass().getDeclaredMethod("fooMethod", Map.class).getGenericParameterTypes()[0]);
+ assertEquals(2, classes.size());
+ assertEquals(String.class, classes.get(0));
+ assertEquals(Bean1.class, classes.get(1));
+
+ classes = JavaIntrospectionHelper
+ .getGenerics(getClass().getDeclaredMethod("fooMethod", List.class).getGenericParameterTypes()[0]);
+ assertEquals(1, classes.size());
+ assertEquals(String.class, classes.get(0));
+
+ }
+
+ private void fooMethod(List<String> foo) {
+
+ }
+
+ private void fooMethod(Map<String, Bean1> foo) {
+
+ }
+
+ public void setTestArray(Target[] array) {
+ }
+
+ private interface W {
+
+ }
+
+ private interface W2 {
+
+ }
+
+ private class X implements W {
+
+ }
+
+ private class Y extends X implements W, W2 {
+
+ }
+
+ private class Z extends Y {
+
+ }
+
+ private class NoInterface {
+
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/util/SuperBean.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/util/SuperBean.java
new file mode 100644
index 0000000000..83aef7fb5e
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/util/SuperBean.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.util;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class SuperBean {
+
+ public static final int ALL_SUPER_FIELDS = 6;
+ public static final int ALL_SUPER_PUBLIC_PROTECTED_FIELDS = 5;
+ public static final int ALL_SUPER_METHODS = 4;
+ public String superField2;
+
+ protected String superField3;
+
+ private String superField1;
+
+ public void setSuperMethod1(String param) {
+ }
+
+ public void setSuperMethod1(int param) {
+ }
+
+ public void override(String param) throws Exception {
+ throw new Exception("Override not handled");
+ }
+
+ public void noOverride() throws Exception {
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/BasicReferenceInvocationHandlerTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/BasicReferenceInvocationHandlerTestCase.java
new file mode 100644
index 0000000000..9e6f54eea0
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/BasicReferenceInvocationHandlerTestCase.java
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.wire;
+
+import java.lang.reflect.Method;
+import java.net.URI;
+
+import org.apache.tuscany.spi.idl.java.JavaInterfaceProcessorRegistry;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.Wire;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
+import org.apache.tuscany.core.mock.component.SimpleTarget;
+import org.apache.tuscany.core.mock.component.SimpleTargetImpl;
+import org.apache.tuscany.core.mock.wire.MockStaticInvoker;
+import org.apache.tuscany.core.mock.wire.MockSyncInterceptor;
+import org.apache.tuscany.core.wire.jdk.JDKInvocationHandler;
+
+/**
+ * @version $$Rev$$ $$Date$$
+ */
+public class BasicReferenceInvocationHandlerTestCase extends TestCase {
+
+ private Method echo;
+
+ public void testInterceptorInvoke() throws Throwable {
+ JavaInterfaceProcessorRegistry registry = new JavaInterfaceProcessorRegistryImpl();
+ ServiceContract<?> contract = registry.introspect(SimpleTarget.class);
+ Operation<?> operation = contract.getOperations().get("echo");
+ MockStaticInvoker invoker = new MockStaticInvoker(echo, new SimpleTargetImpl());
+ InvocationChain chain = new InvocationChainImpl(operation);
+ MockSyncInterceptor interceptor = new MockSyncInterceptor();
+ chain.addInterceptor(interceptor);
+ chain.addInterceptor(new InvokerInterceptor());
+ chain.setTargetInvoker(invoker);
+ //chains.put(echo, chain);
+ Wire wire = new WireImpl();
+ wire.addInvocationChain(operation, chain);
+ wire.setSourceContract(contract);
+ wire.setSourceUri(URI.create("#wire"));
+ JDKInvocationHandler handler = new JDKInvocationHandler(SimpleTarget.class, wire, null);
+ assertEquals("foo", handler.invoke(null, echo, new String[]{"foo"}));
+ assertEquals(1, interceptor.getCount());
+ }
+
+ public void setUp() throws Exception {
+ super.setUp();
+ echo = SimpleTarget.class.getMethod("echo", String.class);
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/CallbackInterfaceInterceptorTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/CallbackInterfaceInterceptorTestCase.java
new file mode 100644
index 0000000000..6c50cb406f
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/CallbackInterfaceInterceptorTestCase.java
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.wire;
+
+import org.osoa.sca.NoRegisteredCallbackException;
+
+import org.apache.tuscany.spi.wire.Interceptor;
+import org.apache.tuscany.spi.wire.Message;
+import org.apache.tuscany.spi.wire.MessageImpl;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class CallbackInterfaceInterceptorTestCase extends TestCase {
+
+ public void testOptimize() throws Exception {
+ CallbackInterfaceInterceptor interceptor = new CallbackInterfaceInterceptor(true);
+ assertFalse(interceptor.isOptimizable());
+ }
+
+ public void testImplements() {
+ CallbackInterfaceInterceptor interceptor = new CallbackInterfaceInterceptor(true);
+ Interceptor next = EasyMock.createMock(Interceptor.class);
+ EasyMock.expect(next.invoke(EasyMock.isA(Message.class))).andReturn(null);
+ EasyMock.replay(next);
+ interceptor.setNext(next);
+ interceptor.invoke(new MessageImpl());
+ EasyMock.verify(next);
+ }
+
+ public void testDoesNotImplement() {
+ CallbackInterfaceInterceptor interceptor = new CallbackInterfaceInterceptor(false);
+ try {
+ interceptor.invoke(new MessageImpl());
+ fail();
+ } catch (NoRegisteredCallbackException e) {
+ // expected
+ }
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/ContractCompatibilityTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/ContractCompatibilityTestCase.java
new file mode 100644
index 0000000000..866ffe341d
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/ContractCompatibilityTestCase.java
@@ -0,0 +1,372 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.wire;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.tuscany.spi.QualifiedName;
+import org.apache.tuscany.spi.component.ReferenceBinding;
+import org.apache.tuscany.spi.model.DataType;
+import org.apache.tuscany.spi.model.Operation;
+import static org.apache.tuscany.spi.model.Operation.NO_CONVERSATION;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.wire.ChainHolder;
+import org.apache.tuscany.spi.wire.IncompatibleServiceContractException;
+import org.apache.tuscany.spi.wire.ProxyCreationException;
+import org.apache.tuscany.spi.wire.Wire;
+import org.apache.tuscany.spi.wire.ProxyService;
+
+import junit.framework.TestCase;
+import org.osoa.sca.CallableReference;
+
+/**
+ * TODO some tests commented out due to DataType.equals() needing to be strict
+ *
+ * @version $Rev$ $Date$
+ */
+public class ContractCompatibilityTestCase extends TestCase {
+
+ private ProxyService proxyService = new MockProxyService();
+
+ public void testNoOperation() throws Exception {
+ ServiceContract source = new MockContract<Type>("FooContract");
+ ServiceContract target = new MockContract<Type>("FooContract");
+ proxyService.checkCompatibility(source, target, false, false);
+ }
+
+ public void testBasic() throws Exception {
+ ServiceContract<Type> source = new MockContract<Type>("FooContract");
+ Operation<Type> opSource1 = new Operation<Type>("op1", null, null, null, false, null, NO_CONVERSATION);
+ Map<String, Operation<Type>> sourceOperations = new HashMap<String, Operation<Type>>();
+ sourceOperations.put("op1", opSource1);
+ source.setOperations(sourceOperations);
+ ServiceContract<Type> target = new MockContract<Type>("FooContract");
+ Operation<Type> opSource2 = new Operation<Type>("op1", null, null, null, false, null, NO_CONVERSATION);
+ Map<String, Operation<Type>> targetOperations = new HashMap<String, Operation<Type>>();
+ targetOperations.put("op1", opSource2);
+ target.setOperations(targetOperations);
+ proxyService.checkCompatibility(source, target, false, false);
+ }
+
+ public void testBasicIncompatibleOperationNames() throws Exception {
+ ServiceContract<Type> source = new MockContract<Type>("FooContract");
+ Operation<Type> opSource1 = new Operation<Type>("op1", null, null, null, false, null, NO_CONVERSATION);
+ Map<String, Operation<Type>> sourceOperations = new HashMap<String, Operation<Type>>();
+ sourceOperations.put("op1", opSource1);
+ source.setOperations(sourceOperations);
+ ServiceContract<Type> target = new MockContract<Type>("FooContract");
+ Operation<Type> opSource2 = new Operation<Type>("op2", null, null, null, false, null, NO_CONVERSATION);
+ Map<String, Operation<Type>> targetOperations = new HashMap<String, Operation<Type>>();
+ targetOperations.put("op2", opSource2);
+ target.setOperations(targetOperations);
+ try {
+ proxyService.checkCompatibility(source, target, false, false);
+ fail();
+ } catch (IncompatibleServiceContractException e) {
+ //expected
+ }
+ }
+
+ public void testInputTypes() throws Exception {
+ ServiceContract<Type> source = new MockContract<Type>("FooContract");
+ List<DataType<Type>> sourceInputTypes = new ArrayList<DataType<Type>>();
+ sourceInputTypes.add(new DataType<Type>(Object.class, Object.class));
+ DataType<List<DataType<Type>>> inputType = new DataType<List<DataType<Type>>>(String.class, sourceInputTypes);
+ Operation<Type> opSource1 = new Operation<Type>("op1", inputType, null, null, false, null, NO_CONVERSATION);
+ Map<String, Operation<Type>> sourceOperations = new HashMap<String, Operation<Type>>();
+ sourceOperations.put("op1", opSource1);
+ source.setOperations(sourceOperations);
+
+ ServiceContract<Type> target = new MockContract<Type>("FooContract");
+ List<DataType<Type>> targetInputTypes = new ArrayList<DataType<Type>>();
+ targetInputTypes.add(new DataType<Type>(Object.class, Object.class));
+ DataType<List<DataType<Type>>> targetInputType =
+ new DataType<List<DataType<Type>>>(String.class, targetInputTypes);
+
+ Operation<Type> opTarget =
+ new Operation<Type>("op1", targetInputType, null, null, false, null, NO_CONVERSATION);
+ Map<String, Operation<Type>> targetOperations = new HashMap<String, Operation<Type>>();
+ targetOperations.put("op1", opTarget);
+ target.setOperations(targetOperations);
+ proxyService.checkCompatibility(source, target, false, false);
+ }
+
+
+ public void testIncompatibleInputTypes() throws Exception {
+ ServiceContract<Type> source = new MockContract<Type>("FooContract");
+ List<DataType<Type>> sourceInputTypes = new ArrayList<DataType<Type>>();
+ sourceInputTypes.add(new DataType<Type>(Integer.class, Integer.class));
+ DataType<List<DataType<Type>>> inputType = new DataType<List<DataType<Type>>>(String.class, sourceInputTypes);
+ Operation<Type> opSource1 = new Operation<Type>("op1", inputType, null, null, false, null, NO_CONVERSATION);
+ Map<String, Operation<Type>> sourceOperations = new HashMap<String, Operation<Type>>();
+ sourceOperations.put("op1", opSource1);
+ source.setOperations(sourceOperations);
+
+ ServiceContract<Type> target = new MockContract<Type>("FooContract");
+ List<DataType<Type>> targetInputTypes = new ArrayList<DataType<Type>>();
+ targetInputTypes.add(new DataType<Type>(String.class, String.class));
+ DataType<List<DataType<Type>>> targetInputType =
+ new DataType<List<DataType<Type>>>(String.class, targetInputTypes);
+
+ Operation<Type> opTarget =
+ new Operation<Type>("op1", targetInputType, null, null, false, null, NO_CONVERSATION);
+ Map<String, Operation<Type>> targetOperations = new HashMap<String, Operation<Type>>();
+ targetOperations.put("op1", opTarget);
+ target.setOperations(targetOperations);
+ try {
+ proxyService.checkCompatibility(source, target, false, false);
+ fail();
+ } catch (IncompatibleServiceContractException e) {
+ //expected
+ }
+ }
+
+ /**
+ * Verfies source input types can be super types of the target
+ */
+ public void testSourceSuperTypeInputCompatibility() throws Exception {
+// ServiceContract<Type> source = new MockContract<Type>("FooContract");
+// List<DataType<Type>> sourceInputTypes = new ArrayList<DataType<Type>>();
+// sourceInputTypes.add(new DataType<Type>(Object.class, Object.class));
+// DataType<List<DataType<Type>>> inputType = new DataType<List<DataType<Type>>>(String.class, sourceInputTypes);
+// Operation<Type> opSource1 = new Operation<Type>("op1", inputType, null, null, false, null);
+// Map<String, Operation<Type>> sourceOperations = new HashMap<String, Operation<Type>>();
+// sourceOperations.put("op1", opSource1);
+// source.setOperations(sourceOperations);
+//
+// ServiceContract<Type> target = new MockContract<Type>("FooContract");
+// List<DataType<Type>> targetInputTypes = new ArrayList<DataType<Type>>();
+// targetInputTypes.add(new DataType<Type>(String.class, String.class));
+// DataType<List<DataType<Type>>> targetInputType =
+// new DataType<List<DataType<Type>>>(String.class, targetInputTypes);
+//
+// Operation<Type> opTarget = new Operation<Type>("op1", targetInputType, null, null, false, null);
+// Map<String, Operation<Type>> targetOperations = new HashMap<String, Operation<Type>>();
+// targetOperations.put("op1", opTarget);
+// target.setOperations(targetOperations);
+// wireService.checkCompatibility(source, target, false);
+ }
+
+ public void testOutputTypes() throws Exception {
+ ServiceContract<Type> source = new MockContract<Type>("FooContract");
+ DataType<Type> sourceOutputType = new DataType<Type>(String.class, String.class);
+ Operation<Type> opSource1 =
+ new Operation<Type>("op1", null, sourceOutputType, null, false, null, NO_CONVERSATION);
+ Map<String, Operation<Type>> sourceOperations = new HashMap<String, Operation<Type>>();
+ sourceOperations.put("op1", opSource1);
+ source.setOperations(sourceOperations);
+
+ ServiceContract<Type> target = new MockContract<Type>("FooContract");
+ DataType<Type> targetOutputType = new DataType<Type>(String.class, String.class);
+ Operation<Type> opTarget =
+ new Operation<Type>("op1", null, targetOutputType, null, false, null, NO_CONVERSATION);
+ Map<String, Operation<Type>> targetOperations = new HashMap<String, Operation<Type>>();
+ targetOperations.put("op1", opTarget);
+ target.setOperations(targetOperations);
+ proxyService.checkCompatibility(source, target, false, false);
+ }
+
+ /**
+ * Verfies a return type that is a supertype of of the target is compatible
+ */
+ public void testSupertypeOutputTypes() throws Exception {
+// ServiceContract<Type> source = new MockContract<Type>("FooContract");
+// DataType<Type> sourceOutputType = new DataType<Type>(Object.class, Object.class);
+// Operation<Type> opSource1 = new Operation<Type>("op1", null, sourceOutputType, null, false, null);
+// Map<String, Operation<Type>> sourceOperations = new HashMap<String, Operation<Type>>();
+// sourceOperations.put("op1", opSource1);
+// source.setOperations(sourceOperations);
+//
+// ServiceContract<Type> target = new MockContract<Type>("FooContract");
+// DataType<Type> targetOutputType = new DataType<Type>(String.class, String.class);
+// Operation<Type> opTarget = new Operation<Type>("op1", null, targetOutputType, null, false, null);
+// Map<String, Operation<Type>> targetOperations = new HashMap<String, Operation<Type>>();
+// targetOperations.put("op1", opTarget);
+// target.setOperations(targetOperations);
+// wireService.checkCompatibility(source, target, false);
+ }
+
+ public void testIncompatibleOutputTypes() throws Exception {
+ ServiceContract<Type> source = new MockContract<Type>("FooContract");
+ DataType<Type> sourceOutputType = new DataType<Type>(String.class, String.class);
+ Operation<Type> opSource1 =
+ new Operation<Type>("op1", null, sourceOutputType, null, false, null, NO_CONVERSATION);
+ Map<String, Operation<Type>> sourceOperations = new HashMap<String, Operation<Type>>();
+ sourceOperations.put("op1", opSource1);
+ source.setOperations(sourceOperations);
+
+ ServiceContract<Type> target = new MockContract<Type>("FooContract");
+ DataType<Type> targetOutputType = new DataType<Type>(Integer.class, Integer.class);
+ Operation<Type> opTarget =
+ new Operation<Type>("op1", null, targetOutputType, null, false, null, NO_CONVERSATION);
+ Map<String, Operation<Type>> targetOperations = new HashMap<String, Operation<Type>>();
+ targetOperations.put("op1", opTarget);
+ target.setOperations(targetOperations);
+ try {
+ proxyService.checkCompatibility(source, target, false, false);
+ fail();
+ } catch (IncompatibleServiceContractException e) {
+ //expected
+ }
+ }
+
+ public void testFaultTypes() throws Exception {
+ ServiceContract<Type> source = new MockContract<Type>("FooContract");
+ DataType<Type> sourceFaultType = new DataType<Type>(String.class, String.class);
+ List<DataType<Type>> sourceFaultTypes = new ArrayList<DataType<Type>>();
+ sourceFaultTypes.add(0, sourceFaultType);
+ Operation<Type> opSource1 =
+ new Operation<Type>("op1", null, null, sourceFaultTypes, false, null, NO_CONVERSATION);
+ Map<String, Operation<Type>> sourceOperations = new HashMap<String, Operation<Type>>();
+ sourceOperations.put("op1", opSource1);
+ source.setOperations(sourceOperations);
+
+ ServiceContract<Type> target = new MockContract<Type>("FooContract");
+ DataType<Type> targetFaultType = new DataType<Type>(String.class, String.class);
+ List<DataType<Type>> targetFaultTypes = new ArrayList<DataType<Type>>();
+ targetFaultTypes.add(0, targetFaultType);
+
+ Operation<Type> opTarget =
+ new Operation<Type>("op1", null, null, targetFaultTypes, false, null, NO_CONVERSATION);
+ Map<String, Operation<Type>> targetOperations = new HashMap<String, Operation<Type>>();
+ targetOperations.put("op1", opTarget);
+ target.setOperations(targetOperations);
+ proxyService.checkCompatibility(source, target, false, false);
+ }
+
+ public void testSourceFaultTargetNoFaultCompatibility() throws Exception {
+ ServiceContract<Type> source = new MockContract<Type>("FooContract");
+ DataType<Type> sourceFaultType = new DataType<Type>(String.class, String.class);
+ List<DataType<Type>> sourceFaultTypes = new ArrayList<DataType<Type>>();
+ sourceFaultTypes.add(0, sourceFaultType);
+ Operation<Type> opSource1 =
+ new Operation<Type>("op1", null, null, sourceFaultTypes, false, null, NO_CONVERSATION);
+ Map<String, Operation<Type>> sourceOperations = new HashMap<String, Operation<Type>>();
+ sourceOperations.put("op1", opSource1);
+ source.setOperations(sourceOperations);
+
+ ServiceContract<Type> target = new MockContract<Type>("FooContract");
+ Operation<Type> opTarget = new Operation<Type>("op1", null, null, null, false, null, NO_CONVERSATION);
+ Map<String, Operation<Type>> targetOperations = new HashMap<String, Operation<Type>>();
+ targetOperations.put("op1", opTarget);
+ target.setOperations(targetOperations);
+ proxyService.checkCompatibility(source, target, false, false);
+ }
+
+ /**
+ * Verifies a source's fault which is a supertype of the target's fault are compatibile
+ *
+ * @throws Exception
+ */
+ public void testFaultSuperTypes() throws Exception {
+// ServiceContract<Type> source = new MockContract<Type>("FooContract");
+// DataType<Type> sourceFaultType = new DataType<Type>(Exception.class, Exception.class);
+// List<DataType<Type>> sourceFaultTypes = new ArrayList<DataType<Type>>();
+// sourceFaultTypes.add(0, sourceFaultType);
+// Operation<Type> opSource1 = new Operation<Type>("op1", null, null, sourceFaultTypes, false, null);
+// Map<String, Operation<Type>> sourceOperations = new HashMap<String, Operation<Type>>();
+// sourceOperations.put("op1", opSource1);
+// source.setOperations(sourceOperations);
+//
+// ServiceContract<Type> target = new MockContract<Type>("FooContract");
+// DataType<Type> targetFaultType = new DataType<Type>(TuscanyException.class, TuscanyException.class);
+// List<DataType<Type>> targetFaultTypes = new ArrayList<DataType<Type>>();
+// targetFaultTypes.add(0, targetFaultType);
+//
+// Operation<Type> opTarget = new Operation<Type>("op1", null, null, targetFaultTypes, false, null);
+// Map<String, Operation<Type>> targetOperations = new HashMap<String, Operation<Type>>();
+// targetOperations.put("op1", opTarget);
+// target.setOperations(targetOperations);
+// wireService.checkCompatibility(source, target, false);
+ }
+
+ /**
+ * Verifies a source's faults which are supertypes and a superset of the target's faults are compatibile
+ */
+ public void testFaultSuperTypesAndSuperset() throws Exception {
+// ServiceContract<Type> source = new MockContract<Type>("FooContract");
+// DataType<Type> sourceFaultType = new DataType<Type>(Exception.class, Exception.class);
+// DataType<Type> sourceFaultType2 = new DataType<Type>(RuntimeException.class, RuntimeException.class);
+// List<DataType<Type>> sourceFaultTypes = new ArrayList<DataType<Type>>();
+// sourceFaultTypes.add(0, sourceFaultType);
+// sourceFaultTypes.add(1, sourceFaultType2);
+// Operation<Type> opSource1 = new Operation<Type>("op1", null, null, sourceFaultTypes, false, null);
+// Map<String, Operation<Type>> sourceOperations = new HashMap<String, Operation<Type>>();
+// sourceOperations.put("op1", opSource1);
+// source.setOperations(sourceOperations);
+//
+// ServiceContract<Type> target = new MockContract<Type>("FooContract");
+// DataType<Type> targetFaultType = new DataType<Type>(TuscanyException.class, TuscanyException.class);
+// List<DataType<Type>> targetFaultTypes = new ArrayList<DataType<Type>>();
+// targetFaultTypes.add(0, targetFaultType);
+//
+// Operation<Type> opTarget = new Operation<Type>("op1", null, null, targetFaultTypes, false, null);
+// Map<String, Operation<Type>> targetOperations = new HashMap<String, Operation<Type>>();
+// targetOperations.put("op1", opTarget);
+// target.setOperations(targetOperations);
+// wireService.checkCompatibility(source, target, false);
+ }
+
+ private class MockContract<T> extends ServiceContract<T> {
+ public MockContract() {
+ }
+
+ public MockContract(Class interfaceClass) {
+ super(interfaceClass);
+ }
+
+ public MockContract(String interfaceName) {
+ super(interfaceName);
+ }
+ }
+
+ private class MockProxyService extends ProxyServiceExtension {
+ public MockProxyService() {
+ super(null);
+ }
+
+ public <T> T createProxy(Class<T> interfaze, Wire wire) throws ProxyCreationException {
+ throw new UnsupportedOperationException();
+ }
+
+ public <T> T createProxy(Class<T> interfaze, Wire wire, Map<Method, ChainHolder> mapping)
+ throws ProxyCreationException {
+ throw new UnsupportedOperationException();
+ }
+
+ public Object createCallbackProxy(Class<?> interfaze, List<Wire> wires) throws ProxyCreationException {
+ return null;
+ }
+
+ public void createWires(ReferenceBinding referenceBinding, ServiceContract<?> contract,
+ QualifiedName targetName) {
+ throw new UnsupportedOperationException();
+ }
+
+ public <B, R extends CallableReference<B>> R cast(B target) throws IllegalArgumentException {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/IncompatibleServiceContractExceptionFormatterTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/IncompatibleServiceContractExceptionFormatterTestCase.java
new file mode 100644
index 0000000000..a9f455bc62
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/IncompatibleServiceContractExceptionFormatterTestCase.java
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.wire;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.wire.IncompatibleServiceContractException;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.host.monitor.FormatterRegistry;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class IncompatibleServiceContractExceptionFormatterTestCase extends TestCase {
+ FormatterRegistry registry = EasyMock.createNiceMock(FormatterRegistry.class);
+ IncompatibleServiceContractExceptionFormatter formatter =
+ new IncompatibleServiceContractExceptionFormatter(registry);
+
+ public void testFormat() throws Exception {
+ ServiceContract<Object> source = new ServiceContract<Object>() {
+ };
+ source.setInterfaceName("sourceInterface");
+ ServiceContract<Object> target = new ServiceContract<Object>() {
+ };
+ target.setInterfaceName("targetInterface");
+ Operation<Object> sourceOp = new Operation<Object>("sourceOp", null, null, null);
+ Operation<Object> targetOp = new Operation<Object>("targetOp", null, null, null);
+
+ IncompatibleServiceContractException e =
+ new IncompatibleServiceContractException("message", source, target, sourceOp, targetOp);
+ StringWriter writer = new StringWriter();
+ PrintWriter pw = new PrintWriter(writer);
+ formatter.write(pw, e);
+ String buffer = writer.toString();
+ assertTrue(buffer.indexOf("message") >= 0);
+ assertTrue(buffer.indexOf("sourceInterface") >= 0);
+ assertTrue(buffer.indexOf("targetInterface") >= 0);
+ assertTrue(buffer.indexOf("sourceOp") >= 0);
+ assertTrue(buffer.indexOf("targetOp") >= 0);
+ }
+
+
+ public void testFormatNulls() throws Exception {
+ ServiceContract<Object> source = new ServiceContract<Object>() {
+ };
+ source.setInterfaceName("sourceInterface");
+ ServiceContract<Object> target = new ServiceContract<Object>() {
+ };
+ target.setInterfaceName("targetInterface");
+
+ IncompatibleServiceContractException e =
+ new IncompatibleServiceContractException("message", source, target);
+ StringWriter writer = new StringWriter();
+ PrintWriter pw = new PrintWriter(writer);
+ formatter.write(pw, e);
+ String buffer = writer.toString();
+ assertTrue(buffer.indexOf("message") >= 0);
+ assertTrue(buffer.indexOf("sourceInterface") >= 0);
+ assertTrue(buffer.indexOf("targetInterface") >= 0);
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/InvocationChainImplTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/InvocationChainImplTestCase.java
new file mode 100644
index 0000000000..9875058abb
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/InvocationChainImplTestCase.java
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.wire;
+
+import java.lang.reflect.Type;
+
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.wire.Interceptor;
+import org.apache.tuscany.spi.wire.Message;
+import org.apache.tuscany.spi.wire.InvocationChain;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class InvocationChainImplTestCase extends TestCase {
+
+ public void testInsertAtPos() throws Exception {
+ InvocationChain chain = new InvocationChainImpl(new Operation<Type>("foo", null, null, null));
+ Interceptor inter3 = new MockInterceptor();
+ Interceptor inter2 = new MockInterceptor();
+ Interceptor inter1 = new MockInterceptor();
+ chain.addInterceptor(inter3);
+ chain.addInterceptor(0, inter1);
+ chain.addInterceptor(1, inter2);
+ Interceptor head = chain.getHeadInterceptor();
+ assertEquals(inter1, head);
+ assertEquals(inter2, head.getNext());
+ assertEquals(inter3, head.getNext().getNext());
+ }
+
+ public void testInsertAtEnd() throws Exception {
+ InvocationChain chain = new InvocationChainImpl(new Operation<Type>("foo", null, null, null));
+ Interceptor inter2 = new MockInterceptor();
+ Interceptor inter1 = new MockInterceptor();
+ chain.addInterceptor(0, inter1);
+ chain.addInterceptor(1, inter2);
+ Interceptor head = chain.getHeadInterceptor();
+ assertEquals(inter1, head);
+ assertEquals(inter2, head.getNext());
+ assertEquals(inter2, chain.getTailInterceptor());
+
+ }
+
+ private class MockInterceptor implements Interceptor {
+
+ private Interceptor next;
+
+ public Message invoke(Message msg) {
+ return null;
+ }
+
+ public void setNext(Interceptor next) {
+ this.next = next;
+ }
+
+ public Interceptor getNext() {
+ return next;
+ }
+
+ public boolean isOptimizable() {
+ return false;
+ }
+ }
+
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/InvocationConfigurationErrorTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/InvocationConfigurationErrorTestCase.java
new file mode 100644
index 0000000000..b8e0b0b8ea
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/InvocationConfigurationErrorTestCase.java
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.wire;
+
+import java.lang.reflect.Method;
+
+import org.apache.tuscany.spi.idl.java.JavaInterfaceProcessorRegistry;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.Message;
+import org.apache.tuscany.spi.wire.MessageImpl;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
+import org.apache.tuscany.core.mock.component.SimpleTarget;
+import org.apache.tuscany.core.mock.component.SimpleTargetImpl;
+import org.apache.tuscany.core.mock.wire.MockStaticInvoker;
+import org.apache.tuscany.core.mock.wire.MockSyncInterceptor;
+
+/**
+ * Tests error propagation through an innvocation
+ *
+ * @version $Rev$ $Date$
+ */
+public class InvocationConfigurationErrorTestCase extends TestCase {
+
+ private ServiceContract<?> contract;
+ private Method hello;
+
+ public InvocationConfigurationErrorTestCase() {
+ super();
+ }
+
+ public InvocationConfigurationErrorTestCase(String arg0) {
+ super(arg0);
+ }
+
+ public void setUp() throws Exception {
+ super.setUp();
+ JavaInterfaceProcessorRegistry registry = new JavaInterfaceProcessorRegistryImpl();
+ contract = registry.introspect(SimpleTarget.class);
+ hello = SimpleTarget.class.getMethod("hello", String.class);
+ }
+
+ /**
+ * Tests basic wiring of a source to a target, including handlers and interceptors
+ */
+ public void testInvokeWithInterceptors() throws Exception {
+ Operation operation = contract.getOperations().get("hello");
+ InvocationChain source = new InvocationChainImpl(operation);
+ MockSyncInterceptor sourceInterceptor = new MockSyncInterceptor();
+ source.addInterceptor(sourceInterceptor);
+
+ InvocationChain target = new InvocationChainImpl(operation);
+ MockSyncInterceptor targetInterceptor = new MockSyncInterceptor();
+ target.addInterceptor(targetInterceptor);
+ target.addInterceptor(new InvokerInterceptor());
+
+ // connect the source to the target
+ source.addInterceptor(target.getHeadInterceptor());
+ MockStaticInvoker invoker = new MockStaticInvoker(hello, new SimpleTargetImpl());
+ source.setTargetInvoker(invoker);
+
+ Message msg = new MessageImpl();
+ msg.setTargetInvoker(invoker);
+ Message response = source.getHeadInterceptor().invoke(msg);
+ assertTrue(response.isFault());
+ assertTrue(response.getBody() instanceof IllegalArgumentException);
+ assertEquals(1, sourceInterceptor.getCount());
+ assertEquals(1, targetInterceptor.getCount());
+
+ }
+
+}
+
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/InvocationConfigurationTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/InvocationConfigurationTestCase.java
new file mode 100644
index 0000000000..000101771a
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/InvocationConfigurationTestCase.java
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.wire;
+
+import java.lang.reflect.Method;
+
+import org.apache.tuscany.spi.idl.InvalidServiceContractException;
+import org.apache.tuscany.spi.idl.java.JavaInterfaceProcessorRegistry;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.Message;
+import org.apache.tuscany.spi.wire.MessageImpl;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
+import org.apache.tuscany.core.mock.component.SimpleTarget;
+import org.apache.tuscany.core.mock.component.SimpleTargetImpl;
+import org.apache.tuscany.core.mock.wire.MockStaticInvoker;
+import org.apache.tuscany.core.mock.wire.MockSyncInterceptor;
+
+public class InvocationConfigurationTestCase extends TestCase {
+
+ private Method hello;
+ private Operation operation;
+
+
+ public InvocationConfigurationTestCase() {
+ super();
+ }
+
+ public InvocationConfigurationTestCase(String arg0) {
+ super(arg0);
+ }
+
+ public void setUp() throws Exception {
+ super.setUp();
+ JavaInterfaceProcessorRegistry registry = new JavaInterfaceProcessorRegistryImpl();
+ ServiceContract<?> contract;
+ try {
+ contract = registry.introspect(SimpleTarget.class);
+ } catch (InvalidServiceContractException e) {
+ throw new AssertionError();
+ }
+
+ operation = contract.getOperations().get("echo");
+ hello = SimpleTarget.class.getMethod("hello", String.class);
+ }
+
+ /**
+ * Tests basic wiring of a source to a target, including handlers and interceptors
+ */
+ public void testInvokeWithInterceptors() throws Exception {
+ InvocationChain source = new InvocationChainImpl(operation);
+ MockSyncInterceptor sourceInterceptor = new MockSyncInterceptor();
+ source.addInterceptor(sourceInterceptor);
+
+ InvocationChain target = new InvocationChainImpl(operation);
+ MockSyncInterceptor targetInterceptor = new MockSyncInterceptor();
+ target.addInterceptor(targetInterceptor);
+ target.addInterceptor(new InvokerInterceptor());
+
+ // connect the source to the target
+ source.addInterceptor(target.getHeadInterceptor());
+ MockStaticInvoker invoker = new MockStaticInvoker(hello, new SimpleTargetImpl());
+ source.setTargetInvoker(invoker);
+
+ Message msg = new MessageImpl();
+ msg.setBody("foo");
+ msg.setTargetInvoker(invoker);
+ Message response = source.getHeadInterceptor().invoke(msg);
+ assertEquals("foo", response.getBody());
+ assertEquals(1, sourceInterceptor.getCount());
+ assertEquals(1, targetInterceptor.getCount());
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/InvocationHandlerTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/InvocationHandlerTestCase.java
new file mode 100644
index 0000000000..f37ce6cd7c
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/InvocationHandlerTestCase.java
@@ -0,0 +1,129 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.wire;
+
+import java.lang.reflect.Method;
+import java.net.URI;
+
+import org.apache.tuscany.spi.idl.java.JavaIDLUtils;
+import org.apache.tuscany.spi.idl.java.JavaInterfaceProcessorRegistry;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.Wire;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
+import org.apache.tuscany.core.mock.component.SimpleTarget;
+import org.apache.tuscany.core.mock.component.SimpleTargetImpl;
+import org.apache.tuscany.core.mock.wire.MockStaticInvoker;
+import org.apache.tuscany.core.mock.wire.MockSyncInterceptor;
+import org.apache.tuscany.core.wire.jdk.JDKInvocationHandler;
+
+public class InvocationHandlerTestCase extends TestCase {
+
+ private Method hello;
+ private ServiceContract<?> contract;
+
+ public InvocationHandlerTestCase() {
+ super();
+ }
+
+ public InvocationHandlerTestCase(String arg0) {
+ super(arg0);
+ }
+
+ public void testBasicInvoke() throws Throwable {
+ Wire wire = new WireImpl();
+ wire.setSourceUri(URI.create("#wire"));
+ Operation operation = contract.getOperations().get("hello");
+ wire.addInvocationChain(operation, createChain(operation));
+ wire.setSourceContract(contract);
+ JDKInvocationHandler handler = new JDKInvocationHandler(SimpleTarget.class, wire, null);
+ assertEquals("foo", handler.invoke(hello, new Object[]{"foo"}));
+ }
+
+ public void testErrorInvoke() throws Throwable {
+ Wire wire = new WireImpl();
+ wire.setSourceUri(URI.create("#wire"));
+ Operation operation = contract.getOperations().get("hello");
+ wire.addInvocationChain(operation, createChain(operation));
+ wire.setSourceContract(contract);
+ JDKInvocationHandler handler = new JDKInvocationHandler(SimpleTarget.class, wire, null);
+ try {
+ handler.invoke(hello, new Object[]{});
+ fail("Expected " + IllegalArgumentException.class.getName());
+ } catch (IllegalArgumentException e) {
+ // should throw
+ }
+ }
+
+ public void testDirectErrorInvoke() throws Throwable {
+ Operation operation = contract.getOperations().get("hello");
+ InvocationChain source = new InvocationChainImpl(operation);
+ MockStaticInvoker invoker = new MockStaticInvoker(hello, new SimpleTargetImpl());
+ source.setTargetInvoker(invoker);
+
+ Wire wire = new WireImpl();
+ wire.setSourceUri(URI.create("#wire"));
+ wire.setSourceContract(contract);
+ wire.addInvocationChain(operation, source);
+ JDKInvocationHandler handler = new JDKInvocationHandler(SimpleTarget.class, wire, null);
+ try {
+ assertEquals("foo", handler.invoke(hello, new Object[]{}));
+ fail("Expected " + IllegalArgumentException.class.getName());
+ } catch (IllegalArgumentException e) {
+ // should throw
+ }
+ }
+
+ public void testDirectInvoke() throws Throwable {
+ Operation operation = contract.getOperations().get("hello");
+ InvocationChain source = new InvocationChainImpl(operation);
+ MockStaticInvoker invoker = new MockStaticInvoker(hello, new SimpleTargetImpl());
+ source.setTargetInvoker(invoker);
+
+ Wire wire = new WireImpl();
+ wire.setSourceUri(URI.create("#wire"));
+ wire.setSourceContract(contract);
+ wire.addInvocationChain(operation, source);
+ JDKInvocationHandler handler = new JDKInvocationHandler(SimpleTarget.class, wire, null);
+ assertEquals("foo", handler.invoke(hello, new Object[]{"foo"}));
+ }
+
+ private InvocationChain createChain(Operation operation) {
+ InvocationChain chain = new InvocationChainImpl(operation);
+ MockSyncInterceptor targetInterceptor = new MockSyncInterceptor();
+ chain.addInterceptor(targetInterceptor);
+ chain.addInterceptor(new InvokerInterceptor());
+
+ Method method = JavaIDLUtils.findMethod(operation, SimpleTarget.class.getMethods());
+ MockStaticInvoker invoker = new MockStaticInvoker(method, new SimpleTargetImpl());
+ chain.setTargetInvoker(invoker);
+ return chain;
+ }
+
+ public void setUp() throws Exception {
+ super.setUp();
+ JavaInterfaceProcessorRegistry registry = new JavaInterfaceProcessorRegistryImpl();
+ contract = registry.introspect(SimpleTarget.class);
+ hello = SimpleTarget.class.getMethod("hello", String.class);
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/NonBlockingInterceptorTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/NonBlockingInterceptorTestCase.java
new file mode 100644
index 0000000000..c08d1453db
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/NonBlockingInterceptorTestCase.java
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.wire;
+
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.services.work.WorkScheduler;
+import org.apache.tuscany.spi.wire.Interceptor;
+import org.apache.tuscany.spi.wire.Message;
+import org.apache.tuscany.spi.wire.MessageImpl;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.getCurrentArguments;
+import static org.easymock.EasyMock.isA;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+import org.easymock.IAnswer;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class NonBlockingInterceptorTestCase extends TestCase {
+
+ public void testInvoke() throws Exception {
+ WorkScheduler scheduler = createMock(WorkScheduler.class);
+ scheduler.scheduleWork(isA(Runnable.class));
+ expectLastCall().andStubAnswer(new IAnswer<Object>() {
+ public Object answer() throws Throwable {
+ Runnable runnable = (Runnable) getCurrentArguments()[0];
+ runnable.run();
+ return null;
+ }
+ });
+ replay(scheduler);
+ WorkContext context = createMock(WorkContext.class);
+ String convID = "convID";
+ EasyMock.expect(context.getIdentifier(Scope.CONVERSATION)).andReturn(convID);
+ context.setCorrelationId(null);
+ context.setIdentifier(Scope.CONVERSATION, convID);
+ EasyMock.replay(context);
+ Message msg = new MessageImpl();
+ Interceptor next = EasyMock.createMock(Interceptor.class);
+ EasyMock.expect(next.invoke(EasyMock.eq(msg))).andReturn(msg);
+ EasyMock.replay(next);
+ Interceptor interceptor = new NonBlockingInterceptor(scheduler, context, next);
+ interceptor.invoke(msg);
+ verify(context);
+ verify(next);
+ }
+
+ public void testOptimizable() {
+ NonBlockingInterceptor interceptor = new NonBlockingInterceptor(null, null);
+ assertFalse(interceptor.isOptimizable());
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/OptimizedWireObjectFactoryTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/OptimizedWireObjectFactoryTestCase.java
new file mode 100644
index 0000000000..5293678d12
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/OptimizedWireObjectFactoryTestCase.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.wire;
+
+import org.apache.tuscany.spi.wire.Wire;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class OptimizedWireObjectFactoryTestCase extends TestCase {
+
+ public void testGetInstance() throws Exception {
+ Foo foo = new Foo();
+ Wire wire = EasyMock.createMock(Wire.class);
+ EasyMock.expect(wire.getTargetInstance()).andReturn(foo);
+ EasyMock.replay(wire);
+ OptimizedWireObjectFactory<Foo> factory = new OptimizedWireObjectFactory<Foo>(Foo.class, wire);
+ assertEquals(foo, factory.getInstance());
+ EasyMock.verify(wire);
+ }
+
+ private class Foo {
+
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/WireImplTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/WireImplTestCase.java
new file mode 100644
index 0000000000..e337133523
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/WireImplTestCase.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.wire;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.wire.Wire;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class WireImplTestCase extends TestCase {
+
+ /**
+ * Tests that the target wire returns null if there is no connected wire. This behavior is needed for optional
+ * autowires.
+ */
+ public void testGetNonExistentTarget() throws Exception {
+ Wire wire = new WireImpl();
+ assertNull(wire.getTargetInstance());
+ }
+
+ public void testTargetInstance() throws Exception {
+ Wire wire = new WireImpl();
+ AtomicComponent component = EasyMock.createMock(AtomicComponent.class);
+ EasyMock.expect(component.getTargetInstance()).andReturn(new Object());
+ EasyMock.replay(component);
+ wire.setTarget(component);
+ assertNotNull(wire.getTargetInstance());
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/WireObjectFactoryTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/WireObjectFactoryTestCase.java
new file mode 100644
index 0000000000..9f21b9efdb
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/WireObjectFactoryTestCase.java
@@ -0,0 +1,138 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.wire;
+
+import java.lang.reflect.Type;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.tuscany.spi.idl.java.JavaServiceContract;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.wire.ProxyService;
+import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.Wire;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class WireObjectFactoryTestCase extends TestCase {
+
+ @SuppressWarnings({"unchecked"})
+ public void testCreateInstance() throws Exception {
+ Operation<Type> op = new Operation<Type>("hello", null, null, null);
+ InvocationChain chain = new InvocationChainImpl(op);
+ Wire wire = EasyMock.createMock(Wire.class);
+ Map<Operation<?>, InvocationChain> chains = new HashMap<Operation<?>, InvocationChain>();
+ chains.put(op, chain);
+ EasyMock.expect(wire.getInvocationChains()).andReturn(chains);
+ EasyMock.expect(wire.isOptimizable()).andReturn(false);
+ EasyMock.replay(wire);
+ ProxyService service = EasyMock.createMock(ProxyService.class);
+ service.createProxy(EasyMock.eq(Foo.class), EasyMock.eq(wire), EasyMock.isA(Map.class));
+ EasyMock.expectLastCall().andReturn(new Foo() {
+ public void hello() {
+
+ }
+ });
+ EasyMock.replay(service);
+
+ WireObjectFactory<Foo> factory = new WireObjectFactory<Foo>(Foo.class, wire, service);
+ factory.getInstance();
+ EasyMock.verify(service);
+ EasyMock.verify(wire);
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testOptimizedCreateInstance() throws Exception {
+ ServiceContract<?> contract = new JavaServiceContract(Foo.class);
+ Wire wire = EasyMock.createMock(Wire.class);
+ EasyMock.expect(wire.isOptimizable()).andReturn(true);
+ EasyMock.expect(wire.getSourceContract()).andReturn(contract).atLeastOnce();
+ EasyMock.expect(wire.getInvocationChains()).andReturn((Map) Collections.emptyMap());
+ EasyMock.expect(wire.getTargetInstance()).andReturn(new Foo() {
+ public void hello() {
+ }
+ });
+ EasyMock.replay(wire);
+ WireObjectFactory<Foo> factory = new WireObjectFactory<Foo>(Foo.class, wire, null);
+ factory.getInstance();
+ EasyMock.verify(wire);
+
+ }
+
+ /**
+ * Verifies that a proxy is created when the required client contract is different than the wire contract
+ */
+ @SuppressWarnings("unchecked")
+ public void testCannotOptimizeDifferentContractsCreateInstance() throws Exception {
+ ServiceContract<?> contract = new JavaServiceContract(Object.class);
+ Wire wire = EasyMock.createMock(Wire.class);
+ EasyMock.expect(wire.isOptimizable()).andReturn(true);
+ EasyMock.expect(wire.getSourceContract()).andReturn(contract).atLeastOnce();
+ EasyMock.expect(wire.getInvocationChains()).andReturn((Map) Collections.emptyMap());
+ EasyMock.replay(wire);
+ ProxyService service = EasyMock.createMock(ProxyService.class);
+ service.createProxy(EasyMock.eq(Foo.class), EasyMock.eq(wire), EasyMock.isA(Map.class));
+ EasyMock.expectLastCall().andReturn(new Foo() {
+ public void hello() {
+
+ }
+ });
+ EasyMock.replay(service);
+
+ WireObjectFactory<Foo> factory = new WireObjectFactory<Foo>(Foo.class, wire, service);
+ factory.getInstance();
+ EasyMock.verify(service);
+ EasyMock.verify(wire);
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testNoJavaInterfaceCreateInstance() throws Exception {
+ ServiceContract<?> contract = new JavaServiceContract();
+ Wire wire = EasyMock.createMock(Wire.class);
+ EasyMock.expect(wire.isOptimizable()).andReturn(true);
+ EasyMock.expect(wire.getSourceContract()).andReturn(contract).atLeastOnce();
+ EasyMock.expect(wire.getInvocationChains()).andReturn((Map) Collections.emptyMap());
+ EasyMock.replay(wire);
+ ProxyService service = EasyMock.createMock(ProxyService.class);
+ service.createProxy(EasyMock.eq(Foo.class), EasyMock.eq(wire), EasyMock.isA(Map.class));
+ EasyMock.expectLastCall().andReturn(new Foo() {
+ public void hello() {
+
+ }
+ });
+ EasyMock.replay(service);
+
+ WireObjectFactory<Foo> factory = new WireObjectFactory<Foo>(Foo.class, wire, service);
+ factory.getInstance();
+ EasyMock.verify(service);
+ EasyMock.verify(wire);
+ }
+
+ private interface Foo {
+ void hello();
+ }
+
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/WireOptimizationTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/WireOptimizationTestCase.java
new file mode 100644
index 0000000000..1db3892471
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/WireOptimizationTestCase.java
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.wire;
+
+import java.lang.reflect.Type;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.model.Operation;
+import static org.apache.tuscany.spi.model.Operation.NO_CONVERSATION;
+import org.apache.tuscany.spi.wire.Interceptor;
+import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.Message;
+import org.apache.tuscany.spi.wire.Wire;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * Verifies wire optimization analysis
+ *
+ * @version $$Rev$$ $$Date$$
+ */
+public class WireOptimizationTestCase extends TestCase {
+ private Operation operation;
+
+ public void foo() {
+ }
+
+ public void testWireInterceptorOptimization() throws Exception {
+ AtomicComponent component = EasyMock.createNiceMock(AtomicComponent.class);
+ EasyMock.replay(component);
+ Wire wire = new WireImpl();
+ InvocationChain chain = new InvocationChainImpl(operation);
+ chain.addInterceptor(new OptimizableInterceptor());
+ wire.addInvocationChain(operation, chain);
+ assertTrue(WireUtils.isOptimizable(wire));
+ }
+
+ public void testWireNonInterceptorOptimization() throws Exception {
+ AtomicComponent component = EasyMock.createNiceMock(AtomicComponent.class);
+ EasyMock.replay(component);
+ Wire wire = new WireImpl();
+ InvocationChain chain = new InvocationChainImpl(operation);
+ chain.addInterceptor(new NonOptimizableInterceptor());
+ wire.addInvocationChain(operation, chain);
+ assertFalse(WireUtils.isOptimizable(wire));
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ operation = new Operation<Type>("foo", null, null, null, false, null, NO_CONVERSATION);
+
+ }
+
+ private class OptimizableInterceptor implements Interceptor {
+
+ public Message invoke(Message msg) {
+ return null;
+ }
+
+ public void setNext(Interceptor next) {
+
+ }
+
+ public Interceptor getNext() {
+ return null;
+ }
+
+ public boolean isOptimizable() {
+ return true;
+ }
+ }
+
+ private class NonOptimizableInterceptor implements Interceptor {
+
+ public Message invoke(Message msg) {
+ return null;
+ }
+
+ public void setNext(Interceptor next) {
+
+ }
+
+ public Interceptor getNext() {
+ return null;
+ }
+
+ public boolean isOptimizable() {
+ return false;
+ }
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/WireUtilsTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/WireUtilsTestCase.java
new file mode 100644
index 0000000000..9845a55c47
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/WireUtilsTestCase.java
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.wire;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.Type;
+import java.util.Map;
+
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.wire.ChainHolder;
+import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.Wire;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class WireUtilsTestCase extends TestCase {
+ private Method m;
+
+ public void testCreateInterfaceToWireMapping() throws Exception {
+ Wire wire = new WireImpl();
+ Operation<Type> op = new Operation<Type>("hello", null, null, null);
+ InvocationChain chain = new InvocationChainImpl(op);
+ wire.addInvocationChain(op, chain);
+ Map<Method, ChainHolder> chains = WireUtils.createInterfaceToWireMapping(Foo.class, wire);
+ assertEquals(1, chains.size());
+ assertNotNull(chains.get(m));
+ }
+
+ public void testCreateInterfaceToWireMappingNoOperation() throws Exception {
+ Wire wire = new WireImpl();
+ Operation<Type> op = new Operation<Type>("goodbye", null, null, null);
+ InvocationChain chain = new InvocationChainImpl(op);
+ wire.addInvocationChain(op, chain);
+ try {
+ WireUtils.createInterfaceToWireMapping(Foo.class, wire);
+ fail();
+ } catch (NoMethodForOperationException e) {
+ // expected
+ }
+ }
+
+ public void testCreateMapping() throws Exception {
+ Wire wire = new WireImpl();
+ Operation<Type> op = new Operation<Type>("hello", null, null, null);
+ InvocationChain chain = new InvocationChainImpl(op);
+ wire.addInvocationChain(op, chain);
+ Map<Method, InvocationChain> chains = WireUtils.createInboundMapping(wire, new Method[]{m});
+ assertEquals(1, chains.size());
+ assertNotNull(chains.get(m));
+ }
+
+ public void testCreateMappingNoOperation() throws Exception {
+ Wire wire = new WireImpl();
+ Operation<Type> op = new Operation<Type>("goodbye", null, null, null);
+ InvocationChain chain = new InvocationChainImpl(op);
+ wire.addInvocationChain(op, chain);
+ try {
+ WireUtils.createInboundMapping(wire, new Method[]{m});
+ fail();
+ } catch (NoMethodForOperationException e) {
+ // expected
+ }
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ m = Foo.class.getMethod("hello");
+ }
+
+ private interface Foo {
+ void hello();
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandlerSerializationTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandlerSerializationTestCase.java
new file mode 100644
index 0000000000..ff4f882b42
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandlerSerializationTestCase.java
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.wire.jdk;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.SCAExternalizable;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.wire.Wire;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.component.WorkContextImpl;
+import org.apache.tuscany.core.wire.WireImpl;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class JDKCallbackInvocationHandlerSerializationTestCase extends TestCase {
+ private WorkContext workContext;
+ private List<Wire> wires;
+ private AtomicComponent component;
+
+ public void testSerializeDeserialize() throws Exception {
+ JDKCallbackInvocationHandler handler = new JDKCallbackInvocationHandler(wires, workContext);
+ ByteArrayOutputStream stream = new ByteArrayOutputStream();
+ ObjectOutputStream ostream = new ObjectOutputStream(stream);
+ ostream.writeObject(handler);
+
+ ObjectInputStream istream = new ObjectInputStream(new ByteArrayInputStream(stream.toByteArray()));
+ SCAExternalizable externalizable = (SCAExternalizable) istream.readObject();
+
+ externalizable.setWorkContext(workContext);
+ externalizable.reactivate();
+ EasyMock.verify(component);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ URI uri = URI.create("#foo");
+ Wire wire = new WireImpl();
+ wire.setSourceUri(uri);
+ wires = new ArrayList<Wire>();
+ wires.add(wire);
+ List<Wire> wireList = new ArrayList<Wire>();
+ wireList.add(wire);
+ component = EasyMock.createMock(AtomicComponent.class);
+ EasyMock.expect(component.getWires("foo")).andReturn(wireList);
+ EasyMock.replay(component);
+ workContext = new WorkContextImpl();
+ workContext.setCurrentAtomicComponent(component);
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ workContext.setCurrentAtomicComponent(null);
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandlerTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandlerTestCase.java
new file mode 100644
index 0000000000..90e5c4f818
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandlerTestCase.java
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.wire.jdk;
+
+import java.lang.reflect.Proxy;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.tuscany.spi.idl.java.JavaServiceContract;
+import org.apache.tuscany.spi.wire.Wire;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.component.WorkContextImpl;
+import org.apache.tuscany.core.wire.WireImpl;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class JDKCallbackInvocationHandlerTestCase extends TestCase {
+
+ public void testToString() {
+ Wire wire = new WireImpl();
+ URI uri = URI.create("#wire");
+ wire.setSourceUri(uri);
+ List<Wire> wires = new ArrayList<Wire>();
+ wires.add(wire);
+ wire.setSourceContract(new JavaServiceContract(Foo.class));
+ JDKCallbackInvocationHandler handler = new JDKCallbackInvocationHandler(wires, new WorkContextImpl());
+ Foo foo = (Foo) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[]{Foo.class}, handler);
+ assertNotNull(foo.toString());
+ }
+
+ public void testHashCode() {
+ Wire wire = new WireImpl();
+ wire.setSourceContract(new JavaServiceContract(Foo.class));
+ URI uri = URI.create("#wire");
+ wire.setSourceUri(uri);
+ List<Wire> wires = new ArrayList<Wire>();
+ wires.add(wire);
+ JDKCallbackInvocationHandler handler = new JDKCallbackInvocationHandler(wires, new WorkContextImpl());
+ Foo foo = (Foo) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[]{Foo.class}, handler);
+ assertNotNull(foo.hashCode());
+ }
+
+ private interface Foo {
+
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKInvocationHandlerProxyTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKInvocationHandlerProxyTestCase.java
new file mode 100644
index 0000000000..28c3b58f3a
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKInvocationHandlerProxyTestCase.java
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.wire.jdk;
+
+import java.lang.reflect.Method;
+import java.net.URI;
+
+import org.apache.tuscany.spi.idl.java.JavaInterfaceProcessorRegistry;
+import org.apache.tuscany.spi.idl.java.JavaServiceContract;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.MessageImpl;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+import org.apache.tuscany.spi.wire.Wire;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
+import org.apache.tuscany.core.wire.InvocationChainImpl;
+import org.apache.tuscany.core.wire.WireImpl;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class JDKInvocationHandlerProxyTestCase extends TestCase {
+ private JavaInterfaceProcessorRegistry registry = new JavaInterfaceProcessorRegistryImpl();
+ private Method clientHello;
+
+ /**
+ * Verifies a handler configured to use a different interface than the wire target can dispatch
+ */
+ public void testDifferentInterface() throws Throwable {
+ Wire wire = new WireImpl();
+ JavaServiceContract contract = registry.introspect(Target.class);
+ for (Operation<?> operation : contract.getOperations().values()) {
+ InvocationChain chain = new InvocationChainImpl(operation);
+ wire.addInvocationChain(operation, chain);
+ }
+ wire.setSourceContract(contract);
+ wire.setSourceUri(URI.create("foo#bar"));
+ TargetInvoker targetInvoker = EasyMock.createMock(TargetInvoker.class);
+ EasyMock.expect(targetInvoker.invokeTarget(EasyMock.isNull(), EasyMock.eq(TargetInvoker.NONE)))
+ .andReturn(new MessageImpl());
+ EasyMock.expect(targetInvoker.isCacheable()).andReturn(false);
+ EasyMock.replay(targetInvoker);
+ wire.getInvocationChains().values().iterator().next().setTargetInvoker(targetInvoker);
+
+ JDKInvocationHandler handler = new JDKInvocationHandler(Client.class, wire, null);
+ handler.invoke(null, clientHello, null);
+ EasyMock.verify(targetInvoker);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ clientHello = Client.class.getMethod("hello");
+ }
+
+ private interface Target {
+ String hello();
+ }
+
+ private interface Client {
+ String hello();
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKInvocationHandlerSerializationTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKInvocationHandlerSerializationTestCase.java
new file mode 100644
index 0000000000..4c613011a3
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKInvocationHandlerSerializationTestCase.java
@@ -0,0 +1,129 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.wire.jdk;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.SCAObject;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.model.Operation;
+import static org.apache.tuscany.spi.model.Operation.NO_CONVERSATION;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.Message;
+import org.apache.tuscany.spi.wire.MessageImpl;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+import org.apache.tuscany.spi.wire.Wire;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.component.WorkContextImpl;
+import org.apache.tuscany.core.wire.InvocationChainImpl;
+import org.apache.tuscany.core.wire.InvokerInterceptor;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class JDKInvocationHandlerSerializationTestCase extends TestCase {
+ private Wire wire;
+ private WorkContext workContext;
+ private TargetInvoker invoker;
+
+ public void testSerializeDeserialize() throws Throwable {
+ JDKInvocationHandler handler =
+ new JDKInvocationHandler(Foo.class, wire, workContext);
+ handler.invoke(Foo.class.getMethod("invoke"), null);
+ ByteArrayOutputStream stream = new ByteArrayOutputStream();
+ ObjectOutputStream ostream = new ObjectOutputStream(stream);
+ ostream.writeObject(handler);
+
+ ObjectInputStream istream = new ObjectInputStream(new ByteArrayInputStream(stream.toByteArray()));
+ JDKInvocationHandler externalizable = (JDKInvocationHandler) istream.readObject();
+
+ externalizable.setWorkContext(workContext);
+ externalizable.reactivate();
+ externalizable.invoke(Foo.class.getMethod("invoke"), null);
+ EasyMock.verify(invoker);
+ EasyMock.verify(wire);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ SCAObject container = EasyMock.createMock(SCAObject.class);
+ ServiceContract<Foo> contract = new ServiceContract<Foo>() {
+ };
+ contract.setInterfaceClass(Foo.class);
+ contract.setConversational(false);
+ EasyMock.expect(container.getUri()).andReturn(URI.create("bar")).atLeastOnce();
+
+ wire = EasyMock.createMock(Wire.class);
+ Map<Operation<?>, InvocationChain> map = new HashMap<Operation<?>, InvocationChain>();
+ Operation<Object> operation = new Operation<Object>("invoke", null, null, null, false, null, NO_CONVERSATION);
+ ServiceContract<Object> opContract = new ServiceContract<Object>() {
+ };
+ contract.setInterfaceClass(Foo.class);
+ contract.setConversational(false);
+ operation.setServiceContract(opContract);
+ map.put(operation, createChain(operation));
+ EasyMock.expect(wire.getSourceContract()).andReturn(contract).atLeastOnce();
+ URI uri = URI.create("#foo");
+ EasyMock.expect(wire.getSourceUri()).andReturn(uri).atLeastOnce();
+ EasyMock.expect(wire.getInvocationChains()).andReturn(map).times(2);
+ EasyMock.replay(wire);
+ List<Wire> list = new ArrayList<Wire>();
+ list.add(wire);
+ AtomicComponent component = EasyMock.createMock(AtomicComponent.class);
+ EasyMock.expect(component.getWires("foo")).andReturn(list);
+ EasyMock.replay(component);
+ workContext = new WorkContextImpl();
+ workContext.setCurrentAtomicComponent(component);
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ workContext.setCurrentAtomicComponent(null);
+ }
+
+ private InvocationChain createChain(Operation operation) {
+ invoker = EasyMock.createMock(TargetInvoker.class);
+ EasyMock.expect(invoker.invoke(EasyMock.isA(Message.class))).andReturn(new MessageImpl()).times(2);
+ EasyMock.expect(invoker.isCacheable()).andReturn(false).atLeastOnce();
+ EasyMock.replay(invoker);
+ InvocationChain chain = new InvocationChainImpl(operation);
+ chain.setTargetInvoker(invoker);
+ chain.addInterceptor(new InvokerInterceptor());
+ return chain;
+ }
+
+ public class Foo {
+
+ public void invoke() {
+ }
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKInvocationHandlerTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKInvocationHandlerTestCase.java
new file mode 100644
index 0000000000..7d88c0c7a1
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKInvocationHandlerTestCase.java
@@ -0,0 +1,156 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.wire.jdk;
+
+import java.lang.reflect.Array;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Proxy;
+import java.lang.reflect.Type;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.idl.java.JavaServiceContract;
+import org.apache.tuscany.spi.model.DataType;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.InvocationRuntimeException;
+import org.apache.tuscany.spi.wire.Message;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+import org.apache.tuscany.spi.wire.Wire;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.component.WorkContextImpl;
+import org.apache.tuscany.core.wire.InvocationChainImpl;
+import org.apache.tuscany.core.wire.WireImpl;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class JDKInvocationHandlerTestCase extends TestCase {
+
+ public void testToString() {
+ Wire wire = new WireImpl();
+ ServiceContract contract = new JavaServiceContract(Foo.class);
+ contract.setConversational(false);
+ wire.setSourceContract(contract);
+ wire.setSourceUri(URI.create("foo#bar"));
+ JDKInvocationHandler handler = new JDKInvocationHandler(Foo.class, wire, null);
+ Foo foo = (Foo) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[]{Foo.class}, handler);
+ assertNotNull(foo.toString());
+ }
+
+ public void testHashCode() {
+ Wire wire = new WireImpl();
+ ServiceContract contract = new JavaServiceContract(Foo.class);
+ contract.setConversational(false);
+ wire.setSourceContract(contract);
+ wire.setSourceUri(URI.create("foo#bar"));
+ JDKInvocationHandler handler = new JDKInvocationHandler(Foo.class, wire, null);
+ Foo foo = (Foo) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[]{Foo.class}, handler);
+ assertNotNull(foo.hashCode());
+ }
+
+ public void testConversational() throws Throwable {
+ Wire wire = new WireImpl();
+ DataType<Type> type1 = new DataType<Type>(String.class, String.class);
+ List<DataType<Type>> types = new ArrayList<DataType<Type>>();
+ types.add(type1);
+ DataType<List<DataType<Type>>> inputType1 = new DataType<List<DataType<Type>>>(Object[].class, types);
+ DataType<Type> outputType1 = new DataType<Type>(String.class, String.class);
+ Operation<Type> op1 = new Operation<Type>("test", inputType1, outputType1, null);
+ ServiceContract<Type> contract = new JavaServiceContract(Foo.class);
+ contract.setConversational(true);
+ op1.setServiceContract(contract);
+
+ WorkContext wc = new WorkContextImpl();
+ MockInvoker invoker = new MockInvoker(wc);
+
+ InvocationChain chain = new InvocationChainImpl(op1);
+ chain.setTargetInvoker(invoker);
+ wire.addInvocationChain(op1, chain);
+ URI uri = URI.create("fooRef");
+ wire.setSourceUri(uri);
+ wire.setSourceContract(contract);
+
+ String convID = UUID.randomUUID().toString();
+ wc.setIdentifier(Scope.CONVERSATION, convID);
+ invoker.setCurrentConversationID(convID);
+
+ JDKInvocationHandler handler = new JDKInvocationHandler(Foo.class, wire, wc);
+ handler.invoke(Foo.class.getMethod("test", String.class), new Object[]{"bar"});
+ String currentConvID = (String) wc.getIdentifier(Scope.CONVERSATION);
+ assertSame(convID, currentConvID);
+
+ JDKInvocationHandler handler2 = new JDKInvocationHandler(Foo.class, wire, wc);
+ handler2.invoke(Foo.class.getMethod("test", String.class), new Object[]{"bar"});
+ currentConvID = (String) wc.getIdentifier(Scope.CONVERSATION);
+ assertSame(convID, currentConvID);
+ }
+
+ private interface Foo {
+ String test(String s);
+ }
+
+ private class MockInvoker implements TargetInvoker {
+
+ private WorkContext wc;
+ private String currentConversationID;
+
+ public MockInvoker(WorkContext wc) {
+ this.wc = wc;
+ }
+
+ public void setCurrentConversationID(String id) {
+ currentConversationID = id;
+ }
+
+ public Object invokeTarget(final Object payload, final short sequence) throws InvocationTargetException {
+ assertEquals("bar", Array.get(payload, 0));
+ String convID = (String) wc.getIdentifier(Scope.CONVERSATION);
+ assertSame(convID, currentConversationID);
+ return "response";
+ }
+
+ public Message invoke(Message msg) throws InvocationRuntimeException {
+ fail();
+ return null;
+ }
+
+ public boolean isCacheable() {
+ return false;
+ }
+
+ public void setCacheable(boolean cacheable) {
+
+ }
+
+ public boolean isOptimizable() {
+ return false;
+ }
+
+ public Object clone() throws CloneNotSupportedException {
+ return super.clone();
+ }
+ }
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKProxyTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKProxyTestCase.java
new file mode 100644
index 0000000000..d140c699c6
--- /dev/null
+++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKProxyTestCase.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.wire.jdk;
+
+import java.lang.reflect.Proxy;
+import java.net.URI;
+
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.wire.Wire;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.wire.WireImpl;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class JDKProxyTestCase extends TestCase {
+ private JDKProxyService proxyService;
+
+ public void testCreateProxy() {
+ URI uri = URI.create("#service");
+ Wire wire = new WireImpl();
+ wire.setSourceUri(uri);
+ ServiceContract contract = new ServiceContract() {
+ };
+ wire.setSourceContract(contract);
+ TestInterface proxy = proxyService.createProxy(TestInterface.class, wire);
+ assertTrue(Proxy.isProxyClass(proxy.getClass()));
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ proxyService = new JDKProxyService();
+ }
+
+ public static interface TestInterface {
+ int primitives(int i);
+
+ String objects(String object);
+ }
+}