From 3caf8614f25d6b1962e20331fdf423c863bc02f3 Mon Sep 17 00:00:00 2001 From: lresende Date: Wed, 11 Nov 2009 23:13:31 +0000 Subject: Moving 1.x branches git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@835144 13f79535-47bb-0310-9956-ffa450edef68 --- .../local/AbstractLocalTargetInvokerTestCase.java | 72 -- .../binding/local/LocalBindingBuilderTestCase.java | 38 - .../binding/local/LocalBindingLoaderTestCase.java | 70 -- ...ckTargetInvokerInvocationExceptionTestCase.java | 86 --- .../local/LocalCallbackTargetInvokerTestCase.java | 82 --- ...ocalCallbackTargetInvokerThrowableTestCase.java | 98 --- .../binding/local/LocalTargetInvokerTestCase.java | 127 ---- .../core/bootstrap/BootstrapperTestCase.java | 42 -- .../builder/AbstractConnectorImplTestCase.java | 306 -------- .../core/builder/AtomicConnectorTestCase.java | 125 ---- .../builder/BuilderRegistryNoBindingsTestCase.java | 80 --- .../core/builder/BuilderRegistryTestCase.java | 219 ------ .../core/builder/ConnectorImplTestCase.java | 322 --------- .../core/builder/ConnectorPostProcessTestCase.java | 104 --- .../builder/IllegalCallbackExceptionTestCase.java | 43 -- .../builder/InboundtoOutboundConnectTestCase.java | 168 ----- .../IncompatibleInterfacesExceptionTestCase.java | 41 -- .../InvalidTargetTypeExceptionTestCase.java | 41 -- .../core/builder/LocalReferenceWiringTestCase.java | 236 ------- ...rwardNonBlockingCallbackConnectionTestCase.java | 172 ----- ...ckingForwardSyncCallbackConnectionTestCase.java | 171 ----- .../builder/OutboundToInboundConnectTestCase.java | 184 ----- .../core/builder/ReferenceConnectorTestCase.java | 169 ----- .../core/builder/ServiceConnectorTestCase.java | 172 ----- ...nchronousForwardCallbackConnectionTestCase.java | 256 ------- .../TargetServiceNotFoundExceptionTestCase.java | 41 -- .../WirePostProcessorRegistryImplTestCase.java | 63 -- .../builder/WiringExceptionFormatterTestCase.java | 88 --- .../core/component/WorkContextImplTestCase.java | 65 -- .../core/component/event/EventTestCase.java | 72 -- .../scope/AbstractScopeContainerTestCase.java | 126 ---- .../scope/BasicCompositeScopeTestCase.java | 127 ---- .../scope/BasicConversationalScopeTestCase.java | 129 ---- .../scope/BasicHttpSessionScopeTestCase.java | 145 ---- .../component/scope/BasicRequestScopeTestCase.java | 128 ---- .../scope/BasicStatelessScopeTestCase.java | 120 ---- .../CompositeScopeInitDestroyErrorTestCase.java | 78 -- .../CompositeScopeInstanceLifecycleTestCase.java | 186 ----- .../scope/CompositeScopeObjectFactoryTestCase.java | 38 - .../scope/CompositeScopeRestartTestCase.java | 99 --- ...lScopeContainerDestroyOnExpirationTestCase.java | 121 ---- ...ConversationalScopeContainerMaxAgeTestCase.java | 76 -- ...rsationalScopeContainerMaxIdleTimeTestCase.java | 79 --- ...rsationalScopeContainerPersistenceTestCase.java | 181 ----- ...nversationalScopeInstanceLifecycleTestCase.java | 70 -- .../scope/ConversationalScopeRestartTestCase.java | 112 --- .../scope/DependencyLifecycleTestCase.java | 170 ----- .../HttpSessionScopeInitDestroyErrorTestCase.java | 69 -- .../HttpSessionScopeInstanceLifecycleTestCase.java | 136 ---- .../scope/HttpSessionScopeRestartTestCase.java | 105 --- .../component/scope/InstanceWrapperTestCase.java | 66 -- .../tuscany/core/component/scope/MockFactory.java | 137 ---- .../RequestScopeInitDestroyErrorTestCase.java | 63 -- .../RequestScopeInstanceLifecycleTestCase.java | 129 ---- .../scope/RequestScopeRestartTestCase.java | 99 --- .../component/scope/ScopeRegistryTestCase.java | 80 --- .../scope/StatelessScopeContainerTestCase.java | 48 -- .../scope/StatelessScopeObjectFactoryTestCase.java | 37 - .../core/component/scope/WorkContextTestCase.java | 212 ------ .../impl/DataBindingInterceptorTestCase.java | 132 ---- .../DataBindingJavaInterfaceProcessorTestCase.java | 80 --- .../impl/DataBindingLoaderTestCase.java | 79 --- .../impl/DataBindingRegistryImplTestCase.java | 98 --- .../core/databinding/impl/DataBindingTestCase.java | 45 -- ...ndingWirePostProcessorOptimizationTestCase.java | 111 --- .../impl/DataBindingWirePostProcessorTestCase.java | 231 ------ .../databinding/impl/DirectedGraphTestCase.java | 89 --- .../databinding/impl/IDLTransformerTestCase.java | 217 ------ .../databinding/impl/MediatorImplTestCase.java | 118 ---- .../impl/PassByValueInterceptorTestCase.java | 75 -- .../impl/PassByValueWirePostProcessorTestCase.java | 266 ------- .../impl/TransformerRegistryImplTestCase.java | 106 --- .../DOMNode2JavaBeanTransformerTestCase.java | 187 ----- .../JavaBean2DOMNodeTransformerTestCase.java | 127 ---- .../core/databinding/xml/DOM2StAXTestCase.java | 89 --- .../core/databinding/xml/DataPipeTestCase.java | 89 --- .../xml/JavaBean2XMLStreamReaderTestCase.java | 133 ---- .../core/databinding/xml/Node2StringTestCase.java | 35 - .../xml/PushTransformationTestCase.java | 81 --- .../core/databinding/xml/StAXHelperTestCase.java | 47 -- .../databinding/xml/TraxTransformerTestCase.java | 99 --- .../core/deployer/BootstrapDeployerTestCase.java | 168 ----- .../java/ConversationalIntrospectionTestCase.java | 82 --- ...JavaInterfaceProcessorRegistryImplTestCase.java | 100 --- .../IntrospectionRegistryTestCase.java | 124 ---- .../PojoAtomicComponentTestCase.java | 159 ----- .../tuscany/core/implementation/TestUtils.java | 74 -- .../composite/AutowireResolutionTestCase.java | 87 --- .../implementation/composite/AutowireTestCase.java | 230 ------ .../composite/CompositeBuilderTestCase.java | 215 ------ .../CompositeComponentImplBasicTestCase.java | 119 ---- .../CompositeComponentImplSystemWireTestCase.java | 170 ----- .../composite/CompositeComponentImplTestCase.java | 179 ----- .../CompositeComponentResolutionTestCase.java | 84 --- .../composite/CompositeLifecycleTestCase.java | 120 ---- .../CompositeLoaderWireResolutionTestCase.java | 232 ------ .../composite/CompositePropagationTestCase.java | 95 --- .../composite/DuplicateRegistrationTestCase.java | 105 --- .../ImplementationCompositeLoaderTestCase.java | 194 ----- .../composite/JavaObjectRegistrationTestCase.java | 88 --- .../composite/ManagedRequestContextTestCase.java | 42 -- .../composite/ReferenceImplTestCase.java | 61 -- .../composite/ServiceImplTestCase.java | 61 -- .../composite/SystemComponentBuilderTestCase.java | 180 ----- .../SystemSingletonAtomicComponentTestCase.java | 61 -- ...vaAtomicComponentMetadataInjectionTestCase.java | 37 - ...avaAtomicComponentNegativeMetadataTestCase.java | 49 -- .../java/JavaBuilderPropertyTestCase.java | 137 ---- ...JavaComponentBuilderConversationIDTestCase.java | 80 --- .../java/JavaComponentBuilderMetadataTestCase.java | 112 --- .../JavaComponentBuilderReferenceTestCase.java | 149 ---- .../java/JavaComponentBuilderResourceTestCase.java | 81 --- .../java/JavaComponentTypeLoaderTestCase.java | 78 -- .../java/JavaReferenceWireTestCase.java | 153 ---- .../JavaTargetInvokerBasicInvocationTestCase.java | 188 ----- .../java/JavaTargetInvokerMediationTestCase.java | 61 -- ...TargetInvokerNonBlockingInvocationTestCase.java | 229 ------ .../java/JavaTargetInvokerSequenceTestCase.java | 117 --- .../JavaTargetInvokerStatelessDestroyTestCase.java | 54 -- .../java/JavaTargetInvokerTestCase.java | 53 -- .../implementation/java/MultiplicityTestCase.java | 34 - .../java/ResourceInjectionTestCase.java | 111 --- .../integration/CallbackInvocationTestCase.java | 395 ----------- .../integration/OutboundWireToJavaTestCase.java | 233 ------ .../AllowsPassByReferenceProcessorTestCase.java | 59 -- .../processor/ConstructorAutowireTestCase.java | 154 ---- .../ConstructorProcessorExtensibilityTestCase.java | 82 --- .../processor/ConstructorProcessorTestCase.java | 185 ----- .../processor/ConstructorPropertyTestCase.java | 168 ----- .../processor/ConstructorReferenceTestCase.java | 172 ----- .../processor/ConstructorResourceTestCase.java | 166 ----- .../processor/ContextProcessorTestCase.java | 197 ------ .../processor/ConversationProcessorTestCase.java | 151 ---- .../processor/ConvertTimeMillisTestCase.java | 110 --- .../processor/DestroyProcessorTestCase.java | 100 --- .../processor/EagerInitProcessorTestCase.java | 54 -- .../processor/HeuristicAndPropertyTestCase.java | 70 -- .../processor/HeuristicConstructorTestCase.java | 330 --------- .../processor/HeuristicPojoProcessorTestCase.java | 395 ----------- .../HeutisticExtensibleConstructorTestCase.java | 129 ---- .../ImplementationProcessorServiceTestCase.java | 117 --- ...plementationProcessorServiceUniqueTestCase.java | 67 -- .../processor/InitProcessorTestCase.java | 98 --- .../processor/MonitorProcessorTestCase.java | 180 ----- .../processor/PropertyProcessorTestCase.java | 204 ------ .../processor/ReferenceProcessorTestCase.java | 225 ------ .../processor/ResourceProcessorTestCase.java | 99 --- .../processor/ScopeProcessorTestCase.java | 128 ---- .../processor/ServiceCallbackTestCase.java | 166 ----- .../processor/ServiceProcessorTestCase.java | 136 ---- .../SystemComponentBuilderResourceTestCase.java | 75 -- .../component/SystemAtomicComponentTestCase.java | 124 ---- ...ystemAtomicComponentWireInvocationTestCase.java | 60 -- .../loader/SystemComponentTypeLoaderTestCase.java | 82 --- .../loader/SystemImplementationLoaderTestCase.java | 106 --- .../CallbackWireObjectFactoryTestCase.java | 47 -- .../core/injection/FieldInjectorTestCase.java | 48 -- .../core/injection/JNDIObjectFactoryTestCase.java | 61 -- .../core/injection/MethodEventInvokerTestCase.java | 72 -- .../core/injection/MethodInjectorTestCase.java | 79 --- .../core/injection/PojoObjectFactoryTestCase.java | 64 -- .../RequestContextObjectFactoryTestCase.java | 37 - .../injection/ResourceObjectFactoryTestCase.java | 152 ---- .../injection/SingletonObjectFactoryTestCase.java | 33 - .../conversation/AbstractConversationTestCase.java | 62 -- .../ConversationIdleExpireTestCase.java | 140 ---- .../ConversationMaxAgeExpireTestCase.java | 141 ---- .../ConversationStartStopEndTestCase.java | 141 ---- .../IntrospectionRegistryIntegrationTestCase.java | 131 ---- .../builder/SystemBuilderPropertyTestCase.java | 89 --- .../tuscany/core/integration/mock/MockFactory.java | 278 -------- .../integration/scope/ScopeReferenceTestCase.java | 781 --------------------- .../wire/DifferentInterfaceWireTestCase.java | 137 ---- .../wire/ReferenceInjectionTestCase.java | 72 -- .../oneway/OneWayWireToJavaInvocationTestCase.java | 130 ---- .../loader/ComponentLoaderNoBindingTestCase.java | 91 --- .../loader/ComponentLoaderPropertyTestCase.java | 90 --- .../loader/ComponentLoaderReferenceTestCase.java | 87 --- .../core/loader/ComponentLoaderTestCase.java | 201 ------ .../loader/ComponentLoaderValidationTestCase.java | 170 ----- .../ComponentReferenceOverridingTestCase.java | 178 ----- .../loader/ComponentTypeElementLoaderTestCase.java | 90 --- .../core/loader/DependencyLoaderTestCase.java | 124 ---- .../tuscany/core/loader/IncludeLoaderTestCase.java | 169 ----- .../core/loader/JNDIPropertyFactoryTestCase.java | 66 -- .../loader/LoaderExceptionFormatterTestCase.java | 47 -- .../loader/MultivaluePropertyLoadingTestCase.java | 204 ------ .../core/loader/PolicySetLoaderTestCase.java | 71 -- .../core/loader/PropertyLoaderTestCase.java | 180 ----- .../core/loader/PropertyParsingTestCase.java | 78 -- .../core/loader/ReferenceLoaderTestCase.java | 143 ---- .../tuscany/core/loader/ServiceLoaderTestCase.java | 166 ----- .../loader/StAXLoaderRegistryImplTestCase.java | 131 ---- .../StringParserPropertyFactoryTestCase.java | 133 ---- .../tuscany/core/loader/WireLoaderTestCase.java | 159 ----- .../core/mock/binding/MockServiceBinding.java | 82 --- .../tuscany/core/mock/component/AsyncTarget.java | 31 - .../core/mock/component/BadContextPojo.java | 28 - .../tuscany/core/mock/component/BadNamePojo.java | 26 - .../core/mock/component/BasicInterface.java | 30 - .../core/mock/component/BasicInterfaceImpl.java | 66 -- .../mock/component/CompositeScopeComponent.java | 31 - .../component/CompositeScopeComponentImpl.java | 40 -- .../CompositeScopeDestroyOnlyComponent.java | 36 - .../CompositeScopeInitDestroyComponent.java | 39 - .../component/CompositeScopeInitOnlyComponent.java | 42 -- .../component/ConversationalScopeComponent.java | 29 - .../ConversationalScopeComponentImpl.java | 29 - .../ConversationalScopeDestroyOnlyComponent.java | 37 - .../ConversationalScopeInitDestroyComponent.java | 38 - .../ConversationalScopeInitOnlyComponent.java | 38 - .../core/mock/component/OrderException.java | 40 -- .../core/mock/component/OrderedDependentPojo.java | 29 - .../mock/component/OrderedDependentPojoImpl.java | 36 - .../core/mock/component/OrderedEagerInitPojo.java | 60 -- .../core/mock/component/OrderedInitPojo.java | 28 - .../core/mock/component/OrderedInitPojoImpl.java | 61 -- .../tuscany/core/mock/component/OtherTarget.java | 31 - .../core/mock/component/OtherTargetImpl.java | 39 - .../core/mock/component/RequestScopeComponent.java | 30 - .../RequestScopeDestroyOnlyComponent.java | 38 - .../RequestScopeInitDestroyComponent.java | 38 - .../component/RequestScopeInitOnlyComponent.java | 39 - .../core/mock/component/SessionScopeComponent.java | 30 - .../mock/component/SessionScopeComponentImpl.java | 30 - .../SessionScopeInitDestroyComponent.java | 36 - .../component/SessionScopeInitOnlyComponent.java | 37 - .../tuscany/core/mock/component/SimpleTarget.java | 30 - .../core/mock/component/SimpleTargetImpl.java | 41 -- .../apache/tuscany/core/mock/component/Source.java | 37 - .../tuscany/core/mock/component/SourceImpl.java | 63 -- .../core/mock/component/StatelessComponent.java | 30 - .../mock/component/StatelessComponentImpl.java | 27 - .../apache/tuscany/core/mock/component/Target.java | 32 - .../tuscany/core/mock/component/TargetImpl.java | 38 - .../tuscany/core/mock/wire/MockStaticInvoker.java | 97 --- .../core/mock/wire/MockSyncInterceptor.java | 55 -- .../tuscany/core/mock/wire/MockTargetInvoker.java | 33 - .../monitor/DefaultExceptionFormatterTestCase.java | 63 -- .../tuscany/core/monitor/JavaLoggingTestCase.java | 153 ---- .../core/policy/IntentRegistryImplTestCase.java | 152 ---- .../core/policy/PolicyEngineImplTestCase.java | 140 ---- .../core/property/PropertyHelperTestCase.java | 107 --- .../SimplePropertyObjectFactoryTestCase.java | 113 --- .../artifact/LocalMavenRepositoryTestCase.java | 82 --- .../deployment/AssemblyServiceImplTestCase.java | 107 --- .../ContentTypeDescriberImplTestCase.java | 52 -- .../deployment/ContributionLoaderTestCase.java | 82 --- .../deployment/ContributionRepositoryTestCase.java | 76 -- .../ContributionServiceImplTestCase.java | 72 -- .../CompositeContributionProcessorTestCase.java | 84 --- .../FolderContributionProcessorTestCase.java | 56 -- .../JarContributionProcessorTestCase.java | 53 -- .../JavaContributionProcessorTestCase.java | 79 --- .../DelegatingResourceHostRegistryTestCase.java | 147 ---- .../services/store/memory/MemoryStoreTestCase.java | 164 ----- .../work/jsr237/Jsr237WorkSchedulerTest.java | 81 --- .../work/jsr237/Jsr237WorkSchedulerTestCase.java | 100 --- .../workmanager/ThreadPoolWorkManagerTestCase.java | 132 ---- .../java/org/apache/tuscany/core/util/Bean1.java | 45 -- .../java/org/apache/tuscany/core/util/Bean2.java | 47 -- .../core/util/JavaIntrospectionHelperTestCase.java | 180 ----- .../org/apache/tuscany/core/util/SuperBean.java | 48 -- .../BasicReferenceInvocationHandlerTestCase.java | 69 -- .../wire/CallbackInterfaceInterceptorTestCase.java | 60 -- .../core/wire/ContractCompatibilityTestCase.java | 401 ----------- .../core/wire/InboundInvocationErrorTestCase.java | 166 ----- ...eServiceContractExceptionFormatterTestCase.java | 82 --- .../core/wire/InvocationChainImplTestCase.java | 94 --- .../wire/InvocationConfigurationErrorTestCase.java | 95 --- .../core/wire/InvocationConfigurationTestCase.java | 95 --- .../NonBlockingBridgingInterceptorTestCase.java | 75 -- .../wire/OptimizedWireObjectFactoryTestCase.java | 44 -- .../core/wire/OutboundInvocationErrorTestCase.java | 133 ---- .../wire/OutboundInvocationHandlerTestCase.java | 132 ---- .../tuscany/core/wire/OutboundWireTestCase.java | 38 - .../SynchronousBridgingInterceptorTestCase.java | 44 -- .../core/wire/WireObjectFactoryTestCase.java | 138 ---- .../core/wire/WireOptimizationTestCase.java | 154 ---- .../core/wire/WireServiceExtensionTestCase.java | 333 --------- .../tuscany/core/wire/WireUtilsTestCase.java | 94 --- ...backInvocationHandlerSerializationTestCase.java | 54 -- .../jdk/JDKCallbackInvocationHandlerTestCase.java | 54 -- ...oundInvocationHandlerSerializationTestCase.java | 110 --- .../jdk/JDKInboundInvocationHandlerTestCase.java | 162 ----- .../JDKOutboundInvocationHandlerProxyTestCase.java | 80 --- ...oundInvocationHandlerSerializationTestCase.java | 132 ---- .../jdk/JDKOutboundInvocationHandlerTestCase.java | 176 ----- .../tuscany/core/wire/jdk/JDKProxyTestCase.java | 61 -- 289 files changed, 31694 deletions(-) delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/AbstractLocalTargetInvokerTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalBindingBuilderTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalBindingLoaderTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalCallbackTargetInvokerInvocationExceptionTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalCallbackTargetInvokerTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalCallbackTargetInvokerThrowableTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalTargetInvokerTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/bootstrap/BootstrapperTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/AbstractConnectorImplTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/AtomicConnectorTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/BuilderRegistryNoBindingsTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/BuilderRegistryTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/ConnectorImplTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/ConnectorPostProcessTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/IllegalCallbackExceptionTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/InboundtoOutboundConnectTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/IncompatibleInterfacesExceptionTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/InvalidTargetTypeExceptionTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/LocalReferenceWiringTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/NonBlockingForwardNonBlockingCallbackConnectionTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/NonBlockingForwardSyncCallbackConnectionTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/OutboundToInboundConnectTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/ReferenceConnectorTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/ServiceConnectorTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/SynchronousForwardCallbackConnectionTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/TargetServiceNotFoundExceptionTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/WirePostProcessorRegistryImplTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/WiringExceptionFormatterTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/WorkContextImplTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/event/EventTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/AbstractScopeContainerTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/BasicCompositeScopeTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/BasicConversationalScopeTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/BasicHttpSessionScopeTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/BasicRequestScopeTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/BasicStatelessScopeTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/CompositeScopeInitDestroyErrorTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/CompositeScopeInstanceLifecycleTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/CompositeScopeObjectFactoryTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/CompositeScopeRestartTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeContainerDestroyOnExpirationTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeContainerMaxAgeTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeContainerMaxIdleTimeTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeContainerPersistenceTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeInstanceLifecycleTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeRestartTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/DependencyLifecycleTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/HttpSessionScopeInitDestroyErrorTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/HttpSessionScopeInstanceLifecycleTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/HttpSessionScopeRestartTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/InstanceWrapperTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/MockFactory.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/RequestScopeInitDestroyErrorTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/RequestScopeInstanceLifecycleTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/RequestScopeRestartTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/ScopeRegistryTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/StatelessScopeContainerTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/StatelessScopeObjectFactoryTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/WorkContextTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingInterceptorTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingJavaInterfaceProcessorTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingLoaderTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingRegistryImplTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingWirePostProcessorOptimizationTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingWirePostProcessorTestCase.java delete mode 100755 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DirectedGraphTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/IDLTransformerTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/MediatorImplTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/PassByValueInterceptorTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/PassByValueWirePostProcessorTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/TransformerRegistryImplTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/javabeans/DOMNode2JavaBeanTransformerTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/javabeans/JavaBean2DOMNodeTransformerTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/xml/DOM2StAXTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/xml/DataPipeTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/xml/JavaBean2XMLStreamReaderTestCase.java delete mode 100755 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/xml/Node2StringTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/xml/PushTransformationTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/xml/StAXHelperTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/xml/TraxTransformerTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/deployer/BootstrapDeployerTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/idl/java/ConversationalIntrospectionTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/idl/java/JavaInterfaceProcessorRegistryImplTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/IntrospectionRegistryTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/PojoAtomicComponentTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/TestUtils.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/AutowireResolutionTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/AutowireTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeBuilderTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeComponentImplBasicTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeComponentImplSystemWireTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeComponentImplTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeComponentResolutionTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeLifecycleTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeLoaderWireResolutionTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositePropagationTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/DuplicateRegistrationTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/ImplementationCompositeLoaderTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/JavaObjectRegistrationTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/ManagedRequestContextTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/ReferenceImplTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/ServiceImplTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/SystemComponentBuilderTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/SystemSingletonAtomicComponentTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaAtomicComponentMetadataInjectionTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaAtomicComponentNegativeMetadataTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaBuilderPropertyTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderConversationIDTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderMetadataTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderReferenceTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderResourceTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentTypeLoaderTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaReferenceWireTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerBasicInvocationTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerMediationTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerNonBlockingInvocationTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerSequenceTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerStatelessDestroyTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/MultiplicityTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/ResourceInjectionTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/integration/CallbackInvocationTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/integration/OutboundWireToJavaTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/AllowsPassByReferenceProcessorTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorAutowireTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorProcessorExtensibilityTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorProcessorTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorPropertyTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorReferenceTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorResourceTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ContextProcessorTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConversationProcessorTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConvertTimeMillisTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/DestroyProcessorTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/EagerInitProcessorTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicAndPropertyTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicConstructorTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicPojoProcessorTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeutisticExtensibleConstructorTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ImplementationProcessorServiceTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ImplementationProcessorServiceUniqueTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/InitProcessorTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/MonitorProcessorTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/PropertyProcessorTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ReferenceProcessorTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ResourceProcessorTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ScopeProcessorTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ServiceCallbackTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ServiceProcessorTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/system/builder/SystemComponentBuilderResourceTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/system/component/SystemAtomicComponentTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/system/component/SystemAtomicComponentWireInvocationTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/system/loader/SystemComponentTypeLoaderTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/system/loader/SystemImplementationLoaderTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/injection/CallbackWireObjectFactoryTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/injection/FieldInjectorTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/injection/JNDIObjectFactoryTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/injection/MethodEventInvokerTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/injection/MethodInjectorTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/injection/PojoObjectFactoryTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/injection/RequestContextObjectFactoryTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/injection/ResourceObjectFactoryTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/injection/SingletonObjectFactoryTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/integration/conversation/AbstractConversationTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/integration/conversation/ConversationIdleExpireTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/integration/conversation/ConversationMaxAgeExpireTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/integration/conversation/ConversationStartStopEndTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/integration/implementation/IntrospectionRegistryIntegrationTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/integration/implementation/system/builder/SystemBuilderPropertyTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/integration/mock/MockFactory.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/integration/scope/ScopeReferenceTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/integration/wire/DifferentInterfaceWireTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/integration/wire/ReferenceInjectionTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/integration/wire/oneway/OneWayWireToJavaInvocationTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderNoBindingTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderPropertyTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderReferenceTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderValidationTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentReferenceOverridingTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentTypeElementLoaderTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/DependencyLoaderTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/IncludeLoaderTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/JNDIPropertyFactoryTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/LoaderExceptionFormatterTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/MultivaluePropertyLoadingTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/PolicySetLoaderTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/PropertyLoaderTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/PropertyParsingTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/ReferenceLoaderTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/ServiceLoaderTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/StAXLoaderRegistryImplTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/StringParserPropertyFactoryTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/WireLoaderTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/binding/MockServiceBinding.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/AsyncTarget.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/BadContextPojo.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/BadNamePojo.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/BasicInterface.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/BasicInterfaceImpl.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeComponent.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeComponentImpl.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeDestroyOnlyComponent.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeInitDestroyComponent.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeInitOnlyComponent.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeComponent.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeComponentImpl.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeDestroyOnlyComponent.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeInitDestroyComponent.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeInitOnlyComponent.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OrderException.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OrderedDependentPojo.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OrderedDependentPojoImpl.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OrderedEagerInitPojo.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OrderedInitPojo.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OrderedInitPojoImpl.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OtherTarget.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OtherTargetImpl.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/RequestScopeComponent.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/RequestScopeDestroyOnlyComponent.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/RequestScopeInitDestroyComponent.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/RequestScopeInitOnlyComponent.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/SessionScopeComponent.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/SessionScopeComponentImpl.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/SessionScopeInitDestroyComponent.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/SessionScopeInitOnlyComponent.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/SimpleTarget.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/SimpleTargetImpl.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/Source.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/SourceImpl.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/StatelessComponent.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/StatelessComponentImpl.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/Target.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/TargetImpl.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/wire/MockStaticInvoker.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/wire/MockSyncInterceptor.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/wire/MockTargetInvoker.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/monitor/DefaultExceptionFormatterTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/monitor/JavaLoggingTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/policy/IntentRegistryImplTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/policy/PolicyEngineImplTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/property/PropertyHelperTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/property/SimplePropertyObjectFactoryTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/artifact/LocalMavenRepositoryTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/AssemblyServiceImplTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/ContentTypeDescriberImplTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/ContributionLoaderTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/ContributionRepositoryTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/ContributionServiceImplTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/contribution/CompositeContributionProcessorTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/contribution/FolderContributionProcessorTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/contribution/JarContributionProcessorTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/contribution/JavaContributionProcessorTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/host/DelegatingResourceHostRegistryTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/store/memory/MemoryStoreTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/work/jsr237/Jsr237WorkSchedulerTest.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/work/jsr237/Jsr237WorkSchedulerTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/work/jsr237/workmanager/ThreadPoolWorkManagerTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/util/Bean1.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/util/Bean2.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/util/JavaIntrospectionHelperTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/util/SuperBean.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/BasicReferenceInvocationHandlerTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/CallbackInterfaceInterceptorTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/ContractCompatibilityTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/InboundInvocationErrorTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/IncompatibleServiceContractExceptionFormatterTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/InvocationChainImplTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/InvocationConfigurationErrorTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/InvocationConfigurationTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/NonBlockingBridgingInterceptorTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/OptimizedWireObjectFactoryTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/OutboundInvocationErrorTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/OutboundInvocationHandlerTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/OutboundWireTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/SynchronousBridgingInterceptorTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/WireObjectFactoryTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/WireOptimizationTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/WireServiceExtensionTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/WireUtilsTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandlerSerializationTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandlerTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKInboundInvocationHandlerSerializationTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKInboundInvocationHandlerTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKOutboundInvocationHandlerProxyTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKOutboundInvocationHandlerSerializationTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKOutboundInvocationHandlerTestCase.java delete mode 100644 branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKProxyTestCase.java (limited to 'branches/sca-java-integration/sca/kernel/core/src/test/java/org') diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/AbstractLocalTargetInvokerTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/AbstractLocalTargetInvokerTestCase.java deleted file mode 100644 index 8dc0023332..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/AbstractLocalTargetInvokerTestCase.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.Message; -import org.apache.tuscany.spi.wire.MessageImpl; -import org.apache.tuscany.spi.wire.OutboundInvocationChain; -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() { - 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); - OutboundInvocationChain chain = EasyMock.createMock(OutboundInvocationChain.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); - OutboundInvocationChain chain = EasyMock.createMock(OutboundInvocationChain.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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalBindingBuilderTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalBindingBuilderTestCase.java deleted file mode 100644 index 90f02e80a6..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalBindingBuilderTestCase.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.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.setName("foo"); - ServiceBinding binding = builder.build(null, def, null, null); - assertEquals(LocalServiceBinding.class, binding.getClass()); - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalBindingLoaderTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalBindingLoaderTestCase.java deleted file mode 100644 index 1633d5f8ea..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalBindingLoaderTestCase.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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, 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, 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, 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalCallbackTargetInvokerInvocationExceptionTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalCallbackTargetInvokerInvocationExceptionTestCase.java deleted file mode 100644 index 1976170f54..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalCallbackTargetInvokerInvocationExceptionTestCase.java +++ /dev/null @@ -1,86 +0,0 @@ -package org.apache.tuscany.core.binding.local; - -import java.lang.reflect.Type; -import java.util.HashMap; -import java.util.Map; - -import org.apache.tuscany.spi.model.Operation; -import org.apache.tuscany.spi.wire.InboundWire; -import org.apache.tuscany.spi.wire.Interceptor; -import org.apache.tuscany.spi.wire.Message; -import org.apache.tuscany.spi.wire.MessageImpl; -import org.apache.tuscany.spi.wire.OutboundInvocationChain; - -import junit.framework.TestCase; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class LocalCallbackTargetInvokerInvocationExceptionTestCase extends TestCase { - private InboundWire wire; - private Message message; - private OutboundInvocationChain chain; - private LocalCallbackTargetInvoker invoker; - - /** - * 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 { - Message response = invoker.invoke(message); - assertTrue(response.isFault()); - Object body = response.getBody(); - assertTrue(SomeException.class.equals(body.getClass())); - EasyMock.verify(wire); - EasyMock.verify(chain); - } - - protected void setUp() throws Exception { - super.setUp(); - Object targetAddress = new Object(); - message = new MessageImpl(); - message.pushFromAddress(targetAddress); - message.setBody("foo"); - Message response = new MessageImpl(); - response.setBody("response"); - Operation operation = new Operation("echo", null, null, null); - Interceptor head = new ErrorInterceptor(); - chain = EasyMock.createMock(OutboundInvocationChain.class); - EasyMock.expect(chain.getTargetInvoker()).andReturn(null); - EasyMock.expect(chain.getHeadInterceptor()).andReturn(head); - EasyMock.replay(chain); - Map, OutboundInvocationChain> chains = new HashMap, OutboundInvocationChain>(); - chains.put(operation, chain); - wire = EasyMock.createMock(InboundWire.class); - EasyMock.expect(wire.getSourceCallbackInvocationChains(targetAddress)).andReturn(chains); - EasyMock.replay(wire); - invoker = new LocalCallbackTargetInvoker(operation, wire); - } - - 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalCallbackTargetInvokerTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalCallbackTargetInvokerTestCase.java deleted file mode 100644 index 123f32d66a..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalCallbackTargetInvokerTestCase.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.util.HashMap; -import java.util.Map; - -import org.apache.tuscany.spi.model.Operation; -import org.apache.tuscany.spi.wire.InboundWire; -import org.apache.tuscany.spi.wire.Interceptor; -import org.apache.tuscany.spi.wire.Message; -import org.apache.tuscany.spi.wire.MessageImpl; -import org.apache.tuscany.spi.wire.OutboundInvocationChain; - -import junit.framework.TestCase; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class LocalCallbackTargetInvokerTestCase extends TestCase { - private InboundWire wire; - private Message message; - private OutboundInvocationChain 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(); - Object targetAddress = new Object(); - message = new MessageImpl(); - message.pushFromAddress(targetAddress); - message.setBody("foo"); - Message response = new MessageImpl(); - response.setBody("response"); - Operation operation = new Operation("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(OutboundInvocationChain.class); - EasyMock.expect(chain.getTargetInvoker()).andReturn(null); - EasyMock.expect(chain.getHeadInterceptor()).andReturn(head); - EasyMock.replay(chain); - Map, OutboundInvocationChain> chains = new HashMap, OutboundInvocationChain>(); - chains.put(operation, chain); - wire = EasyMock.createMock(InboundWire.class); - EasyMock.expect(wire.getSourceCallbackInvocationChains(targetAddress)).andReturn(chains); - EasyMock.replay(wire); - - invoker = new LocalCallbackTargetInvoker(operation, wire); - } - - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalCallbackTargetInvokerThrowableTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalCallbackTargetInvokerThrowableTestCase.java deleted file mode 100644 index 9c1bbc616e..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalCallbackTargetInvokerThrowableTestCase.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.lang.reflect.UndeclaredThrowableException; -import java.util.HashMap; -import java.util.Map; - -import org.apache.tuscany.spi.model.Operation; -import org.apache.tuscany.spi.wire.InboundWire; -import org.apache.tuscany.spi.wire.Interceptor; -import org.apache.tuscany.spi.wire.Message; -import org.apache.tuscany.spi.wire.MessageImpl; -import org.apache.tuscany.spi.wire.OutboundInvocationChain; - -import junit.framework.TestCase; -import org.easymock.EasyMock; -import org.easymock.IAnswer; - -/** - * @version $Rev$ $Date$ - */ -public class LocalCallbackTargetInvokerThrowableTestCase extends TestCase { - private InboundWire wire; - private Message message; - private OutboundInvocationChain chain; - private Interceptor head; - private LocalCallbackTargetInvoker invoker; - - /** - * Verfies an exception thrown in the target is propagated to the client correctly - */ - public void testThrowableTargetInvocation() throws Exception { - Message response = invoker.invoke(message); - assertTrue(response.isFault()); - Object body = response.getBody(); - if (!(body instanceof UndeclaredThrowableException)) { - fail(); // EasyMock wraps the Throwable in an UndeclaredThrowableException - } - UndeclaredThrowableException e = (UndeclaredThrowableException) body; - assertTrue(InsidiousException.class.equals(e.getUndeclaredThrowable().getClass())); - EasyMock.verify(wire); - EasyMock.verify(chain); - EasyMock.verify(head); - } - - @SuppressWarnings("unchecked") - protected void setUp() throws Exception { - super.setUp(); - Object targetAddress = new Object(); - message = new MessageImpl(); - message.pushFromAddress(targetAddress); - message.setBody("foo"); - Message response = new MessageImpl(); - response.setBody("response"); - Operation operation = new Operation("echo", null, null, null); - head = EasyMock.createMock(Interceptor.class); - EasyMock.expect(head.invoke(EasyMock.isA(Message.class))).andStubAnswer(new IAnswer() { - public Object answer() throws Throwable { - throw new InsidiousException(); // andThrow() does not seem to work here - } - }); - EasyMock.replay(head); - chain = EasyMock.createMock(OutboundInvocationChain.class); - EasyMock.expect(chain.getTargetInvoker()).andReturn(null); - EasyMock.expect(chain.getHeadInterceptor()).andReturn(head); - EasyMock.replay(chain); - Map, OutboundInvocationChain> chains = new HashMap, OutboundInvocationChain>(); - chains.put(operation, chain); - wire = EasyMock.createMock(InboundWire.class); - EasyMock.expect(wire.getSourceCallbackInvocationChains(targetAddress)).andReturn(chains); - EasyMock.replay(wire); - invoker = new LocalCallbackTargetInvoker(operation, wire); - } - - private class InsidiousException extends Throwable { - - } - - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalTargetInvokerTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalTargetInvokerTestCase.java deleted file mode 100644 index a313d341ed..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalTargetInvokerTestCase.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.util.HashMap; -import java.util.Map; - -import org.apache.tuscany.spi.component.SCAObject; -import org.apache.tuscany.spi.model.Operation; -import org.apache.tuscany.spi.model.ServiceContract; -import org.apache.tuscany.spi.wire.Message; -import org.apache.tuscany.spi.wire.MessageImpl; -import org.apache.tuscany.spi.wire.OutboundInvocationChain; -import org.apache.tuscany.spi.wire.OutboundWire; -import org.apache.tuscany.spi.wire.TargetInvoker; - -import junit.framework.TestCase; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class LocalTargetInvokerTestCase extends TestCase { - private ServiceContract serviceContract; - private Operation operation; - - public void testInvoke() { - TargetInvoker targetInvoker = EasyMock.createMock(TargetInvoker.class); - EasyMock.expect(targetInvoker.invoke(EasyMock.isA(Message.class))).andReturn(new MessageImpl()); - EasyMock.replay(targetInvoker); - OutboundInvocationChain chain = EasyMock.createNiceMock(OutboundInvocationChain.class); - EasyMock.expect(chain.getTargetInvoker()).andReturn(targetInvoker); - EasyMock.replay(chain); - Map, OutboundInvocationChain> chains = new HashMap, OutboundInvocationChain>(); - chains.put(operation, chain); - OutboundWire wire = EasyMock.createNiceMock(OutboundWire.class); - wire.getInvocationChains(); - EasyMock.expectLastCall().andReturn(chains); - EasyMock.expect(wire.getServiceContract()).andReturn(serviceContract); - EasyMock.replay(wire); - 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() { - - }; - contract.setCallbackClass(Object.class); - TargetInvoker targetInvoker = EasyMock.createMock(TargetInvoker.class); - EasyMock.expect(targetInvoker.invoke(EasyMock.isA(Message.class))).andReturn(new MessageImpl()); - EasyMock.replay(targetInvoker); - OutboundInvocationChain chain = EasyMock.createNiceMock(OutboundInvocationChain.class); - EasyMock.expect(chain.getTargetInvoker()).andReturn(targetInvoker); - EasyMock.replay(chain); - Map, OutboundInvocationChain> chains = new HashMap, OutboundInvocationChain>(); - chains.put(operation, chain); - SCAObject container = EasyMock.createMock(SCAObject.class); - EasyMock.expect(container.getName()).andReturn("foo").atLeastOnce(); - EasyMock.replay(container); - OutboundWire wire = EasyMock.createNiceMock(OutboundWire.class); - EasyMock.expect(wire.getContainer()).andReturn(container).atLeastOnce(); - wire.getInvocationChains(); - EasyMock.expectLastCall().andReturn(chains); - EasyMock.expect(wire.getServiceContract()).andReturn(contract); - EasyMock.replay(wire); - TargetInvoker invoker = new LocalTargetInvoker(operation, wire); - Message msg = EasyMock.createMock(Message.class); - msg.pushFromAddress(EasyMock.eq("foo")); - 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); - OutboundInvocationChain chain = EasyMock.createNiceMock(OutboundInvocationChain.class); - EasyMock.expect(chain.getTargetInvoker()).andReturn(targetInvoker); - EasyMock.replay(chain); - Map, OutboundInvocationChain> chains = new HashMap, OutboundInvocationChain>(); - chains.put(operation, chain); - OutboundWire wire = EasyMock.createNiceMock(OutboundWire.class); - wire.getInvocationChains(); - EasyMock.expectLastCall().andReturn(chains); - EasyMock.expect(wire.getServiceContract()).andReturn(serviceContract); - EasyMock.replay(wire); - 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() { - }; - operation = new Operation("foo", null, null, null); - } - - - private class TestException extends RuntimeException { - - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/bootstrap/BootstrapperTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/bootstrap/BootstrapperTestCase.java deleted file mode 100644 index 728902e82b..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/bootstrap/BootstrapperTestCase.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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); - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/AbstractConnectorImplTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/AbstractConnectorImplTestCase.java deleted file mode 100644 index b828262d6e..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/AbstractConnectorImplTestCase.java +++ /dev/null @@ -1,306 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.InvocationTargetException; -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 javax.xml.namespace.QName; - -import org.apache.tuscany.spi.QualifiedName; -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.CompositeComponent; -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.TargetInvokerCreationException; -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.InboundInvocationChain; -import org.apache.tuscany.spi.wire.InboundWire; -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.MessageImpl; -import org.apache.tuscany.spi.wire.OutboundInvocationChain; -import org.apache.tuscany.spi.wire.OutboundWire; -import org.apache.tuscany.spi.wire.TargetInvoker; -import org.apache.tuscany.spi.wire.WireService; - -import junit.framework.TestCase; -import org.apache.tuscany.core.binding.local.LocalReferenceBinding; -import org.apache.tuscany.core.binding.local.LocalServiceBinding; -import org.apache.tuscany.core.implementation.composite.ServiceImpl; -import org.apache.tuscany.core.mock.binding.MockServiceBinding; -import org.apache.tuscany.core.wire.InboundInvocationChainImpl; -import org.apache.tuscany.core.wire.InboundWireImpl; -import org.apache.tuscany.core.wire.InvokerInterceptor; -import org.apache.tuscany.core.wire.OutboundInvocationChainImpl; -import org.apache.tuscany.core.wire.OutboundWireImpl; -import org.apache.tuscany.core.wire.SynchronousBridgingInterceptor; -import org.apache.tuscany.core.wire.jdk.JDKWireService; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public abstract class AbstractConnectorImplTestCase extends TestCase { - protected static final String TARGET = "target"; - protected static final QualifiedName TARGET_NAME = new QualifiedName(TARGET); - protected static final String TARGET_SERVICE = "FooService"; - protected static final QualifiedName TARGET_SERVICE_NAME = new QualifiedName("target/FooService"); - protected static final String RESPONSE = "response"; - - protected ConnectorImpl connector; - protected ServiceContract contract; - protected Operation operation; - - protected void setUp() throws Exception { - super.setUp(); - WireService wireService = new JDKWireService(null, null); - connector = new ConnectorImpl(wireService, null, null, null); - contract = new JavaServiceContract(Foo.class); - operation = new Operation("bar", null, null, null); - } - - protected AtomicComponent createAtomicTarget() throws Exception { - InboundInvocationChain chain = new InboundInvocationChainImpl(operation); - chain.addInterceptor(new InvokerInterceptor()); - InboundWire targetWire = new InboundWireImpl(); - targetWire.setServiceContract(contract); - targetWire.addInvocationChain(operation, chain); - - MockInvoker mockInvoker = new MockInvoker(); - - // create the target - AtomicComponent target = EasyMock.createMock(AtomicComponent.class); - EasyMock.expect(target.getName()).andReturn(TARGET).anyTimes(); - EasyMock.expect(target.isOptimizable()).andReturn(false).anyTimes(); - EasyMock.expect(target.getScope()).andReturn(Scope.COMPOSITE).atLeastOnce(); - EasyMock.expect(target.isSystem()).andReturn(false).atLeastOnce(); - target.getInboundWire(EasyMock.eq(TARGET_SERVICE)); - EasyMock.expectLastCall().andReturn(targetWire).atLeastOnce(); - target.createTargetInvoker(EasyMock.eq(TARGET_SERVICE), EasyMock.eq(operation), EasyMock.eq(targetWire)); - EasyMock.expectLastCall().andReturn(mockInvoker); - EasyMock.replay(target); - targetWire.setContainer(target); - return target; - } - - protected AtomicComponent createAtomicSource(CompositeComponent parent) throws Exception { - // create the outbound wire and chain from the source component - OutboundInvocationChain outboundChain = new OutboundInvocationChainImpl(operation); - - OutboundWire outboundWire = new OutboundWireImpl(); - outboundWire.setTargetName(TARGET_SERVICE_NAME); - outboundWire.setServiceContract(contract); - outboundWire.addInvocationChain(operation, outboundChain); - - Map> outboundWires = new HashMap>(); - List list = new ArrayList(); - list.add(outboundWire); - outboundWires.put(TARGET_SERVICE, list); - - // create the source - AtomicComponent source = EasyMock.createMock(AtomicComponent.class); - EasyMock.expect(source.isSystem()).andReturn(false).atLeastOnce(); - EasyMock.expect(source.getScope()).andReturn(Scope.COMPOSITE); - EasyMock.expect(source.getParent()).andReturn(parent).atLeastOnce(); - EasyMock.expect(source.getOutboundWires()).andReturn(outboundWires).atLeastOnce(); - EasyMock.expect(source.getName()).andReturn("source").atLeastOnce(); - source.getInboundWires(); - EasyMock.expectLastCall().andReturn(Collections.emptyList()); - EasyMock.replay(source); - - outboundWire.setContainer(source); - return source; - } - - - protected Service createServiceNonLocalBinding() throws WireConnectException { - QName qName = new QName("foo", "bar"); - ServiceBinding serviceBinding = new MockServiceBinding(); - InboundInvocationChain targetInboundChain = new InboundInvocationChainImpl(operation); - targetInboundChain.addInterceptor(new SynchronousBridgingInterceptor()); - InboundWire serviceInboundWire = new InboundWireImpl(qName); - serviceInboundWire.setServiceContract(contract); - serviceInboundWire.addInvocationChain(operation, targetInboundChain); - serviceInboundWire.setContainer(serviceBinding); - - OutboundInvocationChain targetOutboundChain = new OutboundInvocationChainImpl(operation); - // place an invoker interceptor on the end - targetOutboundChain.addInterceptor(new InvokerInterceptor()); - OutboundWire targetOutboundWire = new OutboundWireImpl(qName); - targetOutboundWire.setServiceContract(contract); - targetOutboundWire.addInvocationChain(operation, targetOutboundChain); - targetOutboundWire.setContainer(serviceBinding); - - serviceBinding.setInboundWire(serviceInboundWire); - serviceBinding.setOutboundWire(targetOutboundWire); - // manually connect the service chains - connector.connect(targetInboundChain, targetOutboundChain); - Service service = new ServiceImpl(TARGET, null, contract); - service.addServiceBinding(serviceBinding); - return service; - } - - /** - * Creates a service configured with the local binding and places an invoker interceptor on the end of each outbound - * chain for invocation testing without needing to wire the service to a target - * - * @throws org.apache.tuscany.core.builder.WireConnectException - * - */ - protected Service createLocalService(CompositeComponent parent) throws WireConnectException { - LocalServiceBinding serviceBinding = new LocalServiceBinding(TARGET, parent); - InboundInvocationChain targetInboundChain = new InboundInvocationChainImpl(operation); - targetInboundChain.addInterceptor(new SynchronousBridgingInterceptor()); - InboundWire localServiceInboundWire = new InboundWireImpl(); - localServiceInboundWire.setServiceContract(contract); - localServiceInboundWire.addInvocationChain(operation, targetInboundChain); - localServiceInboundWire.setContainer(serviceBinding); - - OutboundInvocationChain targetOutboundChain = new OutboundInvocationChainImpl(operation); - // place an invoker interceptor on the end - targetOutboundChain.addInterceptor(new InvokerInterceptor()); - OutboundWire targetOutboundWire = new OutboundWireImpl(); - targetOutboundWire.setServiceContract(contract); - targetOutboundWire.addInvocationChain(operation, targetOutboundChain); - targetOutboundWire.setContainer(serviceBinding); - - serviceBinding.setInboundWire(localServiceInboundWire); - serviceBinding.setOutboundWire(targetOutboundWire); - // manually connect the service chains - connector.connect(targetInboundChain, targetOutboundChain); - Service service = new ServiceImpl(TARGET, null, contract); - service.addServiceBinding(serviceBinding); - return service; - } - - protected ReferenceBinding createLocalReferenceBinding(QualifiedName target) - throws TargetInvokerCreationException { - ReferenceBinding referenceBinding = new LocalReferenceBinding("local", null); - InboundInvocationChain inboundChain = new InboundInvocationChainImpl(operation); - InboundWire referenceInboundWire = new InboundWireImpl(); - referenceInboundWire.setServiceContract(contract); - referenceInboundWire.setContainer(referenceBinding); - referenceInboundWire.addInvocationChain(operation, inboundChain); - - OutboundInvocationChain outboundChain = new OutboundInvocationChainImpl(operation); - // Outbound chains always contains at least one interceptor - outboundChain.addInterceptor(new SynchronousBridgingInterceptor()); - OutboundWire outboundWire = new OutboundWireImpl(); - outboundWire.setServiceContract(contract); - outboundWire.setTargetName(target); - outboundWire.addInvocationChain(operation, outboundChain); - outboundWire.setContainer(referenceBinding); - - referenceBinding.setInboundWire(referenceInboundWire); - referenceBinding.setOutboundWire(outboundWire); - - return referenceBinding; - } - - protected InboundWire createLocalInboundWire(CompositeComponent parent) throws WireConnectException { - InboundInvocationChain chain = new InboundInvocationChainImpl(operation); - chain.addInterceptor(new SynchronousBridgingInterceptor()); - InboundWire wire = new InboundWireImpl(); - wire.setServiceContract(contract); - LocalReferenceBinding referenceBinding = new LocalReferenceBinding("", parent); - wire.setContainer(referenceBinding); - wire.addInvocationChain(operation, chain); - - OutboundInvocationChain targetOutboundChain = new OutboundInvocationChainImpl(operation); - // place an invoker interceptor on the end - targetOutboundChain.addInterceptor(new InvokerInterceptor()); - OutboundWire targetOutboundWire = new OutboundWireImpl(); - targetOutboundWire.setServiceContract(contract); - targetOutboundWire.addInvocationChain(operation, targetOutboundChain); - referenceBinding.setInboundWire(wire); - referenceBinding.setOutboundWire(targetOutboundWire); - // manually connect the service chains - connector.connect(chain, targetOutboundChain); - return wire; - } - - protected static class MockInvoker implements TargetInvoker { - public Object invokeTarget(final Object payload, final short sequence) throws InvocationTargetException { - return null; - } - - public Message invoke(Message msg) throws InvocationRuntimeException { - Message resp = new MessageImpl(); - resp.setBody(RESPONSE); - return resp; - } - - public boolean isCacheable() { - return false; - } - - public void setCacheable(boolean cacheable) { - - } - - public boolean isOptimizable() { - return false; - } - - public Object clone() throws CloneNotSupportedException { - return super.clone(); - } - } - - protected static class MockInterceptor implements Interceptor { - private Interceptor next; - private boolean invoked; - - public Message invoke(Message msg) { - invoked = true; - return next.invoke(msg); - } - - public void setNext(Interceptor next) { - this.next = next; - } - - public Interceptor getNext() { - return next; - } - - public boolean isInvoked() { - return invoked; - } - - public boolean isOptimizable() { - return false; - } - } - - protected interface Foo { - String echo(); - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/AtomicConnectorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/AtomicConnectorTestCase.java deleted file mode 100644 index f89ba7ea8d..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/AtomicConnectorTestCase.java +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.util.List; -import java.util.Map; - -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.component.Service; -import org.apache.tuscany.spi.component.ServiceBinding; -import org.apache.tuscany.spi.model.Scope; -import org.apache.tuscany.spi.wire.InboundInvocationChain; -import org.apache.tuscany.spi.wire.InboundWire; -import org.apache.tuscany.spi.wire.Message; -import org.apache.tuscany.spi.wire.MessageImpl; -import org.apache.tuscany.spi.wire.OutboundInvocationChain; -import org.apache.tuscany.spi.wire.OutboundWire; - -import org.apache.tuscany.core.implementation.composite.ServiceImpl; -import org.apache.tuscany.core.wire.InboundInvocationChainImpl; -import org.apache.tuscany.core.wire.InboundWireImpl; -import org.apache.tuscany.core.wire.OutboundInvocationChainImpl; -import org.apache.tuscany.core.wire.OutboundWireImpl; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class AtomicConnectorTestCase extends AbstractConnectorImplTestCase { - - public void testConnectSynchronousServiceWiresToAtomicTarget() throws Exception { - AtomicComponent target = createAtomicTarget(); - - // create the parent composite - CompositeComponent parent = EasyMock.createMock(CompositeComponent.class); - EasyMock.expect(parent.getChild("target")).andReturn(target); - EasyMock.replay(parent); - - InboundInvocationChain inboundChain = new InboundInvocationChainImpl(operation); - InboundWire inboundWire = new InboundWireImpl(); - inboundWire.addInvocationChain(operation, inboundChain); - inboundWire.setServiceContract(contract); - - OutboundInvocationChain outboundChain = new OutboundInvocationChainImpl(operation); - OutboundWire outboundWire = new OutboundWireImpl(); - outboundWire.setTargetName(TARGET_SERVICE_NAME); - outboundWire.addInvocationChain(operation, outboundChain); - outboundWire.setServiceContract(contract); - - // create the binding - ServiceBinding binding = EasyMock.createMock(ServiceBinding.class); - EasyMock.expect(binding.getName()).andReturn("source"); - binding.setService(EasyMock.isA(Service.class)); - EasyMock.expect(binding.isSystem()).andReturn(false).atLeastOnce(); - EasyMock.expect(binding.getInboundWire()).andReturn(inboundWire).atLeastOnce(); - EasyMock.expect(binding.getOutboundWire()).andReturn(outboundWire); - EasyMock.expect(binding.getScope()).andReturn(Scope.SYSTEM); - EasyMock.replay(binding); - - outboundWire.setContainer(binding); - inboundWire.setContainer(binding); - - Service service = new ServiceImpl("foo", parent, null); - service.addServiceBinding(binding); - - connector.connect(service); - MessageImpl msg = new MessageImpl(); - msg.setTargetInvoker(inboundChain.getTargetInvoker()); - Message resp = inboundChain.getHeadInterceptor().invoke(msg); - assertEquals(RESPONSE, resp.getBody()); - EasyMock.verify(binding); - } - - public void testConnectNonBlockingServiceWiresToAtomicTarget() throws Exception { - // JFM FIXME - } - - public void testConnectCallbackServiceWiresToAtomicTarget() throws Exception { - // JFM FIXME - } - - /** - * Verifies connecting a wire from an atomic component to a target atomic component with one synchronous operation - */ - public void testConnectAtomicComponentToAtomicComponentSyncWire() throws Exception { - - AtomicComponent target = createAtomicTarget(); - // create the parent composite - CompositeComponent parent = EasyMock.createMock(CompositeComponent.class); - EasyMock.expect(parent.getChild("target")).andReturn(target); - EasyMock.replay(parent); - AtomicComponent source = createAtomicSource(parent); - connector.connect(source); - - MessageImpl msg = new MessageImpl(); - Map> wires = source.getOutboundWires(); - OutboundWire wire = wires.get(TARGET_SERVICE).get(0); - OutboundInvocationChain chain = wire.getInvocationChains().get(operation); - msg.setTargetInvoker(chain.getTargetInvoker()); - Message resp = chain.getHeadInterceptor().invoke(msg); - assertEquals(RESPONSE, resp.getBody()); - } - - protected void setUp() throws Exception { - super.setUp(); - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/BuilderRegistryNoBindingsTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/BuilderRegistryNoBindingsTestCase.java deleted file mode 100644 index 16f2846921..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/BuilderRegistryNoBindingsTestCase.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.CompositeComponent; -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.ComponentTypeReferenceDefinition; -import org.apache.tuscany.spi.model.Multiplicity; -import org.apache.tuscany.spi.model.AbstractReferenceDefinition; -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.apache.tuscany.core.deployer.RootDeploymentContext; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class BuilderRegistryNoBindingsTestCase extends TestCase { - private DeploymentContext deploymentContext; - private CompositeComponent parent; - private BuilderRegistry registry; - - public void testNoServiceBindings() throws Exception { - ServiceBinding binding = EasyMock.createNiceMock(ServiceBinding.class); - EasyMock.replay(binding); - ServiceDefinition definition = new ServiceDefinition("foo", null, false); - definition.setTarget(new URI("foo")); - Service service = registry.build(parent, definition, deploymentContext); - assertEquals(1, service.getServiceBindings().size()); - assertTrue(service.getServiceBindings().get(0) instanceof LocalServiceBinding); - } - - public void testReferenceBindingBuilderDispatch() throws Exception { - ReferenceBinding binding = EasyMock.createNiceMock(ReferenceBinding.class); - EasyMock.replay(binding); - AbstractReferenceDefinition definition = new ComponentTypeReferenceDefinition("foo", null, Multiplicity.ONE_ONE); - Reference reference = registry.build(parent, definition, deploymentContext); - assertEquals(1, reference.getReferenceBindings().size()); - assertTrue(reference.getReferenceBindings().get(0) instanceof LocalReferenceBinding); - } - - protected void setUp() throws Exception { - super.setUp(); - deploymentContext = new RootDeploymentContext(null, null, null, null); - parent = EasyMock.createNiceMock(CompositeComponent.class); - EasyMock.replay(parent); - registry = new BuilderRegistryImpl(null, null); - registry.register(LocalBindingDefinition.class, new LocalBindingBuilder()); - } - - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/BuilderRegistryTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/BuilderRegistryTestCase.java deleted file mode 100644 index 572babf817..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/BuilderRegistryTestCase.java +++ /dev/null @@ -1,219 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.QualifiedName; -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.CompositeComponent; -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.ComponentTypeReferenceDefinition; -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.AbstractReferenceDefinition; -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.WireService; - -import junit.framework.TestCase; -import org.apache.tuscany.core.deployer.RootDeploymentContext; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class BuilderRegistryTestCase extends TestCase { - private DeploymentContext deploymentContext; - //private BuilderRegistryImpl registry; - private CompositeComponent parent; - - public void testRegistration() throws Exception { - MockBuilder builder = new MockBuilder(); - BuilderRegistry registry = new BuilderRegistryImpl(null, null); - registry.register(CompositeImplementation.class, builder); - CompositeImplementation implementation = new CompositeImplementation(); - ComponentDefinition componentDefinition = - new ComponentDefinition(implementation); - componentDefinition.getImplementation().setComponentType(new CompositeComponentType()); - registry.build(parent, componentDefinition, deploymentContext); - } - - @SuppressWarnings({"unchecked"}) - public void testServiceBindingBuilderDispatch() throws Exception { - WireService wireService = EasyMock.createMock(WireService.class); - wireService.createWires(EasyMock.isA(ServiceBinding.class), - (ServiceContract) EasyMock.isNull(), EasyMock.isA(String.class) - ); - EasyMock.expectLastCall().times(2); - EasyMock.replay(wireService); - BuilderRegistry registry = new BuilderRegistryImpl(null, wireService); - ServiceBinding binding = EasyMock.createNiceMock(ServiceBinding.class); - EasyMock.replay(binding); - BindingBuilder builder = EasyMock.createMock(BindingBuilder.class); - EasyMock.expect(builder.build(EasyMock.isA(CompositeComponent.class), - 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("foo", null, false); - definition.addBinding(new MockBindingDefinition()); - definition.addBinding(new MockBindingDefinition()); - definition.setTarget(new URI("foo")); - Service service = registry.build(parent, definition, deploymentContext); - assertEquals(2, service.getServiceBindings().size()); - EasyMock.verify(wireService); - } - - @SuppressWarnings({"unchecked"}) - public void testReferenceBindingBuilderDispatch() throws Exception { - WireService wireService = EasyMock.createMock(WireService.class); - wireService.createWires(EasyMock.isA(ReferenceBinding.class), - (ServiceContract) EasyMock.isNull(), (QualifiedName) EasyMock.isNull() - ); - EasyMock.expectLastCall().times(2); - EasyMock.replay(wireService); - BuilderRegistry registry = new BuilderRegistryImpl(null, wireService); - ReferenceBinding binding = EasyMock.createNiceMock(ReferenceBinding.class); - EasyMock.replay(binding); - BindingBuilder builder = EasyMock.createMock(BindingBuilder.class); - EasyMock.expect(builder.build(EasyMock.isA(CompositeComponent.class), - EasyMock.isA(AbstractReferenceDefinition.class), - EasyMock.isA(MockBindingDefinition.class), - EasyMock.isA(DeploymentContext.class))).andReturn(binding).times(2); - EasyMock.replay(builder); - registry.register(MockBindingDefinition.class, builder); - AbstractReferenceDefinition definition = new ComponentTypeReferenceDefinition("foo", null, ONE_ONE); - definition.addBinding(new MockBindingDefinition()); - definition.addBinding(new MockBindingDefinition()); - Reference reference = registry.build(parent, definition, deploymentContext); - assertEquals(2, reference.getReferenceBindings().size()); - EasyMock.verify(wireService); - } - - @SuppressWarnings({"unchecked"}) - public void testComponentImplementationDispatch() 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); - WireService wireService = EasyMock.createMock(WireService.class); - wireService.createWires(EasyMock.isA(AtomicComponent.class), - EasyMock.isA(ComponentDefinition.class)); - EasyMock.replay(wireService); - BuilderRegistry registry = new BuilderRegistryImpl(scopeRegistry, wireService); - - AtomicComponent component = EasyMock.createNiceMock(AtomicComponent.class); - EasyMock.replay(component); - ComponentBuilder builder = EasyMock.createMock(ComponentBuilder.class); - EasyMock.expect(builder.build(EasyMock.isA(CompositeComponent.class), - EasyMock.isA(ComponentDefinition.class), - EasyMock.isA(DeploymentContext.class))).andReturn(component); - EasyMock.replay(builder); - registry.register(FooImplementation.class, builder); - - FooImplementation impl = new FooImplementation(); - impl.setComponentType(new ComponentType()); - ComponentDefinition definition = new ComponentDefinition("foo", impl); - Component ret = registry.build(parent, definition, deploymentContext); - assertNotNull(ret); - EasyMock.verify(wireService); - } - - @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); - WireService wireService = EasyMock.createMock(WireService.class); - wireService.createWires(EasyMock.isA(AtomicComponent.class), - EasyMock.isA(ComponentDefinition.class)); - EasyMock.replay(wireService); - BuilderRegistry registry = new BuilderRegistryImpl(scopeRegistry, wireService); - - AtomicComponent component = EasyMock.createNiceMock(AtomicComponent.class); - EasyMock.replay(component); - ComponentBuilder builder = EasyMock.createMock(ComponentBuilder.class); - EasyMock.expect(builder.build(EasyMock.isA(CompositeComponent.class), - 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); - ComponentDefinition definition = new ComponentDefinition("foo", impl); - try { - registry.build(parent, definition, deploymentContext); - fail("Should throw NoConversationalContractException"); - } catch (NoConversationalContractException e) { - // expected - } - } - - protected void setUp() throws Exception { - super.setUp(); - deploymentContext = new RootDeploymentContext(null, null, null, null); - parent = EasyMock.createNiceMock(CompositeComponent.class); - EasyMock.replay(parent); - } - - private class MockBuilder implements ComponentBuilder { - public Component build(CompositeComponent parent, - ComponentDefinition componentDefinition, - DeploymentContext deploymentContext) throws BuilderConfigException { - return null; - } - } - - private class MockBindingDefinition extends BindingDefinition { - public Object clone() { - MockBindingDefinition mockClone = new MockBindingDefinition(); - mockClone.setTargetUri(URI.create(this.getTargetUri().toString())); - return mockClone; - } - } - - private class FooImplementation extends Implementation { - - } - - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/ConnectorImplTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/ConnectorImplTestCase.java deleted file mode 100644 index fc5daa6b12..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/ConnectorImplTestCase.java +++ /dev/null @@ -1,322 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.util.Collections; - -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.component.ReferenceBinding; -import org.apache.tuscany.spi.component.SCAObject; -import org.apache.tuscany.spi.model.Operation; -import org.apache.tuscany.spi.model.Scope; -import org.apache.tuscany.spi.wire.InboundInvocationChain; -import org.apache.tuscany.spi.wire.InboundWire; -import org.apache.tuscany.spi.wire.Interceptor; -import org.apache.tuscany.spi.wire.Message; -import org.apache.tuscany.spi.wire.MessageImpl; -import org.apache.tuscany.spi.wire.OutboundInvocationChain; -import org.apache.tuscany.spi.wire.OutboundWire; -import org.apache.tuscany.spi.wire.TargetInvoker; - -import org.apache.tuscany.core.wire.InboundInvocationChainImpl; -import org.apache.tuscany.core.wire.InboundWireImpl; -import org.apache.tuscany.core.wire.InvokerInterceptor; -import org.apache.tuscany.core.wire.OutboundInvocationChainImpl; -import org.apache.tuscany.core.wire.OutboundWireImpl; -import org.apache.tuscany.core.wire.SynchronousBridgingInterceptor; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class ConnectorImplTestCase extends AbstractConnectorImplTestCase { - - public void testConnectTargetNotFound() throws Exception { - CompositeComponent parent = EasyMock.createMock(CompositeComponent.class); - EasyMock.expect(parent.getName()).andReturn("parent"); - parent.getChild(EasyMock.isA(String.class)); - EasyMock.expectLastCall().andReturn(null); - EasyMock.replay(parent); - try { - AtomicComponent source = createAtomicSource(parent); - connector.connect(source); - fail(); - } catch (TargetServiceNotFoundException e) { - // expected - } - } - - public void testOutboundToInboundOptimization() throws Exception { - AtomicComponent container = EasyMock.createNiceMock(AtomicComponent.class); - EasyMock.expect(container.isSystem()).andReturn(true); - EasyMock.replay(container); - InboundWire inboundWire = new InboundWireImpl(); - inboundWire.setContainer(container); - OutboundWire outboundWire = EasyMock.createMock(OutboundWire.class); - outboundWire.setTargetWire(EasyMock.eq(inboundWire)); - EasyMock.expect(outboundWire.getContainer()).andReturn(container).atLeastOnce(); - EasyMock.replay(outboundWire); - - connector.connect(outboundWire, inboundWire, true); - EasyMock.verify(outboundWire); - } - - /** - * Verifies that stateless targets with a destructor are not optimized as the destructor callback event must be - * issued by the TargetInvoker after it dispatches to the target - */ - public void testOutboundToInboundNoOptimizationBecauseStatelessDestructor() throws Exception { - AtomicComponent container = EasyMock.createNiceMock(AtomicComponent.class); - EasyMock.expect(container.isSystem()).andReturn(false); - EasyMock.expect(container.getScope()).andReturn(Scope.STATELESS); - EasyMock.expect(container.isDestroyable()).andReturn(true); - EasyMock.replay(container); - InboundWire inboundWire = new InboundWireImpl(); - inboundWire.setContainer(container); - OutboundWire outboundWire = EasyMock.createMock(OutboundWire.class); - outboundWire.getInvocationChains(); - EasyMock.expectLastCall().andReturn(Collections.emptyMap()).atLeastOnce(); - outboundWire.getTargetCallbackInvocationChains(); - EasyMock.expectLastCall().andReturn(Collections.emptyMap()).atLeastOnce(); - EasyMock.expect(outboundWire.getContainer()).andReturn(container).atLeastOnce(); - EasyMock.replay(outboundWire); - - connector.connect(outboundWire, inboundWire, true); - EasyMock.verify(outboundWire); - } - - public void testOutboundToInboundNoOptimizationAtomic() throws Exception { - AtomicComponent container = EasyMock.createNiceMock(AtomicComponent.class); - EasyMock.expect(container.isSystem()).andReturn(false); - EasyMock.expect(container.getScope()).andReturn(Scope.STATELESS); - EasyMock.expect(container.isOptimizable()).andReturn(false); - EasyMock.replay(container); - InboundWire inboundWire = new InboundWireImpl(); - inboundWire.setContainer(container); - OutboundWire outboundWire = EasyMock.createMock(OutboundWire.class); - EasyMock.expect(outboundWire.getContainer()).andReturn(container).atLeastOnce(); - outboundWire.getInvocationChains(); - EasyMock.expectLastCall().andReturn(Collections.emptyMap()).atLeastOnce(); - outboundWire.getTargetCallbackInvocationChains(); - EasyMock.expectLastCall().andReturn(Collections.emptyMap()).atLeastOnce(); - EasyMock.replay(outboundWire); - - connector.connect(outboundWire, inboundWire, true); - EasyMock.verify(outboundWire); - } - - public void testOutboundToInboundNoOptimizationNonAtomicTarget() throws Exception { - ReferenceBinding container = EasyMock.createNiceMock(ReferenceBinding.class); - EasyMock.expect(container.isSystem()).andReturn(false); - EasyMock.replay(container); - InboundWire inboundWire = new InboundWireImpl(); - inboundWire.setContainer(container); - OutboundWire outboundWire = EasyMock.createMock(OutboundWire.class); - outboundWire.getInvocationChains(); - EasyMock.expectLastCall().andReturn(Collections.emptyMap()).atLeastOnce(); - outboundWire.getTargetCallbackInvocationChains(); - EasyMock.expectLastCall().andReturn(Collections.emptyMap()).atLeastOnce(); - EasyMock.expect(outboundWire.getContainer()).andReturn(container).atLeastOnce(); - EasyMock.replay(outboundWire); - - connector.connect(outboundWire, inboundWire, true); - EasyMock.verify(outboundWire); - } - - public void testOutboundToInboundChainConnect() throws Exception { - TargetInvoker invoker = new MockInvoker(); - InboundInvocationChain inboundChain = new InboundInvocationChainImpl(operation); - inboundChain.addInterceptor(new InvokerInterceptor()); - OutboundInvocationChain outboundChain = new OutboundInvocationChainImpl(operation); - connector.connect(outboundChain, inboundChain, invoker, false); - Interceptor interceptor = outboundChain.getHeadInterceptor(); - assertTrue(interceptor instanceof SynchronousBridgingInterceptor); - MessageImpl msg = new MessageImpl(); - msg.setTargetInvoker(new MockInvoker()); - Message resp = interceptor.invoke(msg); - assertEquals(RESPONSE, resp.getBody()); - } - - public void testOutboundToInboundChainConnectNoInboundInterceptor() { - TargetInvoker invoker = new MockInvoker(); - InboundInvocationChain inboundChain = new InboundInvocationChainImpl(operation); - OutboundInvocationChain outboundChain = new OutboundInvocationChainImpl(operation); - try { - connector.connect(outboundChain, inboundChain, invoker, false); - fail(); - } catch (WireConnectException e) { - // expected - } - } - - public void testInboundToOutboundChainConnect() throws Exception { - InboundInvocationChain inboundChain = new InboundInvocationChainImpl(operation); - OutboundInvocationChain outboundChain = new OutboundInvocationChainImpl(operation); - outboundChain.addInterceptor(new InvokerInterceptor()); - connector.connect(inboundChain, outboundChain); - Interceptor interceptor = inboundChain.getHeadInterceptor(); - assertTrue(interceptor instanceof SynchronousBridgingInterceptor); - MessageImpl msg = new MessageImpl(); - msg.setTargetInvoker(new MockInvoker()); - Message resp = interceptor.invoke(msg); - assertEquals(RESPONSE, resp.getBody()); - } - - public void testInboundToOutboundChainConnectNoOutboundInterceptors() throws Exception { - InboundInvocationChain inboundChain = new InboundInvocationChainImpl(operation); - OutboundInvocationChain outboundChain = new OutboundInvocationChainImpl(operation); - try { - connector.connect(inboundChain, outboundChain); - fail(); - } catch (WireConnectException e) { - // expected - } - } - - public void testInboundOutboundSystemWireOptimization() throws Exception { - SCAObject container = EasyMock.createMock(SCAObject.class); - EasyMock.expect(container.isSystem()).andReturn(true); - EasyMock.replay(container); - InboundWire inboundWire = EasyMock.createMock(InboundWire.class); - inboundWire.setTargetWire(EasyMock.isA(OutboundWire.class)); - EasyMock.expect(inboundWire.getContainer()).andReturn(container).atLeastOnce(); - EasyMock.replay(inboundWire); - OutboundWire outboundWire = new OutboundWireImpl(); - outboundWire.setContainer(container); - connector.connect(inboundWire, outboundWire, true); - EasyMock.verify(inboundWire); - EasyMock.verify(container); - } - - public void testOutboundInboundSystemWireOptimization() throws Exception { - SCAObject container = EasyMock.createMock(SCAObject.class); - EasyMock.expect(container.isSystem()).andReturn(true); - EasyMock.replay(container); - OutboundWire outboundWire = EasyMock.createMock(OutboundWire.class); - outboundWire.setTargetWire(EasyMock.isA(InboundWire.class)); - EasyMock.expect(outboundWire.getContainer()).andReturn(container).atLeastOnce(); - EasyMock.replay(outboundWire); - InboundWire inboundWire = new InboundWireImpl(); - inboundWire.setContainer(container); - connector.connect(outboundWire, inboundWire, true); - EasyMock.verify(outboundWire); - EasyMock.verify(container); - } - - public void testIncompatibleInboundOutboundWiresConnect() throws Exception { - Operation operation = new Operation("bar", null, null, null); - InboundWire inboundWire = new InboundWireImpl(); - inboundWire.addInvocationChain(operation, new InboundInvocationChainImpl(operation)); - OutboundWire outboundWire = new OutboundWireImpl(); - try { - connector.connect(inboundWire, outboundWire, false); - fail(); - } catch (IncompatibleInterfacesException e) { - // expected - } - - } - - public void testIncompatibleOutboundInboundWiresConnect() throws Exception { - SCAObject container = EasyMock.createNiceMock(SCAObject.class); - EasyMock.expect(container.isSystem()).andReturn(false); - EasyMock.replay(container); - Operation operation = new Operation("bar", null, null, null); - InboundWire inboundWire = new InboundWireImpl(); - inboundWire.setContainer(container); - OutboundWire outboundWire = new OutboundWireImpl(); - outboundWire.setContainer(container); - outboundWire.addInvocationChain(operation, new OutboundInvocationChainImpl(operation)); - try { - connector.connect(outboundWire, inboundWire, false); - fail(); - } catch (IncompatibleInterfacesException e) { - // expected - } - - } - - 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 testInvalidConnectObject() throws Exception { - try { - connector.connect(EasyMock.createNiceMock(SCAObject.class)); - fail(); - } catch (AssertionError e) { - // expected - } - } - - protected void setUp() throws Exception { - super.setUp(); - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/ConnectorPostProcessTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/ConnectorPostProcessTestCase.java deleted file mode 100644 index 857b17eff5..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/ConnectorPostProcessTestCase.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.util.HashMap; -import java.util.Map; - -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.model.Operation; -import org.apache.tuscany.spi.model.ServiceContract; -import org.apache.tuscany.spi.wire.InboundInvocationChain; -import org.apache.tuscany.spi.wire.InboundWire; -import org.apache.tuscany.spi.wire.OutboundInvocationChain; -import org.apache.tuscany.spi.wire.OutboundWire; -import org.apache.tuscany.spi.wire.WirePostProcessorRegistry; -import org.apache.tuscany.spi.wire.WireService; - -import junit.framework.TestCase; -import org.easymock.EasyMock; -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.createNiceMock; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.expectLastCall; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; - -/** - * @version $Rev$ $Date$ - */ -public class ConnectorPostProcessTestCase extends TestCase { - - public void testInboundToOutboundPostProcessCalled() throws Exception { - OutboundWire owire = createNiceMock(OutboundWire.class); - replay(owire); - InboundWire iwire = createNiceMock(InboundWire.class); - Map, InboundInvocationChain> chains = new HashMap, InboundInvocationChain>(); - expect(iwire.getInvocationChains()).andReturn(chains); - replay(iwire); - WirePostProcessorRegistry registry = createMock(WirePostProcessorRegistry.class); - registry.process(EasyMock.eq(iwire), EasyMock.eq(owire)); - replay(registry); - WireService wireService = createMock(WireService.class); - wireService.checkCompatibility((ServiceContract) EasyMock.anyObject(), - (ServiceContract) EasyMock.anyObject(), EasyMock.eq(false)); - expectLastCall().anyTimes(); - replay(wireService); - ConnectorImpl connector = new ConnectorImpl(wireService, registry, null, null); - connector.connect(iwire, owire, false); - verify(registry); - } - - public void testOutboundToInboundPostProcessCalled() throws Exception { - AtomicComponent source = createNiceMock(AtomicComponent.class); - expect(source.getName()).andReturn("Component"); - replay(source); - - AtomicComponent target = createNiceMock(AtomicComponent.class); - expect(target.getName()).andReturn("Component"); - replay(target); - - OutboundWire owire = createNiceMock(OutboundWire.class); - EasyMock.expect(owire.getContainer()).andReturn(source); - - Map, OutboundInvocationChain> chains = new HashMap, OutboundInvocationChain>(); - expect(owire.getInvocationChains()).andReturn(chains); - Map, InboundInvocationChain> ichains = new HashMap, InboundInvocationChain>(); - expect(owire.getTargetCallbackInvocationChains()).andReturn(ichains); - replay(owire); - InboundWire iwire = createNiceMock(InboundWire.class); - expect(iwire.getSourceCallbackInvocationChains("Component")).andReturn(chains); - EasyMock.expect(iwire.getContainer()).andReturn(target); - replay(iwire); - WirePostProcessorRegistry registry = createMock(WirePostProcessorRegistry.class); - registry.process(EasyMock.eq(owire), EasyMock.eq(iwire)); - replay(registry); - WireService wireService = createMock(WireService.class); - wireService.checkCompatibility((ServiceContract) EasyMock.anyObject(), - (ServiceContract) EasyMock.anyObject(), EasyMock.eq(false)); - expectLastCall().anyTimes(); - replay(wireService); - ConnectorImpl connector = new ConnectorImpl(wireService, registry, null, null); - - connector.connect(owire, iwire, false); - verify(registry); - } - - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/IllegalCallbackExceptionTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/IllegalCallbackExceptionTestCase.java deleted file mode 100644 index 40ddc837c7..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/IllegalCallbackExceptionTestCase.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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 junit.framework.TestCase; - -/** - * @version $Rev$ $Date$ - */ -public class IllegalCallbackExceptionTestCase extends TestCase { - - public void testInstantiation() throws Exception { - IllegalCallbackException e = new IllegalCallbackException("message", - "identifier", - "source name", - "ref name", - "target name", - "service name"); - assertEquals("message", e.getMessage()); - assertEquals("identifier", e.getIdentifier()); - assertEquals("source name", e.getSourceName()); - assertEquals("ref name", e.getReferenceName()); - assertEquals("target name", e.getTargetName()); - assertEquals("service name", e.getTargetServiceName()); - - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/InboundtoOutboundConnectTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/InboundtoOutboundConnectTestCase.java deleted file mode 100644 index 4676dbb7cc..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/InboundtoOutboundConnectTestCase.java +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.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.InboundInvocationChain; -import org.apache.tuscany.spi.wire.Message; -import org.apache.tuscany.spi.wire.MessageImpl; -import org.apache.tuscany.spi.wire.OutboundInvocationChain; -import org.apache.tuscany.spi.wire.TargetInvoker; - -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.wire.MockSyncInterceptor; -import org.apache.tuscany.core.wire.InboundInvocationChainImpl; -import org.apache.tuscany.core.wire.InvokerInterceptor; -import org.apache.tuscany.core.wire.OutboundInvocationChainImpl; -import org.easymock.EasyMock; - -/** - * Verifies connection strategies between {@link org.apache.tuscany.spi.wire.OutboundInvocationChain}s and {@link - * org.apache.tuscany.spi.wire.InboundInvocationChain}s - * - * @version $$Rev$$ $$Date$$ - */ -public class InboundtoOutboundConnectTestCase extends TestCase { - private Operation operation; - private ConnectorImpl connector; - - public void testNoInterceptors() throws Exception { - InboundInvocationChain inboundChain = new InboundInvocationChainImpl(operation); - OutboundInvocationChain outboundChain = new OutboundInvocationChainImpl(operation); - outboundChain.addInterceptor(new InvokerInterceptor()); - TargetInvoker invoker = EasyMock.createNiceMock(TargetInvoker.class); - EasyMock.expect(invoker.invoke(EasyMock.isA(Message.class))).andReturn(new MessageImpl()); - EasyMock.replay(invoker); - connector.connect(inboundChain, outboundChain); - inboundChain.setTargetInvoker(invoker); - inboundChain.prepare(); - Message msg = new MessageImpl(); - msg.setTargetInvoker(invoker); - inboundChain.getHeadInterceptor().invoke(msg); - EasyMock.verify(invoker); - } - - - /** - * Verifies an invocation with a single source interceptor - */ - public void testSourceInterceptor() throws Exception { - MockSyncInterceptor interceptor = new MockSyncInterceptor(); - InboundInvocationChain inboundChain = new InboundInvocationChainImpl(operation); - inboundChain.addInterceptor(interceptor); - OutboundInvocationChain outboundChain = new OutboundInvocationChainImpl(operation); - outboundChain.addInterceptor(new InvokerInterceptor()); - Message msg = new MessageImpl(); - TargetInvoker invoker = EasyMock.createNiceMock(TargetInvoker.class); - EasyMock.expect(invoker.invoke(EasyMock.eq(msg))).andReturn(msg); - EasyMock.replay(invoker); - assertEquals(0, interceptor.getCount()); - connector.connect(inboundChain, outboundChain); - inboundChain.setTargetInvoker(invoker); - inboundChain.prepare(); - msg.setTargetInvoker(inboundChain.getTargetInvoker()); - assertEquals(msg, inboundChain.getHeadInterceptor().invoke(msg)); - assertEquals(1, interceptor.getCount()); - EasyMock.verify(invoker); - } - - /** - * Verifies an invocation with a single target interceptor - */ - public void testTargetInterceptor() throws Exception { - MockSyncInterceptor interceptor = new MockSyncInterceptor(); - InboundInvocationChain inboundChain = new InboundInvocationChainImpl(operation); - inboundChain.addInterceptor(interceptor); - OutboundInvocationChain outboundChain = new OutboundInvocationChainImpl(operation); - outboundChain.addInterceptor(new InvokerInterceptor()); - Message msg = new MessageImpl(); - TargetInvoker invoker = EasyMock.createNiceMock(TargetInvoker.class); - EasyMock.expect(invoker.invoke(EasyMock.eq(msg))).andReturn(msg); - EasyMock.replay(invoker); - assertEquals(0, interceptor.getCount()); - connector.connect(inboundChain, outboundChain); - inboundChain.setTargetInvoker(invoker); - inboundChain.prepare(); - msg.setTargetInvoker(inboundChain.getTargetInvoker()); - assertEquals(msg, inboundChain.getHeadInterceptor().invoke(msg)); - assertEquals(1, interceptor.getCount()); - EasyMock.verify(invoker); - } - - /** - * Verifies an invocation with a source and target interceptor - */ - public void testSourceTargetInterceptor() throws Exception { - MockSyncInterceptor sourceInterceptor = new MockSyncInterceptor(); - MockSyncInterceptor targetInterceptor = new MockSyncInterceptor(); - OutboundInvocationChain outboundChain = new OutboundInvocationChainImpl(operation); - outboundChain.addInterceptor(sourceInterceptor); - outboundChain.addInterceptor(new InvokerInterceptor()); - InboundInvocationChain inboundChain = new InboundInvocationChainImpl(operation); - inboundChain.addInterceptor(targetInterceptor); - Message msg = new MessageImpl(); - TargetInvoker invoker = EasyMock.createNiceMock(TargetInvoker.class); - EasyMock.expect(invoker.invoke(EasyMock.eq(msg))).andReturn(msg); - EasyMock.replay(invoker); - assertEquals(0, sourceInterceptor.getCount()); - assertEquals(0, targetInterceptor.getCount()); - connector.connect(inboundChain, outboundChain); - inboundChain.setTargetInvoker(invoker); - inboundChain.prepare(); - msg.setTargetInvoker(inboundChain.getTargetInvoker()); - assertEquals(msg, inboundChain.getHeadInterceptor().invoke(msg)); - assertEquals(1, sourceInterceptor.getCount()); - assertEquals(1, targetInterceptor.getCount()); - EasyMock.verify(invoker); - } - - public void testOptimizeSet() throws Exception { - OutboundInvocationChain outboundChain = new OutboundInvocationChainImpl(operation); - outboundChain.addInterceptor(new InvokerInterceptor()); - InboundInvocationChain inboundChain = new InboundInvocationChainImpl(operation); - Message msg = new MessageImpl(); - TargetInvoker invoker = EasyMock.createNiceMock(TargetInvoker.class); - EasyMock.expect(invoker.invoke(EasyMock.eq(msg))).andReturn(msg); - EasyMock.replay(invoker); - connector.connect(inboundChain, outboundChain); - inboundChain.setTargetInvoker(invoker); - inboundChain.prepare(); - msg.setTargetInvoker(inboundChain.getTargetInvoker()); - assertEquals(msg, inboundChain.getHeadInterceptor().invoke(msg)); - EasyMock.verify(invoker); - } - - protected void setUp() throws Exception { - super.setUp(); - connector = new ConnectorImpl(); - JavaInterfaceProcessorRegistry registry = new JavaInterfaceProcessorRegistryImpl(); - ServiceContract contract; - try { - contract = registry.introspect(SimpleTarget.class); - } catch (InvalidServiceContractException e) { - throw new AssertionError(); - } - operation = contract.getOperations().get("echo"); - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/IncompatibleInterfacesExceptionTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/IncompatibleInterfacesExceptionTestCase.java deleted file mode 100644 index 7fa6633258..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/IncompatibleInterfacesExceptionTestCase.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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 junit.framework.TestCase; - -/** - * @version $Rev$ $Date$ - */ -public class IncompatibleInterfacesExceptionTestCase extends TestCase { - - public void testInstantiation() throws Exception { - IncompatibleInterfacesException e = new IncompatibleInterfacesException("message", - "source name", - "ref name", - "target name", - "service name"); - assertEquals("message", e.getMessage()); - assertEquals("source name", e.getSourceName()); - assertEquals("ref name", e.getReferenceName()); - assertEquals("target name", e.getTargetName()); - assertEquals("service name", e.getTargetServiceName()); - - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/InvalidTargetTypeExceptionTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/InvalidTargetTypeExceptionTestCase.java deleted file mode 100644 index c34be84745..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/InvalidTargetTypeExceptionTestCase.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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 junit.framework.TestCase; - -/** - * @version $Rev$ $Date$ - */ -public class InvalidTargetTypeExceptionTestCase extends TestCase { - - public void testInstantiation() throws Exception { - InvalidTargetTypeException e = new InvalidTargetTypeException("message", - "source name", - "ref name", - "target name", - "service name"); - assertEquals("message", e.getMessage()); - assertEquals("source name", e.getSourceName()); - assertEquals("ref name", e.getReferenceName()); - assertEquals("target name", e.getTargetName()); - assertEquals("service name", e.getTargetServiceName()); - - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/LocalReferenceWiringTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/LocalReferenceWiringTestCase.java deleted file mode 100644 index 0806708056..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/LocalReferenceWiringTestCase.java +++ /dev/null @@ -1,236 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.util.Collections; - -import org.apache.tuscany.spi.QualifiedName; -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.CompositeComponent; -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.model.Scope; -import org.apache.tuscany.spi.wire.InboundInvocationChain; -import org.apache.tuscany.spi.wire.InboundWire; -import org.apache.tuscany.spi.wire.Interceptor; -import org.apache.tuscany.spi.wire.Message; -import org.apache.tuscany.spi.wire.MessageImpl; - -import org.apache.tuscany.core.implementation.composite.CompositeComponentImpl; -import org.apache.tuscany.core.implementation.composite.ReferenceImpl; -import org.easymock.EasyMock; -import org.easymock.IAnswer; - -/** - * Verifies various wiring "scenarios" or paths through the connector - * - * @version $Rev$ $Date$ - */ -public class LocalReferenceWiringTestCase extends AbstractConnectorImplTestCase { - protected ReferenceBinding referenceBinding; - private Reference reference; - - /** - * Verifies the case where the outbound reference wire is connected to a target atomic component that is a sibling - * to the reference's parent composite. This wiring scenario occurs when a reference is configured with the local - * binding. - */ - public void testConnectLocalReferenceBindingToAtomicComponentService() throws Exception { - final AtomicComponent atomicComponent = createAtomicTarget(); - CompositeComponent topComposite = EasyMock.createMock(CompositeComponent.class); - topComposite.getChild(TARGET); - EasyMock.expectLastCall().andStubAnswer(new IAnswer() { - public Object answer() throws Throwable { - return atomicComponent; - } - }); - EasyMock.replay(topComposite); - CompositeComponent parent = new CompositeComponentImpl("parent", topComposite, connector, null); - reference = createLocalReference(parent, TARGET_SERVICE_NAME); - parent.register(reference); - // connect to the target - connector.connect(parent); - // connect the internal reference chains - connector.connect(reference); - InboundInvocationChain chain = referenceBinding.getInboundWire().getInvocationChains().get(operation); - Interceptor interceptor = chain.getHeadInterceptor(); - MessageImpl msg = new MessageImpl(); - msg.setTargetInvoker(new MockInvoker()); - Message resp = interceptor.invoke(msg); - assertEquals(RESPONSE, resp.getBody()); - } - - /** - * Verifies the case where the outbound reference wire is connected to a target composite service that is a sibling - * to the reference's parent composite. This wiring scenario occurs when a reference is configured with the local - * binding. - */ - public void testConnectLocalReferenceBindingToCompositeService() throws Exception { - final CompositeComponent topComposite = EasyMock.createMock(CompositeComponent.class); - - topComposite.getInboundWire(TARGET); - EasyMock.expectLastCall().andStubAnswer(new IAnswer() { - public Object answer() throws Throwable { - return createLocalInboundWire(topComposite); - } - }); - final Service service = createLocalService(topComposite); - topComposite.getChild(TARGET); - EasyMock.expectLastCall().andStubAnswer(new IAnswer() { - public Object answer() throws Throwable { - return service; - } - }); - EasyMock.replay(topComposite); - - CompositeComponent parent = new CompositeComponentImpl("parent", topComposite, connector, null); - reference = createLocalReference(parent, TARGET_NAME); - parent.register(reference); - connector.connect(parent); - connector.connect(reference); - InboundInvocationChain chain = referenceBinding.getInboundWire().getInvocationChains().get(operation); - Interceptor interceptor = chain.getHeadInterceptor(); - MessageImpl msg = new MessageImpl(); - msg.setTargetInvoker(new MockInvoker()); - Message resp = interceptor.invoke(msg); - assertEquals(RESPONSE, resp.getBody()); - } - - /** - * Verfies an exception if the target composite service (a sibling to the reference's parent) does not have a local - * binding - */ - public void testConnectLocalReferenceBindingToCompositeServiceNoMatchingBinding() throws Exception { - final Service service = createServiceNonLocalBinding(); - CompositeComponent topComposite = EasyMock.createMock(CompositeComponent.class); - EasyMock.expect(topComposite.getName()).andReturn("foo"); - topComposite.getChild(TARGET); - EasyMock.expectLastCall().andStubAnswer(new IAnswer() { - public Object answer() throws Throwable { - return service; - } - }); - EasyMock.replay(topComposite); - - CompositeComponent parent = new CompositeComponentImpl("parent", topComposite, connector, null); - reference = createLocalReference(parent, TARGET_NAME); - parent.register(reference); - try { - connector.connect(parent); - fail(); - } catch (NoCompatibleBindingsException e) { - // expected - } - } - - /** - * Verifies a connection to a service offered by a sibling composite of the reference's parent - * - * @throws Exception - */ - public void testConnectLocalReferenceBindingToSiblingCompositeService() throws Exception { - final CompositeComponent sibling = EasyMock.createMock(CompositeComponent.class); - final InboundWire localServiceInboundWire = createLocalInboundWire(sibling); - EasyMock.expect(sibling.getName()).andReturn("sibling").atLeastOnce(); - sibling.getInboundWires(); - EasyMock.expectLastCall().andReturn(Collections.emptyList()).atLeastOnce(); - EasyMock.expect(sibling.isSystem()).andReturn(false).atLeastOnce(); - sibling.getInboundWire(TARGET_SERVICE); - EasyMock.expectLastCall().andStubAnswer(new IAnswer() { - public Object answer() throws Throwable { - return localServiceInboundWire; - } - }); - EasyMock.expect(sibling.getScope()).andReturn(Scope.SYSTEM).anyTimes(); - EasyMock.replay(sibling); - - CompositeComponent topComposite = EasyMock.createMock(CompositeComponent.class); - EasyMock.expect(topComposite.getName()).andReturn("foo").atLeastOnce(); - topComposite.getChild(TARGET); - EasyMock.expectLastCall().andStubAnswer(new IAnswer() { - public Object answer() throws Throwable { - return sibling; - } - }); - EasyMock.replay(topComposite); - - CompositeComponent parent = new CompositeComponentImpl("parent", topComposite, connector, null); - reference = createLocalReference(parent, TARGET_SERVICE_NAME); - parent.register(reference); - parent.register(sibling); - connector.connect(parent); - connector.connect(reference); - InboundInvocationChain chain = referenceBinding.getInboundWire().getInvocationChains().get(operation); - Interceptor interceptor = chain.getHeadInterceptor(); - MessageImpl msg = new MessageImpl(); - msg.setTargetInvoker(new MockInvoker()); - Message resp = interceptor.invoke(msg); - assertEquals(RESPONSE, resp.getBody()); - } - - public void testConnectLocalReferenceBindingToSiblingCompositeServiceNoMatchingBinding() throws Exception { - try { - final CompositeComponent sibling = EasyMock.createMock(CompositeComponent.class); - sibling.getInboundWire(TARGET_SERVICE); - EasyMock.expectLastCall().andReturn(null); - EasyMock.expect(sibling.getName()).andReturn("sibling").atLeastOnce(); - EasyMock.expect(sibling.getScope()).andReturn(Scope.SYSTEM).atLeastOnce(); - EasyMock.expectLastCall().andStubAnswer(new IAnswer() { - public Object answer() throws Throwable { - return null; - } - }); - EasyMock.replay(sibling); - - CompositeComponent topComposite = EasyMock.createMock(CompositeComponent.class); - topComposite.getChild(TARGET); - EasyMock.expectLastCall().andStubAnswer(new IAnswer() { - public Object answer() throws Throwable { - return sibling; - } - }); - EasyMock.expect(topComposite.getName()).andReturn("top").atLeastOnce(); - EasyMock.replay(topComposite); - - CompositeComponent parent = new CompositeComponentImpl("parent", topComposite, connector, null); - - reference = createLocalReference(parent, TARGET_SERVICE_NAME); - parent.register(reference); - connector.connect(parent); - fail(); - } catch (TargetServiceNotFoundException e) { - // expected - } - } - - protected void setUp() throws Exception { - super.setUp(); - } - - - private Reference createLocalReference(CompositeComponent parent, QualifiedName target) throws Exception { - referenceBinding = createLocalReferenceBinding(target); - Reference reference = new ReferenceImpl("foo", parent, contract); - reference.addReferenceBinding(referenceBinding); - return reference; - } - - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/NonBlockingForwardNonBlockingCallbackConnectionTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/NonBlockingForwardNonBlockingCallbackConnectionTestCase.java deleted file mode 100644 index 896a98b773..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/NonBlockingForwardNonBlockingCallbackConnectionTestCase.java +++ /dev/null @@ -1,172 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.util.HashMap; -import java.util.Map; - -import org.apache.tuscany.spi.QualifiedName; -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.WorkContext; -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.services.work.NotificationListener; -import org.apache.tuscany.spi.services.work.WorkScheduler; -import org.apache.tuscany.spi.wire.InboundInvocationChain; -import org.apache.tuscany.spi.wire.InboundWire; -import org.apache.tuscany.spi.wire.Interceptor; -import org.apache.tuscany.spi.wire.Message; -import org.apache.tuscany.spi.wire.MessageImpl; -import org.apache.tuscany.spi.wire.OutboundInvocationChain; -import org.apache.tuscany.spi.wire.OutboundWire; -import org.apache.tuscany.spi.wire.TargetInvoker; -import org.apache.tuscany.spi.wire.WireService; - -import junit.framework.TestCase; -import org.apache.tuscany.core.component.WorkContextImpl; -import org.apache.tuscany.core.wire.InboundInvocationChainImpl; -import org.apache.tuscany.core.wire.InboundWireImpl; -import org.apache.tuscany.core.wire.OutboundInvocationChainImpl; -import org.apache.tuscany.core.wire.OutboundWireImpl; -import org.apache.tuscany.core.wire.jdk.JDKWireService; -import org.easymock.EasyMock; - -/** - * Verifies connections with non-blocking forward and callback invocations - * - * @version $Rev$ $Date$ - */ -public class NonBlockingForwardNonBlockingCallbackConnectionTestCase extends TestCase { - private Operation operation; - private Operation callbackOperation; - private ServiceContract contract; - private ConnectorImpl connector; - - public void testNonBlockingForwardAndNonBlockingCallbackAtomicToAtomic() throws Exception { - AtomicComponent target = EasyMock.createMock(AtomicComponent.class); - EasyMock.expect(target.isSystem()).andReturn(false).anyTimes(); - EasyMock.expect(target.getName()).andReturn("target").anyTimes(); - EasyMock.expect(target.createTargetInvoker(EasyMock.eq("service"), - EasyMock.isA(Operation.class), - EasyMock.isA(InboundWire.class))).andReturn(EasyMock.createNiceMock(TargetInvoker.class)); - EasyMock.replay(target); - - InboundWire inboundWire = new InboundWireImpl(); - inboundWire.setContainer(target); - inboundWire.setServiceContract(contract); - InboundInvocationChain inboundChain = new InboundInvocationChainImpl(operation); - inboundChain.addInterceptor(new NonBlockingForwardNonBlockingCallbackConnectionTestCase.MockInterceptor()); - inboundWire.addInvocationChain(operation, inboundChain); - - AtomicComponent source = createSource(); - OutboundWire outboundWire = new OutboundWireImpl(); - outboundWire.setContainer(source); - outboundWire.setServiceContract(contract); - outboundWire.setTargetName(new QualifiedName("target/service")); - OutboundInvocationChain outboundChain = new OutboundInvocationChainImpl(operation); - outboundWire.addInvocationChain(operation, outboundChain); - - InboundInvocationChain callbackInboundChain = new InboundInvocationChainImpl(callbackOperation); - callbackInboundChain - .addInterceptor(new NonBlockingForwardNonBlockingCallbackConnectionTestCase.MockInterceptor()); - Map, InboundInvocationChain> chains = new HashMap, InboundInvocationChain>(); - chains.put(callbackOperation, callbackInboundChain); - outboundWire.addTargetCallbackInvocationChains(chains); - - connector.connect(outboundWire, inboundWire, true); - - // test the forward request - Message msg = new MessageImpl(); - msg.setBody("foo"); - Message ret = outboundChain.getHeadInterceptor().invoke(msg); - assertEquals(null, ret.getBody()); - - // test the callback - msg = new MessageImpl(); - msg.setBody("callback"); - Map, OutboundInvocationChain> callbackChains = - inboundWire.getSourceCallbackInvocationChains("source"); - OutboundInvocationChain callbackInvocationChain = callbackChains.get(callbackOperation); - ret = callbackInvocationChain.getHeadInterceptor().invoke(msg); - assertEquals(null, ret.getBody()); - - EasyMock.verify(source); - EasyMock.verify(target); - } - - protected void setUp() throws Exception { - super.setUp(); - WorkContext context = new WorkContextImpl(); - WireService wireService = new JDKWireService(null, null); - WorkScheduler scheduler = new MockWorkScheduler(); - connector = new ConnectorImpl(wireService, null, scheduler, context); - operation = new Operation("bar", null, null, null); - operation.setNonBlocking(true); - callbackOperation = new Operation("callback", null, null, null); - callbackOperation.setNonBlocking(true); - contract = new JavaServiceContract(); - Map> ops = new HashMap>(); - ops.put("callback", callbackOperation); - contract.setCallbackOperations(ops); - } - - private AtomicComponent createSource() throws Exception { - AtomicComponent component = EasyMock.createMock(AtomicComponent.class); - EasyMock.expect(component.getName()).andReturn("source").atLeastOnce(); - EasyMock.expect(component.isSystem()).andReturn(false).anyTimes(); - EasyMock.expect(component.createTargetInvoker(EasyMock.eq("callback"), - EasyMock.isA(Operation.class), - (InboundWire) EasyMock.isNull())).andReturn(EasyMock.createNiceMock(TargetInvoker.class)); - EasyMock.replay(component); - return component; - } - - private class MockInterceptor implements Interceptor { - - public Message invoke(Message msg) { - return msg; - } - - public void setNext(Interceptor next) { - - } - - public Interceptor getNext() { - return null; - } - - public boolean isOptimizable() { - return false; - } - } - - private class MockWorkScheduler implements WorkScheduler { - - public void scheduleWork(T work, NotificationListener listener) { - throw new UnsupportedOperationException(); - } - - public void scheduleWork(T work) { - work.run(); - } - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/NonBlockingForwardSyncCallbackConnectionTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/NonBlockingForwardSyncCallbackConnectionTestCase.java deleted file mode 100644 index 0e425b73bf..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/NonBlockingForwardSyncCallbackConnectionTestCase.java +++ /dev/null @@ -1,171 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.util.Map; -import java.util.HashMap; - -import org.apache.tuscany.spi.model.Operation; -import org.apache.tuscany.spi.model.ServiceContract; -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.WorkContext; -import org.apache.tuscany.spi.wire.InboundWire; -import org.apache.tuscany.spi.wire.TargetInvoker; -import org.apache.tuscany.spi.wire.InboundInvocationChain; -import org.apache.tuscany.spi.wire.OutboundWire; -import org.apache.tuscany.spi.wire.OutboundInvocationChain; -import org.apache.tuscany.spi.wire.Message; -import org.apache.tuscany.spi.wire.MessageImpl; -import org.apache.tuscany.spi.wire.WireService; -import org.apache.tuscany.spi.wire.Interceptor; -import org.apache.tuscany.spi.QualifiedName; -import org.apache.tuscany.spi.idl.java.JavaServiceContract; -import org.apache.tuscany.spi.services.work.WorkScheduler; -import org.apache.tuscany.spi.services.work.NotificationListener; - -import junit.framework.TestCase; -import org.easymock.EasyMock; -import org.apache.tuscany.core.wire.InboundWireImpl; -import org.apache.tuscany.core.wire.InboundInvocationChainImpl; -import org.apache.tuscany.core.wire.OutboundWireImpl; -import org.apache.tuscany.core.wire.OutboundInvocationChainImpl; -import org.apache.tuscany.core.wire.jdk.JDKWireService; -import org.apache.tuscany.core.component.WorkContextImpl; - -/** - * Verifies connections with non-blocking forward and synchronous callback invocations - * - * @version $Rev$ $Date$ - */ -public class NonBlockingForwardSyncCallbackConnectionTestCase extends TestCase { - private Operation operation; - private Operation callbackOperation; - private ServiceContract contract; - private ConnectorImpl connector; - - public void testNonBlockingForwardAndSyncCallbackAtomicToAtomic() throws Exception { - AtomicComponent target = EasyMock.createMock(AtomicComponent.class); - EasyMock.expect(target.isSystem()).andReturn(false).anyTimes(); - EasyMock.expect(target.getName()).andReturn("target").anyTimes(); - EasyMock.expect(target.createTargetInvoker(EasyMock.eq("service"), - EasyMock.isA(Operation.class), - EasyMock.isA(InboundWire.class))).andReturn(EasyMock.createNiceMock(TargetInvoker.class)); - EasyMock.replay(target); - - InboundWire inboundWire = new InboundWireImpl(); - inboundWire.setContainer(target); - inboundWire.setServiceContract(contract); - InboundInvocationChain inboundChain = new InboundInvocationChainImpl(operation); - inboundChain.addInterceptor(new NonBlockingForwardSyncCallbackConnectionTestCase.MockInterceptor()); - inboundWire.addInvocationChain(operation, inboundChain); - - AtomicComponent source = createSource(); - OutboundWire outboundWire = new OutboundWireImpl(); - outboundWire.setContainer(source); - outboundWire.setServiceContract(contract); - outboundWire.setTargetName(new QualifiedName("target/service")); - OutboundInvocationChain outboundChain = new OutboundInvocationChainImpl(operation); - outboundWire.addInvocationChain(operation, outboundChain); - - InboundInvocationChain callbackInboundChain = new InboundInvocationChainImpl(callbackOperation); - callbackInboundChain.addInterceptor(new NonBlockingForwardSyncCallbackConnectionTestCase.MockInterceptor()); - Map, InboundInvocationChain> chains = new HashMap, InboundInvocationChain>(); - chains.put(callbackOperation, callbackInboundChain); - outboundWire.addTargetCallbackInvocationChains(chains); - - connector.connect(outboundWire, inboundWire, true); - - // test the forward request - Message msg = new MessageImpl(); - msg.setBody("foo"); - Message ret = outboundChain.getHeadInterceptor().invoke(msg); - assertEquals(null, ret.getBody()); - - // test the callback - msg = new MessageImpl(); - msg.setBody("callback"); - Map, OutboundInvocationChain> callbackChains = - inboundWire.getSourceCallbackInvocationChains("source"); - OutboundInvocationChain callbackInvocationChain = callbackChains.get(callbackOperation); - ret = callbackInvocationChain.getHeadInterceptor().invoke(msg); - assertEquals("callback", ret.getBody()); - - EasyMock.verify(source); - EasyMock.verify(target); - } - - - protected void setUp() throws Exception { - super.setUp(); - WorkContext context = new WorkContextImpl(); - WireService wireService = new JDKWireService(null, null); - WorkScheduler scheduler = new NonBlockingForwardSyncCallbackConnectionTestCase.MockWorkScheduler(); - connector = new ConnectorImpl(wireService, null, scheduler, context); - operation = new Operation("bar", null, null, null); - operation.setNonBlocking(true); - callbackOperation = new Operation("callback", null, null, null); - contract = new JavaServiceContract(); - Map> ops = new HashMap>(); - ops.put("callback", callbackOperation); - contract.setCallbackOperations(ops); - } - - private AtomicComponent createSource() throws Exception { - AtomicComponent component = EasyMock.createMock(AtomicComponent.class); - EasyMock.expect(component.getName()).andReturn("source").atLeastOnce(); - EasyMock.expect(component.isSystem()).andReturn(false).anyTimes(); - EasyMock.expect(component.createTargetInvoker(EasyMock.eq("callback"), - EasyMock.isA(Operation.class), - (InboundWire) EasyMock.isNull())).andReturn(EasyMock.createNiceMock(TargetInvoker.class)); - EasyMock.replay(component); - return component; - } - - private class MockInterceptor implements Interceptor { - - public Message invoke(Message msg) { - return msg; - } - - public void setNext(Interceptor next) { - - } - - public Interceptor getNext() { - return null; - } - - public boolean isOptimizable() { - return false; - } - } - - private class MockWorkScheduler implements WorkScheduler { - - public void scheduleWork(T work, NotificationListener listener) { - throw new UnsupportedOperationException(); - } - - public void scheduleWork(T work) { - work.run(); - } - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/OutboundToInboundConnectTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/OutboundToInboundConnectTestCase.java deleted file mode 100644 index 2c8e2c3fa8..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/OutboundToInboundConnectTestCase.java +++ /dev/null @@ -1,184 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.util.ArrayList; -import java.util.List; - -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.InboundInvocationChain; -import org.apache.tuscany.spi.wire.Interceptor; -import org.apache.tuscany.spi.wire.Message; -import org.apache.tuscany.spi.wire.MessageImpl; -import org.apache.tuscany.spi.wire.OutboundInvocationChain; -import org.apache.tuscany.spi.wire.TargetInvoker; -import static org.apache.tuscany.spi.wire.TargetInvoker.NONE; - -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.wire.MockSyncInterceptor; -import org.apache.tuscany.core.wire.InboundInvocationChainImpl; -import org.apache.tuscany.core.wire.InvokerInterceptor; -import org.apache.tuscany.core.wire.OutboundInvocationChainImpl; -import org.easymock.EasyMock; -import static org.easymock.EasyMock.createNiceMock; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; - -/** - * Verifies connection strategies between {@link org.apache.tuscany.spi.wire.OutboundInvocationChain}s and {@link - * org.apache.tuscany.spi.wire.InboundInvocationChain}s - * - * @version $$Rev$$ $$Date$$ - */ -public class OutboundToInboundConnectTestCase extends TestCase { - - public void testNoInterceptorsNoHandlers() throws Exception { - ConnectorImpl connector = new ConnectorImpl(); - InboundInvocationChain inboundChain = setupTarget(null); - OutboundInvocationChain outboundChain = setupSource(null); - String[] val = new String[]{"foo"}; - TargetInvoker invoker = createNiceMock(TargetInvoker.class); - expect(invoker.invokeTarget(EasyMock.eq(val), EasyMock.eq(NONE))).andReturn(val); - replay(invoker); - connector.connect(outboundChain, inboundChain, invoker, false); - inboundChain.prepare(); - assertEquals(val, outboundChain.getTargetInvoker().invokeTarget(val, NONE)); - verify(invoker); - } - - - /** - * Verifies an invocation with a single source interceptor - */ - public void testSourceInterceptor() throws Exception { - ConnectorImpl connector = new ConnectorImpl(); - MockSyncInterceptor interceptor = new MockSyncInterceptor(); - List interceptors = new ArrayList(); - interceptors.add(interceptor); - OutboundInvocationChain outboundChain = setupSource(interceptors); - InboundInvocationChain inboundChain = setupTarget(null); - Message msg = new MessageImpl(); - TargetInvoker invoker = createNiceMock(TargetInvoker.class); - expect(invoker.invoke(EasyMock.eq(msg))).andReturn(msg); - replay(invoker); - assertEquals(0, interceptor.getCount()); - connector.connect(outboundChain, inboundChain, invoker, false); - inboundChain.prepare(); - msg.setTargetInvoker(outboundChain.getTargetInvoker()); - assertEquals(msg, outboundChain.getHeadInterceptor().invoke(msg)); - assertEquals(1, interceptor.getCount()); - verify(invoker); - } - - /** - * Verifies an invocation with a single target interceptor - */ - public void testTargetInterceptor() throws Exception { - ConnectorImpl connector = new ConnectorImpl(); - MockSyncInterceptor interceptor = new MockSyncInterceptor(); - List interceptors = new ArrayList(); - interceptors.add(interceptor); - OutboundInvocationChain outboundChain = setupSource(null); - InboundInvocationChain inboundChain = setupTarget(interceptors); - Message msg = new MessageImpl(); - TargetInvoker invoker = createNiceMock(TargetInvoker.class); - expect(invoker.invoke(EasyMock.eq(msg))).andReturn(msg); - replay(invoker); - assertEquals(0, interceptor.getCount()); - connector.connect(outboundChain, inboundChain, invoker, false); - inboundChain.prepare(); - msg.setTargetInvoker(outboundChain.getTargetInvoker()); - assertEquals(msg, outboundChain.getHeadInterceptor().invoke(msg)); - assertEquals(1, interceptor.getCount()); - verify(invoker); - } - - /** - * Verifies an invocation with a source and target interceptor - */ - public void testSourceTargetInterceptor() throws Exception { - ConnectorImpl connector = new ConnectorImpl(); - MockSyncInterceptor sourceInterceptor = new MockSyncInterceptor(); - List sourceInterceptors = new ArrayList(); - sourceInterceptors.add(sourceInterceptor); - MockSyncInterceptor targetInterceptor = new MockSyncInterceptor(); - List targetInterceptors = new ArrayList(); - targetInterceptors.add(targetInterceptor); - OutboundInvocationChain outboundChain = setupSource(sourceInterceptors); - InboundInvocationChain inboundChain = setupTarget(targetInterceptors); - Message msg = new MessageImpl(); - TargetInvoker invoker = createNiceMock(TargetInvoker.class); - expect(invoker.invoke(EasyMock.eq(msg))).andReturn(msg); - replay(invoker); - assertEquals(0, sourceInterceptor.getCount()); - assertEquals(0, targetInterceptor.getCount()); - connector.connect(outboundChain, inboundChain, invoker, false); - inboundChain.prepare(); - msg.setTargetInvoker(outboundChain.getTargetInvoker()); - assertEquals(msg, outboundChain.getHeadInterceptor().invoke(msg)); - assertEquals(1, sourceInterceptor.getCount()); - assertEquals(1, targetInterceptor.getCount()); - verify(invoker); - } - - - public InboundInvocationChain setupTarget(List interceptors) { - JavaInterfaceProcessorRegistry registry = new JavaInterfaceProcessorRegistryImpl(); - ServiceContract contract; - try { - contract = registry.introspect(SimpleTarget.class); - } catch (InvalidServiceContractException e) { - throw new AssertionError(); - } - Operation operation = contract.getOperations().get("echo"); - InboundInvocationChainImpl chain = new InboundInvocationChainImpl(operation); - if (interceptors != null) { - for (Interceptor interceptor : interceptors) { - chain.addInterceptor(interceptor); - } - } - chain.addInterceptor(new InvokerInterceptor()); // add tail interceptor - return chain; - } - - public OutboundInvocationChain setupSource(List interceptors) { - JavaInterfaceProcessorRegistry registry = new JavaInterfaceProcessorRegistryImpl(); - ServiceContract contract; - try { - contract = registry.introspect(SimpleTarget.class); - } catch (InvalidServiceContractException e) { - throw new AssertionError(); - } - Operation operation = contract.getOperations().get("echo"); - OutboundInvocationChainImpl chain = new OutboundInvocationChainImpl(operation); - if (interceptors != null) { - for (Interceptor interceptor : interceptors) { - chain.addInterceptor(interceptor); - } - } - return chain; - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/ReferenceConnectorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/ReferenceConnectorTestCase.java deleted file mode 100644 index d3e7263045..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/ReferenceConnectorTestCase.java +++ /dev/null @@ -1,169 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.component.AtomicComponent; -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.component.Reference; -import org.apache.tuscany.spi.component.ReferenceBinding; -import org.apache.tuscany.spi.model.Operation; -import org.apache.tuscany.spi.model.ServiceContract; -import org.apache.tuscany.spi.wire.InboundInvocationChain; -import org.apache.tuscany.spi.wire.InboundWire; -import org.apache.tuscany.spi.wire.Interceptor; -import org.apache.tuscany.spi.wire.Message; -import org.apache.tuscany.spi.wire.MessageImpl; -import org.apache.tuscany.spi.wire.OutboundInvocationChain; -import org.apache.tuscany.spi.wire.OutboundWire; - -import org.apache.tuscany.core.implementation.composite.ReferenceImpl; -import org.apache.tuscany.core.wire.InboundInvocationChainImpl; -import org.apache.tuscany.core.wire.InboundWireImpl; -import org.apache.tuscany.core.wire.InvokerInterceptor; -import org.apache.tuscany.core.wire.OutboundInvocationChainImpl; -import org.apache.tuscany.core.wire.OutboundWireImpl; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class ReferenceConnectorTestCase extends AbstractConnectorImplTestCase { - private AtomicComponent source; - private CompositeComponent parent; - - public void testConnectReferenceWiresNoInboundInterceptors() throws Exception { - InboundInvocationChain inboundChain = new InboundInvocationChainImpl(operation); - InboundWire inboundWire = new InboundWireImpl(); - inboundWire.setServiceContract(contract); - inboundWire.addInvocationChain(operation, inboundChain); - - OutboundInvocationChain outboundChain = new OutboundInvocationChainImpl(operation); - // Outbound chains always contains at least one interceptor - outboundChain.addInterceptor(new InvokerInterceptor()); - OutboundWire outboundWire = new OutboundWireImpl(); - outboundWire.setServiceContract(contract); - outboundWire.setTargetName(TARGET_SERVICE_NAME); - outboundWire.addInvocationChain(operation, outboundChain); - - ReferenceBinding referenceBinding = EasyMock.createMock(ReferenceBinding.class); - referenceBinding.setReference(EasyMock.isA(Reference.class)); - EasyMock.expect(referenceBinding.createTargetInvoker(contract, operation)).andReturn(null); - EasyMock.expect(referenceBinding.getInboundWire()).andReturn(inboundWire); - EasyMock.expect(referenceBinding.getOutboundWire()).andReturn(outboundWire); - EasyMock.expect(referenceBinding.isSystem()).andReturn(false).atLeastOnce(); - EasyMock.replay(referenceBinding); - inboundWire.setContainer(referenceBinding); - outboundWire.setContainer(referenceBinding); - - Reference reference = new ReferenceImpl("foo", parent, contract); - reference.addReferenceBinding(referenceBinding); - - connector.connect(reference); - - EasyMock.verify(referenceBinding); - Interceptor interceptor = inboundChain.getHeadInterceptor(); - MessageImpl msg = new MessageImpl(); - msg.setTargetInvoker(new MockInvoker()); - Message resp = interceptor.invoke(msg); - assertEquals(RESPONSE, resp.getBody()); - } - - public void testConnectReferenceWiresWithInboundInterceptors() throws Exception { - MockInterceptor inboundInterceptor = new MockInterceptor(); - InboundInvocationChain inboundChain = new InboundInvocationChainImpl(operation); - inboundChain.addInterceptor(inboundInterceptor); - InboundWire inboundWire = new InboundWireImpl(); - inboundWire.setServiceContract(contract); - inboundWire.addInvocationChain(operation, inboundChain); - - OutboundInvocationChain outboundChain = new OutboundInvocationChainImpl(operation); - // Outbound always contains at lease one interceptor - outboundChain.addInterceptor(new InvokerInterceptor()); - OutboundWire outboundWire = new OutboundWireImpl(); - outboundWire.setServiceContract(contract); - outboundWire.setTargetName(TARGET_SERVICE_NAME); - outboundWire.addInvocationChain(operation, outboundChain); - - ReferenceBinding referenceBinding = EasyMock.createMock(ReferenceBinding.class); - referenceBinding.setReference(EasyMock.isA(Reference.class)); - EasyMock.expect(referenceBinding.createTargetInvoker(contract, operation)).andReturn(null); - EasyMock.expect(referenceBinding.getInboundWire()).andReturn(inboundWire); - EasyMock.expect(referenceBinding.getOutboundWire()).andReturn(outboundWire); - EasyMock.expect(referenceBinding.isSystem()).andReturn(false); - EasyMock.replay(referenceBinding); - inboundWire.setContainer(referenceBinding); - outboundWire.setContainer(referenceBinding); - - Reference reference = new ReferenceImpl("foo", parent, contract); - reference.addReferenceBinding(referenceBinding); - - connector.connect(reference); - - EasyMock.verify(referenceBinding); - Interceptor interceptor = inboundChain.getHeadInterceptor(); - MessageImpl msg = new MessageImpl(); - msg.setTargetInvoker(new MockInvoker()); - Message resp = interceptor.invoke(msg); - assertEquals(RESPONSE, resp.getBody()); - assertTrue(inboundInterceptor.isInvoked()); - } - - public void testOutboundWireToInboundReferenceTarget() throws Exception { - AtomicComponent component = EasyMock.createMock(AtomicComponent.class); - EasyMock.expect(component.getName()).andReturn("foo"); - EasyMock.replay(component); - - ReferenceBinding target = EasyMock.createMock(ReferenceBinding.class); - EasyMock.expect(target.isSystem()).andReturn(false); - EasyMock.expect(target.createTargetInvoker(EasyMock.isA(ServiceContract.class), EasyMock.isA(Operation.class))) - .andReturn(new MockInvoker()); - EasyMock.replay(target); - - InboundInvocationChain inboundChain = new InboundInvocationChainImpl(operation); - inboundChain.addInterceptor(new InvokerInterceptor()); - InboundWire targetWire = new InboundWireImpl(); - targetWire.setServiceContract(contract); - targetWire.addInvocationChain(operation, inboundChain); - targetWire.setContainer(target); - - // create the outbound wire and chain from the source component - OutboundInvocationChain sourceChain = new OutboundInvocationChainImpl(operation); - OutboundWire sourceWire = new OutboundWireImpl(); - sourceWire.setServiceContract(contract); - sourceWire.setTargetName(TARGET_SERVICE_NAME); - sourceWire.addInvocationChain(operation, sourceChain); - sourceWire.setContainer(component); - sourceWire.setContainer(source); - - connector.connect(sourceWire, targetWire, false); - Interceptor interceptor = sourceChain.getHeadInterceptor(); - MessageImpl msg = new MessageImpl(); - msg.setTargetInvoker(new MockInvoker()); - Message resp = interceptor.invoke(msg); - assertEquals(RESPONSE, resp.getBody()); - } - - protected void setUp() throws Exception { - super.setUp(); - parent = EasyMock.createNiceMock(CompositeComponent.class); - source = EasyMock.createNiceMock(AtomicComponent.class); - EasyMock.replay(source); - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/ServiceConnectorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/ServiceConnectorTestCase.java deleted file mode 100644 index 0ccab5bfea..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/ServiceConnectorTestCase.java +++ /dev/null @@ -1,172 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.component.AtomicComponent; -import org.apache.tuscany.spi.component.CompositeComponent; -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.model.Operation; -import org.apache.tuscany.spi.model.Scope; -import org.apache.tuscany.spi.wire.InboundInvocationChain; -import org.apache.tuscany.spi.wire.InboundWire; -import org.apache.tuscany.spi.wire.Interceptor; -import org.apache.tuscany.spi.wire.Message; -import org.apache.tuscany.spi.wire.MessageImpl; -import org.apache.tuscany.spi.wire.OutboundInvocationChain; -import org.apache.tuscany.spi.wire.OutboundWire; - -import org.apache.tuscany.core.implementation.composite.ReferenceImpl; -import org.apache.tuscany.core.implementation.composite.ServiceImpl; -import org.apache.tuscany.core.mock.binding.MockServiceBinding; -import org.apache.tuscany.core.wire.InboundInvocationChainImpl; -import org.apache.tuscany.core.wire.InboundWireImpl; -import org.apache.tuscany.core.wire.InvokerInterceptor; -import org.apache.tuscany.core.wire.OutboundInvocationChainImpl; -import org.apache.tuscany.core.wire.OutboundWireImpl; -import org.apache.tuscany.core.wire.SynchronousBridgingInterceptor; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class ServiceConnectorTestCase extends AbstractConnectorImplTestCase { - private CompositeComponent parent; - private InboundInvocationChain inboundChain; - private ServiceBinding sourceServiceBinding; - - public void testConnectServiceToAtomicComponent() throws Exception { - configureAtomicTarget(); - Service sourceService = new ServiceImpl("foo", parent, contract); - sourceService.addServiceBinding(sourceServiceBinding); - connector.connect(sourceService); - Interceptor interceptor = inboundChain.getHeadInterceptor(); - MessageImpl msg = new MessageImpl(); - msg.setTargetInvoker(new MockInvoker()); - Message resp = interceptor.invoke(msg); - assertEquals(RESPONSE, resp.getBody()); - } - - public void testConnectServiceToChildCompositeService() throws Exception { - configureChildCompositeServiceTarget(); - Service sourceService = new ServiceImpl("foo", parent, contract); - sourceService.addServiceBinding(sourceServiceBinding); - connector.connect(sourceService); - Interceptor interceptor = inboundChain.getHeadInterceptor(); - MessageImpl msg = new MessageImpl(); - msg.setTargetInvoker(new MockInvoker()); - Message resp = interceptor.invoke(msg); - assertEquals(RESPONSE, resp.getBody()); - } - - public void testConnectServiceToReference() throws Exception { - configureReferenceTarget(); - Service sourceService = new ServiceImpl("foo", parent, contract); - sourceService.addServiceBinding(sourceServiceBinding); - connector.connect(sourceService); - Interceptor interceptor = inboundChain.getHeadInterceptor(); - MessageImpl msg = new MessageImpl(); - msg.setTargetInvoker(new MockInvoker()); - Message resp = interceptor.invoke(msg); - assertEquals(RESPONSE, resp.getBody()); - } - - protected void setUp() throws Exception { - super.setUp(); - inboundChain = new InboundInvocationChainImpl(operation); - InboundWire inboundWire = new InboundWireImpl(); - inboundWire.setServiceContract(contract); - inboundWire.addInvocationChain(operation, inboundChain); - - OutboundInvocationChain outboundChain = new OutboundInvocationChainImpl(operation); - // Outbound chains always contains at least one interceptor - outboundChain.addInterceptor(new SynchronousBridgingInterceptor()); - OutboundWire outboundWire = new OutboundWireImpl(); - outboundWire.setServiceContract(contract); - outboundWire.setTargetName(TARGET_SERVICE_NAME); - outboundWire.addInvocationChain(operation, outboundChain); - - sourceServiceBinding = new MockServiceBinding(); - sourceServiceBinding.setInboundWire(inboundWire); - sourceServiceBinding.setOutboundWire(outboundWire); - inboundWire.setContainer(sourceServiceBinding); - outboundWire.setContainer(sourceServiceBinding); - - } - - private void configureAtomicTarget() throws Exception { - InboundInvocationChain inboundChain = new InboundInvocationChainImpl(operation); - inboundChain.addInterceptor(new InvokerInterceptor()); - InboundWire inboundWire = new InboundWireImpl(); - inboundWire.setServiceContract(contract); - inboundWire.addInvocationChain(operation, inboundChain); - - AtomicComponent atomicTarget = EasyMock.createMock(AtomicComponent.class); - EasyMock.expect(atomicTarget.getInboundWire(EasyMock.isA(String.class))).andReturn(inboundWire).atLeastOnce(); - EasyMock.expect(atomicTarget.getScope()).andReturn(Scope.COMPOSITE); - EasyMock.expect(atomicTarget.isSystem()).andReturn(false); - EasyMock.expect(atomicTarget.createTargetInvoker(EasyMock.isA(String.class), - EasyMock.isA(Operation.class), - EasyMock.isA(InboundWire.class))).andReturn(new MockInvoker()); - EasyMock.replay(atomicTarget); - - inboundWire.setContainer(atomicTarget); - - parent = EasyMock.createNiceMock(CompositeComponent.class); - EasyMock.expect(parent.getChild(TARGET)).andReturn(atomicTarget); - EasyMock.replay(parent); - } - - private void configureChildCompositeServiceTarget() throws Exception { - InboundInvocationChain inboundChain = new InboundInvocationChainImpl(operation); - inboundChain.addInterceptor(new InvokerInterceptor()); - InboundWire inboundWire = new InboundWireImpl(); - inboundWire.setServiceContract(contract); - inboundWire.addInvocationChain(operation, inboundChain); - - CompositeComponent compositeTarget = EasyMock.createMock(CompositeComponent.class); - Service service = createLocalService(compositeTarget); - ServiceBinding binding = service.getServiceBindings().get(0); - EasyMock.expect(compositeTarget.getInboundWire(TARGET_SERVICE)).andReturn(binding.getInboundWire()); - EasyMock.expect(compositeTarget.getScope()).andReturn(Scope.SYSTEM).anyTimes(); - EasyMock.replay(compositeTarget); - - inboundWire.setContainer(compositeTarget); - - parent = EasyMock.createNiceMock(CompositeComponent.class); - EasyMock.expect(parent.getChild(TARGET)).andReturn(compositeTarget); - EasyMock.replay(parent); - } - - - private void configureReferenceTarget() throws Exception { - ReferenceBinding binding = createLocalReferenceBinding(TARGET_NAME); - Reference referenceTarget = new ReferenceImpl(TARGET, parent, contract); - referenceTarget.addReferenceBinding(binding); - // put a terminating interceptor on the outbound wire of the reference for testing an invocation - binding.getOutboundWire().getInvocationChains().get(operation).addInterceptor(new InvokerInterceptor()); - connector.connect(binding.getInboundWire(), binding.getOutboundWire(), true); - parent = EasyMock.createNiceMock(CompositeComponent.class); - EasyMock.expect(parent.getChild(TARGET)).andReturn(referenceTarget); - EasyMock.replay(parent); - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/SynchronousForwardCallbackConnectionTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/SynchronousForwardCallbackConnectionTestCase.java deleted file mode 100644 index 9beca64444..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/SynchronousForwardCallbackConnectionTestCase.java +++ /dev/null @@ -1,256 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.util.HashMap; -import java.util.Map; - -import org.apache.tuscany.spi.QualifiedName; -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.ReferenceBinding; -import org.apache.tuscany.spi.component.ServiceBinding; -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.InboundInvocationChain; -import org.apache.tuscany.spi.wire.InboundWire; -import org.apache.tuscany.spi.wire.Interceptor; -import org.apache.tuscany.spi.wire.Message; -import org.apache.tuscany.spi.wire.MessageImpl; -import org.apache.tuscany.spi.wire.OutboundInvocationChain; -import org.apache.tuscany.spi.wire.OutboundWire; -import org.apache.tuscany.spi.wire.TargetInvoker; -import org.apache.tuscany.spi.wire.WireService; - -import junit.framework.TestCase; -import org.apache.tuscany.core.wire.InboundInvocationChainImpl; -import org.apache.tuscany.core.wire.InboundWireImpl; -import org.apache.tuscany.core.wire.OutboundInvocationChainImpl; -import org.apache.tuscany.core.wire.OutboundWireImpl; -import org.apache.tuscany.core.wire.jdk.JDKWireService; -import org.easymock.EasyMock; - -/** - * Verifies connections with synchronous forward and callback invocations - * - * @version $Rev$ $Date$ - */ -public class SynchronousForwardCallbackConnectionTestCase extends TestCase { - private Operation operation; - private Operation callbackOperation; - private ServiceContract contract; - private ConnectorImpl connector; - - public void testSyncForwardAndCallbackAtomicToAtomic() throws Exception { - AtomicComponent target = EasyMock.createMock(AtomicComponent.class); - EasyMock.expect(target.isSystem()).andReturn(false).anyTimes(); - EasyMock.expect(target.getName()).andReturn("target").anyTimes(); - EasyMock.expect(target.createTargetInvoker(EasyMock.eq("service"), - EasyMock.isA(Operation.class), - EasyMock.isA(InboundWire.class))).andReturn(EasyMock.createNiceMock(TargetInvoker.class)); - EasyMock.replay(target); - - InboundWire inboundWire = new InboundWireImpl(); - inboundWire.setContainer(target); - inboundWire.setServiceContract(contract); - InboundInvocationChain inboundChain = new InboundInvocationChainImpl(operation); - inboundChain.addInterceptor(new MockInterceptor()); - inboundWire.addInvocationChain(operation, inboundChain); - - AtomicComponent source = createSource(); - OutboundWire outboundWire = new OutboundWireImpl(); - outboundWire.setContainer(source); - outboundWire.setServiceContract(contract); - outboundWire.setTargetName(new QualifiedName("target/service")); - OutboundInvocationChain outboundChain = new OutboundInvocationChainImpl(operation); - outboundWire.addInvocationChain(operation, outboundChain); - - InboundInvocationChain callbackInboundChain = new InboundInvocationChainImpl(callbackOperation); - callbackInboundChain.addInterceptor(new MockInterceptor()); - Map, InboundInvocationChain> chains = new HashMap, InboundInvocationChain>(); - chains.put(callbackOperation, callbackInboundChain); - outboundWire.addTargetCallbackInvocationChains(chains); - - connector.connect(outboundWire, inboundWire, true); - - // test the forward request - Message msg = new MessageImpl(); - msg.setBody("foo"); - Message ret = outboundChain.getHeadInterceptor().invoke(msg); - assertEquals("foo", ret.getBody()); - - // test the callback - msg = new MessageImpl(); - msg.setBody("callback"); - Map, OutboundInvocationChain> callbackChains = - inboundWire.getSourceCallbackInvocationChains("source"); - OutboundInvocationChain callbackInvocationChain = callbackChains.get(callbackOperation); - ret = callbackInvocationChain.getHeadInterceptor().invoke(msg); - assertEquals("callback", ret.getBody()); - - EasyMock.verify(source); - EasyMock.verify(target); - } - - public void testSyncForwardAndCallbackAtomicToReferenceBinding() throws Exception { - ReferenceBinding target = EasyMock.createMock(ReferenceBinding.class); - EasyMock.expect(target.isSystem()).andReturn(false).anyTimes(); - EasyMock.expect(target.createTargetInvoker(EasyMock.isA(ServiceContract.class), - EasyMock.isA(Operation.class))).andReturn(EasyMock.createNiceMock(TargetInvoker.class)); - EasyMock.replay(target); - - InboundWire inboundWire = new InboundWireImpl(); - inboundWire.setContainer(target); - inboundWire.setServiceContract(contract); - InboundInvocationChain inboundChain = new InboundInvocationChainImpl(operation); - inboundChain.addInterceptor(new MockInterceptor()); - inboundWire.addInvocationChain(operation, inboundChain); - - AtomicComponent source = createSource(); - OutboundWire outboundWire = new OutboundWireImpl(); - outboundWire.setContainer(source); - outboundWire.setServiceContract(contract); - outboundWire.setTargetName(new QualifiedName("target/service")); - OutboundInvocationChain outboundChain = new OutboundInvocationChainImpl(operation); - outboundWire.addInvocationChain(operation, outboundChain); - - InboundInvocationChain callbackInboundChain = new InboundInvocationChainImpl(callbackOperation); - callbackInboundChain.addInterceptor(new MockInterceptor()); - Map, InboundInvocationChain> chains = new HashMap, InboundInvocationChain>(); - chains.put(callbackOperation, callbackInboundChain); - outboundWire.addTargetCallbackInvocationChains(chains); - - connector.connect(outboundWire, inboundWire, true); - // test the forward request - Message msg = new MessageImpl(); - msg.setBody("foo"); - Message ret = outboundChain.getHeadInterceptor().invoke(msg); - assertEquals("foo", ret.getBody()); - - // test the callback - msg = new MessageImpl(); - msg.setBody("callback"); - Map, OutboundInvocationChain> callbackChains = - inboundWire.getSourceCallbackInvocationChains("source"); - OutboundInvocationChain callbackInvocationChain = callbackChains.get(callbackOperation); - ret = callbackInvocationChain.getHeadInterceptor().invoke(msg); - assertEquals("callback", ret.getBody()); - - EasyMock.verify(target); - EasyMock.verify(source); - } - - public void testSyncForwardAndCallbackReferenceBindingToServiceBinding() throws Exception { - ReferenceBinding source = EasyMock.createMock(ReferenceBinding.class); - EasyMock.expect(source.isSystem()).andReturn(false).anyTimes(); - EasyMock.expect(source.getName()).andReturn("source").atLeastOnce(); - EasyMock.expect(source.createTargetInvoker(EasyMock.isA(ServiceContract.class), - EasyMock.isA(Operation.class))).andReturn(EasyMock.createNiceMock(TargetInvoker.class)); - EasyMock.replay(source); - - ServiceBinding target = EasyMock.createMock(ServiceBinding.class); - EasyMock.expect(target.isSystem()).andReturn(false).anyTimes(); - EasyMock.expect(target.createTargetInvoker(EasyMock.isA(ServiceContract.class), - EasyMock.isA(Operation.class))).andReturn(EasyMock.createNiceMock(TargetInvoker.class)); - EasyMock.replay(target); - - InboundWire inboundWire = new InboundWireImpl(); - inboundWire.setContainer(target); - inboundWire.setServiceContract(contract); - InboundInvocationChain inboundChain = new InboundInvocationChainImpl(operation); - inboundChain.addInterceptor(new MockInterceptor()); - inboundWire.addInvocationChain(operation, inboundChain); - - OutboundWire outboundWire = new OutboundWireImpl(); - outboundWire.setContainer(source); - outboundWire.setServiceContract(contract); - outboundWire.setTargetName(new QualifiedName("target/service")); - OutboundInvocationChain outboundChain = new OutboundInvocationChainImpl(operation); - outboundWire.addInvocationChain(operation, outboundChain); - - InboundInvocationChain callbackInboundChain = new InboundInvocationChainImpl(callbackOperation); - callbackInboundChain.addInterceptor(new MockInterceptor()); - Map, InboundInvocationChain> chains = new HashMap, InboundInvocationChain>(); - chains.put(callbackOperation, callbackInboundChain); - outboundWire.addTargetCallbackInvocationChains(chains); - - connector.connect(outboundWire, inboundWire, true); - // test the forward request - Message msg = new MessageImpl(); - msg.setBody("foo"); - Message ret = outboundChain.getHeadInterceptor().invoke(msg); - assertEquals("foo", ret.getBody()); - - // test the callback - msg = new MessageImpl(); - msg.setBody("callback"); - Map, OutboundInvocationChain> callbackChains = - inboundWire.getSourceCallbackInvocationChains("source"); - OutboundInvocationChain callbackInvocationChain = callbackChains.get(callbackOperation); - ret = callbackInvocationChain.getHeadInterceptor().invoke(msg); - assertEquals("callback", ret.getBody()); - - EasyMock.verify(source); - EasyMock.verify(target); - } - - protected void setUp() throws Exception { - super.setUp(); - WireService wireService = new JDKWireService(null, null); - connector = new ConnectorImpl(wireService, null, null, null); - operation = new Operation("bar", null, null, null); - callbackOperation = new Operation("callback", null, null, null); - contract = new JavaServiceContract(); - Map> ops = new HashMap>(); - ops.put("callback", callbackOperation); - contract.setCallbackOperations(ops); - } - - private AtomicComponent createSource() throws Exception { - AtomicComponent component = EasyMock.createMock(AtomicComponent.class); - EasyMock.expect(component.getName()).andReturn("source").atLeastOnce(); - EasyMock.expect(component.isSystem()).andReturn(false).anyTimes(); - EasyMock.expect(component.createTargetInvoker(EasyMock.eq("callback"), - EasyMock.isA(Operation.class), - (InboundWire) EasyMock.isNull())).andReturn(EasyMock.createNiceMock(TargetInvoker.class)); - EasyMock.replay(component); - return component; - } - - private class MockInterceptor implements Interceptor { - - public Message invoke(Message msg) { - return msg; - } - - public void setNext(Interceptor next) { - - } - - public Interceptor getNext() { - return null; - } - - public boolean isOptimizable() { - return false; - } - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/TargetServiceNotFoundExceptionTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/TargetServiceNotFoundExceptionTestCase.java deleted file mode 100644 index b6ecd952e3..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/TargetServiceNotFoundExceptionTestCase.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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 junit.framework.TestCase; - -/** - * @version $Rev$ $Date$ - */ -public class TargetServiceNotFoundExceptionTestCase extends TestCase { - - public void testInstantiation() throws Exception { - TargetServiceNotFoundException e = new TargetServiceNotFoundException("message", - "source name", - "ref name", - "target name", - "service name"); - assertEquals("message", e.getMessage()); - assertEquals("source name", e.getSourceName()); - assertEquals("ref name", e.getReferenceName()); - assertEquals("target name", e.getTargetName()); - assertEquals("service name", e.getTargetServiceName()); - - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/WirePostProcessorRegistryImplTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/WirePostProcessorRegistryImplTestCase.java deleted file mode 100644 index 359733a4fc..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/WirePostProcessorRegistryImplTestCase.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.WirePostProcessor; -import org.apache.tuscany.spi.wire.WirePostProcessorRegistry; -import org.apache.tuscany.spi.wire.InboundWire; -import org.apache.tuscany.spi.wire.OutboundWire; - -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(); - OutboundWire owire = EasyMock.createMock(OutboundWire.class); - InboundWire iwire = EasyMock.createMock(InboundWire.class); - WirePostProcessor processor = createMock(WirePostProcessor.class); - processor.process(EasyMock.eq(owire), EasyMock.eq(iwire)); - EasyMock.replay(processor); - registry.register(processor); - registry.process(owire, iwire); - registry.unregister(processor); - registry.process(owire, iwire); - verify(processor); - } - - public void testProcessInboundToOutbound() throws Exception { - WirePostProcessorRegistry registry = new WirePostProcessorRegistryImpl(); - OutboundWire owire = EasyMock.createMock(OutboundWire.class); - InboundWire iwire = EasyMock.createMock(InboundWire.class); - WirePostProcessor processor = createMock(WirePostProcessor.class); - processor.process(EasyMock.eq(iwire), EasyMock.eq(owire)); - EasyMock.replay(processor); - registry.register(processor); - registry.process(iwire, owire); - verify(processor); - } - - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/WiringExceptionFormatterTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/WiringExceptionFormatterTestCase.java deleted file mode 100644 index 0269fd07e1..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/WiringExceptionFormatterTestCase.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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 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", - "source name", - "ref name", - "target name", - "service name"); - 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 name") >= 0); - assertTrue(buffer.indexOf("ref name") >= 0); - assertTrue(buffer.indexOf("target name") >= 0); - assertTrue(buffer.indexOf("service name") >= 0); - } - - - public void testFormatNulls() throws Exception { - WiringException e = new MockWiringException("message", - "identifier", - "source name", - null, - "target name", - 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); - assertTrue(buffer.indexOf("source name") >= 0); - assertTrue(buffer.indexOf("target name") >= 0); - } - - private class MockWiringException extends WiringException { - - public MockWiringException(String message, String - identifier, - String sourceName, - String referenceName, - String targetName, - String serviceName) { - super(message, identifier); - setSourceName(sourceName); - setReferenceName(referenceName); - setTargetName(targetName); - setTargetServiceName(serviceName); - } - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/WorkContextImplTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/WorkContextImplTestCase.java deleted file mode 100644 index aee910ddaf..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/WorkContextImplTestCase.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/event/EventTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/event/EventTestCase.java deleted file mode 100644 index 79b9757c2c..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/event/EventTestCase.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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 org.apache.tuscany.spi.component.CompositeComponent; - -import junit.framework.TestCase; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class EventTestCase extends TestCase { - - private CompositeComponent component; - - public void testCompositeStart() { - CompositeStart event = new CompositeStart(this, component); - assertEquals(component, event.getComposite()); - } - - public void testCompositeStop() { - CompositeStop event = new CompositeStop(this, component); - assertEquals(component, event.getComposite()); - } - - 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(); - component = EasyMock.createNiceMock(CompositeComponent.class); - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/AbstractScopeContainerTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/AbstractScopeContainerTestCase.java deleted file mode 100644 index f8f8dd5f60..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/AbstractScopeContainerTestCase.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/BasicCompositeScopeTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/BasicCompositeScopeTestCase.java deleted file mode 100644 index cd68b46541..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/BasicCompositeScopeTestCase.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.ScopeContainer; -import org.apache.tuscany.spi.component.TargetNotFoundException; - -import junit.framework.TestCase; -import org.apache.tuscany.core.component.event.CompositeStop; -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 initInvoker; - private EventInvoker 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 CompositeStop(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 CompositeStop(this, null)); - assertTrue(o1.isDestroyed()); - scopeContext.stop(); - } - - protected void setUp() throws Exception { - super.setUp(); - factory = new PojoObjectFactory( - CompositeScopeInitDestroyComponent.class.getConstructor((Class[]) null)); - initInvoker = new MethodEventInvoker(CompositeScopeInitDestroyComponent.class.getMethod( - "init", (Class[]) null)); - destroyInvoker = new MethodEventInvoker(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); - configuration.setName("foo"); - SystemAtomicComponentImpl component = new SystemAtomicComponentImpl(configuration); - component.setScopeContainer(scopeContainer); - component.start(); - return component; - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/BasicConversationalScopeTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/BasicConversationalScopeTestCase.java deleted file mode 100644 index c97f3cb96f..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/BasicConversationalScopeTestCase.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.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 initInvoker; - private EventInvoker 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.class.getConstructor((Class[]) null)); - initInvoker = new MethodEventInvoker( - ConversationalScopeInitDestroyComponent.class.getMethod("init", (Class[]) null)); - destroyInvoker = new MethodEventInvoker( - 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); - configuration.setName("foo"); - SystemAtomicComponentImpl component = new SystemAtomicComponentImpl(configuration); - component.setScopeContainer(scopeContainer); - component.start(); - return component; - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/BasicHttpSessionScopeTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/BasicHttpSessionScopeTestCase.java deleted file mode 100644 index 44e9bbc1d6..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/BasicHttpSessionScopeTestCase.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.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 initInvoker; - private EventInvoker 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.class.getConstructor((Class[]) null)); - initInvoker = new MethodEventInvoker( - SessionScopeInitDestroyComponent.class.getMethod("init", (Class[]) null)); - destroyInvoker = new MethodEventInvoker( - 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); - configuration.setName("foo"); - SystemAtomicComponentImpl component = new SystemAtomicComponentImpl(configuration); - component.setScopeContainer(scopeContainer); - component.start(); - return component; - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/BasicRequestScopeTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/BasicRequestScopeTestCase.java deleted file mode 100644 index 435e7d29b7..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/BasicRequestScopeTestCase.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.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 initInvoker; - private EventInvoker 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.class.getConstructor((Class[]) null)); - initInvoker = new MethodEventInvoker( - RequestScopeInitDestroyComponent.class.getMethod("init", (Class[]) null)); - destroyInvoker = new MethodEventInvoker( - 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); - configuration.setName("foo"); - SystemAtomicComponentImpl component = new SystemAtomicComponentImpl(configuration); - component.setScopeContainer(scopeContainer); - component.start(); - return component; - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/BasicStatelessScopeTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/BasicStatelessScopeTestCase.java deleted file mode 100644 index 9ca9230e5b..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/BasicStatelessScopeTestCase.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.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 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.class.getConstructor((Class[]) null)); - - } - - private AtomicComponent createComponent(ScopeContainer scopeContainer) { - PojoConfiguration configuration = new PojoConfiguration(); - configuration.setInstanceFactory(factory); - configuration.setName("foo"); - AtomicComponent component = new SystemAtomicComponentImpl(configuration); - component.setScopeContainer(scopeContainer); - return component; - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/CompositeScopeInitDestroyErrorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/CompositeScopeInitDestroyErrorTestCase.java deleted file mode 100644 index 8ac4ce46a4..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/CompositeScopeInitDestroyErrorTestCase.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.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.CompositeStart; -import org.apache.tuscany.core.component.event.CompositeStop; -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.getName()).andReturn("foo").atLeastOnce(); - EasyMock.expect(component.createInstance()).andThrow(new ObjectCreationException("")); - EasyMock.expect(component.getInitLevel()).andReturn(1); - EasyMock.replay(component); - scope.register(component); - scope.onEvent(new CompositeStart(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.getName()).andReturn("foo").atLeastOnce(); - 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 CompositeStart(this, null)); - scope.onEvent(new CompositeStop(this, null)); - EasyMock.verify(monitor); - } - - - protected void setUp() throws Exception { - super.setUp(); - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/CompositeScopeInstanceLifecycleTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/CompositeScopeInstanceLifecycleTestCase.java deleted file mode 100644 index 0d70bcf252..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/CompositeScopeInstanceLifecycleTestCase.java +++ /dev/null @@ -1,186 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.CompositeStart; -import org.apache.tuscany.core.component.event.CompositeStop; -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 CompositeStart(this, null)); - assertNotNull(scope.getInstance(component)); - // expire composite - scope.onEvent(new CompositeStop(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 CompositeStart(this, null)); - // expire composite - scope.onEvent(new CompositeStop(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 CompositeStart(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 CompositeStop(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 CompositeStart(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 CompositeStop(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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/CompositeScopeObjectFactoryTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/CompositeScopeObjectFactoryTestCase.java deleted file mode 100644 index 611fbfc13f..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/CompositeScopeObjectFactoryTestCase.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/CompositeScopeRestartTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/CompositeScopeRestartTestCase.java deleted file mode 100644 index 1fdaeed48c..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/CompositeScopeRestartTestCase.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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 org.apache.tuscany.spi.component.AtomicComponent; - -import junit.framework.TestCase; -import org.apache.tuscany.core.component.event.CompositeStart; -import org.apache.tuscany.core.component.event.CompositeStop; -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 initInvoker = - new MethodEventInvoker(InitDestroyOnce.class.getMethod("init")); - MethodEventInvoker destroyInvoker = - new MethodEventInvoker(InitDestroyOnce.class.getMethod("destroy")); - PojoConfiguration configuration = new PojoConfiguration(); - configuration.setInitInvoker(initInvoker); - configuration.setDestroyInvoker(destroyInvoker); - Constructor ctr = InitDestroyOnce.class.getConstructor((Class[]) null); - configuration.setInstanceFactory(new PojoObjectFactory(ctr)); - configuration.setName("InitDestroy"); - AtomicComponent component = new SystemAtomicComponentImpl(configuration); - component.setScopeContainer(scope); - component.start(); - - scope.onEvent(new CompositeStart(this, null)); - Object instance = component.getTargetInstance(); - assertSame(instance, component.getTargetInstance()); - - scope.onEvent(new CompositeStop(this, null)); - scope.stop(); - component.stop(); - - scope.start(); - scope.onEvent(new CompositeStart(this, null)); - component.start(); - assertNotSame(instance, component.getTargetInstance()); - scope.onEvent(new CompositeStop(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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeContainerDestroyOnExpirationTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeContainerDestroyOnExpirationTestCase.java deleted file mode 100644 index a1a3616d0a..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeContainerDestroyOnExpirationTestCase.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeContainerMaxAgeTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeContainerMaxAgeTestCase.java deleted file mode 100644 index 79ea057652..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeContainerMaxAgeTestCase.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.getName()).andReturn("foo").atLeastOnce(); - 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeContainerMaxIdleTimeTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeContainerMaxIdleTimeTestCase.java deleted file mode 100644 index 2ba152d223..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeContainerMaxIdleTimeTestCase.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.getName()).andReturn("foo").atLeastOnce(); - 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeContainerPersistenceTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeContainerPersistenceTestCase.java deleted file mode 100644 index ae7e91a59a..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeContainerPersistenceTestCase.java +++ /dev/null @@ -1,181 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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 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.getName()).andReturn("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.getName()).andReturn("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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeInstanceLifecycleTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeInstanceLifecycleTestCase.java deleted file mode 100644 index 782b175b47..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeInstanceLifecycleTestCase.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeRestartTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeRestartTestCase.java deleted file mode 100644 index bc5ddc7c2c..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeRestartTestCase.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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 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 initInvoker = new MethodEventInvoker( - ConversationalScopeRestartTestCase.InitDestroyOnce.class.getMethod("init")); - MethodEventInvoker destroyInvoker = - new MethodEventInvoker(InitDestroyOnce.class.getMethod("destroy")); - PojoConfiguration configuration = new PojoConfiguration(); - configuration.setInitInvoker(initInvoker); - configuration.setDestroyInvoker(destroyInvoker); - Constructor ctr = InitDestroyOnce.class.getConstructor((Class[]) null); - configuration.setInstanceFactory(new PojoObjectFactory(ctr)); - configuration.setName("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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/DependencyLifecycleTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/DependencyLifecycleTestCase.java deleted file mode 100644 index 4a2497a725..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/DependencyLifecycleTestCase.java +++ /dev/null @@ -1,170 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.CompositeStart; -import org.apache.tuscany.core.component.event.CompositeStop; -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 contexts = MockFactory.createWiredComponents("source", - OrderedDependentPojoImpl.class, - scopeCtx, - "target", - OrderedInitPojoImpl.class, - scopeCtx); - for (AtomicComponent component : contexts.values()) { - scopeCtx.register(component); - } - AtomicComponent sourceComponent = contexts.get("source"); - AtomicComponent targetComponent = contexts.get("target"); - scopeCtx.register(sourceComponent); - scopeCtx.register(targetComponent); - scopeCtx.onEvent(new CompositeStart(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 CompositeStop(this, null)); - assertEquals(0, source.getNumberInstantiated()); - scopeCtx.stop(); - } - - public void testInitDestroyOrderAfterStartCompositeScope() throws Exception { - CompositeScopeContainer scopeCtx = new CompositeScopeContainer(null); - scopeCtx.start(); - Map contexts = MockFactory.createWiredComponents("source", - OrderedDependentPojoImpl.class, - scopeCtx, - "target", - OrderedInitPojoImpl.class, - scopeCtx); - AtomicComponent sourceComponent = contexts.get("source"); - AtomicComponent targetComponent = contexts.get("target"); - scopeCtx.onEvent(new CompositeStart(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 CompositeStop(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 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 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 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/HttpSessionScopeInitDestroyErrorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/HttpSessionScopeInitDestroyErrorTestCase.java deleted file mode 100644 index 7aa2f9a120..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/HttpSessionScopeInitDestroyErrorTestCase.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.getName()).andReturn("foo").atLeastOnce(); - 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/HttpSessionScopeInstanceLifecycleTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/HttpSessionScopeInstanceLifecycleTestCase.java deleted file mode 100644 index 29d6d54450..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/HttpSessionScopeInstanceLifecycleTestCase.java +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/HttpSessionScopeRestartTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/HttpSessionScopeRestartTestCase.java deleted file mode 100644 index eff0eb6d3a..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/HttpSessionScopeRestartTestCase.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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 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 initInvoker = new MethodEventInvoker( - HttpSessionScopeRestartTestCase.InitDestroyOnce.class.getMethod("init")); - MethodEventInvoker destroyInvoker = - new MethodEventInvoker(InitDestroyOnce.class.getMethod("destroy")); - PojoConfiguration configuration = new PojoConfiguration(); - configuration.setInitInvoker(initInvoker); - configuration.setDestroyInvoker(destroyInvoker); - Constructor ctr = InitDestroyOnce.class.getConstructor((Class[]) null); - configuration.setInstanceFactory(new PojoObjectFactory(ctr)); - configuration.setName("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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/InstanceWrapperTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/InstanceWrapperTestCase.java deleted file mode 100644 index 5600987d8b..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/InstanceWrapperTestCase.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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 (IllegalStateException 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/MockFactory.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/MockFactory.java deleted file mode 100644 index db947e0d66..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/MockFactory.java +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.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.QualifiedName; -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.InboundWire; -import org.apache.tuscany.spi.wire.OutboundWire; - -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.InboundWireImpl; -import org.apache.tuscany.core.wire.OutboundWireImpl; - -/** - * @version $$Rev$$ $$Date$$ - */ -public final class MockFactory { - - private MockFactory() { - } - - @SuppressWarnings("unchecked") - public static Map createWiredComponents(String source, - Class sourceClass, - ScopeContainer sourceScopeContainer, - String target, - Class targetClass, - ScopeContainer targetScopeContainer) - throws NoSuchMethodException { - - Map components = new HashMap(); - AtomicComponent targetComponent = createAtomicComponent(target, targetScopeContainer, targetClass); - PojoConfiguration sourceConfig = new PojoConfiguration(); - sourceConfig.setInstanceFactory(new PojoObjectFactory(sourceClass.getConstructor())); - - //create target wire - 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(method)); - - } else if (method.getAnnotation(Destroy.class) != null) { - sourceConfig.setDestroyInvoker(new MethodEventInvoker(method)); - } - } - - } - if (setter == null) { - throw new IllegalArgumentException("No setter found on source for target"); - } - - sourceConfig.addReferenceSite(setter.getName(), setter); - sourceConfig.setName(source); - AtomicComponent sourceComponent = new SystemAtomicComponentImpl(sourceConfig); - sourceComponent.setScopeContainer(sourceScopeContainer); - QualifiedName targetName = new QualifiedName(target); - OutboundWire wire = new OutboundWireImpl(); - wire.setReferenceName(setter.getName()); - wire.setServiceContract(new JavaServiceContract(targetClass)); - InboundWire inboundWire = new InboundWireImpl(); - inboundWire.setContainer(targetComponent); - inboundWire.setServiceContract(new JavaServiceContract(targetClass)); - inboundWire.setServiceName(targetName.getPortName()); - wire.setTargetWire(inboundWire); - sourceComponent.addOutboundWire(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 { - 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(method)); - } else if (method.getAnnotation(Destroy.class) != null) { - configuration.setDestroyInvoker(new MethodEventInvoker(method)); - } - } - configuration.setName(name); - AtomicComponent component = new SystemAtomicComponentImpl(configuration); - component.setScopeContainer(container); - return component; - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/RequestScopeInitDestroyErrorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/RequestScopeInitDestroyErrorTestCase.java deleted file mode 100644 index 3f562c9b61..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/RequestScopeInitDestroyErrorTestCase.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.getName()).andReturn("foo").atLeastOnce(); - 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/RequestScopeInstanceLifecycleTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/RequestScopeInstanceLifecycleTestCase.java deleted file mode 100644 index 6601640c3b..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/RequestScopeInstanceLifecycleTestCase.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/RequestScopeRestartTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/RequestScopeRestartTestCase.java deleted file mode 100644 index 335d8c621d..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/RequestScopeRestartTestCase.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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 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 initInvoker = - new MethodEventInvoker(InitDestroyOnce.class.getMethod("init")); - MethodEventInvoker destroyInvoker = - new MethodEventInvoker(InitDestroyOnce.class.getMethod("destroy")); - PojoConfiguration configuration = new PojoConfiguration(); - configuration.setInitInvoker(initInvoker); - configuration.setDestroyInvoker(destroyInvoker); - Constructor ctr = InitDestroyOnce.class.getConstructor((Class[]) null); - configuration.setInstanceFactory(new PojoObjectFactory(ctr)); - configuration.setName("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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/ScopeRegistryTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/ScopeRegistryTestCase.java deleted file mode 100644 index e1380eb4c0..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/ScopeRegistryTestCase.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/StatelessScopeContainerTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/StatelessScopeContainerTestCase.java deleted file mode 100644 index 89cd9b51d7..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/StatelessScopeContainerTestCase.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/StatelessScopeObjectFactoryTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/StatelessScopeObjectFactoryTestCase.java deleted file mode 100644 index 0902b9d78c..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/StatelessScopeObjectFactoryTestCase.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/WorkContextTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/WorkContextTestCase.java deleted file mode 100644 index 8a9fdf4ac4..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/WorkContextTestCase.java +++ /dev/null @@ -1,212 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.CompositeComponent; -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(); - CompositeComponent component = EasyMock.createNiceMock(CompositeComponent.class); - CompositeComponent component2 = EasyMock.createNiceMock(CompositeComponent.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.setCurrentCorrelationId("msg-005"); - assertEquals(context.getCurrentCorrelationId(), "msg-005"); - context.setCurrentCorrelationId(null); - assertNull(context.getCurrentCorrelationId()); - } - - public void testSetGetCorrelationIdInNewThread() throws InterruptedException { - WorkContext context = new WorkContextImpl(); - context.setCurrentCorrelationId("msg-005"); - assertEquals(context.getCurrentCorrelationId(), "msg-005"); - context.setIdentifier("TX", "002"); - ChildThread t = new ChildThread(context); - t.start(); - t.join(); - assertTrue(t.passed); - context.setCurrentCorrelationId(null); - assertNull(context.getCurrentCorrelationId()); - } - - 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(CompositeComponent.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.getCurrentCorrelationId()); - 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingInterceptorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingInterceptorTestCase.java deleted file mode 100644 index ddfb75568d..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingInterceptorTestCase.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.component.CompositeComponent; -import org.apache.tuscany.spi.databinding.DataBinding; -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.InboundWire; -import org.apache.tuscany.spi.wire.Interceptor; -import org.apache.tuscany.spi.wire.Message; -import org.apache.tuscany.spi.wire.OutboundWire; - -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 type1 = new DataType("xml:string", String.class, String.class); - List> types1 = new ArrayList>(); - types1.add(type1); - DataType>> inputType1 = - new DataType>>("xml:string", Object[].class, types1); - - DataType type2 = new DataType("foo", Foo.class, Foo.class); - List> types2 = new ArrayList>(); - types2.add(type2); - DataType>> inputType2 = - new DataType>>("foo", Object[].class, types2); - - Operation operation1 = - new Operation("call", inputType1, type1, null, false, "xml:string", NO_CONVERSATION); - Operation operation2 = - new Operation("call", inputType2, type2, null, false, "org.w3c.dom.Node", NO_CONVERSATION); - - DataType outputType1 = - new DataType(DataBinding.IDL_OUTPUT, Object.class, operation1.getOutputType()); - DataType outputType2 = - new DataType(DataBinding.IDL_OUTPUT, Object.class, operation2.getOutputType()); - - OutboundWire outboundWire = EasyMock.createMock(OutboundWire.class); - InboundWire inboundWire = EasyMock.createMock(InboundWire.class); - CompositeComponent composite = EasyMock.createMock(CompositeComponent.class); - Component component = EasyMock.createMock(Component.class); - EasyMock.expect(component.getParent()).andReturn(composite).once(); - EasyMock.expect(outboundWire.getContainer()).andReturn(component); - EasyMock.replay(outboundWire, inboundWire, composite, component); - - DataBindingInteceptor interceptor = new DataBindingInteceptor(outboundWire, operation1, operation2); - Mediator mediator = createMock(Mediator.class); - Object[] source = new Object[]{"bar"}; - 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingJavaInterfaceProcessorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingJavaInterfaceProcessorTestCase.java deleted file mode 100644 index 9e181960b4..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingJavaInterfaceProcessorTestCase.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.DataType; -import org.apache.tuscany.spi.databinding.DataBindingRegistry; -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 { - DataBindingRegistry registry = new DataBindingRegistryImpl(); - DataBindingJavaInterfaceProcessor processor = new DataBindingJavaInterfaceProcessor(registry); - JavaServiceContract contract = new JavaServiceContract(MockInterface.class); - Map> operations = new HashMap>(); - Operation operation = new Operation("call", null, null, null, false, null, NO_CONVERSATION); - Operation operation1 = new Operation("call1", null, null, null, false, null, NO_CONVERSATION); - operations.put("call", operation); - operations.put("call1", operation1); - contract.setOperations(operations); - contract.setRemotable(true); - processor.visitInterface(MockInterface.class, null, contract); - Assert.assertEquals("org.w3c.dom.Node", contract.getDataBinding()); - 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") - @Remotable - public static interface MockInterface { - Node call(Node msg); - - @DataType(name = "xml:string") - String call1(String msg); - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingLoaderTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingLoaderTestCase.java deleted file mode 100644 index 02dd10ee97..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingLoaderTestCase.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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, 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, null, reader, null); - Assert.fail("InvalidValueException should have been thrown"); - } catch (InvalidValueException e) { - Assert.assertTrue(true); - } - EasyMock.verify(reader); - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingRegistryImplTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingRegistryImplTestCase.java deleted file mode 100644 index 3ee5460ac3..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingRegistryImplTestCase.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.lang.annotation.Annotation; - -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.getAliases()).andReturn(new String[] {"db1"}).anyTimes(); - expect(db1.getName()).andReturn(ContentHandler.class.getName()).anyTimes(); - DataType dataType1 = new DataType(ContentHandler.class, ContentHandler.class); - expect(db1.introspect(dataType1, null)).andReturn(true); - expect(db1.introspect(EasyMock.not(EasyMock.same(dataType1)), (Annotation[])EasyMock.isNull())) - .andReturn(false).anyTimes(); - replay(db1); - - registry.register(db1); - - DataBinding db2 = createMock(DataBinding.class); - expect(db2.getAliases()).andReturn(new String[] {"db2"}).anyTimes(); - expect(db2.getName()).andReturn(XMLStreamReader.class.getName()).anyTimes(); - DataType dataType2 = new DataType(XMLStreamReader.class, XMLStreamReader.class); - expect(db2.introspect(dataType2, null)).andReturn(true); - expect(db2.introspect(EasyMock.not(EasyMock.same(dataType2)), (Annotation[])EasyMock.isNull())) - .andReturn(false).anyTimes(); - replay(db2); - - registry.register(db2); - - // Lookup by name - String name = db1.getName(); - DataBinding db3 = registry.getDataBinding(name); - assertSame(db1, db3); - - // Look up by alias - DataBinding db5 = registry.getDataBinding("db1"); - assertSame(db1, db5); - - DataType dt = new DataType(ContentHandler.class, null); - registry.introspectType(dt, null); - assertEquals(dataType1.getLogical(), ContentHandler.class); - assertTrue(dt.getDataBinding().equalsIgnoreCase("java.lang.Object")); - - registry.unregister(name); - DataBinding db4 = registry.getDataBinding(name); - assertNull(db4); - - dt = new DataType(null, String.class, null); - registry.introspectType(dt, null); - assertEquals("java.lang.Object", dt.getDataBinding()); - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingTestCase.java deleted file mode 100644 index 5abb520b80..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingTestCase.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.DataType; - -public class DataBindingTestCase extends TestCase { - @SuppressWarnings("unused") - public void testDataType() throws Exception { - Class testClass = Test.class; - DataType d = testClass.getAnnotation(DataType.class); - Assert.assertEquals(d.name(), "sdo"); - - Method method = testClass.getMethod("test", new Class[] {Object.class}); - DataType d2 = method.getAnnotation(DataType.class); - Assert.assertEquals(d2.name(), "jaxb"); - } - - @DataType(name = "sdo") - private static interface Test { - @DataType(name = "jaxb") - Object test(Object object); - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingWirePostProcessorOptimizationTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingWirePostProcessorOptimizationTestCase.java deleted file mode 100644 index d871978cb4..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingWirePostProcessorOptimizationTestCase.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.HashMap; -import java.util.Map; - -import org.apache.tuscany.spi.component.SCAObject; -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.InboundInvocationChain; -import org.apache.tuscany.spi.wire.InboundWire; -import org.apache.tuscany.spi.wire.OutboundInvocationChain; -import org.apache.tuscany.spi.wire.OutboundWire; - -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 OutboundInvocationChain outboundChain; - private OutboundWire outboundWire; - private InboundInvocationChain inboundChain; - private InboundWire inboundWire; - - public void testNoInterceptorInterposedOutboundToInbound() { - processor.process(outboundWire, inboundWire); - EasyMock.verify(outboundChain); - EasyMock.verify(inboundChain); - EasyMock.verify(outboundWire); - EasyMock.verify(inboundWire); - } - - public void testNoInterceptorInterposedInboundToOutbound() { - processor.process(inboundWire, outboundWire); - EasyMock.verify(outboundChain); - EasyMock.verify(inboundChain); - EasyMock.verify(outboundWire); - EasyMock.verify(inboundWire); - } - - - protected void setUp() throws Exception { - super.setUp(); - SCAObject container = EasyMock.createMock(SCAObject.class); - EasyMock.expect(container.getName()).andReturn("foo"); - EasyMock.replay(container); - - Mediator mediator = new MediatorImpl(); - processor = new DataBindingWirePostProcessor(mediator); - - ServiceContract contract = new JavaServiceContract(null); - Operation operation = new Operation("test", null, null, null); - operation.setServiceContract(contract); - Map> operations = new HashMap>(); - operations.put("test", operation); - contract.setOperations(operations); - contract.setCallbackOperations(operations); - - inboundChain = EasyMock.createMock(InboundInvocationChain.class); - EasyMock.replay(inboundChain); - Map, InboundInvocationChain> inboundChains = new HashMap, InboundInvocationChain>(); - inboundChains.put(operation, inboundChain); - - outboundChain = EasyMock.createMock(OutboundInvocationChain.class); - EasyMock.replay(outboundChain); - Map, OutboundInvocationChain> outboundChains = - new HashMap, OutboundInvocationChain>(); - outboundChains.put(operation, outboundChain); - - outboundWire = EasyMock.createMock(OutboundWire.class); - EasyMock.expect(outboundWire.getInvocationChains()).andReturn(outboundChains); - EasyMock.expect(outboundWire.getServiceContract()).andReturn(contract).anyTimes(); - EasyMock.expect(outboundWire.getContainer()).andReturn(container).anyTimes(); - EasyMock.expect(outboundWire.getTargetCallbackInvocationChains()).andReturn(inboundChains).anyTimes(); - EasyMock.replay(outboundWire); - - inboundWire = EasyMock.createMock(InboundWire.class); - EasyMock.expect(inboundWire.getInvocationChains()).andReturn(inboundChains); - EasyMock.expect(inboundWire.getContainer()).andReturn(container).anyTimes(); - EasyMock.expect(inboundWire.getSourceCallbackInvocationChains(EasyMock.eq("foo"))).andReturn(outboundChains) - .anyTimes(); - EasyMock.replay(inboundWire); - - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingWirePostProcessorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingWirePostProcessorTestCase.java deleted file mode 100644 index 29bf91f2c7..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingWirePostProcessorTestCase.java +++ /dev/null @@ -1,231 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.w3c.dom.Node; - -import org.apache.tuscany.spi.component.Component; -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.component.ReferenceBinding; -import org.apache.tuscany.spi.component.ServiceBinding; -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.InboundInvocationChain; -import org.apache.tuscany.spi.wire.InboundWire; -import org.apache.tuscany.spi.wire.Interceptor; -import org.apache.tuscany.spi.wire.OutboundInvocationChain; -import org.apache.tuscany.spi.wire.OutboundWire; - -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; - - /** - * @see junit.framework.TestCase#setUp() - */ - protected void setUp() throws Exception { - super.setUp(); - Mediator mediator = new MediatorImpl(); - this.processor = new DataBindingWirePostProcessor(mediator); - } - - public void testProcess1() { - InboundWire inboundWire = createMock(InboundWire.class); - OutboundWire outboundWire = createMock(OutboundWire.class); - - Component component = createMock(Component.class); - CompositeComponent composite = createMock(CompositeComponent.class); - expect(component.getParent()).andReturn(composite); - expect(inboundWire.getContainer()).andReturn(component); - expect(outboundWire.getContainer()).andReturn(component); - - Map, OutboundInvocationChain> outboundChains = - new HashMap, OutboundInvocationChain>(); - DataType type1 = new DataType(String.class, String.class); - List> types = new ArrayList>(); - types.add(type1); - DataType>> inputType1 = new DataType>>(Object[].class, types); - DataType outputType1 = new DataType(String.class, String.class); - Operation op1 = new Operation("test", inputType1, outputType1, null); - ServiceContract outboundContract = new JavaServiceContract(null); - outboundContract.setDataBinding(String.class.getName()); - op1.setServiceContract(outboundContract); - - OutboundInvocationChain outboundChain = createMock(OutboundInvocationChain.class); - outboundChains.put(op1, outboundChain); - expect(outboundWire.getInvocationChains()).andReturn(outboundChains); - outboundChain.addInterceptor(EasyMock.anyInt(), (Interceptor) EasyMock.anyObject()); - - Map, InboundInvocationChain> inboundChains = - new HashMap, InboundInvocationChain>(); - DataType type2 = new DataType(Node.class, Node.class); - List> types2 = new ArrayList>(); - types2.add(type2); - DataType>> inputType2 = - new DataType>>(Object[].class, types2); - DataType outputType2 = new DataType(String.class, String.class); - Operation op2 = new Operation("test", inputType2, outputType2, null); - ServiceContract inboundContract = new JavaServiceContract(null); - inboundContract.setDataBinding(Node.class.getName()); - op2.setServiceContract(inboundContract); - - InboundInvocationChain inboundChain = createMock(InboundInvocationChain.class); - inboundChains.put(op2, inboundChain); - expect(inboundWire.getInvocationChains()).andReturn(inboundChains); - - ServiceContract contract = new JavaServiceContract(); - Map> operations = Collections.emptyMap(); - contract.setCallbackOperations(operations); - expect(outboundWire.getServiceContract()).andReturn(contract); - - EasyMock.replay(composite, component, inboundWire, outboundWire, inboundChain, outboundChain); - - processor.process(outboundWire, inboundWire); - } - - public void testProcess2() { - InboundWire inboundWire = createMock(InboundWire.class); - OutboundWire outboundWire = createMock(OutboundWire.class); - - ReferenceBinding referenceBinding = createMock(ReferenceBinding.class); - CompositeComponent composite = createMock(CompositeComponent.class); - expect(referenceBinding.getParent()).andReturn(composite); - expect(inboundWire.getContainer()).andReturn(referenceBinding).anyTimes(); - expect(outboundWire.getContainer()).andReturn(referenceBinding).anyTimes(); - - Map, OutboundInvocationChain> outboundChains = - new HashMap, OutboundInvocationChain>(); - DataType type1 = new DataType(String.class, String.class); - List> types = new ArrayList>(); - types.add(type1); - DataType>> inputType1 = new DataType>>(Object[].class, types); - DataType outputType1 = new DataType(String.class, String.class); - Operation op1 = new Operation("test", inputType1, outputType1, null); - ServiceContract outboundContract = new JavaServiceContract(null); - outboundContract.setDataBinding(String.class.getName()); - op1.setServiceContract(outboundContract); - - OutboundInvocationChain outboundChain = createMock(OutboundInvocationChain.class); - outboundChains.put(op1, outboundChain); - expect(outboundWire.getInvocationChains()).andReturn(outboundChains).anyTimes(); - outboundChain.addInterceptor(EasyMock.anyInt(), (Interceptor) EasyMock.anyObject()); - - Map, InboundInvocationChain> inboundChains = - new HashMap, InboundInvocationChain>(); - DataType type2 = new DataType(Node.class, Node.class); - List> types2 = new ArrayList>(); - types2.add(type2); - DataType>> inputType2 = - new DataType>>(Object[].class, types2); - DataType outputType2 = new DataType(String.class, String.class); - Operation op2 = new Operation("test", inputType2, outputType2, null); - ServiceContract inboundContract = new JavaServiceContract(null); - inboundContract.setDataBinding(Node.class.getName()); - op2.setServiceContract(inboundContract); - - InboundInvocationChain inboundChain = createMock(InboundInvocationChain.class); - inboundChains.put(op2, inboundChain); - expect(inboundWire.getInvocationChains()).andReturn(inboundChains).anyTimes(); - - ServiceContract contract = new JavaServiceContract(); - Map> operations = Collections.emptyMap(); - contract.setCallbackOperations(operations); - expect(inboundWire.getServiceContract()).andReturn(contract); - expect(inboundChain.getTailInterceptor()).andReturn(null); - - EasyMock.replay(composite, referenceBinding, inboundWire, outboundWire, inboundChain, outboundChain); - - processor.process(inboundWire, outboundWire); - } - - public void testProcess3() { - InboundWire inboundWire = createMock(InboundWire.class); - OutboundWire outboundWire = createMock(OutboundWire.class); - - ServiceBinding serviceBinding = createMock(ServiceBinding.class); - CompositeComponent composite = createMock(CompositeComponent.class); - expect(serviceBinding.getParent()).andReturn(composite); - expect(inboundWire.getContainer()).andReturn(serviceBinding).anyTimes(); - expect(outboundWire.getContainer()).andReturn(serviceBinding).anyTimes(); - - Map, OutboundInvocationChain> outboundChains = - new HashMap, OutboundInvocationChain>(); - DataType type1 = new DataType(String.class, String.class); - List> types = new ArrayList>(); - types.add(type1); - DataType>> inputType1 = new DataType>>(Object[].class, types); - DataType outputType1 = new DataType(String.class, String.class); - Operation op1 = new Operation("test", inputType1, outputType1, null); - ServiceContract outboundContract = new JavaServiceContract(null); - outboundContract.setDataBinding(String.class.getName()); - op1.setServiceContract(outboundContract); - - OutboundInvocationChain outboundChain = createMock(OutboundInvocationChain.class); - outboundChains.put(op1, outboundChain); - expect(outboundWire.getInvocationChains()).andReturn(outboundChains).anyTimes(); - // outboundChain.addInterceptor(EasyMock.anyInt(), (Interceptor) - // EasyMock.anyObject()); - - Map, InboundInvocationChain> inboundChains = - new HashMap, InboundInvocationChain>(); - DataType type2 = new DataType(Node.class, Node.class); - List> types2 = new ArrayList>(); - types2.add(type2); - DataType>> inputType2 = - new DataType>>(Object[].class, types2); - DataType outputType2 = new DataType(String.class, String.class); - Operation op2 = new Operation("test", inputType2, outputType2, null); - ServiceContract inboundContract = new JavaServiceContract(null); - inboundContract.setDataBinding(Node.class.getName()); - op2.setServiceContract(inboundContract); - - InboundInvocationChain inboundChain = createMock(InboundInvocationChain.class); - inboundChains.put(op2, inboundChain); - expect(inboundWire.getInvocationChains()).andReturn(inboundChains).anyTimes(); - inboundChain.addInterceptor(EasyMock.anyInt(), (Interceptor) EasyMock.anyObject()); - - ServiceContract contract = new JavaServiceContract(); - Map> operations = Collections.emptyMap(); - contract.setCallbackOperations(operations); - expect(inboundWire.getServiceContract()).andReturn(contract); - - EasyMock.replay(composite, serviceBinding, inboundWire, outboundWire, inboundChain, outboundChain); - - processor.process(inboundWire, outboundWire); - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DirectedGraphTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DirectedGraphTestCase.java deleted file mode 100755 index 70244df8e2..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DirectedGraphTestCase.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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 graph; - - protected void setUp() throws Exception { - super.setUp(); - graph = new DirectedGraph(); - 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.Path path = graph.getShortestPath("a", "c"); - - List.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.Path path2 = graph.getShortestPath("b", "e"); - Assert.assertNull(path2); - - DirectedGraph.Path path3 = graph.getShortestPath("a", "a"); - Assert.assertTrue(path3.getWeight() == 0 && path3.getEdges().isEmpty()); - - DirectedGraph.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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/IDLTransformerTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/IDLTransformerTestCase.java deleted file mode 100644 index 7981080f82..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/IDLTransformerTestCase.java +++ /dev/null @@ -1,217 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.databinding.DataBinding.IDL_INPUT; -import static org.apache.tuscany.spi.databinding.DataBinding.IDL_OUTPUT; - -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.idl.ElementInfo; -import org.apache.tuscany.spi.idl.TypeInfo; -import org.apache.tuscany.spi.idl.XMLType; -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 = - "" + "" - + " " - + " Helen Zoe" - + " 47 Eden Street" - + " Cambridge" - + " CB1 1JR" - + " " - + " " - + " Robert Smith" - + " 8 Oak Avenue" - + " Old Town" - + " PA" - + " 95819" - + " " - + " " - + " " - + " Lapis necklace" - + " 1" - + " 99.95" - + " Want this for the holidays" - + " 1999-12-05" - + " " - + " " - + ""; - - 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> types0 = new ArrayList>(); - DataType wrapperType = - new DataType(null, Object.class, new XMLType(new QName(URI_ORDER_XSD, "checkOrderStatus"), null)); - types0.add(wrapperType); - DataType>> inputType0 = - new DataType>>(IDL_INPUT, Object[].class, types0); - - List> types1 = new ArrayList>(); - DataType customerIdType = - new DataType(null, Object.class, new XMLType(new QName(URI_ORDER_XSD, "customerId"), null)); - DataType orderType = - new DataType(null, Object.class, new XMLType(new QName(URI_ORDER_XSD, "order"), null)); - DataType flagType = - new DataType(null, Object.class, new XMLType(new QName(URI_ORDER_XSD, "flag"), null)); - types1.add(customerIdType); - types1.add(orderType); - types1.add(flagType); - - DataType statusType = - new DataType(null, Object.class, new XMLType(new QName(URI_ORDER_XSD, "status"), null)); - DataType responseType = - new DataType(null, Object.class, new XMLType(new QName(URI_ORDER_XSD, "checkOrderStatusResponse"), - null)); - - org.apache.tuscany.spi.model.Operation op = - new org.apache.tuscany.spi.model.Operation("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 inputElements = new ArrayList(); - 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 outputElements = new ArrayList(); - 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(DOMDataBinding.NAME, inputElement, outputElement, inputElements, outputElements); - 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.setMediator(m); - - TransformationContext context = new TransformationContextImpl(); - List> types = new ArrayList>(); - types.add(new DataType(Object.class.getName(), String.class, String.class)); - types.add(new DataType("java.lang.String", String.class, String.class)); - types.add(new DataType(Object.class.getName(), int.class, int.class)); - DataType>> inputType1 = - new DataType>>(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 sourceType = new DataType(IDL_OUTPUT, Object.class, op.getOutputType()); - sourceType.setOperation(op.getOutputType().getOperation()); - - context1.setSourceDataType(sourceType); - DataType targetType = - new DataType(IDL_OUTPUT, Object.class, new DataType("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); - Object st = t2.transform(responseElement, context1); - assertEquals("shipped", st); - - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/MediatorImplTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/MediatorImplTestCase.java deleted file mode 100644 index 3cb7f243a9..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/MediatorImplTestCase.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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 = - "" + "" - + " " - + " Helen Zoe" - + " 47 Eden Street" - + " Cambridge" - + " CB1 1JR" - + " " - + " " - + " Robert Smith" - + " 8 Oak Avenue" - + " Old Town" - + "PA" - + " 95819" - + " " - + " " - + " " - + " Lapis necklace" - + " 1" - + "99.95" - + " Want this for the holidays" - + " 1999-12-05" - + " " - + " " - + ""; - - 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(sourceType, sourceType); - DataType targetDataType = new DataType(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("1999-12-05") != -1); - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/PassByValueInterceptorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/PassByValueInterceptorTestCase.java deleted file mode 100644 index 3e839bdae1..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/PassByValueInterceptorTestCase.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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 org.apache.tuscany.core.databinding.javabeans.JavaBeansDataBinding; -import org.apache.tuscany.spi.databinding.DataBinding; - -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() { - PassByValueInterceptor interceptor = new PassByValueInterceptor(null); - DataBinding db = new JavaBeansDataBinding(); - interceptor.setParameterDatabindings(new DataBinding[] {db, db, db, db, db}); - Object[] copy = interceptor.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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/PassByValueWirePostProcessorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/PassByValueWirePostProcessorTestCase.java deleted file mode 100644 index 1839aa4044..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/PassByValueWirePostProcessorTestCase.java +++ /dev/null @@ -1,266 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.Hashtable; -import java.util.Map; - -import org.apache.tuscany.spi.ObjectCreationException; -import org.apache.tuscany.spi.component.ServiceBinding; -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.idl.java.JavaServiceContract; -import org.apache.tuscany.spi.model.Operation; -import org.apache.tuscany.spi.model.ServiceContract; -import org.apache.tuscany.spi.wire.InboundInvocationChain; -import org.apache.tuscany.spi.wire.InboundWire; -import org.apache.tuscany.spi.wire.Interceptor; -import org.apache.tuscany.spi.wire.OutboundInvocationChain; -import org.apache.tuscany.spi.wire.OutboundWire; -import org.apache.tuscany.spi.wire.TargetInvoker; - -import junit.framework.TestCase; -import org.apache.tuscany.core.wire.InboundInvocationChainImpl; -import org.apache.tuscany.core.wire.OutboundInvocationChainImpl; -import org.apache.tuscany.core.wire.SynchronousBridgingInterceptor; -import org.easymock.EasyMock; -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.expect; - -/** - * 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; - - /** - * @see junit.framework.TestCase#setUp() - */ - protected void setUp() throws Exception { - super.setUp(); - this.processor = new PassByValueWirePostProcessor(); - DataBindingRegistry dataBindingRegistry = createMock(DataBindingRegistry.class); - processor.setDataBindingRegistry(dataBindingRegistry); - } - - public void testProcessInclusionOfInterceptor() { - - InboundWire inboundWire = createMock(InboundWire.class); - OutboundWire outboundWire = createMock(OutboundWire.class); - - ServiceContract serviceContract = new JavaServiceContract(null); - serviceContract.setRemotable(true); - Map, InboundInvocationChain> inChainsMap = - new Hashtable, InboundInvocationChain>(); - - Operation operation1 = new Operation("testMethod", null, null, null); - operation1.setServiceContract(serviceContract); - InboundInvocationChainImpl inChain = new InboundInvocationChainImpl(operation1); - inChainsMap.put(operation1, inChain); - - AtomicComponentExtension componentExtn = new FooComponent(); - componentExtn.setPassByReferenceMethods(new ArrayList()); - - Map, OutboundInvocationChain> outChainsMap = - new Hashtable, OutboundInvocationChain>(); - OutboundInvocationChainImpl outChain = new OutboundInvocationChainImpl(operation1); - outChainsMap.put(operation1, outChain); - - expect(inboundWire.getServiceContract()).andReturn(serviceContract); - expect(inboundWire.getContainer()).andReturn(componentExtn).anyTimes(); - expect(outboundWire.getContainer()).andReturn(componentExtn).anyTimes(); - expect(inboundWire.getServiceContract()).andReturn(serviceContract); - expect(inboundWire.getInvocationChains()).andReturn(inChainsMap); - expect(outboundWire.getServiceContract()).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(outboundWire, inboundWire); - - assertEquals(true, outChain.getHeadInterceptor() instanceof PassByValueInterceptor); - assertEquals(true, outChain.getTailInterceptor().getNext().equals( - inChain.getHeadInterceptor())); - - } - - public void testProcessExclusionOfInterceptorWhenAllowsPassByReference() { - InboundWire inboundWire = createMock(InboundWire.class); - OutboundWire outboundWire = createMock(OutboundWire.class); - - ServiceContract serviceContract = new JavaServiceContract(null); - serviceContract.setRemotable(true); - Map, InboundInvocationChain> inChainsMap = - new Hashtable, InboundInvocationChain>(); - - Operation operation1 = new Operation("testMethod", null, null, null); - InboundInvocationChainImpl inChain = new InboundInvocationChainImpl(operation1); - inChainsMap.put(operation1, inChain); - - AtomicComponentExtension componentExtn = new FooComponent(); - componentExtn.setAllowsPassByReference(true); - componentExtn.setPassByReferenceMethods(new ArrayList()); - - - Map, OutboundInvocationChain> outChainsMap = - new Hashtable, OutboundInvocationChain>(); - OutboundInvocationChainImpl outChain = new OutboundInvocationChainImpl(operation1); - outChainsMap.put(operation1, outChain); - - expect(inboundWire.getServiceContract()).andReturn(serviceContract); - expect(inboundWire.getContainer()).andReturn(componentExtn).anyTimes(); - expect(outboundWire.getContainer()).andReturn(componentExtn).anyTimes(); - expect(inboundWire.getServiceContract()).andReturn(serviceContract); - expect(inboundWire.getInvocationChains()).andReturn(inChainsMap); - expect(outboundWire.getServiceContract()).andReturn(serviceContract).anyTimes(); - 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(outboundWire, inboundWire); - - assertEquals(false, inChain.getHeadInterceptor() instanceof PassByValueInterceptor); - assertEquals(false, - outChain.getTailInterceptor().getNext() instanceof PassByValueInterceptor); - assertEquals(true, outChain.getTailInterceptor().getNext().equals( - inChain.getHeadInterceptor())); - } - - public void testProcessExclusionOfInterceptorWhenAllowsPassByReferenceAtMethod() { - InboundWire inboundWire = createMock(InboundWire.class); - OutboundWire outboundWire = createMock(OutboundWire.class); - - ServiceContract serviceContract = new JavaServiceContract(null); - serviceContract.setRemotable(true); - Map, InboundInvocationChain> inChainsMap = - new Hashtable, InboundInvocationChain>(); - - Operation operation1 = new Operation("testMethod", null, null, null); - InboundInvocationChainImpl inChain = new InboundInvocationChainImpl(operation1); - inChainsMap.put(operation1, inChain); - - AtomicComponentExtension componentExtn = new FooComponent(); - componentExtn.setPassByReferenceMethods(new ArrayList()); - componentExtn.getPassByReferenceMethods().add("testMethod"); - - - Map, OutboundInvocationChain> outChainsMap = - new Hashtable, OutboundInvocationChain>(); - OutboundInvocationChainImpl outChain = new OutboundInvocationChainImpl(operation1); - outChainsMap.put(operation1, outChain); - - expect(inboundWire.getServiceContract()).andReturn(serviceContract); - expect(inboundWire.getContainer()).andReturn(componentExtn).anyTimes(); - expect(outboundWire.getContainer()).andReturn(componentExtn).anyTimes(); - expect(inboundWire.getServiceContract()).andReturn(serviceContract); - expect(inboundWire.getInvocationChains()).andReturn(inChainsMap); - expect(outboundWire.getServiceContract()).andReturn(serviceContract).anyTimes(); - 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(outboundWire, inboundWire); - - assertEquals(false, inChain.getHeadInterceptor() instanceof PassByValueInterceptor); - assertEquals(false, - outChain.getTailInterceptor().getNext() instanceof PassByValueInterceptor); - assertEquals(true, outChain.getTailInterceptor().getNext().equals( - inChain.getHeadInterceptor())); - } - - public void testProcessExclusionOfInterceptorForBinding() { - InboundWire inboundWire = createMock(InboundWire.class); - OutboundWire outboundWire = createMock(OutboundWire.class); - - ServiceBinding serviceBinding = createMock(ServiceBinding.class); - expect(outboundWire.getContainer()).andReturn(serviceBinding).anyTimes(); - expect(inboundWire.getContainer()).andReturn(null).anyTimes(); - - ServiceContract serviceContract = new JavaServiceContract(null); - serviceContract.setRemotable(true); - Map, InboundInvocationChain> inChainsMap = - new Hashtable, InboundInvocationChain>(); - - Operation operation1 = new Operation("testMethod", null, null, null); - InboundInvocationChainImpl inChain = new InboundInvocationChainImpl(operation1); - inChainsMap.put(operation1, inChain); - - Map, OutboundInvocationChain> outChainsMap = - new Hashtable, OutboundInvocationChain>(); - OutboundInvocationChainImpl outChain = new OutboundInvocationChainImpl(operation1); - outChainsMap.put(operation1, outChain); - - 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(outboundWire, inboundWire); - - assertEquals(false, inChain.getHeadInterceptor() instanceof PassByValueInterceptor); - assertEquals(false, - outChain.getTailInterceptor().getNext() instanceof PassByValueInterceptor); - assertEquals(true, outChain.getTailInterceptor().getNext().equals( - inChain.getHeadInterceptor())); - } - - private class FooComponent extends AtomicComponentExtension { - - public FooComponent() { - super(null, null, null, null, null, null, 0); - } - - public Object createInstance() throws ObjectCreationException { - return null; - } - - public Object getTargetInstance() throws TargetResolutionException { - return null; - } - - public TargetInvoker createTargetInvoker(String targetName, Operation operation, InboundWire callbackWire) { - return null; - } - - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/TransformerRegistryImplTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/TransformerRegistryImplTestCase.java deleted file mode 100644 index 6250efd897..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/TransformerRegistryImplTestCase.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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 l1 = registry.getTransformerChain("a", "b"); - Assert.assertTrue(l1.size() == 1 && l1.get(0) == t1); - List l2 = registry.getTransformerChain("a", "c"); - Assert.assertTrue(l2.size() == 2 && l2.get(0) == t1 && l2.get(1) == t2); - List l3 = registry.getTransformerChain("a", "d"); - Assert.assertNull(l3); - - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/javabeans/DOMNode2JavaBeanTransformerTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/javabeans/DOMNode2JavaBeanTransformerTestCase.java deleted file mode 100644 index e654fe3ec9..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/javabeans/DOMNode2JavaBeanTransformerTestCase.java +++ /dev/null @@ -1,187 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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 junit.framework.TestCase; - -import org.apache.tuscany.core.databinding.javabeans.DOMNode2JavaBeanTransformer; -import org.apache.tuscany.core.databinding.javabeans.JavaBean2DOMNodeTransformer; -import org.apache.tuscany.spi.databinding.TransformationContext; -import org.apache.tuscany.spi.databinding.extension.DOMHelper; -import org.apache.tuscany.spi.idl.ElementInfo; -import org.apache.tuscany.spi.idl.TypeInfo; -import org.apache.tuscany.spi.idl.XMLType; -import org.apache.tuscany.spi.model.DataType; -import org.easymock.EasyMock; -import org.w3c.dom.Document; -import org.w3c.dom.Node; -import org.xml.sax.InputSource; - -/** - * 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(); - - /** - * @see junit.framework.TestCase#setUp() - */ - protected void setUp() throws Exception { - super.setUp(); - } - - public void testFieldSettings() throws Exception { - String samplePropertyXML = - "" + "27" - + "79.34" - + "184.52" + "" - + "54" + "158.68" - + "369.04" + "" - + "TestString_1" - + "TestString_2" + "true" - + "false" + ""; - - 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 targetDataType = new DataType(SamplePropertyBean.class, SamplePropertyBean.class); - EasyMock.expect(context.getTargetDataType()).andReturn(targetDataType).anyTimes(); - - DataType sourceDataType = new DataType(null, new XMLType(typeInfo)); - // 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("184.52") == -1); - // test the case for fields that are of array type - assertTrue(nodeString.indexOf("TestString_1" - + "TestString_2") != -1); - // testing the case for non-public field with public getter method - assertTrue(nodeString.indexOf("27") != -1); - // test the case for public field that is a another java bean .i.e. embeded javabean - int startIndex = nodeString.indexOf(""); - int endIndex = nodeString.indexOf(""); - String fragment = nodeString.substring(startIndex, endIndex); - assertTrue(fragment.indexOf("54") != -1); - - // System.out.println(sw.toString()); - - } - - - public static class SamplePropertyBean { - - private float floatNumber = 50; - private SamplePropertyBean innerProperty; - public boolean[] boolArray; - 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/javabeans/JavaBean2DOMNodeTransformerTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/javabeans/JavaBean2DOMNodeTransformerTestCase.java deleted file mode 100644 index 95701cc0fb..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/javabeans/JavaBean2DOMNodeTransformerTestCase.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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 dataType = new DataType(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)); - - System.out.println(sw.toString()); - assertEquals("1020" - + "3040", - 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/xml/DOM2StAXTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/xml/DOM2StAXTestCase.java deleted file mode 100644 index bc9ecb2713..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/xml/DOM2StAXTestCase.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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; - -import org.w3c.dom.Node; - -public class DOM2StAXTestCase extends TestCase { - private static final String IPO_XML = - "" + "" - + " " - + " Helen Zoe" - + " 47 Eden Street" - + " Cambridge" - + " CB1 1JR" - + " " - + " " - + " Robert Smith" - + " 8 Oak Avenue" - + " Old Town" - + " PA" - + " 95819" - + " " - + " " - + " " - + " Lapis necklace" - + " 1" - + " 99.95" - + " Want this for the holidays" - + " 1999-12-05" - + " " - + " " - + ""; - - private static final String CRAZY_XML = - "" - + "E4"; - - /** - * @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); - assertTrue(xml != null && xml.indexOf("1999-12-05") != -1); - } - - public void testTransformation2() { - String2Node t1 = new String2Node(); - Node node = t1.transform(CRAZY_XML, null); - Node2XMLStreamReader t2 = new Node2XMLStreamReader(); - XMLStreamReader reader = t2.transform(node, null); - XMLStreamReader2String t3 = new XMLStreamReader2String(); - String xml = t3.transform(reader, null); - System.out.println(xml); - assertTrue(xml.contains(" transformer = - new PipedTransformer(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("")); - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/xml/JavaBean2XMLStreamReaderTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/xml/JavaBean2XMLStreamReaderTestCase.java deleted file mode 100644 index 6eb2c101df..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/xml/JavaBean2XMLStreamReaderTestCase.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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; - -import org.apache.tuscany.core.databinding.javabeans.JavaBean2XMLStreamReader; - -public class JavaBean2XMLStreamReaderTestCase extends TestCase { - /** - * @see junit.framework.TestCase#setUp() - */ - protected void setUp() throws Exception { - super.setUp(); - } - - public void testTransformation() { - JavaBean2XMLStreamReader t2 = new JavaBean2XMLStreamReader(); - MyBean bean = new MyBean(); - bean.str = "ABC"; - bean.i = 1; - bean.arr = new long[] {1, 2, 3}; - bean.bean = new AnotherBean(); - bean.bean.setName("Name"); - XMLStreamReader reader = t2.transform(bean, null); - XMLStreamReader2String t3 = new XMLStreamReader2String(); - String xml = t3.transform(reader, null); - assertTrue(xml.contains("" - + "123Name" - + "1ABC")); - } - - private static class MyBean { - private String str; - private int i; - private long arr[]; - private AnotherBean bean; - - /** - * @return the arr - */ - public long[] getArr() { - return arr; - } - - /** - * @param arr the arr to set - */ - public void setArr(long[] arr) { - this.arr = arr; - } - - /** - * @return the i - */ - public int getI() { - return i; - } - - /** - * @param i the i to set - */ - public void setI(int i) { - this.i = i; - } - - /** - * @return the str - */ - public String getStr() { - return str; - } - - /** - * @param str the str to set - */ - public void setStr(String str) { - this.str = str; - } - - /** - * @return the bean - */ - public AnotherBean getBean() { - return bean; - } - - /** - * @param bean the bean to set - */ - public void setBean(AnotherBean bean) { - this.bean = bean; - } - - } - - private static class AnotherBean { - private String name; - - /** - * @return the name - */ - public String getName() { - return name; - } - - /** - * @param name the name to set - */ - public void setName(String name) { - this.name = name; - } - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/xml/Node2StringTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/xml/Node2StringTestCase.java deleted file mode 100755 index 9b9aa3b893..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/xml/Node2StringTestCase.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/xml/PushTransformationTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/xml/PushTransformationTestCase.java deleted file mode 100644 index a2318b2faa..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/xml/PushTransformationTestCase.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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 = - "" + "" - + " " - + " Helen Zoe" - + " 47 Eden Street" - + " Cambridge" - + " CB1 1JR" - + " " - + " " - + " Robert Smith" - + " 8 Oak Avenue" - + " Old Town" - + " PA" - + " 95819" - + " " - + " " - + " " - + " Lapis necklace" - + " 1" - + " 99.95" - + " Want this for the holidays" - + " 1999-12-05" - + " " - + " " - + ""; - - /** - * @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 t3 = - new PipedTransformer(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("1999-12-05") != -1); - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/xml/StAXHelperTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/xml/StAXHelperTestCase.java deleted file mode 100644 index 7d18e83ac6..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/xml/StAXHelperTestCase.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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 = - "" + "" - + ""; - - /** - * @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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/xml/TraxTransformerTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/xml/TraxTransformerTestCase.java deleted file mode 100644 index 7e9494d423..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/xml/TraxTransformerTestCase.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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 = "bar"; - - 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/deployer/BootstrapDeployerTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/deployer/BootstrapDeployerTestCase.java deleted file mode 100644 index 20ae7eecb8..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/deployer/BootstrapDeployerTestCase.java +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.URL; -import java.util.Collection; -import java.util.Map; -import javax.xml.stream.XMLInputFactory; - -import org.apache.tuscany.spi.bootstrap.ComponentNames; -import org.apache.tuscany.spi.component.Component; -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.component.SCAObject; -import org.apache.tuscany.spi.deployer.DeploymentContext; -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.CompositeReferenceDefinition; -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.AbstractReferenceDefinition; -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.implementation.system.model.SystemCompositeImplementation; -import org.apache.tuscany.core.mock.component.BasicInterface; -import org.apache.tuscany.core.monitor.NullMonitorFactory; -import static org.easymock.EasyMock.createNiceMock; -import static org.easymock.EasyMock.isA; -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 componentDefinition; - private SystemCompositeImplementation implementation; - - @SuppressWarnings("unchecked") - public void testBoot1Load() throws LoaderException { - CompositeComponent parent = createNiceMock(CompositeComponent.class); - URL scdl = BootstrapDeployerTestCase.class.getResource("boot1.scdl"); - implementation.setScdlLocation(scdl); - deployer.load(parent, componentDefinition, deploymentContext); - CompositeComponentType> composite = - implementation.getComponentType(); - assertNotNull(composite); - assertEquals("boot1", composite.getName()); - - // check parse of - Map 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("service", serviceDefinition.getName()); - assertEquals(BasicInterface.class, serviceDefinition.getServiceContract().getInterfaceClass()); - Collection bindings = serviceDefinition.getBindings(); - assertTrue(bindings.isEmpty()); - - // check parse of - Map>> components = composite.getDeclaredComponents(); - assertEquals(1, components.size()); // included doesn't count - components = composite.getComponents(); - assertEquals(2, components.size()); // included counts - ComponentDefinition> 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 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); - CompositeComponent parent = createNiceMock(CompositeComponent.class); - parent.register(isA(SCAObject.class)); - replay(parent); - // load the boot1 file using the bootstrap deployer - componentDefinition.setName("simple"); - Component component = deployer.deploy(parent, componentDefinition); - assertNotNull(component); - verify(parent); - } - - public void testBoot2Deployment() throws Exception { - URL scdl = BootstrapDeployerTestCase.class.getResource("boot2.scdl"); - implementation.setScdlLocation(scdl); - CompositeComponent parent = createNiceMock(CompositeComponent.class); - parent.register(isA(SCAObject.class)); - replay(parent); - - // load the boot2 file using the bootstrap deployer - componentDefinition.setName("newDeployer"); - CompositeComponent component = (CompositeComponent) deployer.deploy(parent, componentDefinition); - assertNotNull(component); - verify(parent); - component.start(); - SCAObject newDeployer = component.getSystemChild(ComponentNames.TUSCANY_DEPLOYER); - assertNotNull(newDeployer); - SCAObject wireService = component.getSystemChild(ComponentNames.TUSCANY_WIRE_SERVICE); - assertNotNull(wireService); - -/* // FIXME - // load the boot2 file using the newly loaded deployer - parent.reset(); - parent.expects(once()).method("register").withAnyArguments(); - componentDefinition.setName("newDeployer2"); - component = newDeployer.deploy((CompositeComponent) parent.proxy(), componentDefinition); - assertNotNull(component); - parent.verify(); - component.start(); - Deployer newDeployer2 = (Deployer) component.getServiceInstance("deployer"); - assertNotNull(newDeployer2); -*/ - } - - protected void setUp() throws Exception { - super.setUp(); - XMLInputFactory xmlFactory = XMLInputFactory.newInstance(); - Bootstrapper bootstrapper = new DefaultBootstrapper(new NullMonitorFactory(), xmlFactory, null); - deployer = (DeployerImpl) bootstrapper.createDeployer(); - deploymentContext = new RootDeploymentContext(null, xmlFactory, null, null); - implementation = new SystemCompositeImplementation(); - implementation.setClassLoader(getClass().getClassLoader()); - componentDefinition = new ComponentDefinition(implementation); - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/idl/java/ConversationalIntrospectionTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/idl/java/ConversationalIntrospectionTestCase.java deleted file mode 100644 index 5b0fe34705..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/idl/java/ConversationalIntrospectionTestCase.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.EndsConversation; -import org.osoa.sca.annotations.Scope; - -import org.apache.tuscany.spi.idl.InvalidConversationalOperationException; -import org.apache.tuscany.spi.idl.java.JavaServiceContract; -import static org.apache.tuscany.spi.model.InteractionScope.CONVERSATIONAL; -import static org.apache.tuscany.spi.model.InteractionScope.NONCONVERSATIONAL; -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); - assertEquals(CONVERSATIONAL, contract.getInteractionScope()); - 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); - assertEquals(NONCONVERSATIONAL, contract.getInteractionScope()); - int seq = contract.getOperations().get("operation").getConversationSequence(); - assertEquals(Operation.NO_CONVERSATION, seq); - } - - @Scope("CONVERSATION") - private interface Foo { - void operation(); - - @EndsConversation - void endOperation(); - } - - private interface BadFoo { - void operation(); - - @EndsConversation - void endOperation(); - } - - private interface NonConversationalFoo { - void operation(); - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/idl/java/JavaInterfaceProcessorRegistryImplTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/idl/java/JavaInterfaceProcessorRegistryImplTestCase.java deleted file mode 100644 index e3a7deb10a..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/idl/java/JavaInterfaceProcessorRegistryImplTestCase.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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> operations = contract.getOperations(); - assertEquals(1, operations.size()); - Operation baseInt = operations.get("baseInt"); - assertNotNull(baseInt); - - DataType returnType = baseInt.getOutputType(); - assertEquals(Integer.TYPE, returnType.getPhysical()); - assertEquals(Integer.TYPE, returnType.getLogical()); - - List> parameterTypes = baseInt.getInputType().getLogical(); - assertEquals(1, parameterTypes.size()); - DataType arg0 = parameterTypes.get(0); - assertEquals(Integer.TYPE, arg0.getPhysical()); - assertEquals(Integer.TYPE, arg0.getLogical()); - - List> faultTypes = baseInt.getFaultTypes(); - assertEquals(1, faultTypes.size()); - DataType 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/IntrospectionRegistryTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/IntrospectionRegistryTestCase.java deleted file mode 100644 index fb5e7fbb1f..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/IntrospectionRegistryTestCase.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.Method; -import java.lang.reflect.Field; -import java.lang.reflect.Constructor; - -import org.apache.tuscany.spi.component.CompositeComponent; -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.isA(CompositeComponent.class), - EasyMock.eq(Bar.class), - EasyMock.isA(PojoComponentType.class), - EasyMock.isA(DeploymentContext.class)); - processor.visitConstructor(EasyMock.isA(CompositeComponent.class), - EasyMock.isA(Constructor.class), - EasyMock.isA(PojoComponentType.class), - EasyMock.isA(DeploymentContext.class)); - processor.visitMethod(EasyMock.isA(CompositeComponent.class), - EasyMock.isA(Method.class), - EasyMock.isA(PojoComponentType.class), - EasyMock.isA(DeploymentContext.class)); - processor.visitField(EasyMock.isA(CompositeComponent.class), - EasyMock.isA(Field.class), - EasyMock.isA(PojoComponentType.class), - EasyMock.isA(DeploymentContext.class)); - processor.visitSuperClass(EasyMock.isA(CompositeComponent.class), - EasyMock.isA(Class.class), - EasyMock.isA(PojoComponentType.class), - EasyMock.isA(DeploymentContext.class)); - processor.visitEnd(EasyMock.isA(CompositeComponent.class), - 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(EasyMock.createNiceMock(CompositeComponent.class), - Bar.class, - new PojoComponentType>(), - 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/PojoAtomicComponentTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/PojoAtomicComponentTestCase.java deleted file mode 100644 index 6fcef3622e..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/PojoAtomicComponentTestCase.java +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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 org.apache.tuscany.spi.ObjectFactory; -import org.apache.tuscany.spi.component.AtomicComponent; -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.InboundWire; -import org.apache.tuscany.spi.wire.OutboundWire; -import org.apache.tuscany.spi.wire.TargetInvoker; - -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 PojoObjectFactory factory; - - @SuppressWarnings({"unchecked"}) - public void testDestroy() throws Exception { - PojoConfiguration config = new PojoConfiguration(); - config.setInstanceFactory(factory); - EventInvoker 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 testInit() throws Exception { - PojoConfiguration config = new PojoConfiguration(); - config.setInstanceFactory(factory); - EventInvoker 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 { - PojoConfiguration config = new PojoConfiguration(); - config.setInstanceFactory(factory); - TestAtomicComponent component = new TestAtomicComponent(config); - assertTrue(component.isOptimizable()); - } - - @SuppressWarnings({"unchecked"}) - public void testDestroyableButOptimizable() throws Exception { - PojoConfiguration config = new PojoConfiguration(); - config.setInstanceFactory(factory); - EventInvoker 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 { - PojoConfiguration config = new PojoConfiguration(); - config.setInstanceFactory(factory); - TestStatelessAtomicComponent component = new TestStatelessAtomicComponent(config); - assertTrue(component.isOptimizable()); - } - - @SuppressWarnings({"unchecked"}) - public void testNotOptimizable() throws Exception { - PojoConfiguration config = new PojoConfiguration(); - config.setInstanceFactory(factory); - EventInvoker invoker = EasyMock.createMock(EventInvoker.class); - invoker.invokeEvent(EasyMock.notNull()); - EasyMock.replay(invoker); - config.setDestroyInvoker(invoker); - TestStatelessAtomicComponent component = new TestStatelessAtomicComponent(config); - assertFalse(component.isOptimizable()); - } - - protected void setUp() throws Exception { - super.setUp(); - factory = new PojoObjectFactory(Foo.class.getConstructor()); - } - - private class TestAtomicComponent extends PojoAtomicComponent { - - public TestAtomicComponent(PojoConfiguration configuration) { - super(configuration); - } - - public Scope getScope() { - return Scope.COMPOSITE; - } - - protected ObjectFactory createWireFactory(Class interfaze, OutboundWire wire) { - return null; - } - - public TargetInvoker createTargetInvoker(String targetName, Operation operation, InboundWire callbackWire) - throws TargetInvokerCreationException { - return null; - } - } - - private class TestStatelessAtomicComponent extends PojoAtomicComponent { - - public TestStatelessAtomicComponent(PojoConfiguration configuration) { - super(configuration); - } - - public Scope getScope() { - return Scope.STATELESS; - } - - protected ObjectFactory createWireFactory(Class interfaze, OutboundWire wire) { - return null; - } - - public TargetInvoker createTargetInvoker(String targetName, Operation operation, InboundWire callbackWire) - throws TargetInvokerCreationException { - return null; - } - } - - private static class Foo { - public Foo() { - } - } - -} - - diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/TestUtils.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/TestUtils.java deleted file mode 100644 index e18fc99861..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/TestUtils.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.util.ArrayList; -import java.util.List; - -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.CompositeComponent; -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.wire.InboundWire; - -import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl; -import org.apache.tuscany.core.wire.InboundWireImpl; - -/** - * @version $Rev$ $Date$ - */ -public final class TestUtils { - private static final JavaInterfaceProcessorRegistry REGISTRY = new JavaInterfaceProcessorRegistryImpl(); - - private TestUtils() { - } - - public static List populateInboundWires(AtomicComponent component, List wires) - throws InvalidServiceContractException { - for (InboundWire wire : wires) { - wire.setContainer(component); - } - return wires; - } - - public static List createInboundWires(List> interfazes) - throws InvalidServiceContractException { - List wires = new ArrayList(interfazes.size()); - for (Class interfaze : interfazes) { - InboundWire wire = createInboundWire(interfaze); - wires.add(wire); - } - return wires; - } - - public static InboundWire createInboundWire(Class interfaze) throws InvalidServiceContractException { - InboundWire wire = new InboundWireImpl(); - JavaServiceContract contract = REGISTRY.introspect(interfaze); - wire.setServiceContract(contract); - return wire; - } - - public static InboundWire createInboundWire(Class interfaze, CompositeComponent parent) - throws InvalidServiceContractException { - InboundWire wire = createInboundWire(interfaze); - wire.setContainer(parent); - return wire; - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/AutowireResolutionTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/AutowireResolutionTestCase.java deleted file mode 100644 index c644c3d7c4..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/AutowireResolutionTestCase.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.wire.InboundWire; - -import junit.framework.TestCase; -import org.apache.tuscany.core.implementation.TestUtils; -import org.easymock.EasyMock; -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.eq; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; - -/** - * Verfies specific autowire resolution scenarios - * - * @version $Rev$ $Date$ - */ -public class AutowireResolutionTestCase extends TestCase { - - public void testConstruction() { - CompositeComponent parent = createMock(CompositeComponent.class); - replay(parent); - CompositeComponent component = new CompositeComponentImpl("test", parent, null, null); - assertEquals("test", component.getName()); - assertSame(parent, component.getParent()); - verify(parent); - } - - public void testResolvedByAutowire() throws Exception { - CompositeComponent parent = createMock(CompositeComponent.class); - InboundWire wire = TestUtils.createInboundWire(Foo.class, parent); - EasyMock.expect(parent.resolveAutowire(eq(Foo.class))).andReturn(wire); - EasyMock.expect(parent.resolveSystemAutowire(eq(Foo.class))).andReturn(null); - replay(parent); - CompositeComponent component = new CompositeComponentImpl("test", parent, null, null); - assertSame(wire, component.resolveAutowire(Foo.class)); - verify(parent); - } - - public void testSystemResolvedByAutowire() throws Exception { - CompositeComponent parent = createMock(CompositeComponent.class); - InboundWire wire = TestUtils.createInboundWire(Foo.class, parent); - EasyMock.expect(parent.resolveSystemAutowire(eq(Foo.class))).andReturn(wire); - replay(parent); - CompositeComponent component = new CompositeComponentImpl("test", parent, null, null); - assertSame(wire, component.resolveSystemAutowire(Foo.class)); - verify(parent); - } - - /** - * Verify parent resolution strategy for application serviceBindings - */ - public void testNamespaceIsolationAutowire() throws Exception { - Foo foo = new Foo() { - }; - CompositeComponent parent = new CompositeComponentImpl("parent", null, null, null); - parent.registerJavaObject("foo", Foo.class, foo); - CompositeComponent component = new CompositeComponentImpl("test", parent, null, null); - assertNotNull(component.resolveAutowire(Foo.class)); - } - - protected void setUp() throws Exception { - super.setUp(); - } - - public static interface Foo { - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/AutowireTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/AutowireTestCase.java deleted file mode 100644 index 341efcd09c..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/AutowireTestCase.java +++ /dev/null @@ -1,230 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.util.ArrayList; -import java.util.List; - -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.CompositeComponent; -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.wire.InboundWire; - -import junit.framework.TestCase; -import org.apache.tuscany.core.implementation.TestUtils; -import org.easymock.EasyMock; - -/** - * Performs basic autowiring tests to composite artifacts - * - * @version $$Rev$$ $$Date$$ - */ -public class AutowireTestCase extends TestCase { - - /** - * Tests autowiring to an system atomic component - */ - public void testSystemAtomicAutowire() throws Exception { - CompositeComponent parent = new CompositeComponentImpl("parent", null, null, true); - parent.start(); - List> interfaces = new ArrayList>(); - interfaces.add(Source.class); - interfaces.add(Source2.class); - AtomicComponent component = EasyMock.createMock(AtomicComponent.class); - EasyMock.expect(component.getName()).andReturn("source").atLeastOnce(); - EasyMock.expect(component.isSystem()).andReturn(true).atLeastOnce(); - List wires = TestUtils.createInboundWires(interfaces); - EasyMock.expect(component.getInboundWires()).andReturn(wires).atLeastOnce(); - TestUtils.populateInboundWires(component, wires); - EasyMock.replay(component); - parent.register(component); - InboundWire source = parent.resolveSystemAutowire(Source.class); - assertNotNull(source); - InboundWire sourceBase = parent.resolveSystemAutowire(SourceBase.class); - assertSame(source, sourceBase); - InboundWire source2 = parent.resolveSystemAutowire(Source2.class); - assertSame(source.getContainer(), source2.getContainer()); - assertNull(parent.resolveSystemExternalAutowire(Source.class)); - EasyMock.verify(component); - } - - /** - * Tests autowiring to an system atomic component - */ - public void testAtomicAutowire() throws Exception { - CompositeComponent parent = new CompositeComponentImpl("parent", null, null, null); - parent.start(); - - List> interfaces = new ArrayList>(); - interfaces.add(Source.class); - interfaces.add(Source2.class); - AtomicComponent component = EasyMock.createMock(AtomicComponent.class); - EasyMock.expect(component.getName()).andReturn("source").atLeastOnce(); - EasyMock.expect(component.isSystem()).andReturn(false).atLeastOnce(); - List wires = TestUtils.createInboundWires(interfaces); - EasyMock.expect(component.getInboundWires()).andReturn(wires).atLeastOnce(); - TestUtils.populateInboundWires(component, wires); - - EasyMock.replay(component); - parent.register(component); - - InboundWire source = parent.resolveAutowire(Source.class); - assertNotNull(source); - InboundWire sourceBase = parent.resolveAutowire(SourceBase.class); - assertSame(source, sourceBase); - InboundWire source2 = parent.resolveAutowire(Source2.class); - assertSame(source.getContainer(), source2.getContainer()); - assertNull(parent.resolveExternalAutowire(Source.class)); - EasyMock.verify(component); - } - - /** - * Tests autowiring to a system service - */ - public void testSystemServiceAutowire() throws Exception { - CompositeComponent parent = new CompositeComponentImpl("parent", null, null, true); - parent.start(); - - ServiceBinding serviceBinding = EasyMock.createMock(ServiceBinding.class); - InboundWire wire = TestUtils.createInboundWire(Source.class); - wire.setContainer(serviceBinding); - EasyMock.expect(serviceBinding.getInboundWire()).andReturn(wire).atLeastOnce(); - EasyMock.replay(serviceBinding); - - List bindings = new ArrayList(); - bindings.add(serviceBinding); - Service service = EasyMock.createMock(Service.class); - EasyMock.expect(service.getName()).andReturn("service").atLeastOnce(); - EasyMock.expect(service.isSystem()).andReturn(true).atLeastOnce(); - - EasyMock.expect(service.getServiceBindings()).andReturn(bindings).atLeastOnce(); - EasyMock.replay(service); - parent.register(service); - - InboundWire source = parent.resolveSystemExternalAutowire(Source.class); - assertSame(serviceBinding, source.getContainer()); - InboundWire sourceBase = parent.resolveSystemExternalAutowire(SourceBase.class); - assertSame(source, sourceBase); - InboundWire source2 = parent.resolveSystemExternalAutowire(Source2.class); - assertNull(source2); - EasyMock.verify(serviceBinding); - } - - /** - * Tests autowiring to a service - */ - public void testServiceAutowire() throws Exception { - CompositeComponent parent = new CompositeComponentImpl("parent", null, null, true); - parent.start(); - - ServiceBinding serviceBinding = EasyMock.createMock(ServiceBinding.class); - InboundWire wire = TestUtils.createInboundWire(Source.class); - wire.setContainer(serviceBinding); - EasyMock.expect(serviceBinding.getInboundWire()).andReturn(wire).atLeastOnce(); - EasyMock.replay(serviceBinding); - - List bindings = new ArrayList(); - bindings.add(serviceBinding); - Service service = EasyMock.createMock(Service.class); - EasyMock.expect(service.getName()).andReturn("service").atLeastOnce(); - EasyMock.expect(service.isSystem()).andReturn(false).atLeastOnce(); - - EasyMock.expect(service.getServiceBindings()).andReturn(bindings).atLeastOnce(); - EasyMock.replay(service); - parent.register(service); - - InboundWire source = parent.resolveExternalAutowire(Source.class); - assertSame(serviceBinding, source.getContainer()); - InboundWire sourceBase = parent.resolveExternalAutowire(SourceBase.class); - assertSame(source, sourceBase); - InboundWire source2 = parent.resolveExternalAutowire(Source2.class); - assertNull(source2); - EasyMock.verify(serviceBinding); - } - - - /** - * Tests autowiring to a system reference - */ - public void testSystemReferenceAutowire() throws Exception { - CompositeComponent parent = new CompositeComponentImpl("parent", null, null, true); - parent.start(); - - ReferenceBinding binding = EasyMock.createMock(ReferenceBinding.class); - binding.setReference(EasyMock.isA(Reference.class)); - InboundWire wire = TestUtils.createInboundWire(Source.class); - wire.setContainer(binding); - EasyMock.expect(binding.getInboundWire()).andReturn(wire).atLeastOnce(); - EasyMock.replay(binding); - - Reference reference = new ReferenceImpl("foo", null, wire.getServiceContract(), true); - reference.addReferenceBinding(binding); - parent.register(reference); - - InboundWire source = parent.resolveSystemAutowire(Source.class); - assertNotNull(source); - InboundWire sourceBase = parent.resolveSystemAutowire(SourceBase.class); - assertSame(source, sourceBase); - EasyMock.verify(binding); - } - - /** - * Tests autowiring to a reference - */ - public void testReferenceAutowire() throws Exception { - CompositeComponent parent = new CompositeComponentImpl("parent", null, null, true); - parent.start(); - - ReferenceBinding binding = EasyMock.createMock(ReferenceBinding.class); - binding.setReference(EasyMock.isA(Reference.class)); - InboundWire wire = TestUtils.createInboundWire(Source.class); - wire.setContainer(binding); - EasyMock.expect(binding.getInboundWire()).andReturn(wire).atLeastOnce(); - EasyMock.replay(binding); - - Reference reference = new ReferenceImpl("foo", null, wire.getServiceContract(), false); - reference.addReferenceBinding(binding); - parent.register(reference); - - InboundWire source = parent.resolveAutowire(Source.class); - assertNotNull(source); - InboundWire sourceBase = parent.resolveAutowire(SourceBase.class); - assertSame(source, sourceBase); - EasyMock.verify(binding); - } - - - public static class SourceImpl implements Source, Source2 { - public SourceImpl() { - } - } - - public static interface SourceBase { - } - - public static interface Source extends SourceBase { - } - - public static interface Source2 { - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeBuilderTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeBuilderTestCase.java deleted file mode 100644 index 2c47eab4ba..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeBuilderTestCase.java +++ /dev/null @@ -1,215 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.AtomicComponent; -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.component.ScopeContainerMonitor; -import org.apache.tuscany.spi.component.Service; -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.ComponentReferenceDefinition; -import org.apache.tuscany.spi.model.ComponentTypeReferenceDefinition; -import org.apache.tuscany.spi.model.CompositeComponentType; -import org.apache.tuscany.spi.model.CompositeImplementation; -import org.apache.tuscany.spi.model.AbstractReferenceDefinition; -import org.apache.tuscany.spi.model.CompositeReferenceDefinition; -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.WireService; - -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.apache.tuscany.core.wire.jdk.JDKWireService; -import org.easymock.EasyMock; - -/** - * @version $$Rev$$ $$Date$$ - */ -public class CompositeBuilderTestCase extends TestCase { - private DeploymentContext deploymentContext; - - @SuppressWarnings("unchecked") - public void testBuild() throws Exception { - CompositeComponent parent = new CompositeComponentImpl(null, null, null, null); - - CompositeBuilder builder = new CompositeBuilder(); - WireService wireService = new JDKWireService(); - builder.setWireService(wireService); - BuilderRegistryImpl builderRegistry = new BuilderRegistryImpl(null, wireService); - JavaComponentBuilder jBuilder = new JavaComponentBuilder(); - jBuilder.setWireService(wireService); - builderRegistry.register(JavaImplementation.class, jBuilder); - builderRegistry.register(CompositeImplementation.class, builder); - builderRegistry.register(LocalBindingDefinition.class, new LocalBindingBuilder()); - builder.setBuilderRegistry(builderRegistry); - CompositeComponent component = - (CompositeComponent) builder.build(parent, createTopComponentDef(), deploymentContext); - - component.start(); - CompositeComponent sourceComponent = (CompositeComponent) component.getChild("SourceComponent"); - assertTrue(sourceComponent.getChild("InnerSourceService") instanceof Service); - AtomicComponent innerSourceComponent = (AtomicComponent) sourceComponent.getChild("InnerSourceComponent"); - Source innerSourceInstance = (Source) deploymentContext.getCompositeScope().getInstance(innerSourceComponent); - assertNotNull(innerSourceInstance); - component.stop(); - } - - private ComponentDefinition createTopComponentDef() throws Exception { - - CompositeComponentType> outerType = - new CompositeComponentType>(); - outerType.add(createSourceComponentDef()); - outerType.add(createTargetComponentDef()); - - CompositeImplementation outerImpl = new CompositeImplementation(); - outerImpl.setComponentType(outerType); - - return new ComponentDefinition(outerImpl); - } - - private ComponentDefinition createSourceComponentDef() throws Exception { - - CompositeComponentType> innerType = - new CompositeComponentType>(); - innerType.add(createInnerSourceComponentDef()); - CompositeReferenceDefinition reference = new CompositeReferenceDefinition(); - reference.setName("TargetComponentRef"); - JavaInterfaceProcessorRegistry registry = new JavaInterfaceProcessorRegistryImpl(); - JavaServiceContract targetContract = registry.introspect(Target.class); - reference.setServiceContract(targetContract); - innerType.add(reference); - ServiceDefinition service = new ServiceDefinition(); - service.setName("InnerSourceService"); - JavaServiceContract sourceContract = registry.introspect(Source.class); - service.setServiceContract(sourceContract); - service.setTarget(new URI("InnerSourceComponent")); - innerType.add(service); - - CompositeImplementation innerImpl = new CompositeImplementation(); - innerImpl.setComponentType(innerType); - - ComponentDefinition sourceComponentDefinition = - new ComponentDefinition("SourceComponent", innerImpl); - - /*ReferenceTarget refTarget = new ReferenceTarget(); - refTarget.setReferenceName("TargetComponentRef"); - refTarget.addTarget(new URI("TargetComponent")); - sourceComponentDefinition.add(refTarget);*/ - ComponentReferenceDefinition compRef = new ComponentReferenceDefinition(innerType.getReferences().get("TargetComponentRef")); - compRef.setName("TargetComponentRef"); - compRef.addTarget(new URI("TargetComponent")); - sourceComponentDefinition.add(compRef); - - return sourceComponentDefinition; - } - - private ComponentDefinition createInnerSourceComponentDef() throws Exception { - - PojoComponentType> sourceType = - new PojoComponentType>(); - sourceType.setImplementationScope(Scope.COMPOSITE); - JavaMappedReference reference = new JavaMappedReference(); - reference.setName("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.setName("Source"); - sourceServiceDefinition.setServiceContract(sourceContract); - - sourceType.add(sourceServiceDefinition); - sourceType.setConstructorDefinition(new ConstructorDefinition(SourceImpl.class.getConstructor())); - JavaImplementation sourceImpl = new JavaImplementation(SourceImpl.class, sourceType); - ComponentDefinition innerSourceComponentDefinition = - new ComponentDefinition("InnerSourceComponent", sourceImpl); - - ComponentReferenceDefinition compRef = new ComponentReferenceDefinition(sourceType.getReferences().get("targetReference")); - compRef.setName("targetReference"); - compRef.addTarget(new URI("TargetComponentRef")); - innerSourceComponentDefinition.add(compRef); - /*ReferenceTarget refTarget = new ReferenceTarget(); - refTarget.setReferenceName("targetReference"); - refTarget.addTarget(new URI("TargetComponentRef")); - innerSourceComponentDefinition.add(refTarget); - */ - return innerSourceComponentDefinition; - } - - private ComponentDefinition createTargetComponentDef() throws Exception { - - PojoComponentType> targetType = - new PojoComponentType>(); - 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.setName("Target"); - serviceDefinition.setServiceContract(targetContract); - serviceDefinition.setCallbackReferenceName("otherTarget"); - - targetType.add(serviceDefinition); - targetType.setConstructorDefinition(new ConstructorDefinition(TargetImpl.class.getConstructor())); - JavaImplementation targetImpl = new JavaImplementation(TargetImpl.class, targetType); - return new ComponentDefinition("TargetComponent", targetImpl); - } - - 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, container, null); - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeComponentImplBasicTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeComponentImplBasicTestCase.java deleted file mode 100644 index 1f7c8618d2..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeComponentImplBasicTestCase.java +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.util.Collections; - -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.CompositeComponent; -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.event.Event; -import org.apache.tuscany.spi.event.RuntimeEventListener; -import org.apache.tuscany.spi.idl.InvalidServiceContractException; -import org.apache.tuscany.spi.model.Scope; -import org.apache.tuscany.spi.wire.InboundWire; - -import junit.framework.Assert; -import junit.framework.TestCase; -import org.apache.tuscany.core.component.event.CompositeStart; -import org.apache.tuscany.core.implementation.TestUtils; -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; - -/** - * @version $Rev$ $Date$ - */ -public class CompositeComponentImplBasicTestCase extends TestCase { - private AtomicComponent component; - - public void testGetScope() { - CompositeComponent composite = new CompositeComponentImpl("parent", null, null, null); - Assert.assertEquals(Scope.SYSTEM, composite.getScope()); - } - - public void testReferencesServices() throws Exception { - CompositeComponent composite = new CompositeComponentImpl("parent", null, null, null); - Service service = EasyMock.createMock(Service.class); - EasyMock.expect(service.getName()).andReturn("foo").atLeastOnce(); - EasyMock.expect(service.isSystem()).andReturn(false).atLeastOnce(); - service.getServiceBindings(); - EasyMock.expectLastCall().andReturn(Collections.emptyList()).atLeastOnce(); - EasyMock.replay(service); - composite.register(service); - composite.register(getReference("bar")); - } - - public void testOnEvent() { - CompositeComponent composite = new CompositeComponentImpl("parent", null, null, null); - Event event = new Event() { - public Object getSource() { - return null; - } - }; - RuntimeEventListener listener = createMock(RuntimeEventListener.class); - listener.onEvent(isA(CompositeStart.class)); - listener.onEvent(eq(event)); - expectLastCall(); - replay(listener); - composite.addListener(listener); - composite.start(); - composite.onEvent(event); - } - - public void testPrepare() throws Exception { - CompositeComponent composite = new CompositeComponentImpl("parent", null, null, null); - composite.prepare(); - } - - private Reference getReference(String name) throws InvalidServiceContractException { - ReferenceBinding binding = EasyMock.createNiceMock(ReferenceBinding.class); - EasyMock.expect(binding.isSystem()).andReturn(false).atLeastOnce(); - InboundWire wire = TestUtils.createInboundWire(Bar.class); - wire.setContainer(binding); - EasyMock.expect(binding.getInboundWire()).andReturn(wire).atLeastOnce(); - - binding.getName(); - expectLastCall().andReturn(name).anyTimes(); - replay(binding); - - Reference reference = new ReferenceImpl(name, null, wire.getServiceContract()); - reference.addReferenceBinding(binding); - return reference; - } - - protected void setUp() throws Exception { - super.setUp(); - component = EasyMock.createMock(AtomicComponent.class); - EasyMock.expect(component.getName()).andReturn("foo").atLeastOnce(); - EasyMock.expect(component.isSystem()).andReturn(false).atLeastOnce(); - component.getInboundWires(); - EasyMock.expectLastCall().andReturn(Collections.emptyList()).atLeastOnce(); - EasyMock.replay(component); - } - - private interface Bar { - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeComponentImplSystemWireTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeComponentImplSystemWireTestCase.java deleted file mode 100644 index 018e068120..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeComponentImplSystemWireTestCase.java +++ /dev/null @@ -1,170 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.apache.tuscany.spi.QualifiedName; -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.component.PrepareException; -import org.apache.tuscany.spi.component.SCAObject; -import org.apache.tuscany.spi.idl.java.JavaServiceContract; -import org.apache.tuscany.spi.model.Scope; -import org.apache.tuscany.spi.wire.InboundWire; -import org.apache.tuscany.spi.wire.OutboundWire; - -import junit.framework.TestCase; -import org.apache.tuscany.core.builder.ConnectorImpl; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class CompositeComponentImplSystemWireTestCase extends TestCase { - - /** - * Verifies system services in a CompositeComponentImpl are wired during the parent composite's prepare callback - */ - public void testSystemServiceWire() throws Exception { - InboundWire inbound = EasyMock.createMock(InboundWire.class); - EasyMock.expect(inbound.getServiceContract()).andReturn(new JavaServiceContract(Foo.class)).atLeastOnce(); - inbound.getInvocationChains(); - EasyMock.expectLastCall().andReturn(Collections.emptyMap()).atLeastOnce(); - - QualifiedName qName = new QualifiedName("target/bar"); - OutboundWire outbound = EasyMock.createMock(OutboundWire.class); - EasyMock.expect(outbound.getTargetName()).andReturn(qName).atLeastOnce(); - EasyMock.expect(outbound.isAutowire()).andReturn(false); - - outbound.setTargetWire(EasyMock.eq(inbound)); - EasyMock.expect(outbound.getServiceContract()).andReturn(new JavaServiceContract(Foo.class)).atLeastOnce(); - List wires = new ArrayList(); - wires.add(outbound); - Map> wireMap = new HashMap>(); - wireMap.put("ref", wires); - CompositeComponent parent = new CompositeComponentImpl("foo", "foo", null, new ConnectorImpl(), null); - AtomicComponent source = EasyMock.createMock(AtomicComponent.class); - EasyMock.expect(source.getScope()).andReturn(Scope.COMPOSITE).atLeastOnce(); - EasyMock.expect(source.getName()).andReturn("source").atLeastOnce(); - EasyMock.expect(source.getOutboundWires()).andReturn(wireMap); - source.getInboundWires(); - EasyMock.expectLastCall().andReturn(Collections.emptyList()).atLeastOnce(); - EasyMock.expect(source.isSystem()).andReturn(true).atLeastOnce(); - EasyMock.expect(source.getParent()).andReturn(parent).atLeastOnce(); - - source.prepare(); - EasyMock.replay(source); - - EasyMock.expect(outbound.getContainer()).andReturn(source).atLeastOnce(); - EasyMock.replay(outbound); - - parent.register(source); - - AtomicComponent target = EasyMock.createMock(AtomicComponent.class); - EasyMock.expect(target.getName()).andReturn("target").atLeastOnce(); - EasyMock.expect(target.getInboundWire("bar")).andReturn(inbound).atLeastOnce(); - List inboundWires = new ArrayList(); - inboundWires.add(inbound); - EasyMock.expect(target.getInboundWires()).andReturn(inboundWires).atLeastOnce(); - EasyMock.expect(target.getScope()).andReturn(Scope.COMPOSITE).atLeastOnce(); - EasyMock.expect(target.getParent()).andReturn(parent).atLeastOnce(); - - target.prepare(); - target.getOutboundWires(); - EasyMock.expectLastCall().andReturn(Collections.emptyMap()); - EasyMock.expect(target.isSystem()).andReturn(true).atLeastOnce(); - EasyMock.replay(target); - - EasyMock.expect(inbound.getContainer()).andReturn(target); - EasyMock.replay(inbound); - - parent.register(target); - parent.prepare(); - EasyMock.verify(source); - EasyMock.verify(target); - EasyMock.verify(inbound); - EasyMock.verify(outbound); - } - - - /** - * Verifies an application component cannot be wired to a system service in the same composite - */ - public void testSystemServiceIsolationWire() throws Exception { - InboundWire inbound = EasyMock.createMock(InboundWire.class); - EasyMock.expect(inbound.getServiceContract()).andReturn(new JavaServiceContract(Foo.class)).atLeastOnce(); - EasyMock.replay(inbound); - - QualifiedName qName = new QualifiedName("target/bar"); - OutboundWire outbound = EasyMock.createMock(OutboundWire.class); - EasyMock.expect(outbound.isAutowire()).andReturn(false); - EasyMock.expect(outbound.getContainer()).andReturn(EasyMock.createNiceMock(SCAObject.class)); - EasyMock.expect(outbound.getReferenceName()).andReturn("foo"); - EasyMock.expect(outbound.getTargetName()).andReturn(qName).atLeastOnce(); - EasyMock.replay(outbound); - - List wires = new ArrayList(); - wires.add(outbound); - Map> wireMap = new HashMap>(); - wireMap.put("ref", wires); - CompositeComponent parent = new CompositeComponentImpl("foo", "foo", null, new ConnectorImpl(), null); - AtomicComponent source = EasyMock.createMock(AtomicComponent.class); - EasyMock.expect(source.getName()).andReturn("source").atLeastOnce(); - List inboundWires = new ArrayList(); - inboundWires.add(inbound); - source.getInboundWires(); - EasyMock.expectLastCall().andReturn(inboundWires).atLeastOnce(); - EasyMock.expect(source.getOutboundWires()).andReturn(wireMap); - EasyMock.expect(source.isSystem()).andReturn(true).atLeastOnce(); - EasyMock.expect(source.getParent()).andReturn(parent).atLeastOnce(); - EasyMock.replay(source); - - parent.register(source); - - AtomicComponent target = EasyMock.createMock(AtomicComponent.class); - EasyMock.expect(target.getName()).andReturn("target").atLeastOnce(); - inboundWires.add(inbound); - EasyMock.expect(target.getInboundWires()).andReturn(inboundWires).atLeastOnce(); - EasyMock.expect(target.isSystem()).andReturn(false).atLeastOnce(); - EasyMock.replay(target); - - parent.register(target); - try { - parent.prepare(); - fail(); - } catch (PrepareException e) { - //expected - } - EasyMock.verify(source); - EasyMock.verify(target); - EasyMock.verify(inbound); - EasyMock.verify(outbound); - } - - - private class Foo { - - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeComponentImplTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeComponentImplTestCase.java deleted file mode 100644 index eb57c6733d..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeComponentImplTestCase.java +++ /dev/null @@ -1,179 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.util.ArrayList; -import java.util.List; - -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.wire.InboundWire; - -import junit.framework.TestCase; -import org.apache.tuscany.core.implementation.TestUtils; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class CompositeComponentImplTestCase extends TestCase { - - public void testSetUri() throws Exception { - CompositeComponentImpl component = new CompositeComponentImpl("foo", "foo/bar", null, null, null); - assertEquals("foo/bar", component.getURI()); - } - - public void testRegisterSystemService() throws Exception { - List> services = new ArrayList>(); - services.add(Foo.class); - CompositeComponent parent = new CompositeComponentImpl("foo", "foo", null, null, null); - AtomicComponent component = EasyMock.createMock(AtomicComponent.class); - EasyMock.expect(component.getName()).andReturn("bar").atLeastOnce(); - EasyMock.expect(component.isSystem()).andReturn(true).atLeastOnce(); - List wires = TestUtils.createInboundWires(services); - EasyMock.expect(component.getInboundWires()).andReturn(wires).atLeastOnce(); - EasyMock.replay(component); - parent.register(component); - assertNull(parent.getChild("bar")); - assertNotNull(parent.getSystemChild("bar")); - EasyMock.verify(component); - } - - public void testRegister() throws Exception { - List> services = new ArrayList>(); - services.add(Foo.class); - CompositeComponent parent = new CompositeComponentImpl("foo", "foo", null, null, null); - AtomicComponent component = EasyMock.createMock(AtomicComponent.class); - EasyMock.expect(component.getName()).andReturn("bar").atLeastOnce(); - EasyMock.expect(component.isSystem()).andReturn(false).atLeastOnce(); - List wires = TestUtils.createInboundWires(services); - EasyMock.expect(component.getInboundWires()).andReturn(wires).atLeastOnce(); - EasyMock.replay(component); - parent.register(component); - assertNull(parent.getSystemChild("bar")); - assertNotNull(parent.getChild("bar")); - EasyMock.verify(component); - } - - /** - * Verifies a system service and application component can be registered with the same name in a composite - */ - public void testSystemServiceApplicationNamespaceIsolation() throws Exception { - List> services = new ArrayList>(); - services.add(Foo.class); - CompositeComponent parent = new CompositeComponentImpl("foo", "foo", null, null, null); - AtomicComponent component = EasyMock.createMock(AtomicComponent.class); - EasyMock.expect(component.getName()).andReturn("bar").atLeastOnce(); - EasyMock.expect(component.isSystem()).andReturn(true).atLeastOnce(); - List wires = TestUtils.createInboundWires(services); - EasyMock.expect(component.getInboundWires()).andReturn(wires).atLeastOnce(); - EasyMock.replay(component); - parent.register(component); - AtomicComponent component2 = EasyMock.createMock(AtomicComponent.class); - EasyMock.expect(component2.getName()).andReturn("bar").atLeastOnce(); - EasyMock.expect(component2.isSystem()).andReturn(false).atLeastOnce(); - EasyMock.expect(component2.getInboundWires()).andReturn(wires).atLeastOnce(); - EasyMock.replay(component2); - parent.register(component2); - EasyMock.verify(component); - EasyMock.verify(component2); - } - - public void testSystemServiceLifecycle() throws Exception { - List> services = new ArrayList>(); - services.add(Foo.class); - CompositeComponent parent = new CompositeComponentImpl("foo", "foo", null, null, null); - AtomicComponent component = EasyMock.createMock(AtomicComponent.class); - component.start(); - EasyMock.expect(component.getName()).andReturn("bar").atLeastOnce(); - EasyMock.expect(component.isSystem()).andReturn(true).atLeastOnce(); - component.stop(); - List wires = TestUtils.createInboundWires(services); - EasyMock.expect(component.getInboundWires()).andReturn(wires).atLeastOnce(); - EasyMock.replay(component); - parent.register(component); - parent.start(); - parent.stop(); - EasyMock.verify(component); - } - - public void testComponentLifecycle() throws Exception { - List> services = new ArrayList>(); - services.add(Foo.class); - CompositeComponent parent = new CompositeComponentImpl("foo", "foo", null, null, null); - AtomicComponent component = EasyMock.createMock(AtomicComponent.class); - component.start(); - EasyMock.expect(component.getName()).andReturn("bar").atLeastOnce(); - EasyMock.expect(component.isSystem()).andReturn(false).atLeastOnce(); - List wires = TestUtils.createInboundWires(services); - EasyMock.expect(component.getInboundWires()).andReturn(wires).atLeastOnce(); - component.stop(); - EasyMock.replay(component); - parent.register(component); - parent.start(); - parent.stop(); - EasyMock.verify(component); - } - - public void testSystemAutowire() throws Exception { - List> services = new ArrayList>(); - services.add(Foo.class); - CompositeComponent parent = new CompositeComponentImpl("foo", "foo", null, null, null); - AtomicComponent component = EasyMock.createMock(AtomicComponent.class); - component.start(); - EasyMock.expect(component.getName()).andReturn("bar").atLeastOnce(); - EasyMock.expect(component.isSystem()).andReturn(true).atLeastOnce(); - List wires = TestUtils.createInboundWires(services); - EasyMock.expect(component.getInboundWires()).andReturn(wires).atLeastOnce(); - component.stop(); - EasyMock.replay(component); - parent.register(component); - parent.start(); - assertNull(parent.resolveSystemExternalAutowire(Foo.class)); - assertNotNull(parent.resolveSystemAutowire(Foo.class)); - parent.stop(); - EasyMock.verify(component); - } - - - public void testAutowire() throws Exception { - List> services = new ArrayList>(); - services.add(Foo.class); - CompositeComponent parent = new CompositeComponentImpl("foo", "foo", null, null, null); - AtomicComponent component = EasyMock.createMock(AtomicComponent.class); - component.start(); - EasyMock.expect(component.getName()).andReturn("bar").atLeastOnce(); - List wires = TestUtils.createInboundWires(services); - TestUtils.populateInboundWires(component, wires); - EasyMock.expect(component.getInboundWires()).andReturn(wires).atLeastOnce(); - EasyMock.expect(component.isSystem()).andReturn(false).atLeastOnce(); - component.stop(); - EasyMock.replay(component); - parent.register(component); - parent.start(); - assertNull(parent.resolveExternalAutowire(Foo.class)); - assertNotNull(parent.resolveAutowire(Foo.class)); - parent.stop(); - EasyMock.verify(component); - } - - private class Foo { - - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeComponentResolutionTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeComponentResolutionTestCase.java deleted file mode 100644 index f24e1f8e94..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeComponentResolutionTestCase.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.util.ArrayList; -import java.util.List; - -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.wire.InboundWire; - -import junit.framework.TestCase; -import org.apache.tuscany.core.implementation.TestUtils; -import org.apache.tuscany.core.mock.component.Source; -import org.easymock.EasyMock; - -/** - * Verifies an atomic component can be resolved from its parent - * - * @version $$Rev$$ $$Date$$ - */ -public class CompositeComponentResolutionTestCase extends TestCase { - - public void testSystemComponentResolution() throws Exception { - CompositeComponent parent = new CompositeComponentImpl("foo", null, null, true); - parent.start(); - List> interfaces = new ArrayList>(); - interfaces.add(Source.class); - AtomicComponent component = EasyMock.createMock(AtomicComponent.class); - EasyMock.expect(component.getName()).andReturn("source").atLeastOnce(); - EasyMock.expect(component.isSystem()).andReturn(true).atLeastOnce(); - List wires = TestUtils.createInboundWires(interfaces); - TestUtils.populateInboundWires(component, wires); - EasyMock.expect(component.getInboundWires()).andReturn(wires).atLeastOnce(); - EasyMock.replay(component); - parent.register(component); - assertNull(parent.getChild("source")); - assertTrue(parent.getSystemChild("source") instanceof AtomicComponent); - EasyMock.verify(component); - } - - public void testComponentResolution() throws Exception { - CompositeComponent parent = new CompositeComponentImpl("foo", null, null, null); - parent.start(); - List> interfaces = new ArrayList>(); - interfaces.add(Source.class); - AtomicComponent component = EasyMock.createMock(AtomicComponent.class); - EasyMock.expect(component.getName()).andReturn("source").atLeastOnce(); - EasyMock.expect(component.isSystem()).andReturn(false).atLeastOnce(); - List wires = TestUtils.createInboundWires(interfaces); - TestUtils.populateInboundWires(component, wires); - EasyMock.expect(component.getInboundWires()).andReturn(wires).atLeastOnce(); - EasyMock.replay(component); - parent.register(component); - assertNull(parent.getSystemChild("source")); - assertTrue(parent.getChild("source") instanceof AtomicComponent); - EasyMock.verify(component); - } - - - protected void setUp() throws Exception { - super.setUp(); - } - - protected void tearDown() throws Exception { - super.tearDown(); - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeLifecycleTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeLifecycleTestCase.java deleted file mode 100644 index f5d209fe4c..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeLifecycleTestCase.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.util.ArrayList; -import java.util.List; - -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.wire.InboundWire; - -import junit.framework.TestCase; -import org.apache.tuscany.core.implementation.TestUtils; -import org.apache.tuscany.core.mock.component.Source; -import org.easymock.EasyMock; - -/** - * @version $$Rev$$ $$Date$$ - */ -public class CompositeLifecycleTestCase extends TestCase { - - public void testLifecycle() throws Exception { - CompositeComponent composite = new CompositeComponentImpl("foo", null, null, null); - composite.start(); - assertNull(composite.getChild("nothtere")); - composite.stop(); - composite.start(); - assertNull(composite.getChild("nothtere")); - composite.stop(); - } - - public void testSystemRestart() throws Exception { - List> interfaces = new ArrayList>(); - interfaces.add(Source.class); - AtomicComponent component = EasyMock.createMock(AtomicComponent.class); - component.start(); - component.stop(); - EasyMock.expectLastCall().times(2); - EasyMock.expect(component.getName()).andReturn("source").atLeastOnce(); - EasyMock.expect(component.isSystem()).andReturn(true).atLeastOnce(); - - List wires = TestUtils.createInboundWires(interfaces); - TestUtils.populateInboundWires(component, wires); - EasyMock.expect(component.getInboundWires()).andReturn(wires).atLeastOnce(); - - EasyMock.replay(component); - - CompositeComponent composite = new CompositeComponentImpl("foo", null, null, null); - composite.start(); - composite.register(component); - - assertTrue(composite.getSystemChild("source") instanceof AtomicComponent); - composite.stop(); - composite.start(); - assertTrue(composite.getSystemChild("source") instanceof AtomicComponent); - composite.stop(); - EasyMock.verify(component); - } - - public void testRestart() throws Exception { - List> interfaces = new ArrayList>(); - interfaces.add(Source.class); - AtomicComponent component = EasyMock.createMock(AtomicComponent.class); - component.start(); - component.stop(); - EasyMock.expectLastCall().times(2); - EasyMock.expect(component.getName()).andReturn("source").atLeastOnce(); - EasyMock.expect(component.isSystem()).andReturn(false).atLeastOnce(); - - List wires = TestUtils.createInboundWires(interfaces); - TestUtils.populateInboundWires(component, wires); - EasyMock.expect(component.getInboundWires()).andReturn(wires).atLeastOnce(); - - EasyMock.replay(component); - - CompositeComponent composite = new CompositeComponentImpl("foo", null, null, null); - composite.start(); - composite.register(component); - - assertTrue(composite.getChild("source") instanceof AtomicComponent); - composite.stop(); - composite.start(); - assertTrue(composite.getChild("source") instanceof AtomicComponent); - composite.stop(); - EasyMock.verify(component); - } - - public void testChildStoppedBeforeParent() throws Exception { - CompositeComponent parent = new CompositeComponentImpl("parent", null, null, null); - CompositeComponent child = new CompositeComponentImpl("child", null, null, null); - parent.register(child); - parent.start(); - child.stop(); - parent.stop(); - } - - protected void setUp() throws Exception { - super.setUp(); - } - - protected void tearDown() throws Exception { - super.tearDown(); - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeLoaderWireResolutionTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeLoaderWireResolutionTestCase.java deleted file mode 100644 index 9906528a84..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeLoaderWireResolutionTestCase.java +++ /dev/null @@ -1,232 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.InvalidPromotedReferenceException; -import org.apache.tuscany.spi.loader.InvalidWireException; -import org.apache.tuscany.spi.model.ComponentDefinition; -import org.apache.tuscany.spi.model.ComponentReferenceDefinition; -import org.apache.tuscany.spi.model.ComponentTypeReferenceDefinition; -import org.apache.tuscany.spi.model.CompositeComponentType; -import org.apache.tuscany.spi.model.CompositeReferenceDefinition; -import org.apache.tuscany.spi.model.Property; -import org.apache.tuscany.spi.model.AbstractReferenceDefinition; -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> componentType; - private CompositeLoader compositeLoader = new CompositeLoader(null, null); - - public void setUp() throws Exception { - componentType = new CompositeComponentType>(); - componentType.setName("TestComposite"); - //add a service to the composite - ServiceDefinition serviceDefn = new ServiceDefinition("compositeService1", null, true); - ServiceDefinition boundSvcDefn = new ServiceDefinition("boundSvc", null, true, null); - ServiceDefinition boundSvcDefnWithTarget = - new ServiceDefinition("boundSvcWithTarget", null, true); - boundSvcDefnWithTarget.setTarget(new URI("orgTarget")); - componentType.add(serviceDefn); - componentType.add(boundSvcDefn); - componentType.add(boundSvcDefnWithTarget); - - CompositeReferenceDefinition compositeReference = new CompositeReferenceDefinition("compositeReference", null); - componentType.add(compositeReference); - - PojoComponentType> pojoComponentType1 = - new PojoComponentType>(); - ServiceDefinition pojoSvc1 = new ServiceDefinition("pojoSvc1", null, false); - pojoComponentType1.add(pojoSvc1); - ComponentTypeReferenceDefinition pojoRef1 = new ComponentTypeReferenceDefinition("pojoRef1", null); - pojoComponentType1.add(pojoRef1); - JavaImplementation pojoImpl1 = new JavaImplementation(null, pojoComponentType1); - - ComponentDefinition component1 = - new ComponentDefinition("Component1", pojoImpl1); - component1.add(new ComponentReferenceDefinition(pojoRef1)); - componentType.add(component1); - - PojoComponentType> pojoComponentType2 = - new PojoComponentType>(); - ServiceDefinition pojoSvc2 = new ServiceDefinition("pojoSvc2", null, false); - pojoComponentType2.add(pojoSvc2); - ServiceDefinition pojoSvc3 = new ServiceDefinition("pojoSvc3", null, false); - pojoComponentType2.add(pojoSvc3); - ComponentTypeReferenceDefinition pojoRef2 = new ComponentTypeReferenceDefinition("pojoRef2", null); - pojoComponentType2.add(pojoRef2); - ComponentTypeReferenceDefinition pojoRef3 = new ComponentTypeReferenceDefinition("pojoRef3", null); - pojoComponentType2.add(pojoRef3); - JavaImplementation pojoImpl2 = new JavaImplementation(null, pojoComponentType2); - - ComponentDefinition component2 = - new ComponentDefinition("Component2", pojoImpl2); - component2.add(new ComponentReferenceDefinition(pojoRef2)); - component2.add(new ComponentReferenceDefinition(pojoRef3)); - componentType.add(component2); - } - - 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, InvalidPromotedReferenceException { - //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, InvalidPromotedReferenceException { - //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")); - 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, InvalidPromotedReferenceException { - //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 { - //undefined source and targets - WireDefinition wireDefn = new WireDefinition(); - wireDefn.setSource(new URI("Component1")); - wireDefn.setTarget(new URI("Component2/pojoSvc3")); - componentType.add(wireDefn); - compositeLoader.resolveWires(componentType); - } - - public void testComponent2ComponentUnQualifedInvalid() throws URISyntaxException, InvalidPromotedReferenceException { - //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, InvalidPromotedReferenceException { - //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 - } - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositePropagationTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositePropagationTestCase.java deleted file mode 100644 index 36e6e98809..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositePropagationTestCase.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.util.ArrayList; -import java.util.List; - -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.wire.InboundWire; - -import junit.framework.TestCase; -import org.apache.tuscany.core.implementation.TestUtils; -import org.apache.tuscany.core.mock.component.Source; -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$ $Date$ - */ -public class CompositePropagationTestCase extends TestCase { - - private CompositeComponent parent; - private CompositeComponent child2; - - public void testSystemLifecyclePropagation() throws Exception { - parent.start(); - List> interfaces = new ArrayList>(); - interfaces.add(Source.class); - AtomicComponent component = createMock(AtomicComponent.class); - expect(component.getName()).andReturn("source").anyTimes(); - component.stop(); - EasyMock.expect(component.isSystem()).andReturn(true).atLeastOnce(); - List wires = TestUtils.createInboundWires(interfaces); - TestUtils.populateInboundWires(component, wires); - EasyMock.expect(component.getInboundWires()).andReturn(wires).atLeastOnce(); - - replay(component); - child2.register(component); - parent.stop(); - verify(component); - } - - public void testLifecyclePropagation() throws Exception { - parent.start(); - List> interfaces = new ArrayList>(); - interfaces.add(Source.class); - AtomicComponent component = createMock(AtomicComponent.class); - expect(component.getName()).andReturn("source").anyTimes(); - component.stop(); - EasyMock.expect(component.isSystem()).andReturn(false).atLeastOnce(); - List wires = TestUtils.createInboundWires(interfaces); - TestUtils.populateInboundWires(component, wires); - EasyMock.expect(component.getInboundWires()).andReturn(wires).atLeastOnce(); - replay(component); - child2.register(component); - parent.stop(); - verify(component); - } - - - protected void setUp() throws Exception { - super.setUp(); - parent = new CompositeComponentImpl("parent", null, null, null); - CompositeComponent child1 = new CompositeComponentImpl("child1", parent, null, null); - child2 = new CompositeComponentImpl("child2", child1, null, null); - child1.register(child2); - parent.register(child1); - } - - protected void tearDown() throws Exception { - parent.stop(); - super.tearDown(); - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/DuplicateRegistrationTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/DuplicateRegistrationTestCase.java deleted file mode 100644 index 72c2ffd827..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/DuplicateRegistrationTestCase.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.util.ArrayList; -import java.util.List; - -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.component.DuplicateNameException; -import org.apache.tuscany.spi.wire.InboundWire; - -import junit.framework.TestCase; -import org.apache.tuscany.core.implementation.TestUtils; -import org.apache.tuscany.core.mock.component.Source; -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 testDuplicateRegistration() throws Exception { - CompositeComponent parent = new CompositeComponentImpl(null, null, null, null); - parent.start(); - - List> interfaces = new ArrayList>(); - interfaces.add(Source.class); - AtomicComponent component1 = EasyMock.createMock(AtomicComponent.class); - EasyMock.expect(component1.getName()).andReturn("source").atLeastOnce(); - EasyMock.expect(component1.isSystem()).andReturn(true).atLeastOnce(); - component1.stop(); - List wires = TestUtils.createInboundWires(interfaces); - TestUtils.populateInboundWires(component1, wires); - EasyMock.expect(component1.getInboundWires()).andReturn(wires).atLeastOnce(); - EasyMock.replay(component1); - - AtomicComponent component2 = EasyMock.createMock(AtomicComponent.class); - EasyMock.expect(component2.getName()).andReturn("source").atLeastOnce(); - EasyMock.expect(component2.isSystem()).andReturn(true).atLeastOnce(); - component2.stop(); - EasyMock.replay(component2); - - parent.register(component1); - try { - parent.register(component2); - fail(); - } catch (DuplicateNameException e) { - // ok - } - parent.stop(); - } - - public void testDuplicateNameSystemService() throws Exception { - List> services = new ArrayList>(); - services.add(Source.class); - CompositeComponent parent = new CompositeComponentImpl("foo", "foo", null, null, null); - AtomicComponent component = EasyMock.createMock(AtomicComponent.class); - EasyMock.expect(component.getName()).andReturn("bar").atLeastOnce(); - EasyMock.expect(component.isSystem()).andReturn(true).atLeastOnce(); - List wires = TestUtils.createInboundWires(services); - TestUtils.populateInboundWires(component, wires); - EasyMock.expect(component.getInboundWires()).andReturn(wires).atLeastOnce(); - EasyMock.replay(component); - parent.register(component); - AtomicComponent component2 = EasyMock.createMock(AtomicComponent.class); - EasyMock.expect(component2.getName()).andReturn("bar").atLeastOnce(); - EasyMock.expect(component2.isSystem()).andReturn(true).atLeastOnce(); - EasyMock.replay(component2); - try { - parent.register(component2); - fail(); - } catch (DuplicateNameException e) { - // expected - } - } - - - protected void setUp() throws Exception { - super.setUp(); - } - - protected void tearDown() throws Exception { - super.tearDown(); - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/ImplementationCompositeLoaderTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/ImplementationCompositeLoaderTestCase.java deleted file mode 100644 index 7d4ebc1ac3..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/ImplementationCompositeLoaderTestCase.java +++ /dev/null @@ -1,194 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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, 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, 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, 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, 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/JavaObjectRegistrationTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/JavaObjectRegistrationTestCase.java deleted file mode 100644 index f0fdd8b704..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/JavaObjectRegistrationTestCase.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.component.DuplicateNameException; -import org.apache.tuscany.spi.component.SCAObject; - -import junit.framework.TestCase; -import org.apache.tuscany.core.component.event.CompositeStart; -import org.apache.tuscany.core.component.event.CompositeStop; - -/** - * @version $Rev$ $Date$ - */ -public class JavaObjectRegistrationTestCase extends TestCase { - private CompositeComponent composite; - - public void testRegistration() throws Exception { - MockComponent instance = new MockComponent(); - composite.registerJavaObject("foo", MockComponent.class, instance); - SCAObject child = composite.getSystemChild("foo"); - assertTrue(child instanceof AtomicComponent); - MockComponent resolvedInstance = (MockComponent) ((AtomicComponent) child).getTargetInstance(); - assertSame(instance, resolvedInstance); - } - - public void testDuplicateRegistration() throws Exception { - MockComponent instance = new MockComponent(); - composite.registerJavaObject("foo", MockComponent.class, instance); - try { - composite.registerJavaObject("foo", MockComponent.class, instance); - fail(); - } catch (DuplicateNameException e) { - // ok - } - } - - public void testSystemAutowireToObject() throws Exception { - MockComponent instance = new MockComponent(); - composite.registerJavaObject("foo", MockComponent.class, instance); - assertSame(instance, composite.resolveSystemAutowire(MockComponent.class).getTargetService()); - assertNull(composite.resolveSystemExternalAutowire(MockComponent.class)); - } - - public void testApplicationAutowireToObject() throws Exception { - MockComponent instance = new MockComponent(); - composite.registerJavaObject("foo", MockComponent.class, instance); - assertNotNull(composite.resolveAutowire(MockComponent.class)); - assertNull(composite.resolveExternalAutowire(MockComponent.class)); - } - - protected void setUp() throws Exception { - super.setUp(); - composite = new CompositeComponentImpl(null, null, null, null); - composite.start(); - composite.publish(new CompositeStart(this, null)); - } - - protected void tearDown() throws Exception { - composite.publish(new CompositeStop(this, null)); - composite.stop(); - super.tearDown(); - } - - private static class MockComponent { - public String hello(String message) { - return message; - } - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/ManagedRequestContextTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/ManagedRequestContextTestCase.java deleted file mode 100644 index 12299e762b..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/ManagedRequestContextTestCase.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/ReferenceImplTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/ReferenceImplTestCase.java deleted file mode 100644 index 251833a554..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/ReferenceImplTestCase.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.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.setReference(EasyMock.isA(Reference.class)); - binding.start(); - EasyMock.replay(binding); - Reference reference = new ReferenceImpl(null, null, null); - reference.addReferenceBinding(binding); - reference.start(); - EasyMock.verify(binding); - - } - - public void testStop() { - ReferenceBinding binding = EasyMock.createMock(ReferenceBinding.class); - binding.setReference(EasyMock.isA(Reference.class)); - binding.stop(); - EasyMock.replay(binding); - Reference reference = new ReferenceImpl(null, null, null); - reference.addReferenceBinding(binding); - reference.stop(); - EasyMock.verify(binding); - - } - - public void testIsSystem() { - Reference service = new ReferenceImpl(null, null, null, true); - assertTrue(service.isSystem()); - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/ServiceImplTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/ServiceImplTestCase.java deleted file mode 100644 index 88d40a50eb..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/ServiceImplTestCase.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.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.setService(EasyMock.isA(Service.class)); - binding.start(); - EasyMock.replay(binding); - Service service = new ServiceImpl(null, null, null); - service.addServiceBinding(binding); - service.start(); - EasyMock.verify(binding); - - } - - public void testStop() { - ServiceBinding binding = EasyMock.createMock(ServiceBinding.class); - binding.setService(EasyMock.isA(Service.class)); - binding.stop(); - EasyMock.replay(binding); - Service service = new ServiceImpl(null, null, null); - service.addServiceBinding(binding); - service.stop(); - EasyMock.verify(binding); - - } - - public void testIsSystem() { - Service service = new ServiceImpl(null, null, null, null, true); - assertTrue(service.isSystem()); - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/SystemComponentBuilderTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/SystemComponentBuilderTestCase.java deleted file mode 100644 index 4645075a7a..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/SystemComponentBuilderTestCase.java +++ /dev/null @@ -1,180 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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 org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.CompositeComponent; -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.CompositeStart; -import org.apache.tuscany.core.component.event.CompositeStop; -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 { - - CompositeComponent parent; - DeploymentContext deploymentContext; - SystemComponentBuilder builder = new SystemComponentBuilder(); - CompositeScopeContainer container; - - /** - * Verifies lifecycle callbacks are made - */ - public void testLifecycleBuild() throws Exception { - PojoComponentType> type = - new PojoComponentType>(); - 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 ctorDef = new ConstructorDefinition(FooImpl.class.getConstructor()); - type.setConstructorDefinition(ctorDef); - SystemImplementation impl = new SystemImplementation(); - impl.setComponentType(type); - impl.setImplementationClass(FooImpl.class); - ComponentDefinition definition = new ComponentDefinition(impl); - AtomicComponent component = builder.build(parent, definition, deploymentContext); - component.setScopeContainer(container); - component.start(); - container.onEvent(new CompositeStart(this, null)); - FooImpl foo = (FooImpl) component.getTargetInstance(); - assertTrue(foo.initialized); - container.onEvent(new CompositeStop(this, null)); - assertTrue(foo.destroyed); - } - - /** - * Verifies properties are built properly - */ - public void testPropertyBuild() throws Exception { - PojoComponentType> type = - new PojoComponentType>(); - 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 ctorDef = new ConstructorDefinition(FooImpl.class.getConstructor()); - type.setConstructorDefinition(ctorDef); - SystemImplementation impl = new SystemImplementation(); - impl.setComponentType(type); - impl.setImplementationClass(FooImpl.class); - ComponentDefinition definition = new ComponentDefinition(impl); - PropertyValue propVal = new PropertyValue(); - propVal.setName("prop"); - propVal.setValueFactory(new SingletonObjectFactory("value")); - definition.add(propVal); - AtomicComponent component = builder.build(parent, definition, deploymentContext); - component.setScopeContainer(container); - component.start(); - FooImpl foo = (FooImpl) component.getTargetInstance(); - assertEquals("value", foo.prop); - container.onEvent(new CompositeStop(this, null)); - } - - protected void setUp() throws Exception { - super.setUp(); - parent = EasyMock.createNiceMock(CompositeComponent.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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/SystemSingletonAtomicComponentTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/SystemSingletonAtomicComponentTestCase.java deleted file mode 100644 index 9c482b994f..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/SystemSingletonAtomicComponentTestCase.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.util.ArrayList; -import java.util.List; - -import org.apache.tuscany.spi.component.TargetException; - -import junit.framework.TestCase; - -/** - * @version $Rev$ $Date$ - */ -public class SystemSingletonAtomicComponentTestCase extends TestCase { - - public void testGetInstance() throws TargetException { - FooImpl foo = new FooImpl(); - SystemSingletonAtomicComponent component = - new SystemSingletonAtomicComponent("foo", null, Foo.class, foo); - assertEquals(foo, component.getTargetInstance()); - } - - public void testGetInstanceMultipleServices() throws TargetException { - FooImpl foo = new FooImpl(); - List> services = new ArrayList>(); - services.add(Foo.class); - services.add(Bar.class); - SystemSingletonAtomicComponent component = - new SystemSingletonAtomicComponent("foo", null, services, foo); - assertEquals(foo, component.getTargetInstance()); - } - - private interface Foo { - - } - - private interface Bar { - - } - - private class FooImpl implements Foo, Bar { - - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaAtomicComponentMetadataInjectionTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaAtomicComponentMetadataInjectionTestCase.java deleted file mode 100644 index 5186119345..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaAtomicComponentMetadataInjectionTestCase.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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 @ComponentName and @SCAObject 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaAtomicComponentNegativeMetadataTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaAtomicComponentNegativeMetadataTestCase.java deleted file mode 100644 index dfd62c8c53..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaAtomicComponentNegativeMetadataTestCase.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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 @ComponentName specified on a non-String type generates an error. - *

- * NB: the test assumes an error with a message containing "@ComponentName" is generated - */ - public void testBadNameType() throws Exception { - // TODO implement - } - - /** - * Tests that a pojo with @Context specified on a non-CompositeContext type generates an error. - *

- * NB: the test assumes an error with a message containing "@Context" is generated - */ - public void testContextType() throws Exception { - // TODO implement - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaBuilderPropertyTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaBuilderPropertyTestCase.java deleted file mode 100644 index d484a5d944..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaBuilderPropertyTestCase.java +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.ObjectFactory; -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.CompositeComponent; -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.ComponentTypeReferenceDefinition; -import org.apache.tuscany.spi.model.PropertyValue; -import org.apache.tuscany.spi.model.AbstractReferenceDefinition; -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 CompositeComponent parent; - private ScopeRegistry registry; - - @SuppressWarnings("unchecked") - public void testPropertyHandling() throws Exception { - JavaComponentBuilder builder = new JavaComponentBuilder(); - builder.setScopeRegistry(registry); - PojoComponentType> type = - new PojoComponentType>(); - JavaMappedProperty property = new JavaMappedProperty(); - property.setName("test"); - property.setDefaultValueFactory(new SingletonObjectFactory("foo")); - property.setMember(JavaBuilderPropertyTestCase.Foo.class.getMethod("setTest", String.class)); - type.add(property); - type.setConstructorDefinition(new ConstructorDefinition(Foo.class.getConstructor((Class[]) null))); - type.setImplementationScope(Scope.STATELESS); - JavaImplementation impl = new JavaImplementation(Foo.class, type); - ComponentDefinition definition = new ComponentDefinition(impl); - PropertyValue propertyValue = new PropertyValue(property.getName(), property.getDefaultValueFactory()); - definition.getPropertyValues().put(property.getName(), propertyValue); - AtomicComponent component = builder.build(parent, 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> type = - new PojoComponentType>(); - JavaMappedProperty property = new JavaMappedProperty(); - property.setName("test"); - property.setDefaultValueFactory(new SingletonObjectFactory(1)); - property.setMember(JavaBuilderPropertyTestCase.FooInt.class.getMethod("setTest", Integer.TYPE)); - type.add(property); - type.setConstructorDefinition(new ConstructorDefinition(FooInt.class.getConstructor((Class[]) null))); - type.setImplementationScope(Scope.STATELESS); - JavaImplementation impl = new JavaImplementation(Foo.class, type); - ComponentDefinition definition = new ComponentDefinition(impl); - ObjectFactory defaultValueFactory = property.getDefaultValueFactory(); - PropertyValue propertyValue = - new PropertyValue(property.getName(), defaultValueFactory); - definition.getPropertyValues().put(property.getName(), propertyValue); - AtomicComponent component = builder.build(parent, 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(CompositeComponent.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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderConversationIDTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderConversationIDTestCase.java deleted file mode 100644 index 5c83af0e7d..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderConversationIDTestCase.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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 org.apache.tuscany.core.component.WorkContextImpl; -import org.apache.tuscany.spi.component.CompositeComponent; -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.easymock.EasyMock; -import org.osoa.sca.annotations.ConversationID; - -/** - * @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 ctorDef = new ConstructorDefinition(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); - ComponentDefinition definition = new ComponentDefinition("foo", impl); - CompositeComponent parent = EasyMock.createMock(CompositeComponent.class); - JavaAtomicComponent component = (JavaAtomicComponent) builder.build(parent, definition, null); - Foo foo = (Foo) component.createInstance(); - assertEquals("convID", foo.conversationID); - } - - private static class Foo { - - @ConversationID - protected String conversationID; - - public Foo() { - } - - } -} - - diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderMetadataTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderMetadataTestCase.java deleted file mode 100644 index e4adae73d3..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderMetadataTestCase.java +++ /dev/null @@ -1,112 +0,0 @@ -package org.apache.tuscany.core.implementation.java; - -import java.lang.reflect.Constructor; - -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.component.ScopeContainer; -import org.apache.tuscany.spi.deployer.DeploymentContext; -import org.apache.tuscany.spi.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 constructor; - private CompositeComponent parent; - private PojoComponentType> type; - private ComponentDefinition definition; - private ScopeContainer scopeContainer; - - public void testInitLevel() throws Exception { - type.setInitLevel(1); - JavaComponentBuilder builder = new JavaComponentBuilder(); - JavaAtomicComponent component = (JavaAtomicComponent) builder.build(parent, definition, deploymentContext); - assertEquals(1, component.getInitLevel()); - } - - public void testMaxAge() throws Exception { - type.setMaxAge(100); - JavaComponentBuilder builder = new JavaComponentBuilder(); - JavaAtomicComponent component = (JavaAtomicComponent) builder.build(parent, definition, deploymentContext); - assertEquals(100, component.getMaxAge()); - } - - public void testMaxIdleTime() throws Exception { - type.setMaxIdleTime(100); - JavaComponentBuilder builder = new JavaComponentBuilder(); - JavaAtomicComponent component = (JavaAtomicComponent) builder.build(parent, definition, deploymentContext); - assertEquals(100, component.getMaxIdleTime()); - } - - public void testNoMaxAgeNoMaxIdleTime() throws Exception { - JavaComponentBuilder builder = new JavaComponentBuilder(); - JavaAtomicComponent component = (JavaAtomicComponent) builder.build(parent, definition, deploymentContext); - assertEquals(-1, component.getMaxAge()); - assertEquals(-1, component.getMaxIdleTime()); - } - - public void testScope() throws Exception { - JavaComponentBuilder builder = new JavaComponentBuilder(); - JavaAtomicComponent component = (JavaAtomicComponent) builder.build(parent, definition, deploymentContext); - component.setScopeContainer(scopeContainer); - assertEquals(Scope.COMPOSITE, component.getScope()); - } - - protected void setUp() throws Exception { - super.setUp(); - parent = new CompositeComponentImpl(null, null, null, null); - 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>(); - type.setImplementationScope(Scope.COMPOSITE); - JavaMappedReference reference = new JavaMappedReference(); - reference.setName("target"); - reference.setMember(SourceImpl.class.getMethod("setTarget", Target.class)); - type.add(reference); - ServiceContract contract = new JavaServiceContract(Source.class); - JavaMappedService serviceDefinition = new JavaMappedService(); - serviceDefinition.setName("Source"); - serviceDefinition.setServiceContract(contract); - type.add(serviceDefinition); - type.setConstructorDefinition(new ConstructorDefinition(constructor)); - JavaImplementation sourceImpl = new JavaImplementation(SourceImpl.class, type); - definition = new ComponentDefinition(sourceImpl); - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderReferenceTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderReferenceTestCase.java deleted file mode 100644 index c9d1f93a57..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderReferenceTestCase.java +++ /dev/null @@ -1,149 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.util.Collections; -import java.util.HashMap; -import java.util.Map; - -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.component.SCAObject; -import org.apache.tuscany.spi.component.ScopeContainer; -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.InteractionScope; -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.OutboundInvocationChain; -import org.apache.tuscany.spi.wire.OutboundWire; -import org.apache.tuscany.spi.wire.WireService; - -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.JDKWireService; -import org.easymock.EasyMock; -import org.easymock.IAnswer; - -/** - * @version $$Rev$$ $$Date$$ - */ -public class JavaComponentBuilderReferenceTestCase extends TestCase { - private DeploymentContext deploymentContext; - private WireService wireService; - private Constructor constructor; - private CompositeComponent parent; - private OutboundWire wire; - private ScopeContainer scopeContainer; - - public void testBuildReference() throws Exception { - - PojoComponentType> sourceType = - new PojoComponentType>(); - sourceType.setImplementationScope(Scope.COMPOSITE); - JavaMappedReference reference = new JavaMappedReference(); - reference.setName("target"); - reference.setMember(SourceImpl.class.getMethod("setTarget", Target.class)); - sourceType.add(reference); - ServiceContract contract = new JavaServiceContract(Source.class); - JavaMappedService serviceDefinition = new JavaMappedService(); - serviceDefinition.setName("Source"); - serviceDefinition.setServiceContract(contract); - sourceType.add(serviceDefinition); - sourceType.setConstructorDefinition(new ConstructorDefinition(constructor)); - JavaImplementation sourceImpl = new JavaImplementation(SourceImpl.class, sourceType); - ComponentDefinition definition = new ComponentDefinition(sourceImpl); - - JavaComponentBuilder builder = new JavaComponentBuilder(); - builder.setWireService(wireService); - JavaAtomicComponent component = (JavaAtomicComponent) builder.build(parent, definition, deploymentContext); - component.setScopeContainer(scopeContainer); - component.addOutboundWire(wire); - deploymentContext.getCompositeScope().start(); - component.start(); - - Source source = (Source) component.getTargetInstance(); - assertNotNull(source.getTarget()); - component.stop(); - } - - protected void setUp() throws Exception { - super.setUp(); - wireService = new JDKWireService(); - parent = new CompositeComponentImpl(null, null, null, null); - 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() { - private Map cache = new HashMap(); - - 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() { - SCAObject scaObject = EasyMock.createNiceMock(SCAObject.class); - Map, OutboundInvocationChain> chains = Collections.emptyMap(); - wire = EasyMock.createMock(OutboundWire.class); - EasyMock.expect(wire.getReferenceName()).andReturn("target").atLeastOnce(); - EasyMock.expect(wire.getInvocationChains()).andReturn(chains).atLeastOnce(); - EasyMock.expect(wire.isOptimizable()).andReturn(false); - JavaServiceContract targetContract = new JavaServiceContract(Target.class); - targetContract.setInteractionScope(InteractionScope.NONCONVERSATIONAL); - EasyMock.expect(wire.getServiceContract()).andReturn(targetContract).atLeastOnce(); - EasyMock.expect(wire.getContainer()).andReturn(scaObject).atLeastOnce(); - EasyMock.replay(wire); - - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderResourceTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderResourceTestCase.java deleted file mode 100644 index f5ee684e0b..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderResourceTestCase.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.component.CompositeComponent; -import org.apache.tuscany.spi.component.ScopeContainer; -import org.apache.tuscany.spi.component.ScopeRegistry; -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.InboundWire; - -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); - JavaComponentBuilder builder = new JavaComponentBuilder(); - builder.setScopeRegistry(registry); - ConstructorDefinition ctorDef = new ConstructorDefinition(Foo.class.getConstructor()); - PojoComponentType type = new PojoComponentType(); - Resource resource = new Resource(); - resource.setType(String.class); - resource.setName("resource"); - resource.setMember(Foo.class.getDeclaredField("resource")); - type.add(resource); - type.setImplementationScope(Scope.STATELESS); - type.setConstructorDefinition(ctorDef); - JavaImplementation impl = new JavaImplementation(Foo.class, type); - ComponentDefinition definition = new ComponentDefinition("foo", impl); - InboundWire resourceWire = EasyMock.createMock(InboundWire.class); - EasyMock.expect(resourceWire.getTargetService()).andReturn("result"); - EasyMock.replay(resourceWire); - - CompositeComponent parent = EasyMock.createMock(CompositeComponent.class); - EasyMock.expect(parent.resolveSystemAutowire(String.class)).andReturn(resourceWire); - EasyMock.replay(parent); - JavaAtomicComponent component = (JavaAtomicComponent) builder.build(parent, definition, null); - Foo foo = (Foo) component.createInstance(); - assertEquals("result", foo.resource); - EasyMock.verify(parent); - } - - private static class Foo { - - protected String resource; - - public Foo() { - } - - } -} - - diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentTypeLoaderTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentTypeLoaderTestCase.java deleted file mode 100644 index ef74c86d2e..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentTypeLoaderTestCase.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.component.CompositeComponent; -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( - (CompositeComponent) EasyMock.isNull(), - (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(null, new JavaImplementation(), null); - EasyMock.verify(registry); - } - - @SuppressWarnings("unchecked") - public void testPojoComponentTypeCreatedForSideFileLoadAndReturned() throws Exception { - LoaderRegistry registry = EasyMock.createMock(LoaderRegistry.class); - registry.load( - (CompositeComponent) EasyMock.isNull(), - 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()[1]; - } - }); - EasyMock.replay(registry); - JavaComponentTypeLoader loader = new JavaComponentTypeLoader(registry, null); - assertEquals(PojoComponentType.class, loader.loadFromSidefile(null, null, null).getClass()); - EasyMock.verify(registry); - } - - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaReferenceWireTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaReferenceWireTestCase.java deleted file mode 100644 index 0fe6df8b6b..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaReferenceWireTestCase.java +++ /dev/null @@ -1,153 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.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.OutboundInvocationChain; -import org.apache.tuscany.spi.wire.OutboundWire; -import org.apache.tuscany.spi.wire.WireService; - -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 ctr = SourceImpl.class.getConstructor(); - configuration.setInstanceFactory(new PojoObjectFactory(ctr)); - OutboundWire wire = EasyMock.createMock(OutboundWire.class); - wire.getInvocationChains(); - EasyMock.expectLastCall().andReturn(new HashMap, OutboundInvocationChain>()).atLeastOnce(); - EasyMock.expect(wire.getReferenceName()).andReturn("target").atLeastOnce(); - EasyMock.expect(wire.isOptimizable()).andReturn(false); - EasyMock.replay(wire); - WireService service = EasyMock.createMock(WireService.class); - EasyMock.expect(service.createProxy(EasyMock.eq(Target.class), EasyMock.eq(wire), EasyMock.isA(Map.class))) - .andAnswer(new IAnswer() { - public Target answer() throws Throwable { - OutboundWire wire = (OutboundWire) EasyMock.getCurrentArguments()[1]; - wire.getInvocationChains(); - return target; - } - - }).atLeastOnce(); - EasyMock.replay(service); - configuration.setWireService(service); - configuration.setName("source"); - JavaAtomicComponent component = new JavaAtomicComponent(configuration); - component.setScopeContainer(scope); - component.addOutboundWire(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() { - private Map cache = new HashMap(); - - 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerBasicInvocationTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerBasicInvocationTestCase.java deleted file mode 100644 index 30f7948673..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerBasicInvocationTestCase.java +++ /dev/null @@ -1,188 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.wire.InboundWire; -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; - -public class JavaTargetInvokerBasicInvocationTestCase extends TestCase { - private Method echoMethod; - private Method arrayMethod; - private Method nullParamMethod; - private Method primitiveMethod; - private Method checkedMethod; - private Method runtimeMethod; - private InboundWire 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(InboundWire.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, wire, context, monitor); - 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, wire, context, monitor); - - 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, wire, context, monitor); - 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, wire, context, monitor); - 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, wire, context, monitor); - 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, wire, context, monitor); - 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerMediationTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerMediationTestCase.java deleted file mode 100644 index 936673d0a6..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerMediationTestCase.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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, 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerNonBlockingInvocationTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerNonBlockingInvocationTestCase.java deleted file mode 100644 index 25466a01ff..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerNonBlockingInvocationTestCase.java +++ /dev/null @@ -1,229 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.InboundWire; -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 InboundWire wire; - 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.setCurrentCorrelationId(id); - EasyMock.replay(context); - Method method = AsyncTarget.class.getMethod("invoke"); - method.setAccessible(true); - InboundWire wire = EasyMock.createMock(InboundWire.class); - JavaTargetInvoker invoker = new JavaTargetInvoker(method, component, wire, context, monitor); - 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); - wire = EasyMock.createNiceMock(InboundWire.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, wire, context, monitor); - 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, wire, context, monitor); - - 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, wire, context, monitor); - 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, wire, context, monitor); - 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, wire, context, monitor); - 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, wire, context, monitor); - 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerSequenceTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerSequenceTestCase.java deleted file mode 100644 index acb2ed5e14..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerSequenceTestCase.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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, 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, 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, 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, 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerStatelessDestroyTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerStatelessDestroyTestCase.java deleted file mode 100644 index c87649f99e..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerStatelessDestroyTestCase.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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, 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerTestCase.java deleted file mode 100644 index 043af2d891..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerTestCase.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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, 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/MultiplicityTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/MultiplicityTestCase.java deleted file mode 100644 index ba478c9634..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/MultiplicityTestCase.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/ResourceInjectionTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/ResourceInjectionTestCase.java deleted file mode 100644 index f4cc56f158..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/ResourceInjectionTestCase.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.util.ArrayList; -import java.util.List; - -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.component.ScopeContainer; -import org.apache.tuscany.spi.wire.InboundWire; - -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 ctor = Foo.class.getConstructor(); - Field field = Foo.class.getDeclaredField("resource"); - PojoConfiguration configuration = new PojoConfiguration(); - configuration.setName("component"); - configuration.setInstanceFactory(new PojoObjectFactory(ctor)); - configuration.addResourceSite("bar", field); - JavaAtomicComponent component = new JavaAtomicComponent(configuration); - component.setScopeContainer(containter); - - InboundWire wire = EasyMock.createMock(InboundWire.class); - EasyMock.expect(wire.getTargetService()).andReturn("result"); - EasyMock.replay(wire); - - CompositeComponent parent = EasyMock.createMock(CompositeComponent.class); - EasyMock.expect(parent.resolveSystemAutowire(EasyMock.eq(String.class))).andReturn(wire); - EasyMock.replay(parent); - ResourceObjectFactory factory = new ResourceObjectFactory(String.class, false, parent, null); - component.addResourceFactory("bar", factory); - - Foo foo = (Foo) component.createInstance(); - assertEquals("result", foo.resource); - EasyMock.verify(parent); - } - - - public void testResourceConstructorInjection() throws Exception { - ScopeContainer containter = EasyMock.createNiceMock(ScopeContainer.class); - Constructor ctor = FooConstructor.class.getConstructor(String.class); - PojoConfiguration configuration = new PojoConfiguration(); - configuration.setName("component"); - configuration.setInstanceFactory(new PojoObjectFactory(ctor)); - List ctorNames = new ArrayList(); - ctorNames.add("bar"); - configuration.setConstructorParamNames(ctorNames); - JavaAtomicComponent component = new JavaAtomicComponent(configuration); - component.setScopeContainer(containter); - - InboundWire wire = EasyMock.createMock(InboundWire.class); - EasyMock.expect(wire.getTargetService()).andReturn("result"); - EasyMock.replay(wire); - CompositeComponent parent = EasyMock.createMock(CompositeComponent.class); - - EasyMock.expect(parent.resolveSystemAutowire(EasyMock.eq(String.class))).andReturn(wire); - EasyMock.replay(parent); - ResourceObjectFactory factory = new ResourceObjectFactory(String.class, false, parent, null); - component.addResourceFactory("bar", factory); - - FooConstructor foo = (FooConstructor) component.createInstance(); - assertEquals("result", foo.resource); - EasyMock.verify(parent); - } - - 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/integration/CallbackInvocationTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/integration/CallbackInvocationTestCase.java deleted file mode 100644 index 898f89383a..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/integration/CallbackInvocationTestCase.java +++ /dev/null @@ -1,395 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.CompositeComponent; -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.ComponentReferenceDefinition; -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 org.apache.tuscany.spi.wire.WireService; - -import junit.framework.TestCase; -import org.apache.tuscany.core.builder.ConnectorImpl; -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.JDKWireService; -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 WireService wireService; - private WorkScheduler scheduler; - private WorkContext workContext; - - /** - * Verifies callback wires are built and callback invocations are handled properly - */ - public void testComponentToComponentCallback() throws Exception { - ComponentDefinition targetDefinition = createTarget(); - JavaAtomicComponent fooComponent = - (JavaAtomicComponent) builder.build(null, targetDefinition, context); - fooComponent.setScopeContainer(container); - wireService.createWires(fooComponent, targetDefinition); - container.register(fooComponent); - - CompositeComponent parent = createMock(CompositeComponent.class); - parent.getChild(isA(String.class)); - expectLastCall().andReturn(fooComponent).anyTimes(); - replay(parent); - - ComponentDefinition sourceDefinition = createSource("fooClient"); - JavaAtomicComponent clientComponent = - (JavaAtomicComponent) builder.build(parent, sourceDefinition, context); - clientComponent.setScopeContainer(container); - wireService.createWires(clientComponent, sourceDefinition); - container.register(clientComponent); - - Connector connector = new ConnectorImpl(new JDKWireService(), null, scheduler, workContext); - - connector.connect(clientComponent); - 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 { - ComponentDefinition targetDefinition = createTarget(); - JavaAtomicComponent fooComponent = - (JavaAtomicComponent) builder.build(null, targetDefinition, context); - fooComponent.setScopeContainer(container); - wireService.createWires(fooComponent, targetDefinition); - container.register(fooComponent); - - CompositeComponent parent = createMock(CompositeComponent.class); - parent.getChild(isA(String.class)); - expectLastCall().andReturn(fooComponent).anyTimes(); - replay(parent); - - ComponentDefinition sourceDefinition = createPlainSource("fooPlainClient"); - JavaAtomicComponent clientComponent = - (JavaAtomicComponent) builder.build(parent, sourceDefinition, context); - clientComponent.setScopeContainer(container); - wireService.createWires(clientComponent, sourceDefinition); - container.register(clientComponent); - - Connector connector = new ConnectorImpl(new JDKWireService(), null, scheduler, workContext); - - connector.connect(clientComponent); - FooPlainClient client = (FooPlainClient) clientComponent.getTargetInstance(); - try { - client.invoke(); - fail(); - } catch (NoRegisteredCallbackException e) { - // expected - } - } - - /** - * 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 targetDefinition = createTarget(); - JavaAtomicComponent fooComponent = - (JavaAtomicComponent) builder.build(null, targetDefinition, context); - fooComponent.setScopeContainer(container); - wireService.createWires(fooComponent, targetDefinition); - container.register(fooComponent); - - CompositeComponent parent = createMock(CompositeComponent.class); - parent.getChild(isA(String.class)); - expectLastCall().andReturn(fooComponent).anyTimes(); - replay(parent); - - ComponentDefinition sourceDefinition1 = createSource("fooCleint1"); - ComponentDefinition sourceDefinition2 = createSource("fooCleint2"); - JavaAtomicComponent clientComponent1 = - (JavaAtomicComponent) builder.build(parent, sourceDefinition1, context); - clientComponent1.setScopeContainer(container); - wireService.createWires(clientComponent1, sourceDefinition1); - container.register(clientComponent1); - JavaAtomicComponent clientComponent2 = - (JavaAtomicComponent) builder.build(parent, sourceDefinition2, context); - clientComponent2.setScopeContainer(container); - wireService.createWires(clientComponent2, sourceDefinition2); - container.register(clientComponent2); - - Connector connector = new ConnectorImpl(new JDKWireService(), null, scheduler, workContext); - connector.connect(clientComponent1); - connector.connect(clientComponent2); - FooClient client1 = (FooClient) clientComponent1.getTargetInstance(); - client1.invoke(); - assertTrue(client1.invoked); - FooClient client2 = (FooClient) clientComponent2.getTargetInstance(); - client2.invoke(); - assertTrue(client2.invoked); - } - - - private ComponentDefinition createTarget() throws NoSuchMethodException, - InvalidServiceContractException { - ConstructorDefinition ctorDef = new ConstructorDefinition(FooImpl.class.getConstructor()); - PojoComponentType> type = - new PojoComponentType>(); - 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("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("foo", impl); - } - - private ComponentDefinition createSource(String name) - throws NoSuchMethodException, URISyntaxException, InvalidServiceContractException { - ConstructorDefinition ctorDef = - new ConstructorDefinition(FooClient.class.getConstructor()); - PojoComponentType> type = - new PojoComponentType>(); - 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("foo", contract, method); - type.getReferences().put("foo", mappedReference); - ReferenceTarget refTarget = new ReferenceTarget(); - refTarget.setReferenceName("foo"); - refTarget.getTargets().add(new URI("foo")); - JavaImplementation impl = new JavaImplementation(FooClient.class, type); - impl.setComponentType(type); - impl.setImplementationClass(FooClient.class); - ComponentDefinition def = new ComponentDefinition(name, impl); - ComponentReferenceDefinition compRef = new ComponentReferenceDefinition(type.getReferences().get("foo")); - compRef.addTarget(new URI("foo")); - def.add(compRef); - //def.getReferenceTargets().put("foo", refTarget); - return def; - } - - private ComponentDefinition createPlainSource(String name) - throws NoSuchMethodException, URISyntaxException, InvalidServiceContractException { - ConstructorDefinition ctorDef = - new ConstructorDefinition(FooPlainClient.class.getConstructor()); - PojoComponentType> type = - new PojoComponentType>(); - 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("foo", contract, method); - type.getReferences().put("foo", mappedReference); - ReferenceTarget refTarget = new ReferenceTarget(); - refTarget.setReferenceName("foo"); - refTarget.getTargets().add(new URI("foo")); - JavaImplementation impl = new JavaImplementation(FooPlainClient.class, type); - ComponentDefinition def = new ComponentDefinition(name, impl); - ComponentReferenceDefinition compRef = new ComponentReferenceDefinition(type.getReferences().get("foo")); - compRef.addTarget(new URI("foo")); - def.add(compRef); - //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(); - wireService = new JDKWireService(); - 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() { - 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.setWireService(new JDKWireService(workContext, null)); - builder.setWorkScheduler(scheduler); - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/integration/OutboundWireToJavaTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/integration/OutboundWireToJavaTestCase.java deleted file mode 100644 index f2d88955e4..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/integration/OutboundWireToJavaTestCase.java +++ /dev/null @@ -1,233 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.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.QualifiedName; -import org.apache.tuscany.spi.builder.WiringException; -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.component.ScopeContainer; -import org.apache.tuscany.spi.component.WorkContext; -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.InteractionScope; -import org.apache.tuscany.spi.model.Operation; -import org.apache.tuscany.spi.model.Scope; -import org.apache.tuscany.spi.model.ServiceContract; -import org.apache.tuscany.spi.wire.InboundWire; -import org.apache.tuscany.spi.wire.OutboundInvocationChain; -import org.apache.tuscany.spi.wire.OutboundWire; -import org.apache.tuscany.spi.wire.WireService; - -import junit.framework.TestCase; -import org.apache.tuscany.core.builder.ConnectorImpl; -import org.apache.tuscany.core.component.WorkContextImpl; -import org.apache.tuscany.core.component.event.CompositeStart; -import org.apache.tuscany.core.component.event.CompositeStop; -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.integration.mock.MockFactory; -import org.apache.tuscany.core.mock.component.Target; -import org.apache.tuscany.core.mock.component.TargetImpl; -import org.apache.tuscany.core.wire.OutboundInvocationChainImpl; -import org.apache.tuscany.core.wire.OutboundWireImpl; -import org.apache.tuscany.core.wire.jdk.JDKWireService; -import org.easymock.EasyMock; - -/** - * Validates wiring from a wire to Java atomic component by scope - * - * @version $$Rev$$ $$Date$$ - */ -public class OutboundWireToJavaTestCase extends TestCase { - private WorkContext workContext = new WorkContextImpl(); - private WireService wireService = new JDKWireService(new WorkContextImpl(), null); - - public void testToStatelessScope() throws Exception { - StatelessScopeContainer scope = new StatelessScopeContainer(workContext, null); - scope.start(); - final OutboundWire wire = getWire(scope); - Target service = wireService.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 OutboundWire wire = getWire(scope); - Target service = wireService.createProxy(Target.class, wire); - assertNotNull(service); - service.setString("foo"); - - // another request - Executor executor = Executors.newSingleThreadExecutor(); - FutureTask future = new FutureTask(new Runnable() { - public void run() { - scope.onEvent(new RequestStart(this)); - Target service2 = wireService.createProxy(Target.class, wire); - Target target2 = wireService.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 OutboundWire wire = getWire(scope); - Target service = wireService.createProxy(Target.class, wire); - Target target = wireService.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 = wireService.createProxy(Target.class, wire); - assertNotNull(service2); - assertNull(service2.getString()); - Target target2 = wireService.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 CompositeStart(this, null)); - final OutboundWire wire = getWire(scope); - Target service = wireService.createProxy(Target.class, wire); - Target target = wireService.createProxy(Target.class, wire); - assertNotNull(service); - service.setString("foo"); - assertEquals("foo", service.getString()); - assertEquals("foo", target.getString()); - scope.onEvent(new CompositeStop(this, null)); - scope.stop(); - } - - private OutboundWire getWire(ScopeContainer scope) throws NoSuchMethodException, - InvalidServiceContractException, WiringException { - ConnectorImpl connector = new ConnectorImpl(); - CompositeComponent parent = EasyMock.createMock(CompositeComponent.class); - PojoConfiguration configuration = new PojoConfiguration(); - configuration.setInstanceFactory(new PojoObjectFactory(TargetImpl.class.getConstructor())); - configuration.setParent(parent); - configuration.setWorkContext(workContext); - configuration.setName("source"); - - JavaAtomicComponent source = new JavaAtomicComponent(configuration); - source.setScopeContainer(scope); - OutboundWire outboundWire = createOutboundWire(new QualifiedName("target/Target"), Target.class); - outboundWire.setContainer(source); - source.addOutboundWire(outboundWire); - configuration.setName("target"); - JavaAtomicComponent target = new JavaAtomicComponent(configuration); - target.setScopeContainer(scope); - InboundWire targetWire = MockFactory.createInboundWire("Target", Target.class); - targetWire.setContainer(target); - target.addInboundWire(targetWire); - InboundWire inboundWire = target.getInboundWire("Target"); - inboundWire.setContainer(target); - - EasyMock.expect(parent.getChild("target")).andReturn(target); - EasyMock.replay(parent); - - connector.connect(source); - target.start(); - return outboundWire; - } - - private static OutboundWire createOutboundWire(QualifiedName targetName, Class interfaze) - throws InvalidServiceContractException { - OutboundWire wire = new OutboundWireImpl(); - JavaServiceContract contract = new JavaServiceContract(interfaze); - contract.setInteractionScope(InteractionScope.NONCONVERSATIONAL); - wire.setServiceContract(contract); - wire.setTargetName(targetName); - wire.addInvocationChains(createInvocationChains(interfaze)); - return wire; - } - - private static Map, OutboundInvocationChain> createInvocationChains(Class interfaze) - throws InvalidServiceContractException { - Map, OutboundInvocationChain> invocations = new HashMap, OutboundInvocationChain>(); - JavaInterfaceProcessorRegistry registry = new JavaInterfaceProcessorRegistryImpl(); - ServiceContract contract = registry.introspect(interfaze); - for (Operation operation : contract.getOperations().values()) { - OutboundInvocationChain chain = new OutboundInvocationChainImpl(operation); - invocations.put(operation, chain); - } - return invocations; - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/AllowsPassByReferenceProcessorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/AllowsPassByReferenceProcessorTestCase.java deleted file mode 100644 index 9fd3fbfc9d..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/AllowsPassByReferenceProcessorTestCase.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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> type; - AllowsPassByReferenceProcessor processor; - - public void testClassAnnotation() throws Exception { - processor.visitClass(null, Foo.class, type, null); - assertEquals(true, type.isAllowsPassByReference()); - - processor.visitClass(null, Bar.class, type, null); - assertEquals(false, type.isAllowsPassByReference()); - } - - protected void setUp() throws Exception { - super.setUp(); - type = new PojoComponentType>(); - processor = new AllowsPassByReferenceProcessor(); - } - - @AllowsPassByReference - private class Foo { - } - - //no annotation - private class Bar { - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorAutowireTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorAutowireTestCase.java deleted file mode 100644 index c67d226b41..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorAutowireTestCase.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.annotation.Autowire; -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 ConstructorAutowireTestCase extends TestCase { - - ConstructorProcessor processor = - new ConstructorProcessor(new ImplementationProcessorServiceImpl(new JavaInterfaceProcessorRegistryImpl())); - - public void testAutowire() throws Exception { - PojoComponentType> type = - new PojoComponentType>(); - Constructor ctor = Foo.class.getConstructor(Bar.class); - processor.visitConstructor(null, ctor, type, null); - assertNotNull(type.getReferences().get("myRef")); - } - - public void testNamesOnConstructor() throws Exception { - PojoComponentType> type = - new PojoComponentType>(); - Constructor ctor = Foo.class.getConstructor(Bar.class, Bar.class); - processor.visitConstructor(null, ctor, type, null); - assertEquals(2, type.getConstructorDefinition().getInjectionNames().size()); - assertNotNull(type.getReferences().get("myRef1")); - assertNotNull(type.getReferences().get("myRef2")); - } - - public void testNoName() throws Exception { - PojoComponentType> type = - new PojoComponentType>(); - Constructor ctor = Foo2.class.getConstructor(Bar.class); - processor.visitConstructor(null, ctor, type, null); - assertNotNull(type.getReferences().get(Bar.class.getName() + "0")); - } - - public void testInvalidNumberOfNames() throws Exception { - PojoComponentType> type = - new PojoComponentType>(); - Constructor ctor = BadFoo.class.getConstructor(Bar.class, Bar.class); - try { - processor.visitConstructor(null, ctor, type, null); - fail(); - } catch (InvalidAutowireException e) { - // expected - } - } - - public void testNoMatchingNames() throws Exception { - PojoComponentType> type = - new PojoComponentType>(); - Constructor ctor = BadFoo.class.getConstructor(List.class, List.class); - try { - processor.visitConstructor(null, ctor, type, null); - fail(); - } catch (InvalidConstructorException e) { - // expected - } - } - - /** - * Verifies processing executes with additional extension annotations - */ - public void testRandomAnnotation() throws Exception { - PojoComponentType> type = - new PojoComponentType>(); - Constructor ctor = Foo3.class.getConstructor(String.class, String.class); - processor.visitConstructor(null, ctor, type, null); - assertEquals(1, type.getProperties().size()); - assertNotNull(type.getProperties().get("prop1")); - } - - private static interface Bar { - - } - - private static class Foo { - - @org.osoa.sca.annotations.Constructor() - public Foo(@Autowire(name = "myRef") Bar ref) { - - } - - @org.osoa.sca.annotations.Constructor({"myRef1", "myRef2"}) - public Foo(@Autowire Bar ref1, @Autowire Bar ref2) { - - } - - } - - private static class Foo2 { - @org.osoa.sca.annotations.Constructor() - public Foo2(@Autowire Bar ref) { - - } - } - - private static class BadFoo { - - @org.osoa.sca.annotations.Constructor({"ref1"}) - public BadFoo(@Autowire Bar ref1, @Autowire Bar ref2) { - - } - - @org.osoa.sca.annotations.Constructor({"myRef", "myRef2"}) - public BadFoo(@Autowire List ref, @Autowire(name = "myOtherRef") List ref2) { - - } - - } - - public static class Foo3 { - - @org.osoa.sca.annotations.Constructor - public Foo3(@Property(name = "prop1") String prop, @Baz String baz) { - } - } - - public @interface Baz { - - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorProcessorExtensibilityTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorProcessorExtensibilityTestCase.java deleted file mode 100644 index 25a8ab9a1a..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorProcessorExtensibilityTestCase.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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> type = - new PojoComponentType>(); - Constructor ctor1 = Foo.class.getConstructor(String.class, String.class); - processor.visitConstructor(null, 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> type = - new PojoComponentType>(); - Constructor ctor1 = Foo.class.getConstructor(String.class, String.class); - ConstructorDefinition definition = new ConstructorDefinition(ctor1); - definition.getInjectionNames().add(""); - definition.getInjectionNames().add("mybar"); - type.setConstructorDefinition(definition); - processor.visitConstructor(null, 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorProcessorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorProcessorTestCase.java deleted file mode 100644 index 4e48523e8c..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorProcessorTestCase.java +++ /dev/null @@ -1,185 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.annotation.Autowire; -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> type = - new PojoComponentType>(); - try { - processor.visitClass(null, BadFoo.class, type, null); - fail(); - } catch (DuplicateConstructorException e) { - // expected - } - } - - public void testConstructorAnnotation() throws Exception { - PojoComponentType> type = - new PojoComponentType>(); - Constructor ctor1 = Foo.class.getConstructor(String.class); - processor.visitConstructor(null, ctor1, type, null); - assertEquals("foo", type.getConstructorDefinition().getInjectionNames().get(0)); - } - - public void testNoAnnotation() throws Exception { - PojoComponentType> type = - new PojoComponentType>(); - Constructor ctor1 = NoAnnotation.class.getConstructor(); - processor.visitConstructor(null, ctor1, type, null); - assertNull(type.getConstructorDefinition()); - } - - public void testBadAnnotation() throws Exception { - PojoComponentType> type = - new PojoComponentType>(); - Constructor ctor1 = BadAnnotation.class.getConstructor(String.class, Foo.class); - try { - processor.visitConstructor(null, ctor1, type, null); - fail(); - } catch (InvalidConstructorException e) { - // expected - } - } - - public void testMixedParameters() throws Exception { - PojoComponentType> type = - new PojoComponentType>(); - Constructor ctor1 = Mixed.class.getConstructor(String.class, String.class, String.class); - processor.visitConstructor(null, ctor1, type, null); - assertEquals("java.lang.String0", type.getConstructorDefinition().getInjectionNames().get(0)); - assertEquals("foo", type.getConstructorDefinition().getInjectionNames().get(1)); - assertEquals("bar", type.getConstructorDefinition().getInjectionNames().get(2)); - } - - public void testAllAutowireWithNoNames() throws Exception { - PojoComponentType> type = - new PojoComponentType>(); - Constructor ctor1 = - AllAutowireNoName.class.getConstructor(String.class, String.class, String.class); - processor.visitConstructor(null, ctor1, type, null); - assertEquals("java.lang.String0", type.getConstructorDefinition().getInjectionNames().get(0)); - assertEquals("java.lang.String1", type.getConstructorDefinition().getInjectionNames().get(1)); - assertEquals("java.lang.String2", 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(@Autowire String param1, - @Property(name = "foo")String param2, - @Reference(name = "bar")String param3) { - } - } - - public static final class AllAutowireNoName { - @org.osoa.sca.annotations.Constructor - public AllAutowireNoName(@Autowire String param1, @Autowire String param2, @Autowire String param3) { - } - } - - public static final class Multiple { - @org.osoa.sca.annotations.Constructor - public Multiple(@Autowire Collection param1, - @Property(name = "foo")String[] param2, - @Reference(name = "bar", required = true)List param3, - @Property(name = "abc")Set param4, - @Reference(name = "xyz")String[] param5) { - } - } - - public void testMultiplicity() throws Exception { - PojoComponentType> type = - new PojoComponentType>(); - Constructor ctor1 = - Multiple.class.getConstructor(Collection.class, String[].class, List.class, Set.class, String[].class); - processor.visitConstructor(null, ctor1, type, null); - JavaMappedReference ref0 = type.getReferences().get("java.util.Collection0"); - assertNotNull(ref0); - assertEquals(Multiplicity.ONE_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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorPropertyTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorPropertyTestCase.java deleted file mode 100644 index fb125ca0f4..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorPropertyTestCase.java +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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 junit.framework.TestCase; - -import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl; -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 org.osoa.sca.annotations.Property; - -/** - * @version $Rev$ $Date$ - */ -public class ConstructorPropertyTestCase extends TestCase { - - ConstructorProcessor processor = - new ConstructorProcessor(new ImplementationProcessorServiceImpl(new JavaInterfaceProcessorRegistryImpl())); - - public void testProperty() throws Exception { - PojoComponentType> type = - new PojoComponentType>(); - Constructor ctor = Foo.class.getConstructor(String.class); - processor.visitConstructor(null, ctor, type, null); - JavaMappedProperty property = type.getProperties().get("myProp"); - assertEquals(property.isMustSupply(), true); - assertEquals("myProp", property.getName()); - } - - public void testTwoPropertiesSameType() throws Exception { - PojoComponentType> type = - new PojoComponentType>(); - Constructor ctor = Foo.class.getConstructor(String.class, String.class); - processor.visitConstructor(null, ctor, type, null); - assertNotNull(type.getProperties().get("myProp1")); - assertNotNull(type.getProperties().get("myProp2")); - } - - public void testDuplicateProperty() throws Exception { - PojoComponentType> type = - new PojoComponentType>(); - Constructor ctor = BadFoo.class.getConstructor(String.class, String.class); - try { - processor.visitConstructor(null, ctor, type, null); - fail(); - } catch (DuplicatePropertyException e) { - // expected - } - } - - public void testNoName() throws Exception { - PojoComponentType> type = - new PojoComponentType>(); - Constructor ctor = BadFoo.class.getConstructor(String.class); - try { - processor.visitConstructor(null, ctor, type, null); - fail(); - } catch (InvalidPropertyException e) { - // expected - } - } - - public void testNamesOnConstructor() throws Exception { - PojoComponentType> type = - new PojoComponentType>(); - Constructor ctor = Foo.class.getConstructor(Integer.class); - processor.visitConstructor(null, ctor, type, null); - assertNotNull(type.getProperties().get("myProp")); - } - - public void testInvalidNumberOfNames() throws Exception { - PojoComponentType> type = - new PojoComponentType>(); - Constructor ctor = BadFoo.class.getConstructor(Integer.class, Integer.class); - try { - processor.visitConstructor(null, ctor, type, null); - fail(); - } catch (InvalidPropertyException e) { - // expected - } - } - - public void testNoMatchingNames() throws Exception { - PojoComponentType> type = - new PojoComponentType>(); - Constructor ctor = BadFoo.class.getConstructor(List.class, List.class); - try { - processor.visitConstructor(null, 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorReferenceTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorReferenceTestCase.java deleted file mode 100644 index 152f3b63d1..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorReferenceTestCase.java +++ /dev/null @@ -1,172 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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 { - - ConstructorProcessor processor; - - public void testReference() throws Exception { - PojoComponentType> type = - new PojoComponentType>(); - Constructor ctor = Foo.class.getConstructor(String.class); - processor.visitConstructor(null, ctor, type, null); - JavaMappedReference reference = type.getReferences().get("myRef"); - assertEquals("myRef", reference.getName()); - } - - public void testTwoReferencesSameType() throws Exception { - PojoComponentType> type = - new PojoComponentType>(); - Constructor ctor = Foo.class.getConstructor(String.class, String.class); - processor.visitConstructor(null, ctor, type, null); - assertNotNull(type.getReferences().get("myRef1")); - assertNotNull(type.getReferences().get("myRef2")); - } - - public void testDuplicateProperty() throws Exception { - PojoComponentType> type = - new PojoComponentType>(); - Constructor ctor = BadFoo.class.getConstructor(String.class, String.class); - try { - processor.visitConstructor(null, ctor, type, null); - fail(); - } catch (DuplicateReferenceException e) { - // expected - } - } - - public void testNoName() throws Exception { - PojoComponentType> type = - new PojoComponentType>(); - Constructor ctor = BadFoo.class.getConstructor(String.class); - try { - processor.visitConstructor(null, ctor, type, null); - fail(); - } catch (InvalidReferenceException e) { - // expected - } - } - - public void testNamesOnConstructor() throws Exception { - PojoComponentType> type = - new PojoComponentType>(); - Constructor ctor = Foo.class.getConstructor(Integer.class); - processor.visitConstructor(null, ctor, type, null); - assertNotNull(type.getReferences().get("myRef")); - } - - public void testInvalidNumberOfNames() throws Exception { - PojoComponentType> type = - new PojoComponentType>(); - Constructor ctor = BadFoo.class.getConstructor(Integer.class, Integer.class); - try { - processor.visitConstructor(null, ctor, type, null); - fail(); - } catch (InvalidReferenceException e) { - // expected - } - } - - public void testNoMatchingNames() throws Exception { - PojoComponentType> type = - new PojoComponentType>(); - Constructor ctor = BadFoo.class.getConstructor(List.class, List.class); - try { - processor.visitConstructor(null, 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 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorResourceTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorResourceTestCase.java deleted file mode 100644 index c691a4d6bc..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorResourceTestCase.java +++ /dev/null @@ -1,166 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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> type = - new PojoComponentType>(); - Constructor ctor = Foo.class.getConstructor(String.class); - processor.visitConstructor(null, ctor, type, null); - org.apache.tuscany.spi.implementation.java.Resource resource = type.getResources().get("myResource"); - assertFalse(resource.isOptional()); - } - - public void testTwoResourcesSameType() throws Exception { - PojoComponentType> type = - new PojoComponentType>(); - Constructor ctor = Foo.class.getConstructor(String.class, String.class); - processor.visitConstructor(null, ctor, type, null); - assertNotNull(type.getResources().get("myResource1")); - assertNotNull(type.getResources().get("myResource2")); - } - - public void testDuplicateResource() throws Exception { - PojoComponentType> type = - new PojoComponentType>(); - Constructor ctor = BadFoo.class.getConstructor(String.class, String.class); - try { - processor.visitConstructor(null, ctor, type, null); - fail(); - } catch (DuplicateResourceException e) { - // expected - } - } - - public void testNoName() throws Exception { - PojoComponentType> type = - new PojoComponentType>(); - Constructor ctor = - ConstructorResourceTestCase.BadFoo.class.getConstructor(String.class); - try { - processor.visitConstructor(null, ctor, type, null); - fail(); - } catch (InvalidResourceException e) { - // expected - } - } - - public void testNamesOnConstructor() throws Exception { - PojoComponentType> type = - new PojoComponentType>(); - Constructor ctor = Foo.class.getConstructor(Integer.class); - processor.visitConstructor(null, ctor, type, null); - assertNotNull(type.getResources().get("myResource")); - } - - public void testInvalidNumberOfNames() throws Exception { - PojoComponentType> type = - new PojoComponentType>(); - Constructor ctor = - ConstructorResourceTestCase.BadFoo.class.getConstructor(Integer.class, Integer.class); - try { - processor.visitConstructor(null, ctor, type, null); - fail(); - } catch (InvalidResourceException e) { - // expected - } - } - - public void testNoMatchingNames() throws Exception { - PojoComponentType> type = - new PojoComponentType>(); - Constructor ctor = - ConstructorResourceTestCase.BadFoo.class.getConstructor(List.class, List.class); - try { - processor.visitConstructor(null, 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ContextProcessorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ContextProcessorTestCase.java deleted file mode 100644 index 1ad92bfee9..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ContextProcessorTestCase.java +++ /dev/null @@ -1,197 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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 junit.framework.TestCase; -import org.easymock.EasyMock; -import org.osoa.sca.ComponentContext; -import org.osoa.sca.RequestContext; -import org.osoa.sca.annotations.Context; - -import org.apache.tuscany.spi.component.CompositeComponent; -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 org.apache.tuscany.spi.wire.WireService; - -/** - * @version $Rev$ $Date$ - */ -public class ContextProcessorTestCase extends TestCase { - private ContextProcessor processor; - private CompositeComponent composite; - - // FIXME: resurrect to test ComponentContext injection -/* - public void testCompositeContextMethod() throws Exception { - Method method = Foo.class.getMethod("setContext", ComponentContext.class); - PojoComponentType> type = - new PojoComponentType>(); - 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> type = - new PojoComponentType>(); - 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> type = - new PojoComponentType>(); - processor.visitMethod(composite, method, type, null); - assertNotNull(type.getResources().get("requestContext")); - } - - public void testRequestContextField() throws Exception { - Field field = Foo.class.getDeclaredField("requestContext"); - PojoComponentType> type = - new PojoComponentType>(); - processor.visitField(composite, field, type, null); - assertNotNull(type.getResources().get("requestContext")); - } - - public void testInvalidParamType() throws Exception { - Method method = Foo.class.getMethod("setContext", String.class); - PojoComponentType> type = - new PojoComponentType>(); - try { - processor.visitMethod(composite, method, type, null); - fail(); - } catch (UnknownContextTypeException e) { - // expected - } - } - - public void testInvalidParamTypeField() throws Exception { - Field field = Foo.class.getDeclaredField("badContext"); - PojoComponentType> type = - new PojoComponentType>(); - try { - processor.visitField(composite, field, type, null); - fail(); - } catch (UnknownContextTypeException e) { - // expected - } - } - - - public void testInvalidParamNum() throws Exception { - Method method = Foo.class.getMethod("setContext", ComponentContext.class, String.class); - PojoComponentType> type = - new PojoComponentType>(); - try { - processor.visitMethod(composite, method, type, null); - fail(); - } catch (IllegalContextException e) { - // expected - } - } - - public void testInvalidNoParams() throws Exception { - Method method = Foo.class.getMethod("setContext"); - PojoComponentType> type = - new PojoComponentType>(); - try { - processor.visitMethod(composite, method, type, null); - fail(); - } catch (IllegalContextException e) { - // expected - } - } - - public void testNoContext() throws Exception { - Method method = Foo.class.getMethod("noContext", ComponentContext.class); - PojoComponentType> type = - new PojoComponentType>(); - processor.visitMethod(composite, method, type, null); - assertEquals(0, type.getResources().size()); - } - - public void testNoContextField() throws Exception { - Field field = Foo.class.getDeclaredField("noContext"); - PojoComponentType> type = - new PojoComponentType>(); - processor.visitField(composite, field, type, null); - assertEquals(0, type.getResources().size()); - } - - protected void setUp() throws Exception { - super.setUp(); - processor = new ContextProcessor(); - processor.setWireService(EasyMock.createNiceMock(WireService.class)); - processor.setWorkContext(EasyMock.createNiceMock(WorkContext.class)); - composite = EasyMock.createNiceMock(CompositeComponent.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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConversationProcessorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConversationProcessorTestCase.java deleted file mode 100644 index 0433fed3a6..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConversationProcessorTestCase.java +++ /dev/null @@ -1,151 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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 junit.framework.TestCase; - -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.osoa.sca.annotations.ConversationAttributes; -import org.osoa.sca.annotations.ConversationID; -import org.osoa.sca.annotations.Scope; - -/** - * @version $Rev$ $Date$ - */ -public class ConversationProcessorTestCase extends TestCase { - private ConversationProcessor processor = new ConversationProcessor(); - - public void testMaxIdleTime() throws Exception { - PojoComponentType> type = - new PojoComponentType>(); - processor.visitClass(null, FooMaxIdle.class, type, null); - assertEquals(10000L, type.getMaxIdleTime()); - assertEquals(-1, type.getMaxAge()); - } - - public void testMaxAge() throws Exception { - PojoComponentType> type = - new PojoComponentType>(); - processor.visitClass(null, FooMaxAge.class, type, null); - assertEquals(10000L, type.getMaxAge()); - assertEquals(-1, type.getMaxIdleTime()); - } - - public void testBadFooBoth() throws Exception { - PojoComponentType> type = - new PojoComponentType>(); - try { - processor.visitClass(null, BadFooBoth.class, type, null); - fail(); - } catch (InvalidConversationalImplementation e) { - // expected - } - } - - public void testImplicitScope() throws Exception { - PojoComponentType> type = - new PojoComponentType>(); - processor.visitClass(null, ImplicitFooScope.class, type, null); - assertEquals(org.apache.tuscany.spi.model.Scope.CONVERSATION, type.getImplementationScope()); - } - - public void testBadFooScope() throws Exception { - PojoComponentType> type = - new PojoComponentType>(); - try { - processor.visitClass(null, BadFooScope.class, type, null); - fail(); - } catch (InvalidConversationalImplementation e) { - // expected - } - } - - public void testJustConversation() throws Exception { - // TODO do we want these semantics - PojoComponentType> type = - new PojoComponentType>(); - processor.visitClass(null, 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> type = - new PojoComponentType>(); - Field field = FooWithConversationIDField.class.getDeclaredField("conversationID"); - processor.visitField(null, field, type, null); - assertNotNull(type.getConversationIDMember()); - assertEquals(field, type.getConversationIDMember()); - } - - public void testSetConversationIDMethod() throws Exception { - PojoComponentType> type = - new PojoComponentType>(); - Method method = FooWithConversationIDMethod.class.getDeclaredMethods()[0]; - processor.visitMethod(null, 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConvertTimeMillisTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConvertTimeMillisTestCase.java deleted file mode 100644 index 556416a797..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConvertTimeMillisTestCase.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/DestroyProcessorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/DestroyProcessorTestCase.java deleted file mode 100644 index 6929250298..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/DestroyProcessorTestCase.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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> type = - new PojoComponentType>(); - Method method = Foo.class.getMethod("destroy"); - processor.visitMethod(null, method, type, null); - assertNotNull(type.getDestroyMethod()); - } - - public void testBadDestroy() throws Exception { - DestroyProcessor processor = new DestroyProcessor(); - PojoComponentType> type = - new PojoComponentType>(); - Method method = Bar.class.getMethod("badDestroy", String.class); - try { - processor.visitMethod(null, method, type, null); - fail(); - } catch (IllegalDestructorException e) { - // expected - } - } - - public void testTwoDestroy() throws Exception { - DestroyProcessor processor = new DestroyProcessor(); - PojoComponentType> type = - new PojoComponentType>(); - Method method = Bar.class.getMethod("destroy"); - Method method2 = Bar.class.getMethod("destroy2"); - processor.visitMethod(null, method, type, null); - try { - processor.visitMethod(null, 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/EagerInitProcessorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/EagerInitProcessorTestCase.java deleted file mode 100644 index 22770cbfce..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/EagerInitProcessorTestCase.java +++ /dev/null @@ -1,54 +0,0 @@ -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> type = - new PojoComponentType>(); - processor.visitClass(null, NoLevel.class, type, null); - assertEquals(50, type.getInitLevel()); - } - - public void testLevel() throws ProcessingException { - EagerInitProcessor processor = new EagerInitProcessor(); - PojoComponentType> type = - new PojoComponentType>(); - processor.visitClass(null, Level.class, type, null); - assertEquals(50, type.getInitLevel()); - } - - public void testSubclass() throws ProcessingException { - EagerInitProcessor processor = new EagerInitProcessor(); - PojoComponentType> type = - new PojoComponentType>(); - processor.visitClass(null, SubClass.class, type, null); - assertEquals(50, type.getInitLevel()); - } - - @EagerInit - private class NoLevel { - } - - @EagerInit - private class Level { - } - - private class SubClass extends Level { - - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicAndPropertyTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicAndPropertyTestCase.java deleted file mode 100644 index 93de605e33..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicAndPropertyTestCase.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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> type = - new PojoComponentType>(); - Constructor ctor = Foo.class.getConstructor(String.class); - type.setConstructorDefinition(new ConstructorDefinition(ctor)); - propertyProcessor.visitConstructor(null, ctor, type, null); - heuristicProcessor.visitEnd(null, 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicConstructorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicConstructorTestCase.java deleted file mode 100644 index 92f6d54366..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicConstructorTestCase.java +++ /dev/null @@ -1,330 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.Property; -import org.osoa.sca.annotations.Reference; -import org.osoa.sca.annotations.Remotable; - -import org.apache.tuscany.spi.annotation.Autowire; -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> type = - new PojoComponentType>(); - JavaMappedProperty prop = new JavaMappedProperty(); - prop.setName("foo"); - prop.setJavaType(String.class); - type.getProperties().put("foo", prop); - processor.visitEnd(null, 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> type = - new PojoComponentType>(); - JavaMappedReference ref = new JavaMappedReference(); - ref.setName("foo"); - ServiceContract contract = new JavaServiceContract(String.class); - ref.setServiceContract(contract); - type.getReferences().put("foo", ref); - processor.visitEnd(null, 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> type = - new PojoComponentType>(); - - JavaMappedProperty prop = new JavaMappedProperty(); - prop.setName("foo"); - prop.setJavaType(String.class); - type.getProperties().put("foo", prop); - - JavaMappedReference ref = new JavaMappedReference(); - ref.setName("ref"); - ServiceContract contract = new JavaServiceContract(Foo1.class); - ref.setServiceContract(contract); - type.getReferences().put("ref", ref); - processor.visitEnd(null, Foo2.class, type, null); - assertNotNull(type.getConstructorDefinition().getConstructor()); - assertEquals(2, type.getConstructorDefinition().getInjectionNames().size()); - } - - - public void testSingleConstructorResolvableParam() throws Exception { - PojoComponentType> type = - new PojoComponentType>(); - processor.visitEnd(null, Foo5.class, type, null); - assertEquals(String.class, type.getProperties().get("string").getJavaType()); - } - - public void testSingleConstructorResolvableRef() throws Exception { - PojoComponentType> type = - new PojoComponentType>(); - processor.visitEnd(null, Foo6.class, type, null); - assertEquals(Ref.class, - type.getReferences().get("heuristicconstructortestcase$ref").getServiceContract().getInterfaceClass()); - } - - public void testSingleConstructorAmbiguousRef() throws Exception { - PojoComponentType> type = - new PojoComponentType>(); - JavaMappedReference ref = new JavaMappedReference(); - ref.setName("ref"); - ServiceContract contract = new JavaServiceContract(Foo1.class); - ref.setServiceContract(contract); - type.getReferences().put("ref", ref); - JavaMappedReference ref2 = new JavaMappedReference(); - ref2.setName("ref2"); - ref2.setServiceContract(contract); - type.getReferences().put("ref2", ref2); - try { - processor.visitEnd(null, Foo4.class, type, null); - fail(); - } catch (AmbiguousConstructorException e) { - // expected - } - } - - public void testConstructorPropertyAnnotatedParamsOnly() throws Exception { - PojoComponentType> type = - new PojoComponentType>(); - processor.visitEnd(null, Foo7.class, type, null); - assertNotNull(type.getProperties().get("myProp")); - } - - public void testConstructorReferenceAnnotatedParamsOnly() throws Exception { - PojoComponentType> type = - new PojoComponentType>(); - processor.visitEnd(null, Foo8.class, type, null); - assertNotNull(type.getReferences().get("myRef")); - } - - public void testConstructorAutowireAnnotatedParamsOnly() throws Exception { - PojoComponentType> type = - new PojoComponentType>(); - processor.visitEnd(null, Foo9.class, type, null); - assertNotNull(type.getReferences().get("myAutowire")); - } - - @SuppressWarnings("unchecked") - public void testDefaultConstructor() throws Exception { - PojoComponentType> type = - new PojoComponentType>(); - processor.visitEnd(null, Foo3.class, type, null); - assertNotNull(type.getConstructorDefinition().getConstructor()); - } - - public void testSameTypesButAnnotated() throws Exception { - PojoComponentType> type = - new PojoComponentType>(); - processor.visitEnd(null, 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> type = - new PojoComponentType>(); - processor.visitEnd(null, Foo11.class, type, null); - assertEquals(1, type.getProperties().size()); - assertNotNull(type.getProperties().get("prop1")); - } - - public void testAutowire() throws Exception { - PojoComponentType> type = - new PojoComponentType>(); - processor.visitEnd(null, Foo13.class, type, null); - assertEquals(1, type.getReferences().size()); - assertNotNull(type.getReferences().get(String.class.getName() + "0")); - } - - public void testMultipleAutowire() throws Exception { - PojoComponentType> type = - new PojoComponentType>(); - processor.visitEnd(null, Foo15.class, type, null); - assertEquals(2, type.getReferences().size()); - assertNotNull(type.getReferences().get(String.class.getName() + "0")); - assertNotNull(type.getReferences().get(String.class.getName() + "1")); - } - - public void testNoAutowireNameInConstructor() throws Exception { - PojoComponentType> type = - new PojoComponentType>(); - processor.visitEnd(null, Foo16.class, type, null); - assertEquals(2, type.getReferences().size()); - assertNotNull(type.getReferences().get(String.class.getName() + "0")); - assertNotNull(type.getReferences().get("bar")); - assertNotNull(type.getProperties().get("foo")); - } - - public void testPrivateConstructor() throws Exception { - PojoComponentType> type = - new PojoComponentType>(); - try { - processor.visitEnd(null, 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(@Autowire(name = "myAutowire") String autowire) { - } - } - - 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(@Autowire String foo) { - } - } - - public static final class Foo14 { - private Foo14() { - } - } - - public static final class Foo15 { - public Foo15(@Autowire String param1, @Autowire String param2) { - } - } - - public static final class Foo16 { - public Foo16(@Autowire String param1, - @Property(name = "foo") String param2, - @Reference(name = "bar") String param3) { - } - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicPojoProcessorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicPojoProcessorTestCase.java deleted file mode 100644 index 2b3c12a3aa..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicPojoProcessorTestCase.java +++ /dev/null @@ -1,395 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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 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> type = - new PojoComponentType>(); - Constructor ctor = SingleInterfaceImpl.class.getConstructor(); - type.setConstructorDefinition(new ConstructorDefinition(ctor)); - processor.visitEnd(null, 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> type = - new PojoComponentType>(); - Constructor ctor = - SingleInterfaceWithPropertyReferenceImpl.class.getConstructor(); - type.setConstructorDefinition(new ConstructorDefinition(ctor)); - processor.visitEnd(null, 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> type = - new PojoComponentType>(); - Constructor ctor = SingleInterfaceImpl.class.getConstructor(); - type.setConstructorDefinition(new ConstructorDefinition(ctor)); - processor.visitEnd(null, 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> type = - new PojoComponentType>(); - Constructor ctor = RefInterfaceImpl.class.getConstructor(); - type.setConstructorDefinition(new ConstructorDefinition(ctor)); - processor.visitEnd(null, 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> type = - new PojoComponentType>(); - Constructor ctor = ReferenceCollectionImpl.class.getConstructor(); - type.setConstructorDefinition(new ConstructorDefinition(ctor)); - processor.visitEnd(null, 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> type = - new PojoComponentType>(); - Constructor ctor = PropertyCollectionImpl.class.getConstructor(); - type.setConstructorDefinition(new ConstructorDefinition(ctor)); - processor.visitEnd(null, 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> type = - new PojoComponentType>(); - Constructor ctor = RemotableRefImpl.class.getConstructor(); - type.setConstructorDefinition(new ConstructorDefinition(ctor)); - processor.visitEnd(null, RemotableRefImpl.class, type, null); - assertEquals(2, type.getReferences().size()); - assertEquals(0, type.getProperties().size()); - } - - public void testParentInterface() throws ProcessingException, NoSuchMethodException { - PojoComponentType> type = - new PojoComponentType>(); - Constructor ctor = Child.class.getConstructor(); - type.setConstructorDefinition(new ConstructorDefinition(ctor)); - processor.visitEnd(null, 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> type = - new PojoComponentType>(); - JavaMappedReference ref = new JavaMappedReference(); - ref.setName("reference"); - type.add(ref); - JavaMappedReference ref2 = new JavaMappedReference(); - ref2.setName("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(null, MockService.class, type, null); - assertEquals(1, type.getServices().size()); - } - - public void testProtectedRemotableRefField() throws ProcessingException, NoSuchMethodException { - PojoComponentType> type = - new PojoComponentType>(); - Constructor ctor = ProtectedRemotableRefFieldImpl.class.getConstructor(); - type.setConstructorDefinition(new ConstructorDefinition(ctor)); - processor.visitEnd(null, ProtectedRemotableRefFieldImpl.class, type, null); - assertNotNull(type.getReferences().get("otherRef")); - } - - public void testProtectedRemotableRefMethod() throws ProcessingException, NoSuchMethodException { - PojoComponentType> type = - new PojoComponentType>(); - Constructor ctor = ProtectedRemotableRefMethodImpl.class.getConstructor(); - type.setConstructorDefinition(new ConstructorDefinition(ctor)); - processor.visitEnd(null, ProtectedRemotableRefMethodImpl.class, type, null); - assertNotNull(type.getReferences().get("otherRef")); - } - - public void testSetDataTypes() throws Exception { - PojoComponentType> type = - new PojoComponentType>(); - Constructor ctor = PropertyIntTypeOnConstructor.class.getConstructor(int.class); - type.setConstructorDefinition(new ConstructorDefinition(ctor)); - processor.visitEnd(null, 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) { - } - - public void setNonGenericCollectionReference(Collection ref) { - } - - public void setListReference(List ref) { - } - - public void setArrayReference(Ref[] ref) { - } - } - - private static class PropertyCollectionImpl implements Interface1 { - public PropertyCollectionImpl() { - } - - public void setCollectionProperty(Collection prop) { - } - - public void setCollectionProperty2(Collection 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeutisticExtensibleConstructorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeutisticExtensibleConstructorTestCase.java deleted file mode 100644 index 4e6c1063d8..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeutisticExtensibleConstructorTestCase.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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> type = - new PojoComponentType>(); - Constructor ctor = Foo.class.getConstructor(String.class, String.class); - ConstructorDefinition definition = new ConstructorDefinition(ctor); - type.setConstructorDefinition(definition); - JavaMappedProperty property = new JavaMappedProperty(); - property.setName("myBar"); - definition.getInjectionNames().add("myBar"); - type.getProperties().put("myBar", property); - processor.visitEnd(null, Foo.class, type, null); - assertEquals(2, type.getProperties().size()); - } - - /** - * Verifies heuristic processing can be called before an extension annotation processors is called. - *

- * For example, given: - *

 Foo(@Bar String prop, @org.osoa.sca.annotations.Property(name = "foo") String prop2)
- *

- * Heuristic evaluation of @Property can occur prior to another implementation processor evaluating @Bar - * - * @throws Exception - */ - public void testBarAnnotationProcessedLast() throws Exception { - PojoComponentType> type = - new PojoComponentType>(); - processor.visitEnd(null, Foo.class, type, null); - - // now simulate process the bar impl - ConstructorDefinition definition = type.getConstructorDefinition(); - List injectionNames = definition.getInjectionNames(); - injectionNames.remove(0); - injectionNames.add(0, "mybar"); - type.getProperties().put("mybar", new JavaMappedProperty()); - - 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> type = - new PojoComponentType>(); - Constructor ctor = Foo2.class.getConstructor(String.class, String.class, String.class); - ConstructorDefinition definition = new ConstructorDefinition(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(null, 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ImplementationProcessorServiceTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ImplementationProcessorServiceTestCase.java deleted file mode 100644 index e843467866..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ImplementationProcessorServiceTestCase.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.Property; -import org.osoa.sca.annotations.Remotable; -import org.osoa.sca.annotations.Scope; - -import org.apache.tuscany.spi.databinding.extension.SimpleTypeMapperExtension; -import org.apache.tuscany.spi.idl.java.JavaInterfaceProcessorRegistry; -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.InteractionScope; -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 JavaInterfaceProcessorRegistry registry = new JavaInterfaceProcessorRegistryImpl(); - private ImplementationProcessorService implService = new ImplementationProcessorServiceImpl(registry); - - - public void testCreateConversationalService() throws Exception { - JavaMappedService service = implService.createService(Foo.class); - service.setServiceContract(registry.introspect(Foo.class, true)); - assertTrue(Foo.class.equals(service.getServiceContract().getInterfaceClass())); - assertTrue(service.isRemotable()); - assertEquals(InteractionScope.CONVERSATIONAL, service.getServiceContract().getInteractionScope()); - 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); - service.setServiceContract(registry.introspect(Baz.class, true)); - assertTrue(Baz.class.equals(service.getServiceContract().getInterfaceClass())); - assertTrue(!service.isRemotable()); - assertEquals(InteractionScope.NONCONVERSATIONAL, service.getServiceContract().getInteractionScope()); - } - - public void testProcessParamProperty() throws Exception { - PojoComponentType> type = - new PojoComponentType>(); - Constructor ctor = PropertyClass.class.getConstructor(int.class); - Annotation[] paramAnnotations = ctor.getParameterAnnotations()[0]; - List injectionNames = new ArrayList(); - 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()); - } - - - @Callback(Bar.class) - @Remotable - @Scope("CONVERSATION") - 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ImplementationProcessorServiceUniqueTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ImplementationProcessorServiceUniqueTestCase.java deleted file mode 100644 index da45ed2d46..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ImplementationProcessorServiceUniqueTestCase.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/InitProcessorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/InitProcessorTestCase.java deleted file mode 100644 index 13fe7d003a..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/InitProcessorTestCase.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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> type = - new PojoComponentType>(); - Method method = InitProcessorTestCase.Foo.class.getMethod("init"); - processor.visitMethod(null, method, type, null); - assertNotNull(type.getInitMethod()); - assertEquals(0, type.getInitLevel()); - } - - public void testBadInit() throws Exception { - InitProcessor processor = new InitProcessor(); - PojoComponentType> type = - new PojoComponentType>(); - Method method = InitProcessorTestCase.Bar.class.getMethod("badInit", String.class); - try { - processor.visitMethod(null, method, type, null); - fail(); - } catch (IllegalInitException e) { - // expected - } - } - - public void testTwoInit() throws Exception { - InitProcessor processor = new InitProcessor(); - PojoComponentType> type = - new PojoComponentType>(); - Method method = InitProcessorTestCase.Bar.class.getMethod("init"); - Method method2 = InitProcessorTestCase.Bar.class.getMethod("init2"); - processor.visitMethod(null, method, type, null); - try { - processor.visitMethod(null, 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/MonitorProcessorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/MonitorProcessorTestCase.java deleted file mode 100644 index 8982fa3991..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/MonitorProcessorTestCase.java +++ /dev/null @@ -1,180 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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> type = - new PojoComponentType>(); - Method method = Foo.class.getMethod("setMonitor", Foo.class); - EasyMock.expect(monitorFactory.getMonitor(EasyMock.eq(Foo.class))).andReturn(null); - EasyMock.replay(monitorFactory); - processor.visitMethod(null, method, type, null); - Map> properties = type.getProperties(); - assertTrue(properties.get("monitor").getDefaultValueFactory() instanceof SingletonObjectFactory); - EasyMock.verify(monitorFactory); - } - - - public void testBadSetter() throws Exception { - PojoComponentType> type = - new PojoComponentType>(); - Method method = BadMonitor.class.getMethod("setMonitor"); - try { - processor.visitMethod(null, method, type, null); - fail(); - } catch (IllegalPropertyException e) { - // expected - } - } - - public void testField() throws Exception { - PojoComponentType> type = - new PojoComponentType>(); - Field field = Foo.class.getDeclaredField("bar"); - EasyMock.expect(monitorFactory.getMonitor(EasyMock.eq(Foo.class))).andReturn(null); - EasyMock.replay(monitorFactory); - processor.visitField(null, field, type, null); - Map> properties = type.getProperties(); - assertTrue(properties.get("bar").getDefaultValueFactory() instanceof SingletonObjectFactory); - EasyMock.verify(monitorFactory); - } - - public void testConstructor() throws Exception { - PojoComponentType> type = - new PojoComponentType>(); - Constructor ctor = Bar.class.getConstructor(BazMonitor.class); - EasyMock.expect(monitorFactory.getMonitor(EasyMock.eq(BazMonitor.class))).andReturn(null); - EasyMock.replay(monitorFactory); - processor.visitConstructor(null, ctor, type, null); - Map> 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> type = - new PojoComponentType>(); - Constructor ctor = Bar.class.getConstructor(String.class, BazMonitor.class); - EasyMock.expect(monitorFactory.getMonitor(EasyMock.eq(BazMonitor.class))).andReturn(null); - EasyMock.replay(monitorFactory); - ConstructorDefinition definition = new ConstructorDefinition(ctor); - JavaMappedProperty prop = new JavaMappedProperty(); - definition.getInjectionNames().add("prop"); - type.setConstructorDefinition(definition); - type.getProperties().put("prop", prop); - processor.visitConstructor(null, ctor, type, null); - Map> 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> type = - new PojoComponentType>(); - Constructor ctor = Bar.class.getConstructor(String.class, BazMonitor.class); - EasyMock.expect(monitorFactory.getMonitor(EasyMock.eq(BazMonitor.class))).andReturn(null); - EasyMock.replay(monitorFactory); - processor.visitConstructor(null, ctor, type, null); - Map> 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/PropertyProcessorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/PropertyProcessorTestCase.java deleted file mode 100644 index a4a60f13a0..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/PropertyProcessorTestCase.java +++ /dev/null @@ -1,204 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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 junit.framework.TestCase; - -import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl; -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 org.osoa.sca.annotations.Property; - -/** - * @version $Rev$ $Date$ - */ -public class PropertyProcessorTestCase extends TestCase { - - PojoComponentType> type; - PropertyProcessor processor; - - public void testMethodAnnotation() throws Exception { - processor.visitMethod(null, Foo.class.getMethod("setFoo", String.class), type, null); - assertNotNull(type.getProperties().get("foo")); - } - - public void testMethodRequired() throws Exception { - processor.visitMethod(null, Foo.class.getMethod("setFooRequired", String.class), type, null); - JavaMappedProperty prop = type.getProperties().get("fooRequired"); - assertNotNull(prop); - } - - public void testMethodName() throws Exception { - processor.visitMethod(null, Foo.class.getMethod("setBarMethod", String.class), type, null); - assertNotNull(type.getProperties().get("bar")); - } - - public void testFieldAnnotation() throws Exception { - processor.visitField(null, Foo.class.getDeclaredField("baz"), type, null); - assertNotNull(type.getProperties().get("baz")); - } - - public void testFieldRequired() throws Exception { - processor.visitField(null, Foo.class.getDeclaredField("bazRequired"), type, null); - JavaMappedProperty prop = type.getProperties().get("bazRequired"); - assertNotNull(prop); - } - - public void testFieldName() throws Exception { - processor.visitField(null, Foo.class.getDeclaredField("bazField"), type, null); - assertNotNull(type.getProperties().get("theBaz")); - } - - public void testDuplicateFields() throws Exception { - processor.visitField(null, Bar.class.getDeclaredField("dup"), type, null); - try { - processor.visitField(null, Bar.class.getDeclaredField("baz"), type, null); - fail(); - } catch (DuplicatePropertyException e) { - // expected - } - } - - public void testDuplicateMethods() throws Exception { - processor.visitMethod(null, Bar.class.getMethod("dupMethod", String.class), type, null); - try { - processor.visitMethod(null, Bar.class.getMethod("dupSomeMethod", String.class), type, null); - fail(); - } catch (DuplicatePropertyException e) { - // expected - } - } - - public void testInvalidProperty() throws Exception { - try { - processor.visitMethod(null, Bar.class.getMethod("badMethod"), type, null); - fail(); - } catch (IllegalPropertyException e) { - // expected - } - } - - protected void setUp() throws Exception { - super.setUp(); - type = new PojoComponentType>(); - 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 refs1; - - @Property - protected String[] refs2; - - @Property - public void setRefs3(String[] refs) { - } - - @Property - public void setRefs4(Collection refs) { - } - - } - - public void testMultiplicityCollection() throws Exception { - processor.visitField(null, 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(null, 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(null, 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(null, 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ReferenceProcessorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ReferenceProcessorTestCase.java deleted file mode 100644 index 80d3687170..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ReferenceProcessorTestCase.java +++ /dev/null @@ -1,225 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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> type = - new PojoComponentType>(); - ReferenceProcessor processor = new ReferenceProcessor(new JavaInterfaceProcessorRegistryImpl()); - - public void testMethodAnnotation() throws Exception { - processor.visitMethod(null, 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(null, - ReferenceProcessorTestCase.Foo.class.getMethod("setFooRequired", Ref.class), - type, - null); - JavaMappedReference prop = type.getReferences().get("fooRequired"); - assertNotNull(prop); - } - - public void testMethodName() throws Exception { - processor.visitMethod(null, - ReferenceProcessorTestCase.Foo.class.getMethod("setBarMethod", Ref.class), - type, - null); - assertNotNull(type.getReferences().get("bar")); - } - - public void testFieldAnnotation() throws Exception { - processor.visitField(null, 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(null, ReferenceProcessorTestCase.Foo.class.getDeclaredField("bazRequired"), type, null); - JavaMappedReference prop = type.getReferences().get("bazRequired"); - assertNotNull(prop); - } - - public void testFieldName() throws Exception { - processor.visitField(null, ReferenceProcessorTestCase.Foo.class.getDeclaredField("bazField"), type, null); - assertNotNull(type.getReferences().get("theBaz")); - } - - public void testDuplicateFields() throws Exception { - processor.visitField(null, ReferenceProcessorTestCase.Bar.class.getDeclaredField("dup"), type, null); - try { - processor.visitField(null, ReferenceProcessorTestCase.Bar.class.getDeclaredField("baz"), type, null); - fail(); - } catch (DuplicateReferenceException e) { - // expected - } - } - - public void testDuplicateMethods() throws Exception { - processor.visitMethod(null, ReferenceProcessorTestCase.Bar.class.getMethod("dupMethod", Ref.class), type, null); - try { - processor.visitMethod(null, - ReferenceProcessorTestCase.Bar.class.getMethod("dupSomeMethod", Ref.class), - type, - null); - fail(); - } catch (DuplicateReferenceException e) { - // expected - } - } - - public void testInvalidProperty() throws Exception { - try { - processor.visitMethod(null, ReferenceProcessorTestCase.Bar.class.getMethod("badMethod"), type, null); - fail(); - } catch (IllegalReferenceException e) { - // expected - } - } - - protected void setUp() throws Exception { - super.setUp(); - type = new PojoComponentType>(); - 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 refs1; - - @Reference(required = false) - protected Ref[] refs2; - - @Reference(required = true) - public void setRefs3(Ref[] refs) { - } - - @Reference(required = false) - public void setRefs4(Collection refs) { - } - - } - - public void testMultiplicity1ToN() throws Exception { - processor.visitField(null, 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()); - } - - public void testMultiplicityTo0ToN() throws Exception { - processor.visitField(null, 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()); - } - - public void testMultiplicity1ToNMethod() throws Exception { - processor.visitMethod(null, 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()); - } - - public void testMultiplicity0ToNMethod() throws Exception { - processor.visitMethod(null, 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()); - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ResourceProcessorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ResourceProcessorTestCase.java deleted file mode 100644 index 96bf4a3ed3..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ResourceProcessorTestCase.java +++ /dev/null @@ -1,99 +0,0 @@ -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> type; - ResourceProcessor processor = new ResourceProcessor(); - - public void testVisitField() throws Exception { - Field field = Foo.class.getDeclaredField("bar"); - processor.visitField(null, 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(null, 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(null, 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(null, method, type, null); - fail(); - } catch (IllegalResourceException e) { - // expected - } - } - - public void testDuplicateResources() throws Exception { - Field field = Foo.class.getDeclaredField("bar"); - processor.visitField(null, field, type, null); - try { - processor.visitField(null, field, type, null); - fail(); - } catch (DuplicateResourceException e) { - //expected - } - } - - protected void setUp() throws Exception { - super.setUp(); - type = new PojoComponentType>(); - } - - 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ScopeProcessorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ScopeProcessorTestCase.java deleted file mode 100644 index dc65dc44f4..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ScopeProcessorTestCase.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.CompositeComponent; -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 { - - CompositeComponent parent; - - public void testCompositeScope() throws ProcessingException { - ScopeProcessor processor = new ScopeProcessor(); - PojoComponentType> type = - new PojoComponentType>(); - - processor.visitClass(parent, Composite.class, type, null); - assertEquals(Scope.COMPOSITE, type.getImplementationScope()); - } - - public void testSessionScope() throws ProcessingException { - ScopeProcessor processor = new ScopeProcessor(); - PojoComponentType> type = - new PojoComponentType>(); - processor.visitClass(parent, Session.class, type, null); - assertEquals(Scope.SESSION, type.getImplementationScope()); - } - - public void testConversationalScope() throws ProcessingException { - ScopeProcessor processor = new ScopeProcessor(); - PojoComponentType> type = - new PojoComponentType>(); - processor.visitClass(parent, Conversation.class, type, null); - assertEquals(Scope.CONVERSATION, type.getImplementationScope()); - } - - public void testRequestScope() throws ProcessingException { - ScopeProcessor processor = new ScopeProcessor(); - PojoComponentType> type = - new PojoComponentType>(); - processor.visitClass(parent, Request.class, type, null); - assertEquals(Scope.REQUEST, type.getImplementationScope()); - } - - public void testSystemScope() throws ProcessingException { - ScopeProcessor processor = new ScopeProcessor(); - PojoComponentType> type = - new PojoComponentType>(); - processor.visitClass(parent, System.class, type, null); - assertEquals(Scope.SYSTEM, type.getImplementationScope()); - } - - public void testStatelessScope() throws ProcessingException { - ScopeProcessor processor = new ScopeProcessor(); - PojoComponentType> type = - new PojoComponentType>(); - processor.visitClass(parent, Stateless.class, type, null); - assertEquals(Scope.STATELESS, type.getImplementationScope()); - } - - public void testNoScope() throws ProcessingException { - ScopeProcessor processor = new ScopeProcessor(); - PojoComponentType> type = - new PojoComponentType>(); - processor.visitClass(parent, None.class, type, null); - assertEquals(Scope.STATELESS, type.getImplementationScope()); - } - - protected void setUp() throws Exception { - super.setUp(); - parent = EasyMock.createNiceMock(CompositeComponent.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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ServiceCallbackTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ServiceCallbackTestCase.java deleted file mode 100644 index 29cae3beae..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ServiceCallbackTestCase.java +++ /dev/null @@ -1,166 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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> type = - new PojoComponentType>(); - processor.visitClass(null, FooImpl.class, type, null); - JavaMappedService service = type.getServices().get(Foo.class.getSimpleName()); - assertNotNull(service); - Method method = FooImpl.class.getMethod("setCallback", FooCallback.class); - processor.visitMethod(null, method, type, null); - assertEquals(method, service.getCallbackMember()); - } - - public void testFieldCallbackInterface() throws Exception { - PojoComponentType> type = - new PojoComponentType>(); - processor.visitClass(null, FooImpl.class, type, null); - JavaMappedService service = type.getServices().get(Foo.class.getSimpleName()); - assertNotNull(service); - Field field = FooImpl.class.getDeclaredField("callback"); - processor.visitField(null, field, type, null); - assertEquals(field, service.getCallbackMember()); - } - - public void testMethodDoesNotMatchCallback() throws Exception { - PojoComponentType> type = - new PojoComponentType>(); - processor.visitClass(null, BadBarImpl.class, type, null); - Method method = BadBarImpl.class.getMethod("setWrongInterfaceCallback", String.class); - try { - processor.visitMethod(null, method, type, null); - fail(); - } catch (IllegalCallbackReferenceException e) { - // expected - } - } - - public void testNoParamCallback() throws Exception { - PojoComponentType> type = - new PojoComponentType>(); - processor.visitClass(null, BadBarImpl.class, type, null); - Method method = BadBarImpl.class.getMethod("setNoParamCallback"); - try { - processor.visitMethod(null, method, type, null); - fail(); - } catch (IllegalCallbackReferenceException e) { - // expected - } - } - - public void testFieldDoesNotMatchCallback() throws Exception { - PojoComponentType> type = - new PojoComponentType>(); - processor.visitClass(null, BadBarImpl.class, type, null); - Field field = BadBarImpl.class.getDeclaredField("wrongInterfaceCallback"); - try { - processor.visitField(null, field, type, null); - fail(); - } catch (IllegalCallbackReferenceException e) { - // expected - } - } - - public void testBadCallbackInterfaceAnnotation() throws Exception { - PojoComponentType> type = - new PojoComponentType>(); - try { - processor.visitClass(null, 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ServiceProcessorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ServiceProcessorTestCase.java deleted file mode 100644 index ed7cc6b8e6..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ServiceProcessorTestCase.java +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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> type; - - public void testMultipleInterfaces() throws Exception { - processor.visitClass(null, 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(null, FooSingle.class, type, null); - assertEquals(1, type.getServices().size()); - assertNotNull(type.getServices().get(Baz.class.getSimpleName())); - } - - public void testMultipleNoService() throws Exception { - processor.visitClass(null, FooMultipleNoService.class, type, null); - assertEquals(0, type.getServices().size()); - } - - public void testRemotableNoService() throws Exception { - processor.visitClass(null, 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(null, BadImpl.class, type, null); - fail(); - } catch (InvalidServiceType e) { - //expected - } - } - - public void testNoInterfaces() throws Exception { - try { - processor.visitClass(null, 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>(); - } - - @Callback(Bar.class) - private interface Baz { - } - - private interface Bar { - } - - @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 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/system/builder/SystemComponentBuilderResourceTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/system/builder/SystemComponentBuilderResourceTestCase.java deleted file mode 100644 index 091f231f37..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/system/builder/SystemComponentBuilderResourceTestCase.java +++ /dev/null @@ -1,75 +0,0 @@ -package org.apache.tuscany.core.implementation.system.builder; - -import junit.framework.TestCase; - -import org.apache.tuscany.core.implementation.system.model.SystemImplementation; -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.CompositeComponent; -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.PojoComponentType; -import org.apache.tuscany.spi.implementation.java.Resource; -import org.apache.tuscany.spi.model.ComponentDefinition; -import org.apache.tuscany.spi.model.ComponentTypeReferenceDefinition; -import org.apache.tuscany.spi.model.Property; -import org.apache.tuscany.spi.model.Scope; -import org.apache.tuscany.spi.model.ServiceDefinition; -import org.apache.tuscany.spi.wire.InboundWire; -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); - SystemComponentBuilder builder = new SystemComponentBuilder(); - builder.setScopeRegistry(registry); - ConstructorDefinition ctorDef = new ConstructorDefinition( - SystemComponentBuilderResourceTestCase.Foo.class.getConstructor()); - PojoComponentType> type = - new PojoComponentType>(); - Resource resource = new Resource(); - resource.setType(String.class); - resource.setName("resource"); - resource.setMember(SystemComponentBuilderResourceTestCase.Foo.class.getDeclaredField("resource")); - type.add(resource); - type.setImplementationScope(Scope.STATELESS); - type.setConstructorDefinition(ctorDef); - SystemImplementation impl = new SystemImplementation(); - impl.setImplementationClass(SystemComponentBuilderResourceTestCase.Foo.class); - impl.setComponentType(type); - ComponentDefinition definition = - new ComponentDefinition("foo", impl); - - InboundWire wire = EasyMock.createMock(InboundWire.class); - EasyMock.expect(wire.getTargetService()).andReturn("result"); - EasyMock.replay(wire); - - CompositeComponent parent = EasyMock.createMock(CompositeComponent.class); - EasyMock.expect(parent.resolveSystemAutowire(String.class)).andReturn(wire); - EasyMock.replay(parent); - AtomicComponent component = builder.build(parent, definition, ctx); - SystemComponentBuilderResourceTestCase.Foo foo = - (SystemComponentBuilderResourceTestCase.Foo) component.createInstance(); - assertEquals("result", foo.resource); - EasyMock.verify(parent); - } - - private static class Foo { - - protected String resource; - - public Foo() { - } - - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/system/component/SystemAtomicComponentTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/system/component/SystemAtomicComponentTestCase.java deleted file mode 100644 index b8789cb8b4..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/system/component/SystemAtomicComponentTestCase.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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 org.apache.tuscany.spi.wire.OutboundWire; - -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 initInvoker; - private EventInvoker destroyInvoker; - - public void testDefaultCreationAndInit() throws Exception { - PojoObjectFactory factory = new PojoObjectFactory(Foo.class.getConstructor((Class[]) null)); - PojoConfiguration configuration = new PojoConfiguration(); - configuration.setInstanceFactory(factory); - configuration.setInitInvoker(initInvoker); - configuration.setName("foo"); - SystemAtomicComponentImpl component = new SystemAtomicComponentImpl(configuration); - Foo foo = (Foo) component.createInstance(); - component.init(foo); - assertTrue(foo.initialized); - } - - public void testDestroy() throws Exception { - PojoObjectFactory factory = new PojoObjectFactory(Foo.class.getConstructor((Class[]) null)); - PojoConfiguration configuration = new PojoConfiguration(); - configuration.setInstanceFactory(factory); - configuration.setDestroyInvoker(destroyInvoker); - configuration.setName("foo"); - SystemAtomicComponentImpl component = new SystemAtomicComponentImpl(configuration); - Foo foo = (Foo) component.createInstance(); - component.destroy(foo); - assertTrue(foo.destroyed); - } - - public void testReferenceAndPropertyConstructor() throws Exception { - PojoObjectFactory factory = new PojoObjectFactory(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("foo"); - SystemAtomicComponentImpl component = new SystemAtomicComponentImpl(configuration); - component.addPropertyFactory("foo", new SingletonObjectFactory("baz")); - Foo target = new Foo(); - OutboundWire wire = EasyMock.createMock(OutboundWire.class); - EasyMock.expect(wire.getTargetService()).andReturn(target); - EasyMock.expect(wire.getReferenceName()).andReturn("ref").anyTimes(); - EasyMock.replay(wire); - component.addOutboundWire(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(Foo.class.getMethod("init")); - destroyInvoker = new MethodEventInvoker(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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/system/component/SystemAtomicComponentWireInvocationTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/system/component/SystemAtomicComponentWireInvocationTestCase.java deleted file mode 100644 index c4a2664228..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/system/component/SystemAtomicComponentWireInvocationTestCase.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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 org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.wire.OutboundWire; - -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.class.getConstructor())); - configuration.setName("source"); - AtomicComponent component = new SystemAtomicComponentImpl(configuration); - component.setScopeContainer(scope); - OutboundWire outboundWire = EasyMock.createMock(OutboundWire.class); - EasyMock.expect(outboundWire.getReferenceName()).andReturn("setTarget").atLeastOnce(); - EasyMock.expect(outboundWire.getTargetService()).andReturn(target); - EasyMock.replay(outboundWire); - component.addOutboundWire(outboundWire); - component.start(); - assertSame(((Source) component.getTargetInstance()).getTarget(), target); - EasyMock.verify(outboundWire); - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/system/loader/SystemComponentTypeLoaderTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/system/loader/SystemComponentTypeLoaderTestCase.java deleted file mode 100644 index bc86d82f34..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/system/loader/SystemComponentTypeLoaderTestCase.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.CompositeComponent; -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.AbstractReferenceDefinition; -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.spi.implementation.java.ImplementationProcessorService; -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 { - CompositeComponent parent = EasyMock.createNiceMock(CompositeComponent.class); - SystemImplementation impl = new SystemImplementation(BasicInterfaceImpl.class); - PojoComponentType componentType = loader.loadByIntrospection(parent, 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()); - AbstractReferenceDefinition 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/system/loader/SystemImplementationLoaderTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/system/loader/SystemImplementationLoaderTestCase.java deleted file mode 100644 index 6cb059d629..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/system/loader/SystemImplementationLoaderTestCase.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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/system/1.0-SNAPSHOT", "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, 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, 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/injection/CallbackWireObjectFactoryTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/injection/CallbackWireObjectFactoryTestCase.java deleted file mode 100644 index 0a3a052024..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/injection/CallbackWireObjectFactoryTestCase.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.wire.WireService; - -import junit.framework.TestCase; -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.expectLastCall; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; - -/** - * @version $Rev$ $Date$ - */ -public class CallbackWireObjectFactoryTestCase extends TestCase { - - public void testCreateInstance() throws Exception { - WireService service = createMock(WireService.class); - service.createCallbackProxy(Foo.class, null); - expectLastCall().andReturn(null); - replay(service); - CallbackWireObjectFactory factory = new CallbackWireObjectFactory(Foo.class, service, null); - factory.getInstance(); - verify(service); - } - - private interface Foo { - - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/injection/FieldInjectorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/injection/FieldInjectorTestCase.java deleted file mode 100644 index d31347f7e6..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/injection/FieldInjectorTestCase.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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 injector = new FieldInjector(protectedField, new SingletonObjectFactory("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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/injection/JNDIObjectFactoryTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/injection/JNDIObjectFactoryTestCase.java deleted file mode 100644 index 91214fd02d..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/injection/JNDIObjectFactoryTestCase.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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 factory = new JNDIObjectFactory(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 factory = new JNDIObjectFactory(ctx, "foo"); - try { - factory.getInstance(); - fail(); - } catch (ObjectCreationException e) { - //expected - } - EasyMock.verify(ctx); - } - - - private class Foo { - - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/injection/MethodEventInvokerTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/injection/MethodEventInvokerTestCase.java deleted file mode 100644 index 3bb882da2d..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/injection/MethodEventInvokerTestCase.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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 injector = new MethodEventInvoker(privateMethod); - try { - injector.invokeEvent(new Foo()); - fail(); - } catch (AssertionError e) { - // expected - } - } - - public void testException() throws Exception { - MethodEventInvoker injector = new MethodEventInvoker(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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/injection/MethodInjectorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/injection/MethodInjectorTestCase.java deleted file mode 100644 index b21ba4ccfa..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/injection/MethodInjectorTestCase.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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 factory = new SingletonObjectFactory(new Object()); - MethodInjector injector = new MethodInjector(fooMethod, factory); - try { - injector.inject(new Foo()); - fail(); - } catch (ObjectCreationException e) { - // expected - } - } - - public void testException() throws Exception { - ObjectFactory factory = new SingletonObjectFactory("foo"); - MethodInjector injector = new MethodInjector(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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/injection/PojoObjectFactoryTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/injection/PojoObjectFactoryTestCase.java deleted file mode 100644 index 7aba6dbab3..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/injection/PojoObjectFactoryTestCase.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.List; -import java.util.ArrayList; - -import org.apache.tuscany.spi.ObjectFactory; - -import junit.framework.TestCase; - -/** - * @version $Rev$ $Date$ - */ -public class PojoObjectFactoryTestCase extends TestCase { - - private Constructor ctor; - - public void testConstructorInjection() throws Exception { - List initializers = new ArrayList(); - initializers.add(new SingletonObjectFactory("foo")); - PojoObjectFactory factory = new PojoObjectFactory(ctor, initializers); - Foo foo = factory.getInstance(); - assertEquals("foo", foo.foo); - } - - public void testConstructorInitializerInjection() throws Exception { - PojoObjectFactory factory = new PojoObjectFactory(ctor); - factory.setInitializerFactory(0, new SingletonObjectFactory("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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/injection/RequestContextObjectFactoryTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/injection/RequestContextObjectFactoryTestCase.java deleted file mode 100644 index a1a41bbada..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/injection/RequestContextObjectFactoryTestCase.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/injection/ResourceObjectFactoryTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/injection/ResourceObjectFactoryTestCase.java deleted file mode 100644 index 073bda1458..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/injection/ResourceObjectFactoryTestCase.java +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.AtomicComponent; -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.host.ResourceHost; -import org.apache.tuscany.spi.wire.InboundWire; - -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); - CompositeComponent parent = EasyMock.createMock(CompositeComponent.class); - EasyMock.expect(parent.resolveSystemAutowire(EasyMock.eq(String.class))).andReturn(null); - EasyMock.replay(parent); - ResourceObjectFactory factory = new ResourceObjectFactory(String.class, false, parent, host); - assertEquals("foo", factory.getInstance()); - EasyMock.verify(host); - EasyMock.verify(parent); - } - - 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 factory = - new ResourceObjectFactory(String.class, "sca://localhost/bar", false, null, host); - assertEquals("foo", factory.getInstance()); - EasyMock.verify(host); - } - - public void testResolveFromParentByType() throws Exception { - CompositeComponent parent = EasyMock.createMock(CompositeComponent.class); - InboundWire wire = EasyMock.createMock(InboundWire.class); - EasyMock.expect(wire.getTargetService()).andReturn("foo"); - EasyMock.replay(wire); - - EasyMock.expect(parent.resolveSystemAutowire(EasyMock.eq(String.class))).andReturn(wire); - EasyMock.replay(parent); - ResourceObjectFactory factory = new ResourceObjectFactory(String.class, false, parent, null); - assertEquals("foo", factory.getInstance()); - EasyMock.verify(parent); - } - - public void testResolveFromParentByName() throws Exception { - AtomicComponent component = EasyMock.createMock(AtomicComponent.class); - EasyMock.expect(component.getTargetInstance()).andReturn("foo"); - EasyMock.replay(component); - CompositeComponent parent = EasyMock.createMock(CompositeComponent.class); - EasyMock.expect(parent.getSystemChild(EasyMock.eq("bar"))).andReturn(component); - EasyMock.replay(parent); - ResourceObjectFactory factory = - new ResourceObjectFactory(String.class, "bar", false, parent, null); - assertEquals("foo", factory.getInstance()); - EasyMock.verify(parent); - EasyMock.verify(component); - } - - /** - * Verifies if a resource is not found as a child of the parent, the host namespace will be searched - */ - public void testResolveFromParentThenResolveFromHost() throws Exception { - ResourceHost host = EasyMock.createMock(ResourceHost.class); - EasyMock.expect(host.resolveResource(EasyMock.eq(String.class))).andReturn("foo"); - EasyMock.replay(host); - - CompositeComponent parent = EasyMock.createMock(CompositeComponent.class); - EasyMock.expect(parent.resolveSystemAutowire(EasyMock.eq(String.class))).andReturn(null); - EasyMock.replay(parent); - ResourceObjectFactory factory = new ResourceObjectFactory(String.class, false, parent, host); - assertEquals("foo", factory.getInstance()); - EasyMock.verify(parent); - 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); - CompositeComponent parent = EasyMock.createMock(CompositeComponent.class); - EasyMock.expect(parent.resolveSystemAutowire(EasyMock.eq(String.class))).andReturn(null); - EasyMock.replay(parent); - ResourceObjectFactory factory = new ResourceObjectFactory(String.class, true, parent, host); - assertNull(factory.getInstance()); - EasyMock.verify(parent); - 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); - - InboundWire wire = EasyMock.createMock(InboundWire.class); - EasyMock.expect(wire.getTargetService()).andReturn(null); - EasyMock.replay(wire); - - CompositeComponent parent = EasyMock.createMock(CompositeComponent.class); - EasyMock.expect(parent.resolveSystemAutowire(EasyMock.eq(String.class))).andReturn(null); - EasyMock.replay(parent); - ResourceObjectFactory factory = new ResourceObjectFactory(String.class, false, parent, host); - try { - factory.getInstance(); - fail(); - } catch (ResourceNotFoundException e) { - //expected - } - EasyMock.verify(parent); - 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); - CompositeComponent parent = EasyMock.createMock(CompositeComponent.class); - EasyMock.expect(parent.resolveSystemAutowire(EasyMock.eq(String.class))).andReturn(null); - EasyMock.replay(parent); - ResourceObjectFactory factory = new ResourceObjectFactory(String.class, true, parent, host); - assertNull(factory.getInstance()); - EasyMock.verify(parent); - EasyMock.verify(host); - } - - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/injection/SingletonObjectFactoryTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/injection/SingletonObjectFactoryTestCase.java deleted file mode 100644 index 876e68d5b3..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/injection/SingletonObjectFactoryTestCase.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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 factory = new SingletonObjectFactory(o); - assertEquals(o, factory.getInstance()); - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/integration/conversation/AbstractConversationTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/integration/conversation/AbstractConversationTestCase.java deleted file mode 100644 index f9135e2eb9..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/integration/conversation/AbstractConversationTestCase.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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 org.apache.tuscany.spi.wire.WirePostProcessorRegistry; - -import junit.framework.TestCase; -import org.apache.tuscany.core.builder.ConnectorImpl; -import org.apache.tuscany.core.builder.WirePostProcessorRegistryImpl; -import org.apache.tuscany.core.component.WorkContextImpl; -import org.apache.tuscany.core.component.scope.ConversationalScopeContainer; -import org.apache.tuscany.core.implementation.java.JavaAtomicComponent; -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 ConnectorImpl connector; - protected JavaAtomicComponent target; - - - protected void createRuntime() { - workContext = new WorkContextImpl(); - WirePostProcessorRegistry processorRegistry = new WirePostProcessorRegistryImpl(); - connector = new ConnectorImpl(null, processorRegistry, null, workContext); - store = new MemoryStore(EasyMock.createNiceMock(StoreMonitor.class)); - container = new ConversationalScopeContainer(store, workContext, null); - - } - - protected void initializeRuntime() { - store.init(); - container.start(); - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/integration/conversation/ConversationIdleExpireTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/integration/conversation/ConversationIdleExpireTestCase.java deleted file mode 100644 index 4aec333cad..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/integration/conversation/ConversationIdleExpireTestCase.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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 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.JDKOutboundInvocationHandler; -import org.apache.tuscany.spi.ObjectCreationException; -import org.apache.tuscany.spi.QualifiedName; -import org.apache.tuscany.spi.component.TargetNotFoundException; -import org.apache.tuscany.spi.wire.InboundWire; -import org.apache.tuscany.spi.wire.OutboundWire; -import org.easymock.classextension.EasyMock; -import org.osoa.sca.annotations.EndsConversation; -import org.osoa.sca.annotations.Scope; - -/** - * Verifies conversational resources are cleaned up if the maximum idle time is exceeded - * - * @version $Rev$ $Date$ - */ -public class ConversationIdleExpireTestCase extends AbstractConversationTestCase { - private JDKOutboundInvocationHandler handler; - private OutboundWire owire; - private Foo 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(Foo.class); - targetInstance.operation1(); - targetInstance.operation2(); - targetInstance.end(); - EasyMock.replay(targetInstance); - target = createMaxIdleTimeAtomicComponent(); - // create source component mock - JavaAtomicComponent source = EasyMock.createMock(JavaAtomicComponent.class); - EasyMock.expect(source.getName()).andReturn("source").atLeastOnce(); - EasyMock.expect(source.isSystem()).andReturn(false).atLeastOnce(); - EasyMock.replay(source); - - owire = MockFactory.createOutboundWire("foo", Foo.class); - owire.setContainer(source); - owire.setTargetName(new QualifiedName("foo/bar")); - InboundWire iwire = MockFactory.createInboundWire("foo", Foo.class); - iwire.setContainer(target); - connector.connect(owire, iwire, false); - handler = new JDKOutboundInvocationHandler(Foo.class, owire, workContext); - operation1 = Foo.class.getMethod("operation1"); - operation2 = Foo.class.getMethod("operation2"); - } - - protected void tearDown() throws Exception { - super.tearDown(); - container.stop(); - store.destroy(); - } - - private JavaAtomicComponent createMaxIdleTimeAtomicComponent() throws Exception { - PojoConfiguration configuration = new PojoConfiguration(); - configuration.setName("target"); - configuration.setMaxIdleTime(50); - configuration.setInstanceFactory(new MockPojoFactory(Object.class.getConstructor())); - JavaAtomicComponent component = new JavaAtomicComponent(configuration); - component.setScopeContainer(container); - component.start(); - return component; - } - - private class MockPojoFactory extends PojoObjectFactory { - public MockPojoFactory(Constructor ctr) { - super(ctr); - } - - public Foo getInstance() throws ObjectCreationException { - return targetInstance; - } - } - - @Scope("CONVERSATION") - public static interface Foo { - - void operation1(); - - void operation2(); - - @EndsConversation - void end(); - - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/integration/conversation/ConversationMaxAgeExpireTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/integration/conversation/ConversationMaxAgeExpireTestCase.java deleted file mode 100644 index 1c9bc4a290..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/integration/conversation/ConversationMaxAgeExpireTestCase.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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 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.JDKOutboundInvocationHandler; -import org.apache.tuscany.spi.ObjectCreationException; -import org.apache.tuscany.spi.QualifiedName; -import org.apache.tuscany.spi.component.TargetNotFoundException; -import org.apache.tuscany.spi.wire.InboundWire; -import org.apache.tuscany.spi.wire.OutboundWire; -import org.easymock.classextension.EasyMock; -import org.osoa.sca.annotations.EndsConversation; -import org.osoa.sca.annotations.Scope; - -/** - * Verifies conversational resources are cleaned up if the maximum age is exceeded - * - * @version $Rev$ $Date$ - */ -public class ConversationMaxAgeExpireTestCase extends AbstractConversationTestCase { - private JDKOutboundInvocationHandler handler; - private OutboundWire owire; - private Foo 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(ConversationMaxAgeExpireTestCase.Foo.class); - targetInstance.operation1(); - targetInstance.operation2(); - targetInstance.end(); - EasyMock.replay(targetInstance); - target = createMaxIdleTimeAtomicComponent(); - // create source component mock - JavaAtomicComponent source = EasyMock.createMock(JavaAtomicComponent.class); - EasyMock.expect(source.getName()).andReturn("source").atLeastOnce(); - EasyMock.expect(source.isSystem()).andReturn(false).atLeastOnce(); - EasyMock.replay(source); - - owire = MockFactory.createOutboundWire("foo", Foo.class); - owire.setContainer(source); - owire.setTargetName(new QualifiedName("foo/bar")); - InboundWire iwire = MockFactory.createInboundWire("foo", Foo.class); - iwire.setContainer(target); - connector.connect(owire, iwire, false); - handler = new JDKOutboundInvocationHandler(Foo.class, owire, workContext); - operation1 = Foo.class.getMethod("operation1"); - operation2 = Foo.class.getMethod("operation2"); - } - - protected void tearDown() throws Exception { - super.tearDown(); - container.stop(); - store.destroy(); - } - - private JavaAtomicComponent createMaxIdleTimeAtomicComponent() throws Exception { - PojoConfiguration configuration = new PojoConfiguration(); - configuration.setName("target"); - configuration.setMaxAge(50); - Constructor ctor = Object.class.getConstructor(); - configuration.setInstanceFactory(new ConversationMaxAgeExpireTestCase.MockPojoFactory(ctor)); - JavaAtomicComponent component = new JavaAtomicComponent(configuration); - component.setScopeContainer(container); - component.start(); - return component; - } - - private class MockPojoFactory extends PojoObjectFactory { - public MockPojoFactory(Constructor ctr) { - super(ctr); - } - - public ConversationMaxAgeExpireTestCase.Foo getInstance() throws ObjectCreationException { - return targetInstance; - } - } - - @Scope("CONVERSATION") - public static interface Foo { - - void operation1(); - - void operation2(); - - @EndsConversation - void end(); - - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/integration/conversation/ConversationStartStopEndTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/integration/conversation/ConversationStartStopEndTestCase.java deleted file mode 100644 index e7a0bc3cfc..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/integration/conversation/ConversationStartStopEndTestCase.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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 static org.apache.tuscany.spi.model.Scope.CONVERSATION; - -import java.lang.reflect.Constructor; -import java.lang.reflect.Method; - -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.JDKOutboundInvocationHandler; -import org.apache.tuscany.spi.ObjectCreationException; -import org.apache.tuscany.spi.QualifiedName; -import org.apache.tuscany.spi.wire.InboundWire; -import org.apache.tuscany.spi.wire.OutboundWire; -import org.easymock.classextension.EasyMock; -import org.osoa.sca.annotations.EndsConversation; -import org.osoa.sca.annotations.Scope; - -/** - * 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 { - private OutboundWire owire; - private Foo targetInstance; - private JDKOutboundInvocationHandler 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(Foo.class); - targetInstance.operation1(); - targetInstance.operation2(); - targetInstance.end(); - EasyMock.replay(targetInstance); - // create target component mock - target = createAtomicComponent(); - // create source component mock - JavaAtomicComponent source = EasyMock.createMock(JavaAtomicComponent.class); - EasyMock.expect(source.getName()).andReturn("source").atLeastOnce(); - EasyMock.expect(source.isSystem()).andReturn(false).atLeastOnce(); - EasyMock.replay(source); - - owire = MockFactory.createOutboundWire("foo", Foo.class); - owire.setContainer(source); - owire.setTargetName(new QualifiedName("foo/bar")); - InboundWire iwire = MockFactory.createInboundWire("foo", Foo.class); - iwire.setContainer(target); - connector.connect(owire, iwire, false); - handler = new JDKOutboundInvocationHandler(Foo.class, owire, 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("target"); - configuration.setInstanceFactory(new MockPojoFactory(Object.class.getConstructor())); - JavaAtomicComponent component = new JavaAtomicComponent(configuration); - component.setScopeContainer(container); - component.start(); - return component; - } - - private class MockPojoFactory extends PojoObjectFactory { - public MockPojoFactory(Constructor ctr) { - super(ctr); - } - - public Foo getInstance() throws ObjectCreationException { - return targetInstance; - } - } - - @Scope("CONVERSATION") - public static interface Foo { - - void operation1(); - - void operation2(); - - @EndsConversation - void end(); - - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/integration/implementation/IntrospectionRegistryIntegrationTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/integration/implementation/IntrospectionRegistryIntegrationTestCase.java deleted file mode 100644 index f551aa3e98..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/integration/implementation/IntrospectionRegistryIntegrationTestCase.java +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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 IntegrationRegistry to verify operation with processors - * - * @version $Rev$ $Date$ - */ -public class IntrospectionRegistryIntegrationTestCase extends TestCase { - - private IntrospectionRegistryImpl registry; - - public void testSimpleComponentTypeParsing() throws Exception { - PojoComponentType> type = - new PojoComponentType>(); - registry.introspect(null, 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/integration/implementation/system/builder/SystemBuilderPropertyTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/integration/implementation/system/builder/SystemBuilderPropertyTestCase.java deleted file mode 100644 index 4a4939b495..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/integration/implementation/system/builder/SystemBuilderPropertyTestCase.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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 org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.CompositeComponent; -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.AbstractReferenceDefinition; -import org.apache.tuscany.spi.model.ComponentTypeReferenceDefinition; -import org.apache.tuscany.spi.model.ServiceDefinition; - -import junit.framework.TestCase; -import org.apache.tuscany.core.deployer.RootDeploymentContext; -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; - CompositeComponent parent; - - @SuppressWarnings("unchecked") - public void testPropertyHandling() throws Exception { - SystemComponentBuilder builder = new SystemComponentBuilder(); - PojoComponentType> type = - new PojoComponentType>(); - type.setConstructorDefinition(new ConstructorDefinition(Foo.class.getConstructor((Class[]) null))); - JavaMappedProperty property = new JavaMappedProperty(); - property.setName("test"); - property.setDefaultValueFactory(new SingletonObjectFactory("foo")); - property.setMember(Foo.class.getMethod("setTest", String.class)); - type.add(property); - SystemImplementation impl = new SystemImplementation(); - impl.setComponentType(type); - impl.setImplementationClass(Foo.class); - ComponentDefinition definition = new ComponentDefinition(impl); - AtomicComponent component = builder.build(parent, definition, deploymentContext); - Foo foo = (Foo) component.createInstance(); - assertEquals("foo", foo.getTest()); - } - - protected void setUp() throws Exception { - super.setUp(); - deploymentContext = new RootDeploymentContext(null, null, null, null); - parent = EasyMock.createNiceMock(CompositeComponent.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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/integration/mock/MockFactory.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/integration/mock/MockFactory.java deleted file mode 100644 index 0c331ae7d7..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/integration/mock/MockFactory.java +++ /dev/null @@ -1,278 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.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.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.InboundInvocationChain; -import org.apache.tuscany.spi.wire.InboundWire; -import org.apache.tuscany.spi.wire.Interceptor; -import org.apache.tuscany.spi.wire.OutboundInvocationChain; -import org.apache.tuscany.spi.wire.OutboundWire; -import org.apache.tuscany.spi.wire.WireService; - -import org.apache.tuscany.core.builder.ConnectorImpl; -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.InboundInvocationChainImpl; -import org.apache.tuscany.core.wire.InboundWireImpl; -import org.apache.tuscany.core.wire.InvokerInterceptor; -import org.apache.tuscany.core.wire.OutboundInvocationChainImpl; -import org.apache.tuscany.core.wire.OutboundWireImpl; -import org.apache.tuscany.core.wire.jdk.JDKWireService; - -/** - * @version $$Rev$$ $$Date$$ - */ -public final class MockFactory { - - private static final WireService WIRE_SERVICE = new JDKWireService(new WorkContextImpl(), null); - private static final JavaInterfaceProcessorRegistry REGISTRY = new JavaInterfaceProcessorRegistryImpl(); - private static final ConnectorImpl CONNECTOR = new ConnectorImpl(); - - private MockFactory() { - } - - /** - * Wires two components together where the reference interface is the same as target service - * - * @param sourceName - * @param sourceClass - * @param sourceScope - * @param members - * @param targetName - * @param targetService - * @param targetClass - * @param targetScope - * @return - * @throws Exception - */ - public static Map createWiredComponents(String sourceName, - Class sourceClass, - ScopeContainer sourceScope, - Map members, - String targetName, - Class targetService, - Class targetClass, - ScopeContainer targetScope) throws Exception { - return createWiredComponents(sourceName, - sourceClass, - targetService, - sourceScope, - null, - members, - targetName, - targetService, - targetClass, - targetScope, - null); - - } - - @SuppressWarnings("unchecked") - public static Map createWiredComponents(String sourceName, Class sourceClass, - Class sourceReferenceClass, - ScopeContainer sourceScope, - Interceptor sourceHeadInterceptor, - Map members, - String targetName, Class targetService, - Class targetClass, - ScopeContainer targetScope, - Interceptor targetHeadInterceptor) - throws Exception { - - JavaAtomicComponent targetComponent = - createJavaComponent(targetName, targetScope, targetClass); - String serviceName = targetService.getName().substring(targetService.getName().lastIndexOf('.') + 1); - InboundWire inboundWire = createInboundWire(serviceName, targetService, targetHeadInterceptor); - targetComponent.addInboundWire(inboundWire); - inboundWire.setContainer(targetComponent); - PojoConfiguration configuration = new PojoConfiguration(); - configuration.setInstanceFactory(new PojoObjectFactory(sourceClass.getConstructor())); - configuration.setWireService(WIRE_SERVICE); - for (Map.Entry entry : members.entrySet()) { - configuration.addReferenceSite(entry.getKey(), entry.getValue()); - } - configuration.setWorkContext(new WorkContextImpl()); - configuration.setName(sourceName); - JavaAtomicComponent sourceComponent = new JavaAtomicComponent(configuration); - sourceComponent.setScopeContainer(sourceScope); - OutboundWire outboundWire = createOutboundWire(targetName, sourceReferenceClass, sourceHeadInterceptor); - sourceComponent.addOutboundWire(outboundWire); - outboundWire.setContainer(sourceComponent); - outboundWire.setTargetName(new QualifiedName(targetName + "/" + serviceName)); - targetScope.register(targetComponent); - sourceScope.register(sourceComponent); - CONNECTOR.connect(outboundWire, inboundWire, false); - Map contexts = new HashMap(); - contexts.put(sourceName, sourceComponent); - contexts.put(targetName, targetComponent); - return contexts; - } - - - /** - * Wires two contexts using a multiplicity reference - * - * @param sourceName - * @param sourceClass - * @param sourceReferenceClass - * @param sourceScope - * @param targetName - * @param targetService - * @param targetClass - * @param members - * @param targetScope - * @return - * @throws Exception - */ - @SuppressWarnings("unchecked") - public static Map createWiredMultiplicity(String sourceName, Class sourceClass, - Class sourceReferenceClass, - ScopeContainer sourceScope, - String targetName, Class targetService, - Class targetClass, - Map members, - ScopeContainer targetScope) throws Exception { - JavaAtomicComponent targetComponent = - createJavaComponent(targetName, targetScope, targetClass); - String serviceName = targetService.getName().substring(targetService.getName().lastIndexOf('.') + 1); - InboundWire inboundWire = createInboundWire(serviceName, targetService, null); - targetComponent.addInboundWire(inboundWire); - inboundWire.setContainer(targetComponent); - PojoConfiguration configuration = new PojoConfiguration(); - configuration.setInstanceFactory(new PojoObjectFactory(sourceClass.getConstructor())); - configuration.setWireService(WIRE_SERVICE); - for (Map.Entry entry : members.entrySet()) { - configuration.addReferenceSite(entry.getKey(), entry.getValue()); - } - configuration.setWorkContext(new WorkContextImpl()); - configuration.setName(sourceName); - - JavaAtomicComponent sourceComponent = new JavaAtomicComponent(configuration); - sourceComponent.setScopeContainer(sourceScope); - OutboundWire outboundWire = createOutboundWire(targetName, sourceReferenceClass, null); - outboundWire.setContainer(sourceComponent); - outboundWire.setTargetName(new QualifiedName(targetName + "/" + serviceName)); - List factories = new ArrayList(); - factories.add(outboundWire); - sourceComponent.addOutboundWires(factories); - targetScope.register(targetComponent); - sourceScope.register(sourceComponent); - CONNECTOR.connect(outboundWire, inboundWire, false); - Map components = new HashMap(); - components.put(sourceName, sourceComponent); - components.put(targetName, targetComponent); - return components; - } - - public static InboundWire createInboundWire(String serviceName, Class interfaze) - throws InvalidServiceContractException { - return createInboundWire(serviceName, interfaze, null); - } - - public static InboundWire createInboundWire(String serviceName, Class interfaze, Interceptor interceptor) - throws InvalidServiceContractException { - InboundWire wire = new InboundWireImpl(); - ServiceContract contract = REGISTRY.introspect(interfaze); - wire.setServiceContract(contract); - wire.setServiceName(serviceName); - wire.addInvocationChains(createInboundChains(interfaze, interceptor)); - return wire; - } - - public static OutboundWire createOutboundWire(String refName, Class interfaze) - throws InvalidServiceContractException { - return createOutboundWire(refName, interfaze, null); - } - - public static OutboundWire createOutboundWire(String refName, Class interfaze, Interceptor interceptor) - throws InvalidServiceContractException { - - OutboundWire wire = new OutboundWireImpl(); - wire.setReferenceName(refName); - Map, OutboundInvocationChain> outboundChains = createOutboundChains(interfaze, interceptor); - wire.addInvocationChains(outboundChains); - ServiceContract contract = REGISTRY.introspect(interfaze); - wire.setServiceContract(contract); - return wire; - } - - - @SuppressWarnings("unchecked") - private static JavaAtomicComponent createJavaComponent(String name, ScopeContainer scope, Class clazz) - throws NoSuchMethodException { - PojoConfiguration configuration = new PojoConfiguration(); - configuration.setInstanceFactory(new PojoObjectFactory(clazz.getConstructor())); - configuration.setWireService(WIRE_SERVICE); - configuration.setWorkContext(new WorkContextImpl()); - configuration.setName(name); - JavaAtomicComponent component = new JavaAtomicComponent(configuration); - component.setScopeContainer(scope); - return component; - } - - private static Map, OutboundInvocationChain> createOutboundChains(Class interfaze, - Interceptor interceptor) - throws InvalidServiceContractException { - Map, OutboundInvocationChain> invocations = new HashMap, OutboundInvocationChain>(); - ServiceContract contract = REGISTRY.introspect(interfaze); - for (Operation operation : contract.getOperations().values()) { - OutboundInvocationChain chain = new OutboundInvocationChainImpl(operation); - if (interceptor != null) { - chain.addInterceptor(interceptor); - } - invocations.put(operation, chain); - } - return invocations; - } - - private static Map, InboundInvocationChain> createInboundChains(Class interfaze, - Interceptor interceptor) - throws InvalidServiceContractException { - - Map, InboundInvocationChain> invocations = new HashMap, InboundInvocationChain>(); - ServiceContract contract = REGISTRY.introspect(interfaze); - for (Operation method : contract.getOperations().values()) { - InboundInvocationChain chain = new InboundInvocationChainImpl(method); - if (interceptor != null) { - chain.addInterceptor(interceptor); - } - // add tail interceptor - chain.addInterceptor(new InvokerInterceptor()); - invocations.put(method, chain); - } - return invocations; - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/integration/scope/ScopeReferenceTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/integration/scope/ScopeReferenceTestCase.java deleted file mode 100644 index 4cd5ac8d9b..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/integration/scope/ScopeReferenceTestCase.java +++ /dev/null @@ -1,781 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.CompositeStart; -import org.apache.tuscany.core.component.event.CompositeStop; -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 members; - - /** - * Tests a composite-to-composite scoped wire - */ - public void testCompositeToComposite() throws Exception { - ScopeContainer scope = new CompositeScopeContainer(null); - scope.start(); - - Map contexts = MockFactory.createWiredComponents("source", SourceImpl.class, - scope, members, "target", Target.class, TargetImpl.class, scope); - scope.onEvent(new CompositeStart(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 CompositeStop(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 contexts = MockFactory.createWiredComponents("source", SourceImpl.class, - compositeScope, members, "target", Target.class, TargetImpl.class, sessionScope); - compositeScope.onEvent(new CompositeStart(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 CompositeStop(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 contexts = MockFactory.createWiredComponents("source", SourceImpl.class, - compositeScope, members, "target", Target.class, TargetImpl.class, requestScope); - compositeScope.onEvent(new CompositeStart(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 future = new FutureTask(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 CompositeStop(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 contexts = MockFactory.createWiredComponents("source", SourceImpl.class, - compositeScope, members, "target", Target.class, TargetImpl.class, statelessScope); - compositeScope.onEvent(new CompositeStart(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 CompositeStop(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 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 contexts = MockFactory.createWiredComponents("source", SourceImpl.class, - sessionScope, members, "target", Target.class, TargetImpl.class, compositeScope); - compositeScope.onEvent(new CompositeStart(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 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 future = new FutureTask(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 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 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 future = new FutureTask(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 CompositeStart(this, null)); - - Map 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 future = new FutureTask(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 CompositeStop(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 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 future = new FutureTask(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 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 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 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 future = new FutureTask(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 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 contexts = MockFactory.createWiredComponents("source", SourceImpl.class, - statelessScope, members, "target", Target.class, TargetImpl.class, compositeScope); - compositeScope.onEvent(new CompositeStart(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 CompositeStop(this, null)); - compositeScope.stop(); - statelessScope.stop(); - } - - protected void setUp() throws Exception { - super.setUp(); - members = new HashMap(); - Method[] methods = SourceImpl.class.getMethods(); - for (Method method : methods) { - if (method.getName().startsWith("set")) { - members.put(JavaIntrospectionHelper.toPropertyName(method.getName()), method); - } - } - } - - -} - diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/integration/wire/DifferentInterfaceWireTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/integration/wire/DifferentInterfaceWireTestCase.java deleted file mode 100644 index 431f47b5bf..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/integration/wire/DifferentInterfaceWireTestCase.java +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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 members = new HashMap(); - Method m = SourceImpl.class.getMethod("setTarget", Target.class); - members.put("target", m); - ScopeContainer scope = createMock(); - scope.start(); - Map contexts = - MockFactory.createWiredComponents("source", - SourceImpl.class, - Target.class, - scope, - null, - members, - "target", - OtherTarget.class, - OtherTargetImpl.class, - scope, - null); - 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 members = new HashMap(); - Method m = SourceImpl.class.getMethod("setTargets", List.class); - members.put("target", m); - ScopeContainer scope = createMock(); - scope.start(); - Map 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 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() { - private Map cache = new HashMap(); - - 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/integration/wire/ReferenceInjectionTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/integration/wire/ReferenceInjectionTestCase.java deleted file mode 100644 index 603e334fe9..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/integration/wire/ReferenceInjectionTestCase.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.TargetImpl; -import org.apache.tuscany.core.mock.component.Target; - -/** - * @version $$Rev$$ $$Date$$ - */ -public class ReferenceInjectionTestCase extends TestCase { - - private Map members; - - public void testProxiedReferenceInjection() throws Exception { - ScopeContainer scope = new CompositeScopeContainer(null); - scope.start(); - Map 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(); - Method m = SourceImpl.class.getMethod("setTarget", Target.class); - members.put("target", m); - } - - protected void tearDown() throws Exception { - super.tearDown(); - } - - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/integration/wire/oneway/OneWayWireToJavaInvocationTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/integration/wire/oneway/OneWayWireToJavaInvocationTestCase.java deleted file mode 100644 index 78e349b788..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/integration/wire/oneway/OneWayWireToJavaInvocationTestCase.java +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.InboundInvocationChain; -import org.apache.tuscany.spi.wire.InboundWire; -import org.apache.tuscany.spi.wire.Interceptor; -import org.apache.tuscany.spi.wire.Message; -import org.apache.tuscany.spi.wire.MessageImpl; -import org.apache.tuscany.spi.wire.OutboundInvocationChain; -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.InboundInvocationChainImpl; -import org.apache.tuscany.core.wire.InvokerInterceptor; -import org.apache.tuscany.core.wire.NonBlockingBridgingInterceptor; -import org.apache.tuscany.core.wire.OutboundInvocationChainImpl; -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 OutboundInvocationChain 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); - InboundWire inboundWire = EasyMock.createMock(InboundWire.class); - ExecutionMonitor monitor = EasyMock.createNiceMock(ExecutionMonitor.class); - invoker = new JavaTargetInvoker(method, component, inboundWire, context, monitor); - Operation operation = new Operation("invoke", null, null, null, false, null, TargetInvoker.NONE); - ochain = new OutboundInvocationChainImpl(operation); - NonBlockingBridgingInterceptor bridgeInterceptor = new NonBlockingBridgingInterceptor(scheduler, context); - ochain.addInterceptor(bridgeInterceptor); - InboundInvocationChain ichain = new InboundInvocationChainImpl(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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderNoBindingTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderNoBindingTestCase.java deleted file mode 100644 index 3f6df22677..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderNoBindingTestCase.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.XMLStreamConstants; -import javax.xml.stream.XMLStreamReader; - -import static org.osoa.sca.Constants.SCA_NS; - -import org.apache.tuscany.spi.component.CompositeComponent; -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.ComponentTypeReferenceDefinition; -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.AbstractReferenceDefinition; -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 ComponentTypeReferenceDefinition reference; - - public void testNoServiceBinding() throws Exception { - loader.load(null, null, reader, null); - assert service.getBindings().isEmpty(); - } - - public void testNoReferenceBinding() throws Exception { - loader.load(null, null, reader, null); - assert reference.getBindings().isEmpty(); - } - - protected void setUp() throws Exception { - super.setUp(); - service = new ServiceDefinition(); - reference = new ComponentTypeReferenceDefinition(); - PojoComponentType> type = - new PojoComponentType>(); - type.add(service); - type.add(reference); - JavaImplementation impl = new JavaImplementation(null, type); - LoaderRegistry registry = EasyMock.createMock(LoaderRegistry.class); - EasyMock.expect(registry.load((CompositeComponent) EasyMock.isNull(), - (ModelObject) EasyMock.isNull(), - EasyMock.isA(XMLStreamReader.class), - (DeploymentContext) EasyMock.isNull())).andReturn(impl); - registry.loadComponentType((CompositeComponent) EasyMock.isNull(), - EasyMock.isA(Implementation.class), - (DeploymentContext) EasyMock.isNull()); - 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, "autowire")).andReturn("false"); - EasyMock.expect(reader.getAttributeValue(null, "initLevel")).andReturn("0"); - EasyMock.expect(reader.nextTag()).andReturn(1); - EasyMock.replay(reader); - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderPropertyTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderPropertyTestCase.java deleted file mode 100644 index 5034e5114a..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderPropertyTestCase.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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 junit.framework.TestCase; - -import org.apache.tuscany.core.implementation.java.JavaImplementation; -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.MissingPropertyValueException; -import org.apache.tuscany.spi.loader.PropertyObjectFactory; -import org.apache.tuscany.spi.model.ComponentDefinition; -import org.apache.tuscany.spi.model.ComponentTypeReferenceDefinition; -import org.apache.tuscany.spi.model.Implementation; -import org.apache.tuscany.spi.model.Property; -import org.apache.tuscany.spi.model.AbstractReferenceDefinition; -import org.apache.tuscany.spi.model.ServiceDefinition; -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 testMissingPropertyValueException() throws LoaderException, XMLStreamException { - PojoComponentType> type = - new PojoComponentType>(); - Property property = new Property(); - property.setName("name"); - property.setMustSupply(true); - type.add(property); - - JavaImplementation impl = new JavaImplementation(null, type); - impl.setComponentType(type); - ComponentDefinition> defn = new ComponentDefinition>(impl); - assertTrue(defn.getPropertyValues().isEmpty()); - try { - loader.populatePropertyValues(defn); - fail(); - } catch (Exception e) { - assertTrue(e instanceof MissingPropertyValueException); - } - - } - - 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> componentDefinition) - throws MissingPropertyValueException, LoaderException { - super.populatePropertyValues(componentDefinition); - } - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderReferenceTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderReferenceTestCase.java deleted file mode 100644 index 3d73e53883..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderReferenceTestCase.java +++ /dev/null @@ -1,87 +0,0 @@ -package org.apache.tuscany.core.loader; - -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.CompositeComponent; -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.ComponentTypeReferenceDefinition; -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.AbstractReferenceDefinition; -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 ComponentLoaderReferenceTestCase 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; - - /** - * 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, null, reader, null); - fail(); - } catch (UndefinedReferenceException e) { - // expected - } - } - - protected void setUp() throws Exception { - super.setUp(); - PojoComponentType> type = - new PojoComponentType>(); - 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) isNull(), EasyMock.eq("autowire"))) - .andReturn("false"); - 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.getElementText()).andReturn("text"); - - EasyMock.expect(reader.next()).andReturn(XMLStreamConstants.END_ELEMENT); - EasyMock.replay(reader); - LoaderRegistry mockRegistry = EasyMock.createMock(LoaderRegistry.class); - mockRegistry.loadComponentType((CompositeComponent) isNull(), - EasyMock.isA(Implementation.class), - (DeploymentContext) isNull()); - EasyMock.expect(mockRegistry.load((CompositeComponent) isNull(), - (ModelObject) isNull(), - EasyMock.isA(XMLStreamReader.class), - (DeploymentContext) isNull())).andReturn(impl); - EasyMock.replay(mockRegistry); - loader = new ComponentLoader(mockRegistry, null); - - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderTestCase.java deleted file mode 100644 index f4421941fa..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderTestCase.java +++ /dev/null @@ -1,201 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.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.CompositeComponent; -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.ComponentTypeReferenceDefinition; -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.AbstractReferenceDefinition; -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 NAME = "testComponent"; - private JavaImplementation impl; - - private XMLStreamReader mockReader; - private LoaderRegistry mockRegistry; - private PropertyObjectFactory mockPropertyFactory; - private ComponentLoader loader; - - 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("false"); - 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(CompositeComponent.class), - EasyMock.isA(Implementation.class), - EasyMock.isA(DeploymentContext.class)); - EasyMock.expectLastCall().andStubAnswer(new IAnswer() { - @SuppressWarnings("unchecked") - public Object answer() throws Throwable { - Implementation impl = (Implementation) EasyMock.getCurrentArguments()[1]; - impl.setComponentType(new PojoComponentType()); - return impl; - } - }); - - EasyMock.expect(mockRegistry.load(EasyMock.isA(CompositeComponent.class), - (ModelObject) isNull(), - EasyMock.eq(mockReader), - EasyMock.isA(DeploymentContext.class))).andReturn(impl); - EasyMock.replay(mockRegistry); - ComponentDefinition component = loader.load(EasyMock.createNiceMock(CompositeComponent.class), - null, mockReader, - EasyMock.createNiceMock(DeploymentContext.class)); - assertEquals(NAME, component.getName()); - assertNull(component.getInitLevel()); - } - - 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("false"); - EasyMock.expect(mockReader.nextTag()).andReturn(0); - EasyMock.expect(mockReader.next()).andReturn(XMLStreamConstants.END_ELEMENT); - EasyMock.replay(mockReader); - - mockRegistry.loadComponentType(EasyMock.isA(CompositeComponent.class), - EasyMock.isA(Implementation.class), - EasyMock.isA(DeploymentContext.class)); - - EasyMock.expectLastCall().andStubAnswer(new IAnswer() { - @SuppressWarnings("unchecked") - public Object answer() throws Throwable { - Implementation impl = (Implementation) EasyMock.getCurrentArguments()[1]; - impl.setComponentType(new PojoComponentType()); - return impl; - } - }); - EasyMock.expect(mockRegistry.load(EasyMock.isA(CompositeComponent.class), - (ModelObject) isNull(), - EasyMock.eq(mockReader), - EasyMock.isA(DeploymentContext.class))).andReturn(impl); - EasyMock.replay(mockRegistry); - ComponentDefinition component = loader.load(EasyMock.createNiceMock(CompositeComponent.class), - null, mockReader, - EasyMock.createNiceMock(DeploymentContext.class)); - assertEquals(NAME, component.getName()); - assertEquals(Integer.valueOf(20), component.getInitLevel()); - } - - public void testLoadPropertyWithSource() throws LoaderException, XMLStreamException { - PojoComponentType> type = - new PojoComponentType>(); - Property property = new Property(); - property.setName("name"); - type.add(property); - JavaImplementation impl = new JavaImplementation(); - impl.setComponentType(type); - ComponentDefinition defn = new ComponentDefinition(impl); - XMLStreamReader reader = createMock(XMLStreamReader.class); - expect(reader.getAttributeValue(null, "name")).andReturn("name"); - expect(reader.getAttributeValue(null, "source")).andReturn("$source"); - expect(reader.getAttributeValue(null, "type")).andReturn(null).anyTimes(); - expect(reader.getAttributeValue(null, "element")).andReturn(null).anyTimes(); - expect(reader.getAttributeValue(null, "file")).andReturn(null); - expect(reader.next()).andReturn(XMLStreamConstants.END_ELEMENT); - replay(reader); - loader.loadProperty(reader, null, defn); - 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("false"); - 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(CompositeComponent.class), - EasyMock.isA(Implementation.class), - EasyMock.isA(DeploymentContext.class)); - - EasyMock.expect(mockRegistry.load(EasyMock.isA(CompositeComponent.class), - (ModelObject) isNull(), - EasyMock.eq(mockReader), - EasyMock.isA(DeploymentContext.class))).andReturn(impl); - EasyMock.replay(mockRegistry); - try { - loader.load(EasyMock.createNiceMock(CompositeComponent.class), - null, mockReader, - EasyMock.createNiceMock(DeploymentContext.class)); - fail(); - } catch (UnrecognizedElementException e) { - // expected - } - } - - protected void setUp() throws Exception { - super.setUp(); - impl = new JavaImplementation(); - mockReader = EasyMock.createMock(XMLStreamReader.class); - mockRegistry = EasyMock.createMock(LoaderRegistry.class); - mockPropertyFactory = EasyMock.createMock(PropertyObjectFactory.class); - loader = new ComponentLoader(mockRegistry, mockPropertyFactory); - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderValidationTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderValidationTestCase.java deleted file mode 100644 index 9c5ce0655c..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderValidationTestCase.java +++ /dev/null @@ -1,170 +0,0 @@ -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.ReferenceMultiplicityViolationException; -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.model.ComponentDefinition; -import org.apache.tuscany.spi.model.ComponentReferenceDefinition; -import org.apache.tuscany.spi.model.ComponentTypeReferenceDefinition; -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.AbstractReferenceDefinition; -import org.apache.tuscany.spi.model.ServiceDefinition; -import org.apache.tuscany.spi.model.ReferenceTarget; - -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> type = - new PojoComponentType>(); - ComponentTypeReferenceDefinition refDefinition = new ComponentTypeReferenceDefinition(); - refDefinition.setName("name"); - type.add(refDefinition); - JavaImplementation impl = new JavaImplementation(null, type); - ComponentDefinition> defn = new ComponentDefinition>(impl); - ComponentReferenceDefinition compRef = new ComponentReferenceDefinition(refDefinition); - compRef.addTarget(URI.create("uri")); - defn.add(compRef); - /*ReferenceTarget target = new ReferenceTarget(); - target.setReferenceName("name"); - defn.add(target);*/ - loader.validate(defn); - } - - /*public void testReferenceNotSet() throws LoaderException, XMLStreamException { - PojoComponentType> type = - new PojoComponentType>(); - ComponentTypeReferenceDefinition refDefinition = new ComponentTypeReferenceDefinition(); - refDefinition.setName("name"); - type.add(refDefinition); - JavaImplementation impl = new JavaImplementation(null, type); - ComponentDefinition> defn = new ComponentDefinition>(impl); - try { - loader.validate(defn); - fail(); - } catch (MissingReferenceException e) { - // expected - } - }*/ - - public void testNotRequiredReference() throws LoaderException, XMLStreamException { - PojoComponentType> type = - new PojoComponentType>(); - ComponentTypeReferenceDefinition refDefinition = new ComponentTypeReferenceDefinition(); - refDefinition.setName("name"); - type.add(refDefinition); - JavaImplementation impl = new JavaImplementation(null, type); - ComponentDefinition> defn = new ComponentDefinition>(impl); - loader.validate(defn); - } - - public void testReferenceMultiplicity() throws LoaderException, XMLStreamException { - PojoComponentType> type = - new PojoComponentType>(); - ComponentTypeReferenceDefinition refDefinition = new ComponentTypeReferenceDefinition(); - refDefinition.setName("r1"); - refDefinition.setMultiplicity(Multiplicity.ONE_N); - type.add(refDefinition); - JavaImplementation impl = new JavaImplementation(null, type); - ComponentDefinition> defn = new ComponentDefinition>(impl); - ComponentReferenceDefinition compRef = new ComponentReferenceDefinition(type.getReferences().get("r1")); - compRef.addTarget(URI.create("c1")); - compRef.addTarget(URI.create("c2")); - defn.add(compRef); - /*ReferenceTarget target = new ReferenceTarget(); - target.setReferenceName("r1"); - 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 - } - - defn = new ComponentDefinition>(impl); - compRef = new ComponentReferenceDefinition(type.getReferences().get("r1")); - defn.add(compRef); - 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); - - } - public void testAutowire() throws LoaderException, XMLStreamException { - PojoComponentType> type = - new PojoComponentType>(); - ComponentTypeReferenceDefinition refDefinition = new ComponentTypeReferenceDefinition(); - refDefinition.setName("name"); - refDefinition.setAutowire(true); - type.add(refDefinition); - JavaImplementation impl = new JavaImplementation(null, type); - ComponentDefinition> defn = new ComponentDefinition>(impl); - 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> definition) throws LoaderException { - super.validate(definition); - } - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentReferenceOverridingTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentReferenceOverridingTestCase.java deleted file mode 100644 index ffc6ee7a03..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentReferenceOverridingTestCase.java +++ /dev/null @@ -1,178 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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 java.net.URI; -import java.net.URISyntaxException; - -import javax.xml.stream.XMLInputFactory; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; - -import junit.framework.Assert; - -import org.apache.tuscany.core.binding.local.LocalBindingDefinition; -import org.apache.tuscany.core.implementation.java.JavaImplementation; -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.deployer.DeploymentContext; -import org.apache.tuscany.spi.idl.java.JavaServiceContract; -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.ReferenceMultiplicityOverridingException; -import org.apache.tuscany.spi.model.BindingDefinition; -import org.apache.tuscany.spi.model.ComponentDefinition; -import org.apache.tuscany.spi.model.ComponentTypeReferenceDefinition; -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.ServiceDefinition; -import org.easymock.EasyMock; -import org.junit.Test; - -/** - * Tests to verify overriding of aspects of componenttype reference defintions - * by component definitions - */ -public class ComponentReferenceOverridingTestCase { - private static XMLInputFactory xmlFactory = XMLInputFactory.newInstance();; - private static LoaderRegistryImpl loaderRegistry; - - public XMLStreamReader getReader(String xml) throws XMLStreamException { - XMLStreamReader reader = xmlFactory.createXMLStreamReader(new StringReader(xml)); - reader.next(); - return reader; - } - - - @Test - public void testRefDefNoOverriding() throws LoaderException, - XMLStreamException, - URISyntaxException { - String compDefXml = - "" - + "" - + ""; - - TestComponentLoader compLoader = new TestComponentLoader(EasyMock.createMock(LoaderRegistry.class)); - ComponentDefinition compDef = compLoader.load(null, null, getReader(compDefXml), null); - - //verify if component inherits referece definitions from componentType - Assert.assertNotNull(compDef.getReferences().get("CTRefDef1")); - Assert.assertEquals(Multiplicity.ZERO_N.name(), compDef.getReferences().get("CTRefDef1").getMultiplicity().name()); - Assert.assertEquals("TestComponent1/testService1", - compDef.getReferences().get("CTRefDef1").getTargets().get(1).toString()); - Assert.assertTrue( - TestIfc1.class.isAssignableFrom(compDef.getReferences().get("CTRefDef1").getServiceContract().getInterfaceClass())); - Assert.assertTrue(compDef.getReferences().get("CTRefDef1").getBindings().get(0) instanceof LocalBindingDefinition); - } - - @Test - public void testRefDefValidOverriding() throws LoaderException, - XMLStreamException, - URISyntaxException { - String overridenRef = - "" - + "" - + "" - + "" - + ""; - - TestComponentLoader compLoader = new TestComponentLoader(EasyMock.createMock(LoaderRegistry.class)); - - ComponentDefinition compDef = compLoader.load(null, null, getReader(overridenRef), null); - - //verify if component inherits referece definitions from componentType - Assert.assertNotNull(compDef.getReferences().get("CTRefDef1")); - Assert.assertEquals(Multiplicity.ZERO_ONE.name(), - compDef.getReferences().get("CTRefDef1").getMultiplicity().name()); - Assert.assertEquals("OverridingTarget", - compDef.getReferences().get("CTRefDef1").getTargets().get(0).toString()); - Assert.assertTrue( - TestIfc1.class.isAssignableFrom(compDef.getReferences().get("CTRefDef1").getServiceContract().getInterfaceClass())); - Assert.assertTrue(compDef.getReferences().get("CTRefDef1").getBindings().get(0) instanceof LocalBindingDefinition); - } - - @Test - public void testRefDefInValidOverriding() throws LoaderException, - XMLStreamException, - URISyntaxException { - String overridenRef = - "" - + "" - + "" - + ""; - - TestComponentLoader compLoader = new TestComponentLoader(EasyMock.createMock(LoaderRegistry.class)); - - try { - ComponentDefinition compDef = compLoader.load(null, null, getReader(overridenRef), null); - Assert.fail(); - } catch ( ReferenceMultiplicityOverridingException e) { - //expected behaviour - } - } - - - public static interface TestIfc1 { - public String testMethod1(); - } - - public class TestComponentLoader extends ComponentLoader { - - public TestComponentLoader(LoaderRegistry registry) { - super(registry, null); - } - - @Override - protected Implementation loadImplementation(CompositeComponent parent, - XMLStreamReader reader, - DeploymentContext deploymentContext) throws XMLStreamException, - LoaderException { - ComponentTypeReferenceDefinition ctRefDef = new ComponentTypeReferenceDefinition(); - - ctRefDef.setName("CTRefDef1"); - try { - ctRefDef.addTarget(new URI("TestComponent1")); - ctRefDef.addTarget(new URI("TestComponent1/testService1")); - - ctRefDef.setMultiplicity(Multiplicity.ZERO_N); - - JavaServiceContract svcContract = new JavaServiceContract(TestIfc1.class); - ctRefDef.setServiceContract(svcContract); - - BindingDefinition binding1 = new LocalBindingDefinition(new URI("localBindingUri")); - ctRefDef.addBinding(binding1); - } catch (URISyntaxException e) { - //do nothing... unlikely to happen - } - - PojoComponentType> ct = - new PojoComponentType>(); - ct.add(ctRefDef); - - JavaImplementation javaImpl = new JavaImplementation(); - javaImpl.setComponentType(ct); - reader.next(); - reader.next(); - return javaImpl; - } - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentTypeElementLoaderTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentTypeElementLoaderTestCase.java deleted file mode 100644 index 08272d98bc..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentTypeElementLoaderTestCase.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.component.CompositeComponent; -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.ComponentTypeReferenceDefinition; -import org.apache.tuscany.spi.model.ModelObject; -import org.apache.tuscany.spi.model.Property; -import org.apache.tuscany.spi.model.AbstractReferenceDefinition; -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> type = - new ComponentType>(); - 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(null, type, reader, null); - assertEquals(object, type); - } - - public void testComponentTypePassedAsContext() throws Exception { - ComponentType> type = - new ComponentType>(); - LoaderRegistry registry = EasyMock.createMock(LoaderRegistry.class); - EasyMock.expect(registry.load((CompositeComponent) EasyMock.isNull(), - 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(null, 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, null, reader, null); - assertEquals(ComponentType.class, object.getClass()); - } - - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/DependencyLoaderTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/DependencyLoaderTestCase.java deleted file mode 100644 index 753289f4a6..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/DependencyLoaderTestCase.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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/1.0-SNAPSHOT"; - 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, 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, 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/IncludeLoaderTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/IncludeLoaderTestCase.java deleted file mode 100644 index ed2fde80d3..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/IncludeLoaderTestCase.java +++ /dev/null @@ -1,169 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.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 org.osoa.sca.Constants; - -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.deployer.DeploymentContext; -import org.apache.tuscany.spi.loader.LoaderException; -import org.apache.tuscany.spi.loader.LoaderRegistry; -import org.apache.tuscany.spi.loader.MissingIncludeException; -import org.apache.tuscany.spi.model.CompositeComponentType; -import org.apache.tuscany.spi.model.Include; -import org.apache.tuscany.spi.model.ModelObject; - -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; - -/** - * @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; - - 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, 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(registry.load((CompositeComponent) isNull(), - (ModelObject) isNull(), - eq(includeURL), - eq(CompositeComponentType.class), - isA(DeploymentContext.class))) - .andReturn(null); - replay(registry, reader, context); - - Include include = loader.load(null, 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(registry.load((CompositeComponent) isNull(), - (ModelObject) isNull(), - eq(includeURL), - eq(CompositeComponentType.class), - isA(DeploymentContext.class))) - .andReturn(null); - replay(registry, reader, context); - - Include include = loader.load(null, 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(registry.load((CompositeComponent) isNull(), - (ModelObject) isNull(), - eq(includeURL), - eq(CompositeComponentType.class), - isA(DeploymentContext.class))) - .andReturn(null); - replay(registry, reader, context); - - Include include = loader.load(null, 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); - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/JNDIPropertyFactoryTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/JNDIPropertyFactoryTestCase.java deleted file mode 100644 index 1c65ed42cc..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/JNDIPropertyFactoryTestCase.java +++ /dev/null @@ -1,66 +0,0 @@ -package org.apache.tuscany.core.loader; - -import java.lang.reflect.Type; -import java.util.ArrayList; -import java.util.Hashtable; -import java.util.List; - -import javax.naming.Context; -import javax.naming.NamingException; -import javax.naming.spi.InitialContextFactory; - -import junit.framework.TestCase; - -import org.apache.tuscany.core.injection.JNDIObjectFactory; -import org.apache.tuscany.spi.model.PropertyValue; -import org.easymock.EasyMock; -import org.w3c.dom.Element; - -/** - * @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(); - List docList = new ArrayList(); - docList.add(element); - value.setValue(docList); - 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 extends PropertyValue { - - } - - 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/LoaderExceptionFormatterTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/LoaderExceptionFormatterTestCase.java deleted file mode 100644 index 49c53935dc..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/LoaderExceptionFormatterTestCase.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/MultivaluePropertyLoadingTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/MultivaluePropertyLoadingTestCase.java deleted file mode 100644 index a39ca52fd4..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/MultivaluePropertyLoadingTestCase.java +++ /dev/null @@ -1,204 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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 java.io.StringWriter; - -import javax.xml.namespace.QName; -import javax.xml.stream.XMLInputFactory; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.stream.StreamResult; - -import junit.framework.TestCase; - -import org.apache.tuscany.core.databinding.javabeans.JavaBean2DOMNodeTransformer; -import org.apache.tuscany.spi.loader.LoaderRegistry; -import org.apache.tuscany.spi.model.Property; -import org.easymock.EasyMock; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; -import org.w3c.dom.Text; - -/** - * @version $Rev: 502055 $ $Date: 2007-02-01 05:37:32 +0530 (Thu, 01 Feb 2007) $ - */ -public class MultivaluePropertyLoadingTestCase extends TestCase { - private PropertyLoader propertyLoader; - private XMLInputFactory xmlFactory; - - - public void testPropertyLoading_SimpleType() throws Exception { - String xml = "" - + "" - + "TestPropertyValue1" - + "" - + "" - + "TestPropertyValue2" - + "" - + ""; - - XMLStreamReader reader = getReader(xml); - Property aProperty = propertyLoader.load(null, null, reader, null); - - assertEquals("TestProperty", aProperty.getName()); - assertEquals(new QName("http://www.w3.org/2001/XMLSchema", "string", "xs"), aProperty.getXmlType()); - assertEquals(false, aProperty.isMustSupply()); - assertEquals(true, aProperty.isMany()); - - Element secondValue = aProperty.getDefaultValues().get(1); - - NodeList childNodes = secondValue.getChildNodes(); - assertEquals(1, childNodes.getLength()); - - Text t = (Text) childNodes.item(0); - assertEquals("TestPropertyValue2", t.getTextContent()); - } - - public void testPropertyLoading_Type() throws Exception { - String xml = "" - + "" - + "AValue" - + "InterestingURI" - + "" - + "" - + "BValue" - + "BoringURI" - + "" - + ""; - - - - XMLStreamReader reader = getReader(xml); - Property aProperty = propertyLoader.load(null, null, reader, null); - - assertEquals("complexFoo", aProperty.getName()); - assertEquals(new QName("http://foo.com", "MyComplexType", "foo"), aProperty.getXmlType()); - assertEquals(false, aProperty.isMustSupply()); - assertEquals(true, aProperty.isMany()); - - Element secondValue = aProperty.getDefaultValues().get(1); - - NodeList childNodes = secondValue.getChildNodes(); - assertEquals(2, childNodes.getLength()); - - Element e = (Element) childNodes.item(0); - assertEquals("http://foo.com", e.getNamespaceURI()); - assertEquals("a", e.getLocalName()); - assertEquals("BValue", e.getTextContent()); - e = (Element) childNodes.item(1); - assertEquals("http://foo.com", e.getNamespaceURI()); - assertEquals("b", e.getLocalName()); - assertEquals("BoringURI", e.getTextContent()); - } - - public void testPropertyLoading_Element() throws Exception { - String xml = - "\n" - + "" - + "aValue1" - + "InterestingURI1" - + "" - + "" - + "aValue2" - + "InterestingURI2" - + "" - + ""; - XMLStreamReader reader = getReader(xml); - Property aProperty = propertyLoader.load(null, null, reader, null); - - Element secondElement = aProperty.getDefaultValues().get(1); - - assertEquals(2, aProperty.getDefaultValues().size()); - assertEquals("TestProperty", aProperty.getName()); - assertEquals(new QName("http://foo.com", "TestElement", "foo"), aProperty.getXmlElement()); - assertEquals(false, aProperty.isMustSupply()); - assertEquals(true, aProperty.isMany()); - - NodeList childNodes = secondElement.getChildNodes(); - assertEquals(2, childNodes.getLength()); - - Element e = (Element) childNodes.item(0); - assertEquals("http://foo.com", e.getNamespaceURI()); - assertEquals("a", e.getLocalName()); - assertEquals("aValue2", e.getTextContent()); - e = (Element) childNodes.item(1); - assertEquals("http://foo.com", e.getNamespaceURI()); - assertEquals("b", e.getLocalName()); - assertEquals("InterestingURI2", e.getTextContent()); - } - - public void testManyValueException() throws Exception { - String xml = - "\n" - + "" - + "aValue1" - + "InterestingURI1" - + "" - + "" - + "aValue2" - + "InterestingURI2" - + "" - + ""; - - XMLStreamReader reader = getReader(xml); - - try { - propertyLoader.load(null, null, reader, null); - } catch (Exception e) { - assertTrue(e instanceof ManyPropertyValueLoaderException); - } - } - - 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(); - propertyLoader = new PropertyLoader(EasyMock.createMock(LoaderRegistry.class)); - } - - private void printNode(Node node) throws Exception { - javax.xml.transform.Transformer transformer = - TransformerFactory.newInstance().newTransformer(); - JavaBean2DOMNodeTransformer java2DomTransformer = new JavaBean2DOMNodeTransformer(); - StringWriter sw = new StringWriter(); - transformer.transform(new DOMSource(node), new StreamResult(sw)); - - System.out.println(sw.toString()); - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/PolicySetLoaderTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/PolicySetLoaderTestCase.java deleted file mode 100644 index 8e18c2ff0f..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/PolicySetLoaderTestCase.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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, 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 intentMaps = policySet.getIntentMaps(); - assertEquals(1, intentMaps.size()); - IntentMap intentMap = intentMaps.iterator().next(); - assertEquals("transport", intentMap.getDefaultProvideIntent()); - assertTrue(intentMap.getProvideIntents().contains("sec.confidentiality")); - Collection 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/PropertyLoaderTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/PropertyLoaderTestCase.java deleted file mode 100644 index c357d9bc0a..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/PropertyLoaderTestCase.java +++ /dev/null @@ -1,180 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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 java.io.StringWriter; - -import javax.xml.namespace.QName; -import javax.xml.stream.XMLInputFactory; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.stream.StreamResult; - -import junit.framework.TestCase; - -import org.apache.tuscany.core.databinding.javabeans.JavaBean2DOMNodeTransformer; -import org.apache.tuscany.spi.loader.LoaderRegistry; -import org.apache.tuscany.spi.model.Property; -import org.easymock.EasyMock; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; -import org.w3c.dom.Text; - -/** - * @version $Rev: 502055 $ $Date: 2007-02-01 05:37:32 +0530 (Thu, 01 Feb 2007) $ - */ -public class PropertyLoaderTestCase extends TestCase { - private PropertyLoader propertyLoader; - private XMLInputFactory xmlFactory; - - - public void testPropertyLoading_SimpleType() throws Exception { - String xml = "" - + "TestPropertyValue" - + ""; - - XMLStreamReader reader = getReader(xml); - Property aProperty = propertyLoader.load(null, null, reader, null); - - assertEquals("TestProperty", aProperty.getName()); - assertEquals(new QName("http://www.w3.org/2001/XMLSchema", "string", "xs"), aProperty.getXmlType()); - assertEquals(false, aProperty.isMustSupply()); - assertEquals(false, aProperty.isMany()); - - Element root = aProperty.getDefaultValues().get(0); - - NodeList childNodes = root.getChildNodes(); - assertEquals(1, childNodes.getLength()); - - Text t = (Text) childNodes.item(0); - assertEquals("TestPropertyValue", t.getTextContent()); - } - - - public void testPropertyLoading_Type() throws Exception { - String xml = "" - + "" - + "AValue" - + "InterestingURI" - + "" - + ""; - - XMLStreamReader reader = getReader(xml); - Property aProperty = propertyLoader.load(null, null, reader, null); - assertEquals("complexFoo", aProperty.getName()); - assertEquals(new QName("http://foo.com", "MyComplexType", "foo"), aProperty.getXmlType()); - assertEquals(false, aProperty.isMustSupply()); - assertEquals(false, aProperty.isMany()); - - Element root = aProperty.getDefaultValues().get(0); - - 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 void testPropertyLoading_Element() throws Exception { - String xml = "\n" - + "" - + "aValue" - + "InterestingURI" - + "" - + ""; - XMLStreamReader reader = getReader(xml); - Property aProperty = propertyLoader.load(null, null, reader, null); - - Element root = aProperty.getDefaultValues().get(0); - - assertEquals("TestProperty", aProperty.getName()); - assertEquals(new QName("http://foo.com", "TestElement", "foo"), aProperty.getXmlElement()); - assertEquals(false, aProperty.isMustSupply()); - assertEquals(false, aProperty.isMany()); - - 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 void testPropertyLoadingNoDefault() throws Exception { - String xml = "" - + "aValue" - + "InterestingURI" - + ""; - - XMLStreamReader reader = getReader(xml); - - try { - propertyLoader.load(null, null, reader, null); - } catch (Exception e) { - assertTrue(e instanceof DefaultPropertyValueLoaderException); - } - } - - 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(); - propertyLoader = new PropertyLoader(EasyMock.createMock(LoaderRegistry.class)); - } - - private void printNode(Node node) throws Exception { - javax.xml.transform.Transformer transformer = - TransformerFactory.newInstance().newTransformer(); - JavaBean2DOMNodeTransformer java2DomTransformer = new JavaBean2DOMNodeTransformer(); - StringWriter sw = new StringWriter(); - transformer.transform(new DOMSource(node), new StreamResult(sw)); - - System.out.println(sw.toString()); - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/PropertyParsingTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/PropertyParsingTestCase.java deleted file mode 100644 index a82e5f6b72..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/PropertyParsingTestCase.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.stream.XMLInputFactory; -import javax.xml.stream.XMLStreamReader; -import javax.xml.stream.XMLStreamException; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.DocumentBuilder; - -import junit.framework.TestCase; - -import org.apache.tuscany.spi.util.stax.StaxUtil; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.NodeList; - -/** - * @version $Rev$ $Date$ - */ -public class PropertyParsingTestCase extends TestCase { - private XMLInputFactory xmlFactory; - private DocumentBuilder docBuilder; - private Element root; - - public void testComplexProperty() throws XMLStreamException { - String xml = "" - + "aValue" - + "InterestingURI" - + ""; - - XMLStreamReader reader = getReader(xml); - StaxUtil.loadPropertyValue(reader, root, root.getOwnerDocument()); - 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/ReferenceLoaderTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/ReferenceLoaderTestCase.java deleted file mode 100644 index 6254835f13..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/ReferenceLoaderTestCase.java +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.XMLStreamConstants; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; - -import junit.framework.TestCase; - -import org.apache.tuscany.core.deployer.RootDeploymentContext; -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.ComponentTypeReferenceDefinition; -import org.apache.tuscany.spi.model.Property; -import org.apache.tuscany.spi.model.ServiceContract; -import org.apache.tuscany.spi.model.ServiceDefinition; -import org.easymock.EasyMock; -import org.osoa.sca.Constants; - -/** - * 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 ReferenceLoader loader; - private DeploymentContext deploymentContext; - private XMLStreamReader mockReader; - private LoaderRegistry mockRegistry; - - 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.getAttributeValue(null, "wiredByImpl")).andReturn("false"); - EasyMock.expect(mockReader.getAttributeValue(null, "target")).andReturn(null); - EasyMock.expect(mockReader.next()).andReturn(XMLStreamConstants.END_ELEMENT); - EasyMock.expect(mockReader.getName()).andReturn(REFERENCE).anyTimes(); - EasyMock.replay(mockReader); - ComponentTypeReferenceDefinition referenceDefinition = - loader.load(null, new ComponentType>(), mockReader, null); - assertNotNull(referenceDefinition); - assertEquals(name, referenceDefinition.getName()); - } - - 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.getAttributeValue(null, "wiredByImpl")).andReturn("false"); - EasyMock.expect(mockReader.getAttributeValue(null, "target")).andReturn(null); - EasyMock.expect(mockReader.next()).andReturn(XMLStreamConstants.END_ELEMENT); - EasyMock.expect(mockReader.getName()).andReturn(REFERENCE).anyTimes(); - EasyMock.replay(mockReader); - ComponentType> type = - new ComponentType>(); - ComponentTypeReferenceDefinition referenceDefinition = loader.load(null, type, mockReader, null); - assertTrue(ComponentTypeReferenceDefinition.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.getAttributeValue(null, "wiredByImpl")).andReturn("false"); - EasyMock.expect(mockReader.getAttributeValue(null, "target")).andReturn(null); - 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() { - public Object clone() { - return null; - } - }; - EasyMock.expect(mockRegistry.load(null, null, mockReader, null)).andReturn(binding).times(2); - EasyMock.replay(mockRegistry); - - ComponentType> type = - new ComponentType>(); - ComponentTypeReferenceDefinition referenceDefinition = loader.load(null, type, mockReader, null); - 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.getAttributeValue(null, "wiredByImpl")).andReturn("false"); - EasyMock.expect(mockReader.getAttributeValue(null, "target")).andReturn(null); - EasyMock.expect(mockReader.next()).andReturn(XMLStreamConstants.START_ELEMENT); - EasyMock.expect(mockRegistry.load(null, null, mockReader, deploymentContext)).andReturn(sc); - EasyMock.expect(mockReader.next()).andReturn(XMLStreamConstants.END_ELEMENT); - - EasyMock.replay(mockReader); - EasyMock.replay(mockRegistry); - - ComponentType> type = - new ComponentType>(); - ComponentTypeReferenceDefinition referenceDefinition = loader.load(null, type, mockReader, deploymentContext); - assertNotNull(referenceDefinition); - assertEquals(name, referenceDefinition.getName()); - assertSame(sc, referenceDefinition.getServiceContract()); - } - - protected void setUp() throws Exception { - super.setUp(); - mockReader = EasyMock.createStrictMock(XMLStreamReader.class); - mockRegistry = EasyMock.createMock(LoaderRegistry.class); - loader = new ReferenceLoader(mockRegistry); - deploymentContext = new RootDeploymentContext(null, null, null, null); - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/ServiceLoaderTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/ServiceLoaderTestCase.java deleted file mode 100644 index 6e13256440..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/ServiceLoaderTestCase.java +++ /dev/null @@ -1,166 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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 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.ComponentTypeReferenceDefinition; -import org.apache.tuscany.spi.model.Property; -import org.apache.tuscany.spi.model.AbstractReferenceDefinition; -import org.apache.tuscany.spi.model.ServiceContract; -import org.apache.tuscany.spi.model.ServiceDefinition; - -import junit.framework.TestCase; -import org.apache.tuscany.core.deployer.RootDeploymentContext; -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 BINDING = new QName(SCA_NS, "binding.foo"); - private static final QName REFERENCE = new QName(SCA_NS, "reference"); - private static final QName INTERFACE_JAVA = new QName(SCA_NS, "interface.java"); - - private ServiceLoader loader; - private DeploymentContext deploymentContext; - private XMLStreamReader mockReader; - private LoaderRegistry mockRegistry; - - public void testWithNoInterface() throws LoaderException, XMLStreamException { - String name = "serviceDefinition"; - expect(mockReader.getName()).andReturn(SERVICE).anyTimes(); - expect(mockReader.getAttributeValue(null, "name")).andReturn(name); - expect(mockReader.next()).andReturn(END_ELEMENT); - expect(mockReader.getName()).andReturn(SERVICE).anyTimes(); - replay(mockReader); - ServiceDefinition serviceDefinition = loader.load(null, null, mockReader, null); - assertNotNull(serviceDefinition); - assertEquals(name, serviceDefinition.getName()); - } - - public void testComponentTypeService() throws LoaderException, XMLStreamException { - String name = "service"; - expect(mockReader.getName()).andReturn(SERVICE).anyTimes(); - expect(mockReader.getAttributeValue(null, "name")).andReturn(name); - expect(mockReader.next()).andReturn(END_ELEMENT); - expect(mockReader.getName()).andReturn(SERVICE).anyTimes(); - replay(mockReader); - ComponentType> type = - new ComponentType>(); - ServiceDefinition serviceDefinition = loader.load(null, type, mockReader, null); - 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.next()).andReturn(START_ELEMENT); - expect(mockReader.getName()).andReturn(BINDING); - expect(mockReader.next()).andReturn(START_ELEMENT); - expect(mockReader.getName()).andReturn(BINDING); - expect(mockReader.next()).andReturn(END_ELEMENT); - expect(mockReader.getName()).andReturn(SERVICE).anyTimes(); - replay(mockReader); - - BindingDefinition binding = new BindingDefinition() { - public Object clone() { - return null; - } - }; - expect(mockRegistry.load(null, null, mockReader, null)).andReturn(binding).times(2); - replay(mockRegistry); - - ServiceDefinition serviceDefinition = loader.load(null, null, mockReader, null); - 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.next()).andReturn(START_ELEMENT); - expect(mockReader.getName()).andReturn(INTERFACE_JAVA); - expect(mockRegistry.load(null, null, mockReader, deploymentContext)).andReturn(sc); - expect(mockReader.next()).andReturn(START_ELEMENT); - expect(mockReader.getName()).andReturn(REFERENCE); - expect(mockReader.getElementText()).andReturn(target); - expect(mockReader.next()).andReturn(END_ELEMENT); - expect(mockReader.getName()).andReturn(REFERENCE); - expect(mockReader.next()).andReturn(END_ELEMENT); - expect(mockReader.getName()).andReturn(SERVICE); - - replay(mockReader); - replay(mockRegistry); - - ServiceDefinition serviceDefinition = loader.load(null, null, mockReader, deploymentContext); - assertNotNull(serviceDefinition); - assertEquals(name, serviceDefinition.getName()); - 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.next()).andReturn(START_ELEMENT); - expect(mockReader.getName()).andReturn(INTERFACE_JAVA); - expect(mockRegistry.load(null, 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, null, mockReader, deploymentContext); - assertNotNull(serviceDefinition); - assertEquals(name, serviceDefinition.getName()); - 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); - deploymentContext = new RootDeploymentContext(null, null, null, null); - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/StAXLoaderRegistryImplTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/StAXLoaderRegistryImplTestCase.java deleted file mode 100644 index 74a40c80a9..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/StAXLoaderRegistryImplTestCase.java +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.CompositeComponent; -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 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) 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(EasyMock.isA(CompositeComponent.class), - (ModelObject) isNull(), - EasyMock.eq(mockReader), - EasyMock.eq(deploymentContext))).andReturn(modelObject); - EasyMock.replay(mockLoader); - registry.registerLoader(name, (StAXElementLoader) mockLoader); - CompositeComponent parent = EasyMock.createNiceMock(CompositeComponent.class); - assertSame(modelObject, registry.load(parent, 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, 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.isA(CompositeComponent.class), - EasyMock.eq(modelObject), - EasyMock.eq(mockReader), - EasyMock.eq(deploymentContext))).andReturn(modelObject); - EasyMock.replay(mockLoader); - registry.registerLoader(name, (StAXElementLoader) mockLoader); - CompositeComponent parent = EasyMock.createNiceMock(CompositeComponent.class); - assertSame(modelObject, registry.load(parent, 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); - 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/StringParserPropertyFactoryTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/StringParserPropertyFactoryTestCase.java deleted file mode 100644 index 002eb6646e..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/StringParserPropertyFactoryTestCase.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.ArrayList; -import java.util.List; - -import junit.framework.TestCase; - -import org.apache.tuscany.spi.ObjectFactory; -import org.apache.tuscany.spi.model.Property; -import org.apache.tuscany.spi.model.PropertyValue; -import org.easymock.EasyMock; -import org.w3c.dom.Document; -import org.w3c.dom.Element; - -/** - * @version $Rev$ $Date$ - */ -public class StringParserPropertyFactoryTestCase extends TestCase { - - private PropertyValue 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); - - List valueList = new ArrayList(); - valueList.add(element); - return new PropertyValue(null, valueList); - } - - public void testInteger() throws Exception { - - StringParserPropertyFactory factory = new StringParserPropertyFactory(); - Property property = new Property(); - property.setJavaType(Integer.class); - PropertyValue propertyValue = mock("1"); - ObjectFactory oFactory = factory.createObjectFactory(property, propertyValue); - assertEquals(1, oFactory.getInstance().intValue()); - } - - public void testPrimitiveInt() throws Exception { - StringParserPropertyFactory factory = new StringParserPropertyFactory(); - Property property = new Property(); - property.setJavaType(Integer.TYPE); - PropertyValue propertyValue = mock("1"); - ObjectFactory oFactory = factory.createObjectFactory(property, propertyValue); - assertEquals(1, oFactory.getInstance().intValue()); - } - - public void testString() throws Exception { - StringParserPropertyFactory factory = new StringParserPropertyFactory(); - Property property = new Property(); - property.setJavaType(String.class); - PropertyValue propertyValue = mock("1"); - ObjectFactory oFactory = factory.createObjectFactory(property, propertyValue); - assertEquals("1", oFactory.getInstance()); - } - - public void testByteArray() throws Exception { - StringParserPropertyFactory factory = new StringParserPropertyFactory(); - Property property = new Property(); - property.setJavaType(byte[].class); - PropertyValue propertyValue = mock("1"); - ObjectFactory 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 property = new Property(); - property.setJavaType(Boolean.class); - PropertyValue propertyValue = mock("true"); - ObjectFactory oFactory = factory.createObjectFactory(property, propertyValue); - assertTrue(oFactory.getInstance()); - } - - public void testPrimitiveBoolean() throws Exception { - StringParserPropertyFactory factory = new StringParserPropertyFactory(); - Property property = new Property(); - property.setJavaType(Boolean.TYPE); - PropertyValue propertyValue = mock("true"); - ObjectFactory oFactory = factory.createObjectFactory(property, propertyValue); - assertTrue(oFactory.getInstance()); - } - - public void testStringConstructor() throws Exception { - StringParserPropertyFactory factory = new StringParserPropertyFactory(); - Property property = new Property(); - property.setJavaType(Foo.class); - PropertyValue propertyValue = mock("test"); - ObjectFactory 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/WireLoaderTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/WireLoaderTestCase.java deleted file mode 100644 index 2e42c0e70d..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/WireLoaderTestCase.java +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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 static javax.xml.stream.XMLStreamConstants.END_ELEMENT; -import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; -import org.easymock.EasyMock; - -import static org.osoa.sca.Constants.SCA_NS; - -import javax.xml.namespace.QName; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; -import javax.xml.stream.Location; - -import junit.framework.TestCase; - -import org.apache.tuscany.spi.component.CompositeComponent; -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; - -/** - * @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 CompositeComponent 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(composite, 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(composite, 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(composite, 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(composite, 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(composite, null, reader, context); - fail(); - } catch (InvalidWireException e) { - //expected behaviour - } - verify(registry, reader, context); - } - - 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(CompositeComponent.class); - loader = new WireLoader(registry); - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/binding/MockServiceBinding.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/binding/MockServiceBinding.java deleted file mode 100644 index 8a38665584..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/binding/MockServiceBinding.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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 javax.xml.namespace.QName; - -import org.apache.tuscany.spi.component.AbstractSCAObject; -import org.apache.tuscany.spi.component.Service; -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.Scope; -import org.apache.tuscany.spi.model.ServiceContract; -import org.apache.tuscany.spi.wire.InboundWire; -import org.apache.tuscany.spi.wire.OutboundWire; -import org.apache.tuscany.spi.wire.TargetInvoker; - -/** - * @version $Rev$ $Date$ - */ -public class MockServiceBinding extends AbstractSCAObject implements ServiceBinding { - private InboundWire inboundWire; - private OutboundWire outboundWire; - private ServiceContract bindingServiceContract; - - - public MockServiceBinding() { - super("foo", null); - } - - public QName getBindingType() { - return null; - } - - public void setService(Service service) { - } - - public ServiceContract getBindingServiceContract() { - return bindingServiceContract; - } - - public InboundWire getInboundWire() { - return inboundWire; - } - - public void setInboundWire(InboundWire inboundWire) { - this.inboundWire = inboundWire; - } - - public OutboundWire getOutboundWire() { - return outboundWire; - } - - public void setOutboundWire(OutboundWire outboundWire) { - this.outboundWire = outboundWire; - } - - public TargetInvoker createTargetInvoker(ServiceContract contract, Operation operation) - throws TargetInvokerCreationException { - return null; - } - - public Scope getScope() { - return null; - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/AsyncTarget.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/AsyncTarget.java deleted file mode 100644 index 653d5d7335..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/AsyncTarget.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/BadContextPojo.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/BadContextPojo.java deleted file mode 100644 index 066acc346d..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/BadContextPojo.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/BadNamePojo.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/BadNamePojo.java deleted file mode 100644 index 77ec37f9e4..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/BadNamePojo.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/BasicInterface.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/BasicInterface.java deleted file mode 100644 index b7921c248f..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/BasicInterface.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/BasicInterfaceImpl.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/BasicInterfaceImpl.java deleted file mode 100644 index f7d7bb38cf..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/BasicInterfaceImpl.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeComponent.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeComponent.java deleted file mode 100644 index 88b97216cd..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeComponent.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeComponentImpl.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeComponentImpl.java deleted file mode 100644 index 93ee1f707a..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeComponentImpl.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeDestroyOnlyComponent.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeDestroyOnlyComponent.java deleted file mode 100644 index 16ce3b5569..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeDestroyOnlyComponent.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeInitDestroyComponent.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeInitDestroyComponent.java deleted file mode 100644 index 05b938a87c..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeInitDestroyComponent.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeInitOnlyComponent.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeInitOnlyComponent.java deleted file mode 100644 index f9f80ca15c..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeInitOnlyComponent.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeComponent.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeComponent.java deleted file mode 100644 index c71ac0586f..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeComponent.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeComponentImpl.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeComponentImpl.java deleted file mode 100644 index 5ea7278e1f..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeComponentImpl.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeDestroyOnlyComponent.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeDestroyOnlyComponent.java deleted file mode 100644 index 8cea9efa49..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeDestroyOnlyComponent.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeInitDestroyComponent.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeInitDestroyComponent.java deleted file mode 100644 index 40dbfedf2c..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeInitDestroyComponent.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeInitOnlyComponent.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeInitOnlyComponent.java deleted file mode 100644 index caaa0c39e7..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeInitOnlyComponent.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OrderException.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OrderException.java deleted file mode 100644 index af257c226d..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OrderException.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OrderedDependentPojo.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OrderedDependentPojo.java deleted file mode 100644 index 2033f0eca5..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OrderedDependentPojo.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OrderedDependentPojoImpl.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OrderedDependentPojoImpl.java deleted file mode 100644 index 439c3d143c..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OrderedDependentPojoImpl.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OrderedEagerInitPojo.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OrderedEagerInitPojo.java deleted file mode 100644 index 1986952747..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OrderedEagerInitPojo.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OrderedInitPojo.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OrderedInitPojo.java deleted file mode 100644 index 0b891cfa42..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OrderedInitPojo.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OrderedInitPojoImpl.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OrderedInitPojoImpl.java deleted file mode 100644 index a7063f6353..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OrderedInitPojoImpl.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OtherTarget.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OtherTarget.java deleted file mode 100644 index 0b897daa40..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OtherTarget.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OtherTargetImpl.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OtherTargetImpl.java deleted file mode 100644 index a3b2bbf098..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OtherTargetImpl.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/RequestScopeComponent.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/RequestScopeComponent.java deleted file mode 100644 index 8c7dc107ee..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/RequestScopeComponent.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/RequestScopeDestroyOnlyComponent.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/RequestScopeDestroyOnlyComponent.java deleted file mode 100644 index 5224ceda5f..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/RequestScopeDestroyOnlyComponent.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/RequestScopeInitDestroyComponent.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/RequestScopeInitDestroyComponent.java deleted file mode 100644 index 38b188a4b5..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/RequestScopeInitDestroyComponent.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/RequestScopeInitOnlyComponent.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/RequestScopeInitOnlyComponent.java deleted file mode 100644 index 707f8ab50f..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/RequestScopeInitOnlyComponent.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/SessionScopeComponent.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/SessionScopeComponent.java deleted file mode 100644 index 827ba804f2..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/SessionScopeComponent.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/SessionScopeComponentImpl.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/SessionScopeComponentImpl.java deleted file mode 100644 index e547bf6113..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/SessionScopeComponentImpl.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/SessionScopeInitDestroyComponent.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/SessionScopeInitDestroyComponent.java deleted file mode 100644 index c11bd1bd49..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/SessionScopeInitDestroyComponent.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/SessionScopeInitOnlyComponent.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/SessionScopeInitOnlyComponent.java deleted file mode 100644 index 095cc916ec..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/SessionScopeInitOnlyComponent.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/SimpleTarget.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/SimpleTarget.java deleted file mode 100644 index c78ba00a7a..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/SimpleTarget.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/SimpleTargetImpl.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/SimpleTargetImpl.java deleted file mode 100644 index 634a07a401..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/SimpleTargetImpl.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/Source.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/Source.java deleted file mode 100644 index f7969f748b..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/Source.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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 getTargets(); - - List getTargetsThroughField(); - -} - diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/SourceImpl.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/SourceImpl.java deleted file mode 100644 index 187e33b2bd..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/SourceImpl.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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 targets; - private List targetsThroughField; - private Target[] targetsArray; - - public void setTarget(Target target) { - this.target = target; - } - - public Target getTarget() { - return target; - } - - public List getTargets() { - return targets; - } - - public void setTargets(List targets) { - this.targets = targets; - } - - public List getTargetsThroughField() { - return targetsThroughField; - } - - public Target[] getArrayOfTargets() { - return targetsArray; - } - - public void setArrayOfTargets(Target[] targets) { - targetsArray = targets; - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/StatelessComponent.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/StatelessComponent.java deleted file mode 100644 index c16ac942a3..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/StatelessComponent.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/StatelessComponentImpl.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/StatelessComponentImpl.java deleted file mode 100644 index 64a23c12c8..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/StatelessComponentImpl.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/Target.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/Target.java deleted file mode 100644 index 778c14665d..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/Target.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/TargetImpl.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/TargetImpl.java deleted file mode 100644 index 037dd3a37c..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/TargetImpl.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/wire/MockStaticInvoker.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/wire/MockStaticInvoker.java deleted file mode 100644 index cdd0de7a6d..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/wire/MockStaticInvoker.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/wire/MockSyncInterceptor.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/wire/MockSyncInterceptor.java deleted file mode 100644 index 1fe2c027ab..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/wire/MockSyncInterceptor.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/wire/MockTargetInvoker.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/wire/MockTargetInvoker.java deleted file mode 100644 index 3fcc75bdb4..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/wire/MockTargetInvoker.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/monitor/DefaultExceptionFormatterTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/monitor/DefaultExceptionFormatterTestCase.java deleted file mode 100644 index 2d3f01422d..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/monitor/DefaultExceptionFormatterTestCase.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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") { - }; - e.addContextName("somecontext"); - formatter.write(pw, e); - assertTrue(writer.toString().indexOf("somemessage") >= 0); - assertTrue(writer.toString().indexOf("somecontext") >= 0); - } - - public void testTuscanyRuntimeExceptionFormat() throws Exception { - StringWriter writer = new StringWriter(); - PrintWriter pw = new PrintWriter(writer); - TuscanyRuntimeException e = new TuscanyRuntimeException("somemessage") { - }; - e.addContextName("somecontext"); - formatter.write(pw, e); - assertTrue(writer.toString().indexOf("somemessage") >= 0); - assertTrue(writer.toString().indexOf("somecontext") >= 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/monitor/JavaLoggingTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/monitor/JavaLoggingTestCase.java deleted file mode 100644 index 5fdf035c7a..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/monitor/JavaLoggingTestCase.java +++ /dev/null @@ -1,153 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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 logs = new ArrayList(); - - 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/policy/IntentRegistryImplTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/policy/IntentRegistryImplTestCase.java deleted file mode 100644 index de1c91b741..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/policy/IntentRegistryImplTestCase.java +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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 intentNameList = new ArrayList(); -// 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 intents = new ArrayList(); - intents.add(new IntentName("sec.confidentiality/all")); - Collection 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 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/policy/PolicyEngineImplTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/policy/PolicyEngineImplTestCase.java deleted file mode 100644 index afb8981951..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/policy/PolicyEngineImplTestCase.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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 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, 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 sets = new HashMap(); - - public Collection 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/property/PropertyHelperTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/property/PropertyHelperTestCase.java deleted file mode 100644 index 5ddd0b32ce..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/property/PropertyHelperTestCase.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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 = - "" + "" - + " " - + " Helen Zoe" - + " 47 Eden Street" - + " Cambridge" - + " CB1 1JR" - + " " - + " " - + " Robert Smith" - + " 8 Oak Avenue" - + " Old Town" - + " PA" - + " 95819" - + " " - + " " - + " " - + " Lapis necklace" - + " 1" - + " 99.95" - + " Want this for the holidays" - + " 1999-12-05" - + " " - + " " - + ""; - - /** - * @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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/property/SimplePropertyObjectFactoryTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/property/SimplePropertyObjectFactoryTestCase.java deleted file mode 100644 index ef67533a0a..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/property/SimplePropertyObjectFactoryTestCase.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.util.ArrayList; -import java.util.List; - -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 PropertyValue 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); - - List valueList = new ArrayList(); - valueList.add(element); - return new PropertyValue(null, valueList); - } - - public void testInteger() throws Exception { - - PropertyObjectFactoryImpl factory = new PropertyObjectFactoryImpl(); - Property property = new Property(); - property.setJavaType(Integer.class); - PropertyValue propertyValue = mock("1"); - ObjectFactory oFactory = factory.createObjectFactory(property, propertyValue); - assertEquals(1, oFactory.getInstance().intValue()); - } - - public void testPrimitiveInt() throws Exception { - PropertyObjectFactoryImpl factory = new PropertyObjectFactoryImpl(); - Property property = new Property(); - property.setJavaType(Integer.TYPE); - PropertyValue propertyValue = mock("1"); - ObjectFactory oFactory = factory.createObjectFactory(property, propertyValue); - assertEquals(1, oFactory.getInstance().intValue()); - } - - public void testString() throws Exception { - PropertyObjectFactoryImpl factory = new PropertyObjectFactoryImpl(); - Property property = new Property(); - property.setJavaType(String.class); - PropertyValue propertyValue = mock("1"); - ObjectFactory oFactory = factory.createObjectFactory(property, propertyValue); - assertEquals("1", oFactory.getInstance()); - } - - public void testByteArray() throws Exception { - PropertyObjectFactoryImpl factory = new PropertyObjectFactoryImpl(); - Property property = new Property(); - property.setJavaType(byte[].class); - PropertyValue propertyValue = mock("TWFu"); // BASE64 for "Man" - ObjectFactory 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 property = new Property(); - property.setJavaType(Boolean.class); - PropertyValue propertyValue = mock("true"); - ObjectFactory oFactory = factory.createObjectFactory(property, propertyValue); - assertTrue(oFactory.getInstance()); - } - - public void testPrimitiveBoolean() throws Exception { - PropertyObjectFactoryImpl factory = new PropertyObjectFactoryImpl(); - Property property = new Property(); - property.setJavaType(Boolean.TYPE); - PropertyValue propertyValue = mock("true"); - ObjectFactory oFactory = factory.createObjectFactory(property, propertyValue); - assertTrue(oFactory.getInstance()); - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/artifact/LocalMavenRepositoryTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/artifact/LocalMavenRepositoryTestCase.java deleted file mode 100644 index 0efecb9302..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/artifact/LocalMavenRepositoryTestCase.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/AssemblyServiceImplTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/AssemblyServiceImplTestCase.java deleted file mode 100644 index fb1daf7e5f..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/AssemblyServiceImplTestCase.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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(null, null); - } - - 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/ContentTypeDescriberImplTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/ContentTypeDescriberImplTestCase.java deleted file mode 100644 index 8bb800962f..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/ContentTypeDescriberImplTestCase.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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; - -import org.apache.tuscany.spi.deployer.ContentType; - -public class ContentTypeDescriberImplTestCase extends TestCase { - private ContentTypeDescriberImpl contentTypeBuilder; - - public void testResolveContentType() throws Exception { - URL artifactURL = getClass().getResource("test.scdl"); - assertEquals(ContentType.COMPOSITE, 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/vnd.tuscany.ext", - contentTypeBuilder.getContentType(artifactURL, "application/vnd.tuscany.ext")); - } - - protected void setUp() throws Exception { - super.setUp(); - contentTypeBuilder = new ContentTypeDescriberImpl(); - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/ContributionLoaderTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/ContributionLoaderTestCase.java deleted file mode 100644 index 85e959cb87..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/ContributionLoaderTestCase.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.StringReader; - -import javax.xml.stream.XMLInputFactory; -import javax.xml.stream.XMLStreamReader; - -import org.apache.tuscany.spi.loader.InvalidValueException; -import org.apache.tuscany.spi.model.Contribution; - -import junit.framework.TestCase; - -/** - * @version $Rev$ $Date$ - */ -public class ContributionLoaderTestCase extends TestCase { - - private static final String VALID_XML = - "" - + "" - + "" - + "" - + "" - + "" - + ""; - - private static final String INVALID_XML = - "" - + "" - + "" - + "" - + "" - + "" - + ""; - - private XMLInputFactory factory; - - protected void setUp() throws Exception { - super.setUp(); - factory = XMLInputFactory.newInstance(); - } - - public void testLoad() throws Exception { - XMLStreamReader reader = factory.createXMLStreamReader(new StringReader(VALID_XML)); - ContributionLoader loader = new ContributionLoader(null); - Contribution contribution = loader.load(null, null, reader, null); - assertNotNull(contribution); - assertEquals(1, contribution.getImports().size()); - assertEquals(1, contribution.getExports().size()); - assertEquals(2, contribution.getDeployables().size()); - } - - public void testLoadInvalid() throws Exception { - XMLStreamReader reader = factory.createXMLStreamReader(new StringReader(INVALID_XML)); - ContributionLoader loader = new ContributionLoader(null); - try { - loader.load(null, null, reader, null); - fail("InvalidException should have been thrown"); - } catch (InvalidValueException e) { - assertTrue(true); - } - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/ContributionRepositoryTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/ContributionRepositoryTestCase.java deleted file mode 100644 index 0641520b3c..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/ContributionRepositoryTestCase.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.File; -import java.io.InputStream; -import java.net.URI; -import java.net.URL; - -import org.apache.tuscany.core.util.FileHelper; - -import junit.framework.TestCase; - -public class ContributionRepositoryTestCase extends TestCase { - private ContributionRepositoryImpl repository; - - protected void setUp() throws Exception { - super.setUp(); - // create repository (this should re-create the root directory) - this.repository = new ContributionRepositoryImpl("target/repository/"); - repository.init(); - } - - public void testStore() throws Exception { - String resourceLocation = "/repository/sample-calculator.jar"; - URI contribution = URI.create("sample-calculator.jar"); - 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 = URI.create("sample-calculator.jar"); - 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 = URI.create("sample-calculator.jar"); - InputStream contributionStream = getClass().getResourceAsStream(resourceLocation); - repository.store(contribution, contributionStream); - - assertEquals(1, repository.list().size()); - } - - @Override - protected void tearDown() throws Exception { - super.tearDown(); - FileHelper.deleteDirectory(new File("target/repository")); - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/ContributionServiceImplTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/ContributionServiceImplTestCase.java deleted file mode 100644 index 12c629f8a2..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/ContributionServiceImplTestCase.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.URI; -import java.net.URL; - -import junit.framework.TestCase; - -import org.apache.tuscany.core.services.deployment.contribution.JarContributionProcessor; -import org.apache.tuscany.core.services.deployment.contribution.JavaContributionProcessor; -import org.apache.tuscany.host.deployment.ContributionService; -import org.apache.tuscany.spi.deployer.ContentTypeDescriber; -import org.apache.tuscany.spi.deployer.ContributionProcessorRegistry; -import org.apache.tuscany.spi.deployer.ContributionRepository; - -/** - * 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/contribution/CompositeContributionProcessorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/contribution/CompositeContributionProcessorTestCase.java deleted file mode 100644 index 5d0b3227e8..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/contribution/CompositeContributionProcessorTestCase.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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 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; -import org.apache.tuscany.spi.deployer.ContributionProcessor; -import org.apache.tuscany.spi.implementation.java.ImplementationProcessorService; - -public class CompositeContributionProcessorTestCase extends TestCase { - private static final String CONTRIBUTION = "/repository/sample-calculator.jar"; - private static final String ARTIFACT_URL = "/META-INF/sca/default.scdl"; - 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 getArtifactURL() throws Exception { - URL jarURL = getClass().getResource(CONTRIBUTION); - JarInputStream jar = new JarInputStream(getClass().getResourceAsStream(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 testProcessScdl() throws Exception { - //ContributionProcessor scdlContributionProcessor = new scdlContributionProcessor(registry); - //URL jarURL = this.getClassURL(); - //javaContributionProcessor.processContent(null, jarURL, jarURL.openStream()); - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/contribution/FolderContributionProcessorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/contribution/FolderContributionProcessorTestCase.java deleted file mode 100644 index f6db2e8b7e..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/contribution/FolderContributionProcessorTestCase.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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 java.net.URI; -import java.net.URL; - -import junit.framework.TestCase; - -import org.apache.tuscany.spi.deployer.ContributionProcessorRegistry; -import org.apache.tuscany.spi.model.Contribution; -import org.easymock.EasyMock; - -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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/contribution/JarContributionProcessorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/contribution/JarContributionProcessorTestCase.java deleted file mode 100644 index 06ccd6c3da..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/contribution/JarContributionProcessorTestCase.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.URI; -import java.net.URL; - -import junit.framework.TestCase; - -import org.apache.tuscany.spi.deployer.ContributionProcessorRegistry; -import org.apache.tuscany.spi.model.Contribution; -import org.easymock.EasyMock; - -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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/contribution/JavaContributionProcessorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/contribution/JavaContributionProcessorTestCase.java deleted file mode 100644 index 269e2e6feb..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/contribution/JavaContributionProcessorTestCase.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.URI; -import java.net.URL; - -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; -import org.apache.tuscany.spi.deployer.ContributionProcessor; -import org.apache.tuscany.spi.implementation.java.ImplementationProcessorService; -import org.apache.tuscany.spi.model.Contribution; -import org.apache.tuscany.spi.model.DeployedArtifact; - -public class JavaContributionProcessorTestCase extends TestCase { - private static final String CONTRIBUTION = "/repository/sample-calculator.jar"; - private static final String JAVA_ARTIFACT = "calculator/AddService.class"; - private IntrospectionRegistryImpl registry; - private URI contributionId; - private Contribution contribution; - - 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()); - - contributionId = new URI("sca://contribution/001"); - contribution = new Contribution(contributionId); - contribution.setLocation(getClass().getResource(CONTRIBUTION)); - - DeployedArtifact classArtifact = new DeployedArtifact(contributionId); - classArtifact.setLocation(this.getArtifactURL()); - } - - protected URL getArtifactURL() throws Exception { - URL jarURL = getClass().getResource(CONTRIBUTION); - return new URL("jar:" + jarURL.toString() + "!/" + JAVA_ARTIFACT); - } - - public final void testProcessJavaArtifact() throws Exception { - //ContributionProcessor javaContributionProcessor = new JavaContributionProcessor(registry); - //URL artifactURL = this.getArtifactURL(); - //javaContributionProcessor.processContent(contribution, artifactURL.toURI(), artifactURL.openStream()); - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/host/DelegatingResourceHostRegistryTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/host/DelegatingResourceHostRegistryTestCase.java deleted file mode 100644 index c3eb2fa1bf..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/host/DelegatingResourceHostRegistryTestCase.java +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/store/memory/MemoryStoreTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/store/memory/MemoryStoreTestCase.java deleted file mode 100644 index 5ec1643b47..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/store/memory/MemoryStoreTestCase.java +++ /dev/null @@ -1,164 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.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() { - 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.createNiceMock(AtomicComponent.class); - 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/work/jsr237/Jsr237WorkSchedulerTest.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/work/jsr237/Jsr237WorkSchedulerTest.java deleted file mode 100644 index 1a5cb4ebe1..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/work/jsr237/Jsr237WorkSchedulerTest.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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) ' - */ - 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) ' - */ - public void testScheduleWorkTNotificationListenerOfT() { - - } - - private class MyRunnable implements Runnable { - public void run() { - System.err.println("Test executed"); - } - } - - private class MyNotificationListener implements NotificationListener { - - 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/work/jsr237/Jsr237WorkSchedulerTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/work/jsr237/Jsr237WorkSchedulerTestCase.java deleted file mode 100644 index 3966f65683..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/work/jsr237/Jsr237WorkSchedulerTestCase.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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 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 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/work/jsr237/workmanager/ThreadPoolWorkManagerTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/work/jsr237/workmanager/ThreadPoolWorkManagerTestCase.java deleted file mode 100644 index 33ecd66fdc..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/work/jsr237/workmanager/ThreadPoolWorkManagerTestCase.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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() { - 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() { - 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() { - public Object answer() throws Throwable { - latch2.countDown(); - return null; - } - }); - replay(listener); - Work work = createMock(Work.class); - work.run(); - expectLastCall().andStubAnswer(new IAnswer() { - 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() { - 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/util/Bean1.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/util/Bean1.java deleted file mode 100644 index 79fad549aa..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/util/Bean1.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/util/Bean2.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/util/Bean2.java deleted file mode 100644 index 7f7f03da9e..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/util/Bean2.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/util/JavaIntrospectionHelperTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/util/JavaIntrospectionHelperTestCase.java deleted file mode 100644 index 797b147b54..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/util/JavaIntrospectionHelperTestCase.java +++ /dev/null @@ -1,180 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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 testList; - private Map testMap; - private Target[] testArray; - private String[] testStringArray; - - public JavaIntrospectionHelperTestCase() { - super(); - } - - public JavaIntrospectionHelperTestCase(String arg0) { - super(arg0); - } - - public void testBean1AllPublicProtectedFields() throws Exception { - Set beanFields = JavaIntrospectionHelper.getAllPublicAndProtectedFields(Bean1.class); - assertEquals(4, beanFields.size()); //Bean1.ALL_BEAN1_PUBLIC_PROTECTED_FIELDS - } - - public void testGetSuperAllMethods() throws Exception { - Set superBeanMethods = JavaIntrospectionHelper.getAllUniquePublicProtectedMethods(SuperBean.class); - assertEquals(SuperBean.ALL_SUPER_METHODS, superBeanMethods.size()); - } - - public void testGetBean1AllMethods() throws Exception { - Set beanMethods = JavaIntrospectionHelper.getAllUniquePublicProtectedMethods(Bean1.class); - assertEquals(Bean1.ALL_BEAN1_METHODS, beanMethods.size()); - } - - public void testOverrideMethod() throws Exception { - Set 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 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 interfaces = JavaIntrospectionHelper.getAllInterfaces(Z.class); - assertEquals(2, interfaces.size()); - assertTrue(interfaces.contains(W.class)); - assertTrue(interfaces.contains(W2.class)); - } - - - public void testGetAllInterfacesObject() { - Set interfaces = JavaIntrospectionHelper.getAllInterfaces(Object.class); - assertEquals(0, interfaces.size()); - } - - public void testGetAllInterfacesNoInterfaces() { - Set 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 foo) { - - } - - private void fooMethod(Map 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/util/SuperBean.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/util/SuperBean.java deleted file mode 100644 index 83aef7fb5e..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/util/SuperBean.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/BasicReferenceInvocationHandlerTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/BasicReferenceInvocationHandlerTestCase.java deleted file mode 100644 index b62741a7e7..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/BasicReferenceInvocationHandlerTestCase.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.OutboundInvocationChain; -import org.apache.tuscany.spi.wire.OutboundWire; - -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.JDKOutboundInvocationHandler; - -/** - * @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()); - OutboundInvocationChain chain = new OutboundInvocationChainImpl(operation); - MockSyncInterceptor interceptor = new MockSyncInterceptor(); - chain.addInterceptor(interceptor); - chain.setTargetInterceptor(new InvokerInterceptor()); - chain.setTargetInvoker(invoker); - chain.prepare(); - //chains.put(echo, chain); - OutboundWire wire = new OutboundWireImpl(); - wire.addInvocationChain(operation, chain); - wire.setServiceContract(contract); - JDKOutboundInvocationHandler handler = new JDKOutboundInvocationHandler(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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/CallbackInterfaceInterceptorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/CallbackInterfaceInterceptorTestCase.java deleted file mode 100644 index 6c50cb406f..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/CallbackInterfaceInterceptorTestCase.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/ContractCompatibilityTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/ContractCompatibilityTestCase.java deleted file mode 100644 index d200b983b3..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/ContractCompatibilityTestCase.java +++ /dev/null @@ -1,401 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.AtomicComponent; -import org.apache.tuscany.spi.component.ReferenceBinding; -import org.apache.tuscany.spi.component.ServiceBinding; -import org.apache.tuscany.spi.model.ComponentDefinition; -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.model.ServiceDefinition; -import org.apache.tuscany.spi.wire.InboundInvocationChain; -import org.apache.tuscany.spi.wire.InboundWire; -import org.apache.tuscany.spi.wire.IncompatibleServiceContractException; -import org.apache.tuscany.spi.wire.OutboundChainHolder; -import org.apache.tuscany.spi.wire.OutboundInvocationChain; -import org.apache.tuscany.spi.wire.ProxyCreationException; -import org.apache.tuscany.spi.wire.Wire; -import org.apache.tuscany.spi.wire.WireInvocationHandler; -import org.apache.tuscany.spi.wire.WireService; - -import junit.framework.TestCase; - -/** - * TODO some tests commented out due to DataType.equals() needing to be strict - * - * @version $Rev$ $Date$ - */ -public class ContractCompatibilityTestCase extends TestCase { - - private WireService wireService = new MockWireService(); - - public void testNoOperation() throws Exception { - ServiceContract source = new MockContract("FooContract"); - ServiceContract target = new MockContract("FooContract"); - wireService.checkCompatibility(source, target, false); - } - - public void testBasic() throws Exception { - ServiceContract source = new MockContract("FooContract"); - Operation opSource1 = new Operation("op1", null, null, null, false, null, NO_CONVERSATION); - Map> sourceOperations = new HashMap>(); - sourceOperations.put("op1", opSource1); - source.setOperations(sourceOperations); - ServiceContract target = new MockContract("FooContract"); - Operation opSource2 = new Operation("op1", null, null, null, false, null, NO_CONVERSATION); - Map> targetOperations = new HashMap>(); - targetOperations.put("op1", opSource2); - target.setOperations(targetOperations); - wireService.checkCompatibility(source, target, false); - } - - public void testBasicIncompatibleOperationNames() throws Exception { - ServiceContract source = new MockContract("FooContract"); - Operation opSource1 = new Operation("op1", null, null, null, false, null, NO_CONVERSATION); - Map> sourceOperations = new HashMap>(); - sourceOperations.put("op1", opSource1); - source.setOperations(sourceOperations); - ServiceContract target = new MockContract("FooContract"); - Operation opSource2 = new Operation("op2", null, null, null, false, null, NO_CONVERSATION); - Map> targetOperations = new HashMap>(); - targetOperations.put("op2", opSource2); - target.setOperations(targetOperations); - try { - wireService.checkCompatibility(source, target, false); - fail(); - } catch (IncompatibleServiceContractException e) { - //expected - } - } - - public void testInputTypes() throws Exception { - ServiceContract source = new MockContract("FooContract"); - List> sourceInputTypes = new ArrayList>(); - sourceInputTypes.add(new DataType(Object.class, Object.class)); - DataType>> inputType = new DataType>>(String.class, sourceInputTypes); - Operation opSource1 = new Operation("op1", inputType, null, null, false, null, NO_CONVERSATION); - Map> sourceOperations = new HashMap>(); - sourceOperations.put("op1", opSource1); - source.setOperations(sourceOperations); - - ServiceContract target = new MockContract("FooContract"); - List> targetInputTypes = new ArrayList>(); - targetInputTypes.add(new DataType(Object.class, Object.class)); - DataType>> targetInputType = - new DataType>>(String.class, targetInputTypes); - - Operation opTarget = - new Operation("op1", targetInputType, null, null, false, null, NO_CONVERSATION); - Map> targetOperations = new HashMap>(); - targetOperations.put("op1", opTarget); - target.setOperations(targetOperations); - wireService.checkCompatibility(source, target, false); - } - - - public void testIncompatibleInputTypes() throws Exception { - ServiceContract source = new MockContract("FooContract"); - List> sourceInputTypes = new ArrayList>(); - sourceInputTypes.add(new DataType(Integer.class, Integer.class)); - DataType>> inputType = new DataType>>(String.class, sourceInputTypes); - Operation opSource1 = new Operation("op1", inputType, null, null, false, null, NO_CONVERSATION); - Map> sourceOperations = new HashMap>(); - sourceOperations.put("op1", opSource1); - source.setOperations(sourceOperations); - - ServiceContract target = new MockContract("FooContract"); - List> targetInputTypes = new ArrayList>(); - targetInputTypes.add(new DataType(String.class, String.class)); - DataType>> targetInputType = - new DataType>>(String.class, targetInputTypes); - - Operation opTarget = - new Operation("op1", targetInputType, null, null, false, null, NO_CONVERSATION); - Map> targetOperations = new HashMap>(); - targetOperations.put("op1", opTarget); - target.setOperations(targetOperations); - try { - wireService.checkCompatibility(source, target, false); - fail(); - } catch (IncompatibleServiceContractException e) { - //expected - } - } - - /** - * Verfies source input types can be super types of the target - */ - public void testSourceSuperTypeInputCompatibility() throws Exception { -// ServiceContract source = new MockContract("FooContract"); -// List> sourceInputTypes = new ArrayList>(); -// sourceInputTypes.add(new DataType(Object.class, Object.class)); -// DataType>> inputType = new DataType>>(String.class, sourceInputTypes); -// Operation opSource1 = new Operation("op1", inputType, null, null, false, null); -// Map> sourceOperations = new HashMap>(); -// sourceOperations.put("op1", opSource1); -// source.setOperations(sourceOperations); -// -// ServiceContract target = new MockContract("FooContract"); -// List> targetInputTypes = new ArrayList>(); -// targetInputTypes.add(new DataType(String.class, String.class)); -// DataType>> targetInputType = -// new DataType>>(String.class, targetInputTypes); -// -// Operation opTarget = new Operation("op1", targetInputType, null, null, false, null); -// Map> targetOperations = new HashMap>(); -// targetOperations.put("op1", opTarget); -// target.setOperations(targetOperations); -// wireService.checkCompatibility(source, target, false); - } - - public void testOutputTypes() throws Exception { - ServiceContract source = new MockContract("FooContract"); - DataType sourceOutputType = new DataType(String.class, String.class); - Operation opSource1 = - new Operation("op1", null, sourceOutputType, null, false, null, NO_CONVERSATION); - Map> sourceOperations = new HashMap>(); - sourceOperations.put("op1", opSource1); - source.setOperations(sourceOperations); - - ServiceContract target = new MockContract("FooContract"); - DataType targetOutputType = new DataType(String.class, String.class); - Operation opTarget = - new Operation("op1", null, targetOutputType, null, false, null, NO_CONVERSATION); - Map> targetOperations = new HashMap>(); - targetOperations.put("op1", opTarget); - target.setOperations(targetOperations); - wireService.checkCompatibility(source, target, false); - } - - /** - * Verfies a return type that is a supertype of of the target is compatible - */ - public void testSupertypeOutputTypes() throws Exception { -// ServiceContract source = new MockContract("FooContract"); -// DataType sourceOutputType = new DataType(Object.class, Object.class); -// Operation opSource1 = new Operation("op1", null, sourceOutputType, null, false, null); -// Map> sourceOperations = new HashMap>(); -// sourceOperations.put("op1", opSource1); -// source.setOperations(sourceOperations); -// -// ServiceContract target = new MockContract("FooContract"); -// DataType targetOutputType = new DataType(String.class, String.class); -// Operation opTarget = new Operation("op1", null, targetOutputType, null, false, null); -// Map> targetOperations = new HashMap>(); -// targetOperations.put("op1", opTarget); -// target.setOperations(targetOperations); -// wireService.checkCompatibility(source, target, false); - } - - public void testIncompatibleOutputTypes() throws Exception { - ServiceContract source = new MockContract("FooContract"); - DataType sourceOutputType = new DataType(String.class, String.class); - Operation opSource1 = - new Operation("op1", null, sourceOutputType, null, false, null, NO_CONVERSATION); - Map> sourceOperations = new HashMap>(); - sourceOperations.put("op1", opSource1); - source.setOperations(sourceOperations); - - ServiceContract target = new MockContract("FooContract"); - DataType targetOutputType = new DataType(Integer.class, Integer.class); - Operation opTarget = - new Operation("op1", null, targetOutputType, null, false, null, NO_CONVERSATION); - Map> targetOperations = new HashMap>(); - targetOperations.put("op1", opTarget); - target.setOperations(targetOperations); - try { - wireService.checkCompatibility(source, target, false); - fail(); - } catch (IncompatibleServiceContractException e) { - //expected - } - } - - public void testFaultTypes() throws Exception { - ServiceContract source = new MockContract("FooContract"); - DataType sourceFaultType = new DataType(String.class, String.class); - List> sourceFaultTypes = new ArrayList>(); - sourceFaultTypes.add(0, sourceFaultType); - Operation opSource1 = - new Operation("op1", null, null, sourceFaultTypes, false, null, NO_CONVERSATION); - Map> sourceOperations = new HashMap>(); - sourceOperations.put("op1", opSource1); - source.setOperations(sourceOperations); - - ServiceContract target = new MockContract("FooContract"); - DataType targetFaultType = new DataType(String.class, String.class); - List> targetFaultTypes = new ArrayList>(); - targetFaultTypes.add(0, targetFaultType); - - Operation opTarget = - new Operation("op1", null, null, targetFaultTypes, false, null, NO_CONVERSATION); - Map> targetOperations = new HashMap>(); - targetOperations.put("op1", opTarget); - target.setOperations(targetOperations); - wireService.checkCompatibility(source, target, false); - } - - public void testSourceFaultTargetNoFaultCompatibility() throws Exception { - ServiceContract source = new MockContract("FooContract"); - DataType sourceFaultType = new DataType(String.class, String.class); - List> sourceFaultTypes = new ArrayList>(); - sourceFaultTypes.add(0, sourceFaultType); - Operation opSource1 = - new Operation("op1", null, null, sourceFaultTypes, false, null, NO_CONVERSATION); - Map> sourceOperations = new HashMap>(); - sourceOperations.put("op1", opSource1); - source.setOperations(sourceOperations); - - ServiceContract target = new MockContract("FooContract"); - Operation opTarget = new Operation("op1", null, null, null, false, null, NO_CONVERSATION); - Map> targetOperations = new HashMap>(); - targetOperations.put("op1", opTarget); - target.setOperations(targetOperations); - wireService.checkCompatibility(source, target, 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 source = new MockContract("FooContract"); -// DataType sourceFaultType = new DataType(Exception.class, Exception.class); -// List> sourceFaultTypes = new ArrayList>(); -// sourceFaultTypes.add(0, sourceFaultType); -// Operation opSource1 = new Operation("op1", null, null, sourceFaultTypes, false, null); -// Map> sourceOperations = new HashMap>(); -// sourceOperations.put("op1", opSource1); -// source.setOperations(sourceOperations); -// -// ServiceContract target = new MockContract("FooContract"); -// DataType targetFaultType = new DataType(TuscanyException.class, TuscanyException.class); -// List> targetFaultTypes = new ArrayList>(); -// targetFaultTypes.add(0, targetFaultType); -// -// Operation opTarget = new Operation("op1", null, null, targetFaultTypes, false, null); -// Map> targetOperations = new HashMap>(); -// 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 source = new MockContract("FooContract"); -// DataType sourceFaultType = new DataType(Exception.class, Exception.class); -// DataType sourceFaultType2 = new DataType(RuntimeException.class, RuntimeException.class); -// List> sourceFaultTypes = new ArrayList>(); -// sourceFaultTypes.add(0, sourceFaultType); -// sourceFaultTypes.add(1, sourceFaultType2); -// Operation opSource1 = new Operation("op1", null, null, sourceFaultTypes, false, null); -// Map> sourceOperations = new HashMap>(); -// sourceOperations.put("op1", opSource1); -// source.setOperations(sourceOperations); -// -// ServiceContract target = new MockContract("FooContract"); -// DataType targetFaultType = new DataType(TuscanyException.class, TuscanyException.class); -// List> targetFaultTypes = new ArrayList>(); -// targetFaultTypes.add(0, targetFaultType); -// -// Operation opTarget = new Operation("op1", null, null, targetFaultTypes, false, null); -// Map> targetOperations = new HashMap>(); -// targetOperations.put("op1", opTarget); -// target.setOperations(targetOperations); -// wireService.checkCompatibility(source, target, false); - } - - private class MockContract extends ServiceContract { - public MockContract() { - } - - public MockContract(Class interfaceClass) { - super(interfaceClass); - } - - public MockContract(String interfaceName) { - super(interfaceName); - } - } - - private class MockWireService extends WireServiceExtension { - public MockWireService() { - super(null, null); - } - - public T createProxy(Class interfaze, Wire wire) throws ProxyCreationException { - throw new UnsupportedOperationException(); - } - - public T createProxy(Class interfaze, Wire wire, Map mapping) - throws ProxyCreationException { - throw new UnsupportedOperationException(); - } - - public Object createCallbackProxy(Class interfaze, InboundWire wire) throws ProxyCreationException { - throw new UnsupportedOperationException(); - } - - - public WireInvocationHandler createHandler(Class interfaze, Wire wire) { - throw new UnsupportedOperationException(); - } - - public OutboundInvocationChain createOutboundChain(Operation operation) { - throw new UnsupportedOperationException(); - } - - public InboundInvocationChain createInboundChain(Operation operation) { - throw new UnsupportedOperationException(); - } - - public InboundWire createWire(ServiceDefinition service) { - throw new UnsupportedOperationException(); - } - - public void createWires(AtomicComponent component, ComponentDefinition definition) { - throw new UnsupportedOperationException(); - } - - public void createWires(ReferenceBinding referenceBinding, ServiceContract contract, - QualifiedName targetName) { - throw new UnsupportedOperationException(); - } - - public void createWires(ServiceBinding serviceBinding, ServiceContract contract, String targetName) { - throw new UnsupportedOperationException(); - } - - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/InboundInvocationErrorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/InboundInvocationErrorTestCase.java deleted file mode 100644 index 39e1bf0b46..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/InboundInvocationErrorTestCase.java +++ /dev/null @@ -1,166 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.Proxy; -import java.lang.reflect.Type; -import java.util.HashMap; -import java.util.Map; - -import org.apache.tuscany.spi.component.WorkContext; -import org.apache.tuscany.spi.idl.InvalidServiceContractException; -import org.apache.tuscany.spi.idl.java.JavaInterfaceProcessorRegistry; -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.InboundInvocationChain; -import org.apache.tuscany.spi.wire.InboundWire; - -import junit.framework.TestCase; -import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl; -import org.apache.tuscany.core.mock.wire.MockStaticInvoker; -import org.apache.tuscany.core.mock.wire.MockSyncInterceptor; -import org.apache.tuscany.core.wire.jdk.JDKInboundInvocationHandler; -import org.easymock.classextension.EasyMock; - -/** - * Tests handling of exceptions thrown during an inbound wire invocation - * - * @version $Rev$ $Date$ - */ -public class InboundInvocationErrorTestCase extends TestCase { - private Method checkedMethod; - private Method runtimeMethod; - private Operation checkedOperation; - private Operation runtimeOperation; - - public InboundInvocationErrorTestCase() { - super(); - } - - public InboundInvocationErrorTestCase(String arg0) { - super(arg0); - } - - public void setUp() throws Exception { - super.setUp(); - checkedMethod = - TestBean.class.getDeclaredMethod("checkedException", (Class[]) null); - runtimeMethod = - TestBean.class.getDeclaredMethod("runtimeException", (Class[]) null); - assertNotNull(checkedMethod); - assertNotNull(runtimeMethod); - JavaInterfaceProcessorRegistry registry = new JavaInterfaceProcessorRegistryImpl(); - ServiceContract contract; - try { - contract = registry.introspect(TestBean.class); - } catch (InvalidServiceContractException e) { - throw new AssertionError(); - } - - checkedOperation = contract.getOperations().get("checkedException"); - runtimeOperation = contract.getOperations().get("runtimeException"); - } - - public void testCheckedException() throws Exception { - WorkContext workContext = EasyMock.createNiceMock(WorkContext.class); - EasyMock.replay(workContext); - - Operation operation = - new Operation("checkedException", null, null, null, false, null, NO_CONVERSATION); - Map, InboundInvocationChain> chains = new HashMap, InboundInvocationChain>(); - chains.put(operation, createChain(checkedMethod, checkedOperation)); - InboundWire wire = new InboundWireImpl(); - wire.addInvocationChains(chains); - wire.setServiceContract(new ServiceContract(TestBean.class) { - }); - - JDKInboundInvocationHandler handler = new JDKInboundInvocationHandler(TestBean.class, wire, workContext); - try { - ClassLoader ccl = Thread.currentThread().getContextClassLoader(); - TestBean proxy = (TestBean) Proxy.newProxyInstance(ccl, new Class[]{TestBean.class}, handler); - proxy.checkedException(); - } catch (InboundInvocationErrorTestCase.TestException e) { - return; - } - fail(InboundInvocationErrorTestCase.TestException.class.getName() + " should have been thrown"); - } - - public void testRuntimeException() throws Exception { - WorkContext workContext = EasyMock.createNiceMock(WorkContext.class); - EasyMock.replay(workContext); - - Operation operation = - new Operation("runtimeException", null, null, null, false, null, NO_CONVERSATION); - Map, InboundInvocationChain> chains = new HashMap, InboundInvocationChain>(); - chains.put(operation, createChain(runtimeMethod, runtimeOperation)); - InboundWire wire = new InboundWireImpl(); - wire.addInvocationChains(chains); - wire.setServiceContract(new ServiceContract(TestBean.class) { - }); - - JDKInboundInvocationHandler handler = new JDKInboundInvocationHandler(TestBean.class, wire, workContext); - try { - InboundInvocationErrorTestCase.TestBean proxy = (InboundInvocationErrorTestCase.TestBean) Proxy - .newProxyInstance(Thread.currentThread().getContextClassLoader(), - new Class[]{InboundInvocationErrorTestCase.TestBean.class}, handler); - proxy.runtimeException(); - } catch (InboundInvocationErrorTestCase.TestRuntimeException e) { - return; - } - fail(InboundInvocationErrorTestCase.TestException.class.getName() + " should have been thrown"); - } - - private InboundInvocationChain createChain(Method m, Operation operation) { - MockStaticInvoker invoker = new MockStaticInvoker(m, new TestBeanImpl()); - InboundInvocationChain chain = new InboundInvocationChainImpl(operation); - chain.addInterceptor(new MockSyncInterceptor()); - chain.setTargetInvoker(invoker); - chain.addInterceptor(new InvokerInterceptor()); - chain.prepare(); - return chain; - } - - public interface TestBean { - - void checkedException() throws TestException; - - void runtimeException() throws TestRuntimeException; - - } - - public class TestBeanImpl implements TestBean { - - public void checkedException() throws InboundInvocationErrorTestCase.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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/IncompatibleServiceContractExceptionFormatterTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/IncompatibleServiceContractExceptionFormatterTestCase.java deleted file mode 100644 index a9f455bc62..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/IncompatibleServiceContractExceptionFormatterTestCase.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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 source = new ServiceContract() { - }; - source.setInterfaceName("sourceInterface"); - ServiceContract target = new ServiceContract() { - }; - target.setInterfaceName("targetInterface"); - Operation sourceOp = new Operation("sourceOp", null, null, null); - Operation targetOp = new Operation("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 source = new ServiceContract() { - }; - source.setInterfaceName("sourceInterface"); - ServiceContract target = new ServiceContract() { - }; - 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/InvocationChainImplTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/InvocationChainImplTestCase.java deleted file mode 100644 index 294e98997f..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/InvocationChainImplTestCase.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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 junit.framework.TestCase; - -/** - * @version $Rev$ $Date$ - */ -public class InvocationChainImplTestCase extends TestCase { - - public void testInsertAtPos() throws Exception { - MockChain chain = new MockChain(new Operation("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 { - MockChain chain = new MockChain(new Operation("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 MockChain extends InvocationChainImpl { - - public MockChain(Operation operation) { - super(operation); - } - - public void prepare() { - - } - } - - 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/InvocationConfigurationErrorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/InvocationConfigurationErrorTestCase.java deleted file mode 100644 index aca68a0f25..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/InvocationConfigurationErrorTestCase.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.InboundInvocationChain; -import org.apache.tuscany.spi.wire.Message; -import org.apache.tuscany.spi.wire.MessageImpl; -import org.apache.tuscany.spi.wire.OutboundInvocationChain; - -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"); - OutboundInvocationChain source = new OutboundInvocationChainImpl(operation); - MockSyncInterceptor sourceInterceptor = new MockSyncInterceptor(); - source.addInterceptor(sourceInterceptor); - - InboundInvocationChain target = new InboundInvocationChainImpl(operation); - MockSyncInterceptor targetInterceptor = new MockSyncInterceptor(); - target.addInterceptor(targetInterceptor); - target.addInterceptor(new InvokerInterceptor()); - - // connect the source to the target - source.setTargetInterceptor(target.getHeadInterceptor()); - source.prepare(); - target.prepare(); - 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/InvocationConfigurationTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/InvocationConfigurationTestCase.java deleted file mode 100644 index 62df732a9e..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/InvocationConfigurationTestCase.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.InboundInvocationChain; -import org.apache.tuscany.spi.wire.Message; -import org.apache.tuscany.spi.wire.MessageImpl; -import org.apache.tuscany.spi.wire.OutboundInvocationChain; - -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 { - OutboundInvocationChain source = new OutboundInvocationChainImpl(operation); - MockSyncInterceptor sourceInterceptor = new MockSyncInterceptor(); - source.addInterceptor(sourceInterceptor); - - InboundInvocationChain target = new InboundInvocationChainImpl(operation); - MockSyncInterceptor targetInterceptor = new MockSyncInterceptor(); - target.addInterceptor(targetInterceptor); - target.addInterceptor(new InvokerInterceptor()); - - // connect the source to the target - source.setTargetInterceptor(target.getHeadInterceptor()); - source.prepare(); - target.prepare(); - 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/NonBlockingBridgingInterceptorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/NonBlockingBridgingInterceptorTestCase.java deleted file mode 100644 index 1755fe9d15..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/NonBlockingBridgingInterceptorTestCase.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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 NonBlockingBridgingInterceptorTestCase extends TestCase { - - public void testInvoke() throws Exception { - WorkScheduler scheduler = createMock(WorkScheduler.class); - scheduler.scheduleWork(isA(Runnable.class)); - expectLastCall().andStubAnswer(new IAnswer() { - public Object answer() throws Throwable { - Runnable runnable = (Runnable) getCurrentArguments()[0]; - runnable.run(); - return null; - } - }); - replay(scheduler); - WorkContext context = createMock(WorkContext.class); - String convID = "convID"; - EasyMock.expect(context.getIdentifier(Scope.CONVERSATION)).andReturn(convID); - context.setCurrentCorrelationId(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 NonBlockingBridgingInterceptor(scheduler, context, next); - interceptor.invoke(msg); - verify(context); - verify(next); - } - - public void testOptimizable() { - NonBlockingBridgingInterceptor interceptor = new NonBlockingBridgingInterceptor(null, null); - assertFalse(interceptor.isOptimizable()); - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/OptimizedWireObjectFactoryTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/OptimizedWireObjectFactoryTestCase.java deleted file mode 100644 index e0f094a83e..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/OptimizedWireObjectFactoryTestCase.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.OutboundWire; - -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(); - OutboundWire wire = EasyMock.createMock(OutboundWire.class); - EasyMock.expect(wire.getTargetService()).andReturn(foo); - EasyMock.replay(wire); - OptimizedWireObjectFactory factory = new OptimizedWireObjectFactory(wire); - assertEquals(foo, factory.getInstance()); - EasyMock.verify(wire); - } - - private class Foo { - - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/OutboundInvocationErrorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/OutboundInvocationErrorTestCase.java deleted file mode 100644 index 42caa6eed7..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/OutboundInvocationErrorTestCase.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.Proxy; - -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.OutboundInvocationChain; -import org.apache.tuscany.spi.wire.OutboundWire; - -import junit.framework.TestCase; -import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl; -import org.apache.tuscany.core.mock.wire.MockStaticInvoker; -import org.apache.tuscany.core.mock.wire.MockSyncInterceptor; -import org.apache.tuscany.core.wire.jdk.JDKOutboundInvocationHandler; - -/** - * Tests handling of exceptions thrown during an outbound wire invocation - * - * @version $Rev$ $Date$ - */ -public class OutboundInvocationErrorTestCase extends TestCase { - - private Method checkedMethod; - private Method runtimeMethod; - private JavaInterfaceProcessorRegistry registry = new JavaInterfaceProcessorRegistryImpl(); - - public OutboundInvocationErrorTestCase() { - super(); - } - - public OutboundInvocationErrorTestCase(String arg0) { - super(arg0); - } - - public void setUp() throws Exception { - super.setUp(); - checkedMethod = TestBean.class.getDeclaredMethod("checkedException", (Class[]) null); - runtimeMethod = TestBean.class.getDeclaredMethod("runtimeException", (Class[]) null); - assertNotNull(checkedMethod); - assertNotNull(runtimeMethod); - } - - public void testCheckedException() throws Exception { - OutboundWire wire = new OutboundWireImpl(); - ServiceContract contract = registry.introspect(TestBean.class); - wire.setServiceContract(contract); - Operation operation = contract.getOperations().get("checkedException"); - wire.addInvocationChain(operation, createChain(checkedMethod, operation)); - JDKOutboundInvocationHandler handler = new JDKOutboundInvocationHandler(TestBean.class, wire, null); - try { - TestBean proxy = (TestBean) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), - new Class[]{TestBean.class}, handler); - proxy.checkedException(); - } catch (TestException e) { - return; - } - fail(TestException.class.getName() + " should have been thrown"); - } - - public void testRuntimeException() throws Exception { - OutboundWire wire = new OutboundWireImpl(); - ServiceContract contract = registry.introspect(TestBean.class); - wire.setServiceContract(contract); - Operation operation = contract.getOperations().get("runtimeException"); - OutboundInvocationChain chain = createChain(runtimeMethod, operation); - wire.addInvocationChain(operation, chain); - JDKOutboundInvocationHandler handler = new JDKOutboundInvocationHandler(TestBean.class, wire, null); - try { - TestBean proxy = (TestBean) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), - new Class[]{TestBean.class}, handler); - proxy.runtimeException(); - } catch (TestRuntimeException e) { - return; - } - fail(TestException.class.getName() + " should have been thrown"); - } - - private OutboundInvocationChain createChain(Method m, Operation operation) { - MockStaticInvoker invoker = new MockStaticInvoker(m, new TestBeanImpl()); - OutboundInvocationChain chain = new OutboundInvocationChainImpl(operation); - chain.addInterceptor(new MockSyncInterceptor()); - chain.setTargetInvoker(invoker); - chain.setTargetInterceptor(new InvokerInterceptor()); - chain.prepare(); - return chain; - } - - public interface TestBean { - - void checkedException() throws TestException; - - void runtimeException() throws TestRuntimeException; - - } - - public class TestBeanImpl implements TestBean { - - 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/OutboundInvocationHandlerTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/OutboundInvocationHandlerTestCase.java deleted file mode 100644 index 70d85445ed..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/OutboundInvocationHandlerTestCase.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.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.InboundInvocationChain; -import org.apache.tuscany.spi.wire.OutboundInvocationChain; -import org.apache.tuscany.spi.wire.OutboundWire; - -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.JDKOutboundInvocationHandler; - -public class OutboundInvocationHandlerTestCase extends TestCase { - - private Method hello; - private ServiceContract contract; - - public OutboundInvocationHandlerTestCase() { - super(); - } - - public OutboundInvocationHandlerTestCase(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); - } - - public void testBasicInvoke() throws Throwable { - OutboundWire wire = new OutboundWireImpl(); - Operation operation = contract.getOperations().get("hello"); - wire.addInvocationChain(operation, createChain(operation)); - wire.setServiceContract(contract); - JDKOutboundInvocationHandler handler = new JDKOutboundInvocationHandler(SimpleTarget.class, wire, null); - assertEquals("foo", handler.invoke(hello, new Object[]{"foo"})); - } - - public void testErrorInvoke() throws Throwable { - OutboundWire wire = new OutboundWireImpl(); - Operation operation = contract.getOperations().get("hello"); - wire.addInvocationChain(operation, createChain(operation)); - wire.setServiceContract(contract); - JDKOutboundInvocationHandler handler = new JDKOutboundInvocationHandler(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"); - OutboundInvocationChain source = new OutboundInvocationChainImpl(operation); - MockStaticInvoker invoker = new MockStaticInvoker(hello, new SimpleTargetImpl()); - source.setTargetInvoker(invoker); - - OutboundWire wire = new OutboundWireImpl(); - wire.setServiceContract(contract); - wire.addInvocationChain(operation, source); - JDKOutboundInvocationHandler handler = new JDKOutboundInvocationHandler(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"); - OutboundInvocationChain source = new OutboundInvocationChainImpl(operation); - MockStaticInvoker invoker = new MockStaticInvoker(hello, new SimpleTargetImpl()); - source.setTargetInvoker(invoker); - - OutboundWire wire = new OutboundWireImpl(); - wire.setServiceContract(contract); - wire.addInvocationChain(operation, source); - JDKOutboundInvocationHandler handler = new JDKOutboundInvocationHandler(SimpleTarget.class, wire, null); - assertEquals("foo", handler.invoke(hello, new Object[]{"foo"})); - } - - private OutboundInvocationChain createChain(Operation operation) { - OutboundInvocationChain source = new OutboundInvocationChainImpl(operation); - MockSyncInterceptor sourceInterceptor = new MockSyncInterceptor(); - source.addInterceptor(sourceInterceptor); - - InboundInvocationChain target = new InboundInvocationChainImpl(operation); - MockSyncInterceptor targetInterceptor = new MockSyncInterceptor(); - target.addInterceptor(targetInterceptor); - target.addInterceptor(new InvokerInterceptor()); - - // connect the source to the target - source.setTargetInterceptor(targetInterceptor); - source.prepare(); - target.prepare(); - Method method = JavaIDLUtils.findMethod(operation, SimpleTarget.class.getMethods()); - MockStaticInvoker invoker = new MockStaticInvoker(method, new SimpleTargetImpl()); - source.setTargetInvoker(invoker); - return source; - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/OutboundWireTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/OutboundWireTestCase.java deleted file mode 100644 index 9d0de99ed2..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/OutboundWireTestCase.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.OutboundWire; - -import junit.framework.TestCase; - -/** - * @version $Rev$ $Date$ - */ -public class OutboundWireTestCase extends TestCase { - - /** - * Tests that the target wire returns null if there is no connected wire. This behavior is needed for optional - * autowires. - */ - public void testGetNonExistentTargetService() throws Exception { - OutboundWire wire = new OutboundWireImpl(); - assertNull(wire.getTargetService()); - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/SynchronousBridgingInterceptorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/SynchronousBridgingInterceptorTestCase.java deleted file mode 100644 index f1631fc555..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/SynchronousBridgingInterceptorTestCase.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.Interceptor; -import org.apache.tuscany.spi.wire.Message; -import org.apache.tuscany.spi.wire.MessageImpl; - -import org.easymock.EasyMock; -import static org.easymock.EasyMock.verify; -import junit.framework.TestCase; - -/** - * @version $Rev$ $Date$ - */ -public class SynchronousBridgingInterceptorTestCase extends TestCase { - - public void testInvoke() throws Exception { - 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 SynchronousBridgingInterceptor(next); - interceptor.invoke(msg); - verify(next); - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/WireObjectFactoryTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/WireObjectFactoryTestCase.java deleted file mode 100644 index 537ca21656..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/WireObjectFactoryTestCase.java +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.OutboundInvocationChain; -import org.apache.tuscany.spi.wire.OutboundWire; -import org.apache.tuscany.spi.wire.WireService; - -import junit.framework.TestCase; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class WireObjectFactoryTestCase extends TestCase { - - @SuppressWarnings({"unchecked"}) - public void testCreateInstance() throws Exception { - Operation op = new Operation("hello", null, null, null); - OutboundInvocationChain chain = new OutboundInvocationChainImpl(op); - OutboundWire wire = EasyMock.createMock(OutboundWire.class); - Map, OutboundInvocationChain> chains = new HashMap, OutboundInvocationChain>(); - chains.put(op, chain); - EasyMock.expect(wire.getInvocationChains()).andReturn(chains); - EasyMock.expect(wire.isOptimizable()).andReturn(false); - EasyMock.replay(wire); - WireService service = EasyMock.createMock(WireService.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 factory = new WireObjectFactory(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); - OutboundWire wire = EasyMock.createMock(OutboundWire.class); - EasyMock.expect(wire.isOptimizable()).andReturn(true); - EasyMock.expect(wire.getServiceContract()).andReturn(contract).atLeastOnce(); - EasyMock.expect(wire.getInvocationChains()).andReturn((Map) Collections.emptyMap()); - EasyMock.expect(wire.getTargetService()).andReturn(new Foo() { - public void hello() { - } - }); - EasyMock.replay(wire); - WireObjectFactory factory = new WireObjectFactory(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); - OutboundWire wire = EasyMock.createMock(OutboundWire.class); - EasyMock.expect(wire.isOptimizable()).andReturn(true); - EasyMock.expect(wire.getServiceContract()).andReturn(contract).atLeastOnce(); - EasyMock.expect(wire.getInvocationChains()).andReturn((Map) Collections.emptyMap()); - EasyMock.replay(wire); - WireService service = EasyMock.createMock(WireService.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 factory = new WireObjectFactory(Foo.class, wire, service); - factory.getInstance(); - EasyMock.verify(service); - EasyMock.verify(wire); - } - - @SuppressWarnings("unchecked") - public void testNoJavaInterfaceCreateInstance() throws Exception { - ServiceContract contract = new JavaServiceContract(); - OutboundWire wire = EasyMock.createMock(OutboundWire.class); - EasyMock.expect(wire.isOptimizable()).andReturn(true); - EasyMock.expect(wire.getServiceContract()).andReturn(contract).atLeastOnce(); - EasyMock.expect(wire.getInvocationChains()).andReturn((Map) Collections.emptyMap()); - EasyMock.replay(wire); - WireService service = EasyMock.createMock(WireService.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 factory = new WireObjectFactory(Foo.class, wire, service); - factory.getInstance(); - EasyMock.verify(service); - EasyMock.verify(wire); - } - - private interface Foo { - void hello(); - } - - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/WireOptimizationTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/WireOptimizationTestCase.java deleted file mode 100644 index c0d40c6369..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/WireOptimizationTestCase.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.component.Component; -import org.apache.tuscany.spi.model.Operation; -import static org.apache.tuscany.spi.model.Operation.NO_CONVERSATION; -import org.apache.tuscany.spi.wire.InboundInvocationChain; -import org.apache.tuscany.spi.wire.InboundWire; -import org.apache.tuscany.spi.wire.Interceptor; -import org.apache.tuscany.spi.wire.Message; -import org.apache.tuscany.spi.wire.OutboundInvocationChain; -import org.apache.tuscany.spi.wire.OutboundWire; - -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 testSourceWireInterceptorOptimization() throws Exception { - AtomicComponent component = EasyMock.createNiceMock(AtomicComponent.class); - EasyMock.replay(component); - OutboundWire wire = new OutboundWireImpl(); - wire.setContainer(component); - OutboundInvocationChain chain = new OutboundInvocationChainImpl(operation); - chain.addInterceptor(new OptimizableInterceptor()); - wire.addInvocationChain(operation, chain); - assertTrue(WireUtils.isOptimizable(wire)); - } - - public void testSourceWireNonInterceptorOptimization() throws Exception { - AtomicComponent component = EasyMock.createNiceMock(AtomicComponent.class); - EasyMock.replay(component); - OutboundWire wire = new OutboundWireImpl(); - wire.setContainer(component); - OutboundInvocationChain chain = new OutboundInvocationChainImpl(operation); - chain.addInterceptor(new NonOptimizableInterceptor()); - wire.addInvocationChain(operation, chain); - assertFalse(WireUtils.isOptimizable(wire)); - } - - public void testTargetWireInterceptorOptimization() throws Exception { - AtomicComponent component = EasyMock.createNiceMock(AtomicComponent.class); - EasyMock.expect(component.isOptimizable()).andReturn(true); - EasyMock.replay(component); - InboundWire wire = new InboundWireImpl(); - wire.setContainer(component); - InboundInvocationChain chain = new InboundInvocationChainImpl(operation); - chain.addInterceptor(new OptimizableInterceptor()); - wire.addInvocationChain(operation, chain); - assertTrue(WireUtils.isOptimizable(wire)); - - } - - public void testTargetWireNoOptimizationNonAtomicContainer() throws Exception { - Component component = EasyMock.createNiceMock(Component.class); - EasyMock.expect(component.isOptimizable()).andReturn(true); - EasyMock.replay(component); - InboundWire wire = new InboundWireImpl(); - wire.setContainer(component); - InboundInvocationChain chain = new InboundInvocationChainImpl(operation); - chain.addInterceptor(new OptimizableInterceptor()); - wire.addInvocationChain(operation, chain); - assertTrue(WireUtils.isOptimizable(wire)); - } - - public void testTargetWireNonInterceptorOptimization() throws Exception { - AtomicComponent component = EasyMock.createNiceMock(AtomicComponent.class); - EasyMock.replay(component); - InboundWire wire = new InboundWireImpl(); - wire.setContainer(component); - InboundInvocationChain chain = new InboundInvocationChainImpl(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("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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/WireServiceExtensionTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/WireServiceExtensionTestCase.java deleted file mode 100644 index 1838fd35bd..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/WireServiceExtensionTestCase.java +++ /dev/null @@ -1,333 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.net.URI; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.xml.namespace.QName; - -import org.apache.tuscany.spi.QualifiedName; -import org.apache.tuscany.spi.component.AbstractSCAObject; -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.ServiceBinding; -import org.apache.tuscany.spi.component.TargetInvokerCreationException; -import org.apache.tuscany.spi.component.WorkContext; -import org.apache.tuscany.spi.model.ComponentDefinition; -import org.apache.tuscany.spi.model.ComponentReferenceDefinition; -import org.apache.tuscany.spi.model.ComponentType; -import org.apache.tuscany.spi.model.ComponentTypeReferenceDefinition; -import org.apache.tuscany.spi.model.Implementation; -import org.apache.tuscany.spi.model.Multiplicity; -import org.apache.tuscany.spi.model.Operation; -import org.apache.tuscany.spi.model.Property; -import org.apache.tuscany.spi.model.AbstractReferenceDefinition; -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.InboundInvocationChain; -import org.apache.tuscany.spi.wire.InboundWire; -import org.apache.tuscany.spi.wire.Message; -import org.apache.tuscany.spi.wire.MessageImpl; -import org.apache.tuscany.spi.wire.OutboundChainHolder; -import org.apache.tuscany.spi.wire.OutboundInvocationChain; -import org.apache.tuscany.spi.wire.OutboundWire; -import org.apache.tuscany.spi.wire.ProxyCreationException; -import org.apache.tuscany.spi.wire.TargetInvoker; -import org.apache.tuscany.spi.wire.Wire; -import org.apache.tuscany.spi.wire.WireInvocationHandler; - -import junit.framework.TestCase; -import org.apache.tuscany.core.component.WorkContextImpl; -import org.apache.tuscany.core.mock.binding.MockServiceBinding; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class WireServiceExtensionTestCase extends TestCase { - private TestWireService wireService; - private Operation operation; - private ServiceContract contract; - private Operation callbackOperation; - - public void testCreateInboundChain() throws Exception { - InboundInvocationChain chain = wireService.createInboundChain(operation); - assertEquals(operation, chain.getOperation()); - } - - public void testCreateOutboundChain() throws Exception { - OutboundInvocationChain chain = wireService.createOutboundChain(operation); - assertEquals(operation, chain.getOperation()); - } - - public void testCreateServiceWire() throws Exception { - ServiceDefinition definition = new ServiceDefinition("foo", contract, false); - TargetInvoker invoker = EasyMock.createMock(TargetInvoker.class); - MessageImpl resp = new MessageImpl(); - EasyMock.expect(invoker.invoke(EasyMock.isA(Message.class))).andReturn(resp); - EasyMock.replay(invoker); - InboundWire wire = wireService.createWire(definition); - assertEquals("foo", wire.getServiceName()); - assertEquals(1, wire.getInvocationChains().size()); - assertEquals(contract, wire.getServiceContract()); - InboundInvocationChain chain = wire.getInvocationChains().get(operation); - assertEquals(operation, chain.getOperation()); - // verify the chain is invokable - MessageImpl msg = new MessageImpl(); - msg.setTargetInvoker(invoker); - assertNotNull(chain.getHeadInterceptor().invoke(msg)); - EasyMock.verify(invoker); - } - - /*public void testCreateReferenceWire() throws Exception { - AbstractReferenceDefinition definition = new AbstractReferenceDefinition("foo", contract); - ReferenceTarget target = new ReferenceTarget(); - target.addTarget(new URI("bar")); - target.setReferenceName("refName"); - - OutboundWire wire = wireService.createWire(target, definition).get(0); - assertEquals("refName", wire.getReferenceName()); - assertEquals("bar", wire.getTargetName().toString()); - assertFalse(wire.isAutowire()); - assertEquals(1, wire.getInvocationChains().size()); - assertEquals(contract, wire.getServiceContract()); - OutboundInvocationChain chain = wire.getInvocationChains().get(operation); - assertEquals(operation, chain.getOperation()); - assertNull(chain.getHeadInterceptor()); - assertEquals(Callback.class, wire.getCallbackInterface()); - assertEquals(1, wire.getTargetCallbackInvocationChains().size()); - InboundInvocationChain callbackChain = wire.getTargetCallbackInvocationChains().get(callbackOperation); - assertEquals(callbackOperation, callbackChain.getOperation()); - - TargetInvoker invoker = EasyMock.createMock(TargetInvoker.class); - MessageImpl resp = new MessageImpl(); - EasyMock.expect(invoker.invoke(EasyMock.isA(Message.class))).andReturn(resp); - EasyMock.replay(invoker); - // verify the callback chain is invokable - MessageImpl msg = new MessageImpl(); - msg.setTargetInvoker(invoker); - assertNotNull(callbackChain.getHeadInterceptor().invoke(msg)); - EasyMock.verify(invoker); - }*/ - - public void testCreateAutowireReferenceWire() throws Exception { - ComponentTypeReferenceDefinition definition = new ComponentTypeReferenceDefinition("foo", contract); - definition.setAutowire(true); - ComponentReferenceDefinition compRef = new ComponentReferenceDefinition(definition); - //ReferenceTarget target = new ReferenceTarget(); - //target.setReferenceName("refName"); - OutboundWire wire = wireService.createWire(new ArrayList(), compRef).get(0); - assertTrue(wire.isAutowire()); - assertEquals("foo", wire.getReferenceName()); - assertEquals(contract, wire.getServiceContract()); - assertEquals(Callback.class, wire.getCallbackInterface()); - } - - public void testCreateReferenceMultipleWire() throws Exception { - ComponentTypeReferenceDefinition ctRefDef = new ComponentTypeReferenceDefinition("foo", contract); - ComponentReferenceDefinition definition = new ComponentReferenceDefinition(ctRefDef); - definition.setMultiplicity(Multiplicity.ONE_N); - - //ReferenceTarget target = new ReferenceTarget(); - List target = new ArrayList(); - target.add(new URI("bar")); - target.add(new URI("bar2")); - //target.setReferenceName("refName"); - - List wires = wireService.createWire(target, definition); - assertEquals(2, wires.size()); - } - - public void testCreateComponentWires() throws Exception { - ComponentType> type = - new ComponentType>(); - ComponentTypeReferenceDefinition referenceDefinition = new ComponentTypeReferenceDefinition("refName", contract); - type.add(referenceDefinition); - ServiceDefinition serviceDefinition = new ServiceDefinition("foo", contract, false); - type.add(serviceDefinition); - - Implementation impl = new Implementation() { - }; - impl.setComponentType(type); - - ComponentDefinition> definition = - new ComponentDefinition>("Foo", impl); - ComponentReferenceDefinition compRef = - new ComponentReferenceDefinition(type.getReferences().get("refName")); - compRef.addTarget(new URI("bar")); - definition.add(compRef); - - /*ReferenceTarget target = new ReferenceTarget(); - target.addTarget(new URI("bar")); - target.setReferenceName("refName"); - definition.add(target); - */ - AtomicComponent component = EasyMock.createMock(AtomicComponent.class); - component.addInboundWire(EasyMock.isA(InboundWire.class)); - component.addOutboundWire(EasyMock.isA(OutboundWire.class)); - EasyMock.replay(component); - - wireService.createWires(component, definition); - EasyMock.verify(component); - } - - public void testCreateReferenceBindingWire() throws Exception { - ReferenceBinding binding = new MockReferenceBinding(); - QualifiedName qName = new QualifiedName("target"); - - wireService.createWires(binding, contract, qName); - - InboundWire inboundWire = binding.getInboundWire(); - assertEquals(1, inboundWire.getInvocationChains().size()); - assertEquals(contract, inboundWire.getServiceContract()); - assertEquals(binding, inboundWire.getContainer()); - - OutboundWire outboundWire = binding.getOutboundWire(); - assertEquals("target", outboundWire.getTargetName().toString()); - assertEquals(1, outboundWire.getInvocationChains().size()); - assertEquals(contract, outboundWire.getServiceContract()); - assertEquals(binding, outboundWire.getContainer()); - } - - public void testCreateServiceBindingWire() throws Exception { - ServiceBinding binding = new MockServiceBinding(); - - wireService.createWires(binding, contract, "target"); - - InboundWire inboundWire = binding.getInboundWire(); - assertEquals(1, inboundWire.getInvocationChains().size()); - assertEquals(contract, inboundWire.getServiceContract()); - assertEquals(binding, inboundWire.getContainer()); - - OutboundWire outboundWire = binding.getOutboundWire(); - assertEquals("target", outboundWire.getTargetName().toString()); - assertEquals(1, outboundWire.getInvocationChains().size()); - assertEquals(contract, outboundWire.getServiceContract()); - assertEquals(binding, outboundWire.getContainer()); - assertEquals(1, outboundWire.getTargetCallbackInvocationChains().size()); - } - - protected void setUp() throws Exception { - super.setUp(); - wireService = new TestWireService(new WorkContextImpl()); - - operation = new Operation("foo", null, null, null); - callbackOperation = new Operation("foo", null, null, null); - Map> operations = new HashMap>(); - operations.put("foo", operation); - Map> callbackOperations = new HashMap>(); - callbackOperations.put("foo", callbackOperation); - contract = new ServiceContract() { - }; - contract.setOperations(operations); - contract.setCallbackClass(Callback.class); - contract.setCallbackName(Callback.class.getName()); - contract.setCallbackOperations(callbackOperations); - } - - private interface Callback { - - } - - private class TestWireService extends WireServiceExtension { - protected TestWireService(WorkContext context) { - super(context, null); - } - - public T createProxy(Class interfaze, Wire wire) throws ProxyCreationException { - return null; - } - - public T createProxy(Class interfaze, Wire wire, Map mapping) - throws ProxyCreationException { - return null; - } - - public Object createCallbackProxy(Class interfaze, InboundWire wire) throws ProxyCreationException { - return null; - } - - public WireInvocationHandler createHandler(Class interfaze, Wire wire) { - return null; - } - - - public List createWire(List refTargetURIs, ComponentReferenceDefinition def) { - return super.createWire(refTargetURIs, def); - } - } - - private class MockReferenceBinding extends AbstractSCAObject implements ReferenceBinding { - private ServiceContract bindingServiceContract; - private InboundWire inboundWire; - private OutboundWire outboundWire; - - public MockReferenceBinding() { - super("foo", null); - } - - public ServiceContract getBindingServiceContract() { - return bindingServiceContract; - } - - public QName getBindingType() { - return null; - } - - public void setReference(Reference reference) { - - } - - public InboundWire getInboundWire() { - return inboundWire; - } - - public void setInboundWire(InboundWire inboundWire) { - this.inboundWire = inboundWire; - } - - public OutboundWire getOutboundWire() { - return outboundWire; - } - - public void setOutboundWire(OutboundWire outboundWire) { - this.outboundWire = outboundWire; - } - - public TargetInvoker createTargetInvoker(ServiceContract contract, Operation operation) - throws TargetInvokerCreationException { - return null; - } - - public Scope getScope() { - return null; - } - } - - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/WireUtilsTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/WireUtilsTestCase.java deleted file mode 100644 index 331c0760d9..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/WireUtilsTestCase.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.InboundInvocationChain; -import org.apache.tuscany.spi.wire.InboundWire; -import org.apache.tuscany.spi.wire.OutboundChainHolder; -import org.apache.tuscany.spi.wire.OutboundInvocationChain; -import org.apache.tuscany.spi.wire.OutboundWire; - -import junit.framework.TestCase; - -/** - * @version $Rev$ $Date$ - */ -public class WireUtilsTestCase extends TestCase { - private Method m; - - public void testCreateInterfaceToWireMapping() throws Exception { - OutboundWire wire = new OutboundWireImpl(); - Operation op = new Operation("hello", null, null, null); - OutboundInvocationChain chain = new OutboundInvocationChainImpl(op); - wire.addInvocationChain(op, chain); - Map chains = WireUtils.createInterfaceToWireMapping(Foo.class, wire); - assertEquals(1, chains.size()); - assertNotNull(chains.get(m)); - } - - public void testCreateInterfaceToWireMappingNoOperation() throws Exception { - OutboundWire wire = new OutboundWireImpl(); - Operation op = new Operation("goodbye", null, null, null); - OutboundInvocationChain chain = new OutboundInvocationChainImpl(op); - wire.addInvocationChain(op, chain); - try { - WireUtils.createInterfaceToWireMapping(Foo.class, wire); - fail(); - } catch (NoMethodForOperationException e) { - // expected - } - } - - public void testCreateInboundMapping() throws Exception { - InboundWire wire = new InboundWireImpl(); - Operation op = new Operation("hello", null, null, null); - InboundInvocationChain chain = new InboundInvocationChainImpl(op); - wire.addInvocationChain(op, chain); - Map chains = WireUtils.createInboundMapping(wire, new Method[]{m}); - assertEquals(1, chains.size()); - assertNotNull(chains.get(m)); - } - - public void testCreateInboundMappingNoOperation() throws Exception { - InboundWire wire = new InboundWireImpl(); - Operation op = new Operation("goodbye", null, null, null); - InboundInvocationChain chain = new InboundInvocationChainImpl(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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandlerSerializationTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandlerSerializationTestCase.java deleted file mode 100644 index df4dc63ea4..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandlerSerializationTestCase.java +++ /dev/null @@ -1,54 +0,0 @@ -package org.apache.tuscany.core.wire.jdk; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; - -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.InboundWire; - -import junit.framework.TestCase; -import org.apache.tuscany.core.component.WorkContextImpl; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class JDKCallbackInvocationHandlerSerializationTestCase extends TestCase { - private InboundWire wire; - private WorkContext workContext; - - public void testSerializeDeserialize() throws Exception { - JDKCallbackInvocationHandler handler = new JDKCallbackInvocationHandler(wire, 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(wire); - } - - protected void setUp() throws Exception { - super.setUp(); - wire = EasyMock.createMock(InboundWire.class); - EasyMock.expect(wire.getServiceName()).andReturn("foo").atLeastOnce(); - EasyMock.replay(wire); - AtomicComponent component = EasyMock.createMock(AtomicComponent.class); - EasyMock.expect(component.getInboundWire(EasyMock.eq("foo"))).andReturn(wire); - EasyMock.replay(component); - workContext = new WorkContextImpl(); - workContext.setCurrentAtomicComponent(component); - } - - protected void tearDown() throws Exception { - super.tearDown(); - workContext.setCurrentAtomicComponent(null); - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandlerTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandlerTestCase.java deleted file mode 100644 index b8cbde687d..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandlerTestCase.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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 org.apache.tuscany.spi.idl.java.JavaServiceContract; - -import junit.framework.TestCase; - -import org.apache.tuscany.core.component.WorkContextImpl; -import org.apache.tuscany.core.wire.InboundWireImpl; - -/** - * @version $Rev$ $Date$ - */ -public class JDKCallbackInvocationHandlerTestCase extends TestCase { - - public void testToString() { - InboundWireImpl wire = new InboundWireImpl(); - wire.setServiceContract(new JavaServiceContract(Foo.class)); - JDKCallbackInvocationHandler handler = new JDKCallbackInvocationHandler(wire, new WorkContextImpl()); - Foo foo = (Foo) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[]{Foo.class}, handler); - assertNotNull(foo.toString()); - } - - public void testHashCode() { - InboundWireImpl wire = new InboundWireImpl(); - wire.setServiceContract(new JavaServiceContract(Foo.class)); - JDKCallbackInvocationHandler handler = new JDKCallbackInvocationHandler(wire, new WorkContextImpl()); - Foo foo = (Foo) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[]{Foo.class}, handler); - assertNotNull(foo.hashCode()); - } - - private interface Foo { - - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKInboundInvocationHandlerSerializationTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKInboundInvocationHandlerSerializationTestCase.java deleted file mode 100644 index a631982958..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKInboundInvocationHandlerSerializationTestCase.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.util.HashMap; -import java.util.Map; - -import org.apache.tuscany.spi.component.AtomicComponent; -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.wire.InboundInvocationChain; -import org.apache.tuscany.spi.wire.InboundWire; -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.wire.InboundInvocationChainImpl; -import org.apache.tuscany.core.wire.InvokerInterceptor; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class JDKInboundInvocationHandlerSerializationTestCase extends TestCase { - private InboundWire wire; - private WorkContext workContext; - private TargetInvoker invoker; - - public void testSerializeDeserialize() throws Throwable { - JDKInboundInvocationHandler handler = new JDKInboundInvocationHandler(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())); - JDKInboundInvocationHandler externalizable = (JDKInboundInvocationHandler) istream.readObject(); - - externalizable.setWorkContext(workContext); - externalizable.reactivate(); - externalizable.invoke(Foo.class.getMethod("invoke"), null); - EasyMock.verify(wire); - EasyMock.verify(invoker); - } - - protected void setUp() throws Exception { - super.setUp(); - wire = EasyMock.createMock(InboundWire.class); - Map, InboundInvocationChain> map = new HashMap, InboundInvocationChain>(); - Operation operation = new Operation("invoke", null, null, null, false, null, NO_CONVERSATION); - map.put(operation, createChain(operation)); - - EasyMock.expect(wire.getServiceName()).andReturn("foo").atLeastOnce(); - EasyMock.expect(wire.getInvocationChains()).andReturn(map).times(2); - EasyMock.replay(wire); - AtomicComponent component = EasyMock.createMock(AtomicComponent.class); - EasyMock.expect(component.getInboundWire(EasyMock.eq("foo"))).andReturn(wire); - EasyMock.replay(component); - workContext = new WorkContextImpl(); - workContext.setCurrentAtomicComponent(component); - } - - protected void tearDown() throws Exception { - super.tearDown(); - workContext.setCurrentAtomicComponent(null); - } - - private InboundInvocationChain 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); - InboundInvocationChain chain = new InboundInvocationChainImpl(operation); - chain.setTargetInvoker(invoker); - chain.addInterceptor(new InvokerInterceptor()); - chain.prepare(); - return chain; - } - - public class Foo { - public void invoke() { - } - } - - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKInboundInvocationHandlerTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKInboundInvocationHandlerTestCase.java deleted file mode 100644 index 1a4238c589..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKInboundInvocationHandlerTestCase.java +++ /dev/null @@ -1,162 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.lang.reflect.Proxy; -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.component.WorkContext; -import org.apache.tuscany.spi.idl.InvalidServiceContractException; -import org.apache.tuscany.spi.idl.java.JavaInterfaceProcessorRegistry; -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.InboundInvocationChain; -import org.apache.tuscany.spi.wire.InboundWire; - -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.InboundInvocationChainImpl; -import org.apache.tuscany.core.wire.InboundWireImpl; -import org.apache.tuscany.core.wire.InvokerInterceptor; -import org.easymock.classextension.EasyMock; - -/** - * Verifies invocations on inbound wires - * - * @version $$Rev$$ $$Date$$ - */ -public class JDKInboundInvocationHandlerTestCase extends TestCase { - - private Method echo; - private Operation operation; - - public void testInterceptorInvoke() throws Throwable { - MockStaticInvoker invoker = new MockStaticInvoker(echo, new SimpleTargetImpl()); - InboundInvocationChain chain = new InboundInvocationChainImpl(operation); - MockSyncInterceptor interceptor = new MockSyncInterceptor(); - chain.addInterceptor(interceptor); - chain.addInterceptor(new InvokerInterceptor()); - chain.setTargetInvoker(invoker); - chain.prepare(); - InboundWire wire = createWire(chain); - - WorkContext workContext = EasyMock.createNiceMock(WorkContext.class); - EasyMock.replay(workContext); - JDKInboundInvocationHandler handler = new JDKInboundInvocationHandler(SimpleTarget.class, wire, workContext); - assertEquals("foo", handler.invoke(echo, new String[]{"foo"})); - assertEquals(1, interceptor.getCount()); - } - - public void testDirectErrorInvoke() throws Throwable { - InboundInvocationChain source = new InboundInvocationChainImpl(operation); - MockStaticInvoker invoker = new MockStaticInvoker(echo, new SimpleTargetImpl()); - source.setTargetInvoker(invoker); - InboundWire wire = createWire(source); - - WorkContext workContext = EasyMock.createNiceMock(WorkContext.class); - EasyMock.replay(workContext); - JDKInboundInvocationHandler handler = new JDKInboundInvocationHandler(SimpleTarget.class, wire, workContext); - try { - assertEquals("foo", handler.invoke(echo, new Object[]{})); - fail("Expected " + IllegalArgumentException.class.getName()); - } catch (IllegalArgumentException e) { - // should throw - } - } - - public void testDirectInvoke() throws Throwable { - InboundInvocationChain source = new InboundInvocationChainImpl(operation); - MockStaticInvoker invoker = new MockStaticInvoker(echo, new SimpleTargetImpl()); - source.setTargetInvoker(invoker); - InboundWire wire = createWire(source); - - WorkContext workContext = EasyMock.createNiceMock(WorkContext.class); - EasyMock.replay(workContext); - JDKInboundInvocationHandler handler = new JDKInboundInvocationHandler(SimpleTarget.class, wire, workContext); - assertEquals("foo", handler.invoke(echo, new Object[]{"foo"})); - } - - public void testToString() { - WorkContext workContext = EasyMock.createNiceMock(WorkContext.class); - EasyMock.replay(workContext); - InboundWireImpl wire = new InboundWireImpl(); - wire.setServiceContract(new ServiceContract(Foo.class) { - }); - JDKInboundInvocationHandler handler = new JDKInboundInvocationHandler(SimpleTarget.class, wire, workContext); - Foo foo = (Foo) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[]{Foo.class}, handler); - assertNotNull(foo.toString()); - } - - public void testHashCode() { - WorkContext workContext = EasyMock.createNiceMock(WorkContext.class); - EasyMock.replay(workContext); - InboundWireImpl wire = new InboundWireImpl(); - wire.setServiceContract(new ServiceContract(Foo.class) { - }); - JDKInboundInvocationHandler handler = new JDKInboundInvocationHandler(SimpleTarget.class, wire, workContext); - Foo foo = (Foo) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[]{Foo.class}, handler); - assertNotNull(foo.hashCode()); - } - - 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"); - echo = SimpleTarget.class.getMethod("echo", String.class); - } - - - private InboundWire createWire(InboundInvocationChain chain) { - DataType type = new DataType(String.class, String.class); - List> types = new ArrayList>(); - types.add(type); - DataType>> inputType = - new DataType>>(Object[].class, types); - Operation operation = new Operation("echo", inputType, null, null, false, null, NO_CONVERSATION); - Map, InboundInvocationChain> chains = new HashMap, InboundInvocationChain>(); - chains.put(operation, chain); - InboundWire wire = new InboundWireImpl(); - wire.addInvocationChains(chains); - wire.setServiceContract(new ServiceContract(SimpleTarget.class) { - }); - return wire; - } - - private interface Foo { - - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKOutboundInvocationHandlerProxyTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKOutboundInvocationHandlerProxyTestCase.java deleted file mode 100644 index 39d8113584..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKOutboundInvocationHandlerProxyTestCase.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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 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.MessageImpl; -import org.apache.tuscany.spi.wire.OutboundInvocationChain; -import org.apache.tuscany.spi.wire.OutboundWire; -import org.apache.tuscany.spi.wire.TargetInvoker; - -import junit.framework.TestCase; -import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl; -import org.apache.tuscany.core.wire.OutboundInvocationChainImpl; -import org.apache.tuscany.core.wire.OutboundWireImpl; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class JDKOutboundInvocationHandlerProxyTestCase extends TestCase { - - private JavaInterfaceProcessorRegistry registry = new JavaInterfaceProcessorRegistryImpl(); - private OutboundWire wire; - private Method clientHello; - private TargetInvoker targetInvoker; - - public void testDifferentInterface() throws Throwable { - JDKOutboundInvocationHandler handler = new JDKOutboundInvocationHandler(Client.class, wire, null); - handler.invoke(null, clientHello, null); - EasyMock.verify(targetInvoker); - } - - protected void setUp() throws Exception { - super.setUp(); - wire = new OutboundWireImpl(); - JavaServiceContract contract = registry.introspect(Target.class); - for (Operation operation : contract.getOperations().values()) { - OutboundInvocationChain chain = new OutboundInvocationChainImpl(operation); - wire.addInvocationChain(operation, chain); - 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); - chain.setTargetInvoker(targetInvoker); - } - wire.setServiceContract(contract); - clientHello = Client.class.getMethod("hello"); - - } - - private interface Target { - String hello(); - } - - private interface Client { - String hello(); - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKOutboundInvocationHandlerSerializationTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKOutboundInvocationHandlerSerializationTestCase.java deleted file mode 100644 index c6e449d291..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKOutboundInvocationHandlerSerializationTestCase.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.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.InteractionScope; -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.Message; -import org.apache.tuscany.spi.wire.MessageImpl; -import org.apache.tuscany.spi.wire.OutboundInvocationChain; -import org.apache.tuscany.spi.wire.OutboundWire; -import org.apache.tuscany.spi.wire.TargetInvoker; - -import junit.framework.TestCase; -import org.apache.tuscany.core.component.WorkContextImpl; -import org.apache.tuscany.core.wire.InvokerInterceptor; -import org.apache.tuscany.core.wire.OutboundInvocationChainImpl; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class JDKOutboundInvocationHandlerSerializationTestCase extends TestCase { - private OutboundWire wire; - private WorkContext workContext; - private TargetInvoker invoker; - - public void testSerializeDeserialize() throws Throwable { - JDKOutboundInvocationHandler handler = - new JDKOutboundInvocationHandler(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())); - JDKOutboundInvocationHandler externalizable = (JDKOutboundInvocationHandler) 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 contract = new ServiceContract() { - }; - contract.setInterfaceClass(Foo.class); - contract.setInteractionScope(InteractionScope.NONCONVERSATIONAL); - EasyMock.expect(container.getName()).andReturn("bar").atLeastOnce(); - EasyMock.replay(container); - wire = EasyMock.createMock(OutboundWire.class); - Map, OutboundInvocationChain> map = new HashMap, OutboundInvocationChain>(); - Operation operation = new Operation("invoke", null, null, null, false, null, NO_CONVERSATION); - ServiceContract opContract = new ServiceContract() { - }; - contract.setInterfaceClass(Foo.class); - contract.setInteractionScope(InteractionScope.NONCONVERSATIONAL); - operation.setServiceContract(opContract); - map.put(operation, createChain(operation)); - EasyMock.expect(wire.getContainer()).andReturn(container).atLeastOnce(); - EasyMock.expect(wire.getServiceContract()).andReturn(contract).atLeastOnce(); - EasyMock.expect(wire.getReferenceName()).andReturn("foo").atLeastOnce(); - EasyMock.expect(wire.getInvocationChains()).andReturn(map).times(2); - EasyMock.replay(wire); - Map> wires = new HashMap>(); - List list = new ArrayList(); - list.add(wire); - wires.put("foo", list); - AtomicComponent component = EasyMock.createMock(AtomicComponent.class); - EasyMock.expect(component.getOutboundWires()).andReturn(wires); - EasyMock.replay(component); - workContext = new WorkContextImpl(); - workContext.setCurrentAtomicComponent(component); - } - - protected void tearDown() throws Exception { - super.tearDown(); - workContext.setCurrentAtomicComponent(null); - } - - private OutboundInvocationChain 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); - OutboundInvocationChain chain = new OutboundInvocationChainImpl(operation); - chain.setTargetInvoker(invoker); - chain.addInterceptor(new InvokerInterceptor()); - chain.prepare(); - return chain; - } - - public class Foo { - - public void invoke() { - } - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKOutboundInvocationHandlerTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKOutboundInvocationHandlerTestCase.java deleted file mode 100644 index 4d2af8acf9..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKOutboundInvocationHandlerTestCase.java +++ /dev/null @@ -1,176 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -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.InteractionScope; -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.InvocationRuntimeException; -import org.apache.tuscany.spi.wire.Message; -import org.apache.tuscany.spi.wire.OutboundInvocationChain; -import org.apache.tuscany.spi.wire.OutboundWire; -import org.apache.tuscany.spi.wire.TargetInvoker; - -import junit.framework.TestCase; -import org.apache.tuscany.core.component.WorkContextImpl; -import org.apache.tuscany.core.wire.OutboundWireImpl; -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; - -/** - * @version $Rev$ $Date$ - */ -public class JDKOutboundInvocationHandlerTestCase extends TestCase { - - public void testToString() { - OutboundWireImpl wire = new OutboundWireImpl(); - ServiceContract contract = new JavaServiceContract(Foo.class); - contract.setInteractionScope(InteractionScope.NONCONVERSATIONAL); - wire.setServiceContract(contract); - JDKOutboundInvocationHandler handler = new JDKOutboundInvocationHandler(Foo.class, wire, null); - Foo foo = (Foo) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[]{Foo.class}, handler); - assertNotNull(foo.toString()); - } - - public void testHashCode() { - OutboundWireImpl wire = new OutboundWireImpl(); - ServiceContract contract = new JavaServiceContract(Foo.class); - contract.setInteractionScope(InteractionScope.NONCONVERSATIONAL); - wire.setServiceContract(contract); - JDKOutboundInvocationHandler handler = new JDKOutboundInvocationHandler(Foo.class, wire, null); - Foo foo = (Foo) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[]{Foo.class}, handler); - assertNotNull(foo.hashCode()); - } - - public void testConversational() throws Throwable { - OutboundWire outboundWire = createMock(OutboundWire.class); - Map, OutboundInvocationChain> outboundChains = - new HashMap, OutboundInvocationChain>(); - DataType type1 = new DataType(String.class, String.class); - List> types = new ArrayList>(); - types.add(type1); - DataType>> inputType1 = new DataType>>(Object[].class, types); - DataType outputType1 = new DataType(String.class, String.class); - Operation op1 = new Operation("test", inputType1, outputType1, null); - ServiceContract outboundContract = new JavaServiceContract(Foo.class); - outboundContract.setInteractionScope(InteractionScope.CONVERSATIONAL); - op1.setServiceContract(outboundContract); - - WorkContext wc = new WorkContextImpl(); - MockInvoker invoker = new MockInvoker(wc); - OutboundInvocationChain outboundChain = createMock(OutboundInvocationChain.class); - expect(outboundChain.getTargetInvoker()).andReturn(invoker).anyTimes(); - expect(outboundChain.getHeadInterceptor()).andReturn(null).anyTimes(); - replay(outboundChain); - outboundChains.put(op1, outboundChain); - expect(outboundWire.getInvocationChains()).andReturn(outboundChains).anyTimes(); - expect(outboundWire.getReferenceName()).andReturn("fooRef").atLeastOnce(); - expect(outboundWire.getContainer()).andReturn(null).anyTimes(); - expect(outboundWire.getServiceContract()).andReturn(outboundContract).anyTimes(); - replay(outboundWire); - - String convID = UUID.randomUUID().toString(); - wc.setIdentifier(Scope.CONVERSATION, convID); - invoker.setCurrentConversationID(convID); - - outboundContract.setRemotable(true); - invoker.setRemotableTest(true); - JDKOutboundInvocationHandler handler = new JDKOutboundInvocationHandler(Foo.class, outboundWire, wc); - handler.invoke(Foo.class.getMethod("test", String.class), new Object[]{"bar"}); - String currentConvID = (String) wc.getIdentifier(Scope.CONVERSATION); - assertSame(convID, currentConvID); - - outboundContract.setRemotable(false); - invoker.setRemotableTest(false); - JDKOutboundInvocationHandler handler2 = new JDKOutboundInvocationHandler(Foo.class, outboundWire, 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; - private boolean remotableTest; - - public MockInvoker(WorkContext wc) { - this.wc = wc; - } - - public void setCurrentConversationID(String id) { - currentConversationID = id; - } - - public void setRemotableTest(boolean remotableTest) { - this.remotableTest = remotableTest; - } - - public Object invokeTarget(final Object payload, final short sequence) throws InvocationTargetException { - assertEquals("bar", Array.get(payload, 0)); - String convID = (String) wc.getIdentifier(Scope.CONVERSATION); - if (remotableTest) { - assertNotSame(convID, currentConversationID); - } else { - 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKProxyTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKProxyTestCase.java deleted file mode 100644 index 994d944d98..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKProxyTestCase.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * 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.util.HashMap; -import java.util.Map; - -import org.apache.tuscany.spi.model.Operation; -import org.apache.tuscany.spi.wire.InboundInvocationChain; -import org.apache.tuscany.spi.wire.InboundWire; - -import junit.framework.TestCase; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class JDKProxyTestCase extends TestCase { - private JDKWireService wireService; - private InboundWire inboundWire; - private Map, InboundInvocationChain> chains; - - public void testCreateProxy() { - EasyMock.expect(inboundWire.getServiceName()).andReturn("service"); - EasyMock.expect(inboundWire.getInvocationChains()).andReturn(chains); - EasyMock.replay(inboundWire); - TestInterface intf = wireService.createProxy(TestInterface.class, inboundWire); - assertTrue(Proxy.isProxyClass(intf.getClass())); - EasyMock.verify(inboundWire); - } - - protected void setUp() throws Exception { - super.setUp(); - wireService = new JDKWireService(); - inboundWire = EasyMock.createMock(InboundWire.class); - chains = new HashMap, InboundInvocationChain>(); - } - - public static interface TestInterface { - int primitives(int i); - - String objects(String object); - } -} -- cgit v1.2.3