From 0f72626e59d77f0365c1e6bbb9420f6693ffc67d Mon Sep 17 00:00:00 2001 From: lresende Date: Sat, 21 Nov 2009 07:55:01 +0000 Subject: Moving 1.x tags git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@882848 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/sca/containers/container.java/LICENSE.txt | 202 +++++ .../java/sca/containers/container.java/README.txt | 35 + .../java/sca/containers/container.java/pom.xml | 52 ++ .../java/assembly/JavaAssemblyFactory.java | 30 + .../java/assembly/JavaImplementation.java | 39 + .../assembly/impl/JavaAssemblyFactoryImpl.java | 45 ++ .../java/assembly/impl/JavaImplementationImpl.java | 44 ++ .../java/builder/JavaContextFactoryBuilder.java | 113 +++ .../java/builder/JavaTargetWireBuilder.java | 38 + .../container/java/config/JavaContextFactory.java | 341 +++++++++ .../container/java/context/JavaAtomicContext.java | 165 +++++ .../invocation/AbstractJavaComponentInvoker.java | 93 +++ .../invocation/ScopedJavaComponentInvoker.java | 89 +++ .../StaticJavaComponentTargetInvoker.java | 50 ++ .../java/loader/JavaImplementationLoader.java | 165 +++++ .../tuscany/container/java/Messages.properties | 25 + .../src/main/resources/system.fragment | 41 ++ .../container.java/src/main/test/sca.module | 75 ++ .../assembly/mock/HelloWorldImpl.componentType | 23 + .../java/assembly/mock/HelloWorldImpl.java | 36 + .../java/assembly/mock/HelloWorldService.java | 27 + .../mock/HelloWorldWithFieldProperties.java | 40 + .../java/assembly/mock/NakedHelloWorld.java | 26 + .../mock/NakedHelloWorldWithInterface.java | 28 + .../account/services/account/AccountReport.java | 32 + .../account/services/account/AccountService.java | 25 + .../account/services/account/AccountService.wsdl | 78 ++ .../services/account/AccountServiceImpl.java | 42 ++ .../account/services/account/AccountSummary.java | 46 ++ .../services/accountdata/AccountDataService.java | 26 + .../accountdata/AccountDataServiceImpl.java | 48 ++ .../services/accountdata/CheckingAccount.java | 39 + .../services/accountdata/SavingsAccount.java | 39 + .../account/services/accountdata/StockAccount.java | 48 ++ .../services/stockquote/StockQuoteService.java | 24 + .../services/stockquote/StockQuoteServiceImpl.java | 28 + .../services/stockquote/StockQuoteWebService.wsdl | 98 +++ .../builder/JavaContextFactoryBuilderTestCase.java | 112 +++ .../builder/JavaTargetWireBuilderTestCase.java | 132 ++++ .../container/java/builder/MockHandlerBuilder.java | 120 +++ .../java/builder/MockInterceptorBuilder.java | 66 ++ .../context/DifferentInterfaceWireTestCase.java | 81 ++ .../JavaAtomicContextLifecycleTestCase.java | 59 ++ ...JavaAtomicContextMetadataInjectionTestCase.java | 58 ++ .../JavaAtomicContextNegativeMetadataTestCase.java | 73 ++ .../context/JavaAtomicContextScopeTestCase.java | 95 +++ .../java/context/MultiplicityTestCase.java | 77 ++ .../java/integration/GreetingProvider.java | 24 + .../java/integration/GreetingProviderImpl.java | 42 ++ .../container/java/integration/HelloWorldImpl.java | 29 + .../java/integration/HelloWorldMCImpl.java | 61 ++ .../java/integration/HelloWorldMCTestCase.java | 59 ++ .../java/integration/HelloWorldService.java | 24 + .../java/integration/HelloWorldTestCase.java | 61 ++ .../JavaBuilderContextIntegrationTestCase.java | 189 +++++ .../java/integration/JavaIntegrationTestCase.java | 68 ++ .../integration/JavaRuntimeBootstrapTestCase.java | 53 ++ .../java/integration/StartStopTestCase.java | 68 ++ .../binding/EPtoExternalServiceTestCase.java | 99 +++ .../binding/EntryPointToJavaTestCase.java | 261 +++++++ .../ExternalServiceProxyInvokeTestCase.java | 73 ++ .../binding/JavaToExternalServiceTestCase.java | 61 ++ .../context/ScopeReferenceTestCase.java | 741 +++++++++++++++++++ .../java/invocation/MediationTestCase.java | 53 ++ .../java/invocation/ScopedPojoInvokerTestCase.java | 53 ++ .../java/invocation/StaticPojoInvokerTestCase.java | 154 ++++ .../java/invocation/mock/MockHandler.java | 38 + .../java/invocation/mock/MockSyncInterceptor.java | 45 ++ .../java/invocation/mock/SimpleSource.java | 25 + .../java/invocation/mock/SimpleSourceImpl.java | 36 + .../java/invocation/mock/SimpleTarget.java | 28 + .../java/invocation/mock/SimpleTargetImpl.java | 39 + .../loader/JavaImplementationLoaderTestCase.java | 134 ++++ .../container/java/mock/MockConfigContext.java | 64 ++ .../container/java/mock/MockContextFactory.java | 92 +++ .../tuscany/container/java/mock/MockFactory.java | 819 +++++++++++++++++++++ .../container/java/mock/MockScopeContext.java | 131 ++++ .../java/mock/binding/foo/FooBinding.java | 58 ++ .../java/mock/binding/foo/FooBindingBuilder.java | 114 +++ .../mock/binding/foo/FooBindingWireBuilder.java | 76 ++ .../container/java/mock/binding/foo/FooClient.java | 37 + .../binding/foo/FooEntryPointContextFactory.java | 31 + .../foo/FooExternalServiceContextFactory.java | 32 + .../foo/FooExternalServiceTargetInvoker.java | 78 ++ .../mock/components/AbstractGenericComponent.java | 296 ++++++++ .../java/mock/components/BadContextPojo.java | 26 + .../java/mock/components/BadNamePojo.java | 24 + .../container/java/mock/components/DataObject.java | 38 + .../java/mock/components/GenericComponent.java | 142 ++++ .../java/mock/components/HelloWorldClient.java | 46 ++ .../java/mock/components/LocalComponentImpl.java | 97 +++ .../java/mock/components/ModuleScopeComponent.java | 31 + .../ModuleScopeComponentImpl.componentType | 32 + .../mock/components/ModuleScopeComponentImpl.java | 38 + .../ModuleScopeDestroyOnlyComponent.java | 34 + .../components/ModuleScopeEagerInitComponent.java | 39 + .../ModuleScopeEagerInitDestroyComponent.java | 33 + .../ModuleScopeInitDestroyComponent.java | 37 + .../components/ModuleScopeInitOnlyComponent.java | 41 ++ .../java/mock/components/OtherTarget.java | 27 + .../java/mock/components/OtherTargetImpl.java | 35 + .../java/mock/components/RemotableService.java | 40 + .../java/mock/components/RemotableServiceImpl.java | 61 ++ .../mock/components/RequestScopeComponent.java | 28 + .../mock/components/RequestScopeComponentImpl.java | 25 + .../RequestScopeDestroyOnlyComponent.java | 36 + .../RequestScopeInitDestroyComponent.java | 36 + .../components/RequestScopeInitOnlyComponent.java | 37 + .../mock/components/SessionScopeComponent.java | 28 + .../mock/components/SessionScopeComponentImpl.java | 28 + .../SessionScopeDestroyOnlyComponent.java | 34 + .../SessionScopeInitDestroyComponent.java | 34 + .../components/SessionScopeInitOnlyComponent.java | 35 + .../container/java/mock/components/Source.java | 32 + .../container/java/mock/components/SourceImpl.java | 63 ++ .../java/mock/components/StatelessComponent.java | 28 + .../mock/components/StatelessComponentImpl.java | 25 + .../container/java/mock/components/Target.java | 27 + .../container/java/mock/components/TargetImpl.java | 33 + .../java/scopes/BasicModuleScopeTestCase.java | 139 ++++ .../java/scopes/BasicRequestScopeTestCase.java | 158 ++++ .../java/scopes/BasicSessionScopeTestCase.java | 238 ++++++ .../java/scopes/BasicStatelessScopeTestCase.java | 129 ++++ .../java/scopes/CompositeScopeTestCase.java | 188 +++++ .../java/scopes/DependencyLifecycleTestCase.java | 93 +++ .../java/scopes/ModuleScopeLifecycleTestCase.java | 248 +++++++ .../container/java/scopes/OrderException.java | 38 + .../java/scopes/OrderedDependentPojo.java | 34 + .../java/scopes/OrderedEagerInitPojo.java | 56 ++ .../container/java/scopes/OrderedInitPojo.java | 56 ++ .../java/scopes/RequestScopeLifecycleTestCase.java | 166 +++++ .../java/scopes/RequestScopedOrderedInitPojo.java | 56 ++ .../java/scopes/SessionScopeLifecycleTestCase.java | 176 +++++ .../java/scopes/SessionScopedOrderedInitPojo.java | 56 ++ .../src/test/resources/helloworld/example.wsdl | 23 + .../src/test/resources/helloworld/sca.module | 32 + .../src/test/resources/helloworldmc/sca.module | 40 + .../container/java/assembly/tests/sca.module | 54 ++ .../java/config/ModuleComponentLoaderTest1.module | 24 + .../sca/containers/container.rhino/LICENSE.txt | 202 +++++ .../java/sca/containers/container.rhino/README.txt | 35 + .../java/sca/containers/container.rhino/pom.xml | 68 ++ .../rhino/assembly/JavaScriptImplementation.java | 74 ++ .../builder/JavaScriptContextFactoryBuilder.java | 132 ++++ .../rhino/builder/JavaScriptTargetWireBuilder.java | 40 + .../rhino/config/JavaScriptContextFactory.java | 114 +++ .../rhino/context/JavaScriptComponentContext.java | 140 ++++ .../loader/JavaScriptImplementationLoader.java | 168 +++++ .../container/rhino/rhino/E4XDataBinding.java | 108 +++ .../container/rhino/rhino/RhinoE4XScript.java | 76 ++ .../tuscany/container/rhino/rhino/RhinoScript.java | 290 ++++++++ .../src/main/resources/system.fragment | 32 + .../integration/AbstractJavaScriptTestCase.java | 46 ++ .../container/rhino/integration/BasicTestCase.java | 27 + .../container/rhino/integration/E4XTestCase.java | 29 + .../container/rhino/integration/HelloWorld.java | 26 + .../rhino/integration/InitializationTestCase.java | 33 + .../rhino/integration/PropertiesTestCase.java | 33 + .../container/rhino/integration/Salutation.java | 25 + .../rhino/integration/ServiceRefsTestCase.java | 27 + .../container/rhino/integration/TestMethods.java | 30 + .../rhino/rhino/RhinoE4XScriptTestCase.java | 89 +++ .../container/rhino/rhino/RhinoScriptTestCase.java | 186 +++++ .../rhino/rhino/RhinoE4XScriptTestCase.js | 11 + .../container/rhino/rhino/RhinoScriptTestCase.js | 22 + .../tuscany/container/rhino/rhino/helloworld.wsdl | 97 +++ .../container.rhino/src/test/resources/sca.module | 66 ++ .../resources/tests/HelloWorldImpl1.componentType | 9 + .../src/test/resources/tests/HelloWorldImpl1.js | 20 + .../resources/tests/HelloWorldImpl2.componentType | 11 + .../src/test/resources/tests/HelloWorldImpl2.js | 20 + .../resources/tests/HelloWorldImpl3a.componentType | 13 + .../src/test/resources/tests/HelloWorldImpl3a.js | 20 + .../resources/tests/HelloWorldImpl4.componentType | 9 + .../src/test/resources/tests/HelloWorldImpl4.js | 26 + .../resources/tests/HelloWorldImpl5.componentType | 9 + .../src/test/resources/tests/HelloWorldImpl5.js | 29 + .../resources/tests/SalutationImpl.componentType | 11 + .../src/test/resources/tests/SalutationImpl.js | 20 + .../src/test/resources/tests/e4x.componentType | 9 + .../src/test/resources/tests/e4x.js | 28 + .../src/test/resources/wsdl/helloworld.wsdl | 97 +++ .../java-M1-20060518/java/sca/containers/pom.xml | 37 + 183 files changed, 13562 insertions(+) create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/LICENSE.txt create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/README.txt create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/pom.xml create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/assembly/JavaAssemblyFactory.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/assembly/JavaImplementation.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/assembly/impl/JavaAssemblyFactoryImpl.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/assembly/impl/JavaImplementationImpl.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/builder/JavaContextFactoryBuilder.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/builder/JavaTargetWireBuilder.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/config/JavaContextFactory.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/context/JavaAtomicContext.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/invocation/AbstractJavaComponentInvoker.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/invocation/ScopedJavaComponentInvoker.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/invocation/StaticJavaComponentTargetInvoker.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/loader/JavaImplementationLoader.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/main/resources/org/apache/tuscany/container/java/Messages.properties create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/main/resources/system.fragment create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/main/test/sca.module create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/mock/HelloWorldImpl.componentType create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/mock/HelloWorldImpl.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/mock/HelloWorldService.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/mock/HelloWorldWithFieldProperties.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/mock/NakedHelloWorld.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/mock/NakedHelloWorldWithInterface.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/account/AccountReport.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/account/AccountService.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/account/AccountService.wsdl create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/account/AccountServiceImpl.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/account/AccountSummary.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/accountdata/AccountDataService.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/accountdata/AccountDataServiceImpl.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/accountdata/CheckingAccount.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/accountdata/SavingsAccount.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/accountdata/StockAccount.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/stockquote/StockQuoteService.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/stockquote/StockQuoteServiceImpl.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/stockquote/StockQuoteWebService.wsdl create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/builder/JavaContextFactoryBuilderTestCase.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/builder/JavaTargetWireBuilderTestCase.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/builder/MockHandlerBuilder.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/builder/MockInterceptorBuilder.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/context/DifferentInterfaceWireTestCase.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/context/JavaAtomicContextLifecycleTestCase.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/context/JavaAtomicContextMetadataInjectionTestCase.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/context/JavaAtomicContextNegativeMetadataTestCase.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/context/JavaAtomicContextScopeTestCase.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/context/MultiplicityTestCase.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/GreetingProvider.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/GreetingProviderImpl.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/HelloWorldImpl.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/HelloWorldMCImpl.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/HelloWorldMCTestCase.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/HelloWorldService.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/HelloWorldTestCase.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/JavaBuilderContextIntegrationTestCase.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/JavaIntegrationTestCase.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/JavaRuntimeBootstrapTestCase.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/StartStopTestCase.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/binding/EPtoExternalServiceTestCase.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/binding/EntryPointToJavaTestCase.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/binding/ExternalServiceProxyInvokeTestCase.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/binding/JavaToExternalServiceTestCase.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/context/ScopeReferenceTestCase.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/invocation/MediationTestCase.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/invocation/ScopedPojoInvokerTestCase.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/invocation/StaticPojoInvokerTestCase.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/invocation/mock/MockHandler.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/invocation/mock/MockSyncInterceptor.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/invocation/mock/SimpleSource.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/invocation/mock/SimpleSourceImpl.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/invocation/mock/SimpleTarget.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/invocation/mock/SimpleTargetImpl.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/loader/JavaImplementationLoaderTestCase.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/MockConfigContext.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/MockContextFactory.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/MockFactory.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/MockScopeContext.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/binding/foo/FooBinding.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/binding/foo/FooBindingBuilder.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/binding/foo/FooBindingWireBuilder.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/binding/foo/FooClient.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/binding/foo/FooEntryPointContextFactory.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/binding/foo/FooExternalServiceContextFactory.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/binding/foo/FooExternalServiceTargetInvoker.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/AbstractGenericComponent.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/BadContextPojo.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/BadNamePojo.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/DataObject.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/GenericComponent.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/HelloWorldClient.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/LocalComponentImpl.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/ModuleScopeComponent.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/ModuleScopeComponentImpl.componentType create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/ModuleScopeComponentImpl.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/ModuleScopeDestroyOnlyComponent.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/ModuleScopeEagerInitComponent.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/ModuleScopeEagerInitDestroyComponent.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/ModuleScopeInitDestroyComponent.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/ModuleScopeInitOnlyComponent.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/OtherTarget.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/OtherTargetImpl.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/RemotableService.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/RemotableServiceImpl.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/RequestScopeComponent.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/RequestScopeComponentImpl.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/RequestScopeDestroyOnlyComponent.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/RequestScopeInitDestroyComponent.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/RequestScopeInitOnlyComponent.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/SessionScopeComponent.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/SessionScopeComponentImpl.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/SessionScopeDestroyOnlyComponent.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/SessionScopeInitDestroyComponent.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/SessionScopeInitOnlyComponent.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/Source.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/SourceImpl.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/StatelessComponent.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/StatelessComponentImpl.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/Target.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/TargetImpl.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/BasicModuleScopeTestCase.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/BasicRequestScopeTestCase.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/BasicSessionScopeTestCase.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/BasicStatelessScopeTestCase.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/CompositeScopeTestCase.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/DependencyLifecycleTestCase.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/ModuleScopeLifecycleTestCase.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/OrderException.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/OrderedDependentPojo.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/OrderedEagerInitPojo.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/OrderedInitPojo.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/RequestScopeLifecycleTestCase.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/RequestScopedOrderedInitPojo.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/SessionScopeLifecycleTestCase.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/SessionScopedOrderedInitPojo.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/resources/helloworld/example.wsdl create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/resources/helloworld/sca.module create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/resources/helloworldmc/sca.module create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/resources/org/apache/tuscany/container/java/assembly/tests/sca.module create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/resources/org/apache/tuscany/container/java/config/ModuleComponentLoaderTest1.module create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/LICENSE.txt create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/README.txt create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/pom.xml create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/main/java/org/apache/tuscany/container/rhino/assembly/JavaScriptImplementation.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/main/java/org/apache/tuscany/container/rhino/builder/JavaScriptContextFactoryBuilder.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/main/java/org/apache/tuscany/container/rhino/builder/JavaScriptTargetWireBuilder.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/main/java/org/apache/tuscany/container/rhino/config/JavaScriptContextFactory.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/main/java/org/apache/tuscany/container/rhino/context/JavaScriptComponentContext.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/main/java/org/apache/tuscany/container/rhino/loader/JavaScriptImplementationLoader.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/main/java/org/apache/tuscany/container/rhino/rhino/E4XDataBinding.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/main/java/org/apache/tuscany/container/rhino/rhino/RhinoE4XScript.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/main/java/org/apache/tuscany/container/rhino/rhino/RhinoScript.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/main/resources/system.fragment create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/java/org/apache/tuscany/container/rhino/integration/AbstractJavaScriptTestCase.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/java/org/apache/tuscany/container/rhino/integration/BasicTestCase.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/java/org/apache/tuscany/container/rhino/integration/E4XTestCase.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/java/org/apache/tuscany/container/rhino/integration/HelloWorld.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/java/org/apache/tuscany/container/rhino/integration/InitializationTestCase.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/java/org/apache/tuscany/container/rhino/integration/PropertiesTestCase.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/java/org/apache/tuscany/container/rhino/integration/Salutation.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/java/org/apache/tuscany/container/rhino/integration/ServiceRefsTestCase.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/java/org/apache/tuscany/container/rhino/integration/TestMethods.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/java/org/apache/tuscany/container/rhino/rhino/RhinoE4XScriptTestCase.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/java/org/apache/tuscany/container/rhino/rhino/RhinoScriptTestCase.java create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/resources/org/apache/tuscany/container/rhino/rhino/RhinoE4XScriptTestCase.js create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/resources/org/apache/tuscany/container/rhino/rhino/RhinoScriptTestCase.js create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/resources/org/apache/tuscany/container/rhino/rhino/helloworld.wsdl create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/resources/sca.module create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/resources/tests/HelloWorldImpl1.componentType create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/resources/tests/HelloWorldImpl1.js create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/resources/tests/HelloWorldImpl2.componentType create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/resources/tests/HelloWorldImpl2.js create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/resources/tests/HelloWorldImpl3a.componentType create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/resources/tests/HelloWorldImpl3a.js create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/resources/tests/HelloWorldImpl4.componentType create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/resources/tests/HelloWorldImpl4.js create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/resources/tests/HelloWorldImpl5.componentType create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/resources/tests/HelloWorldImpl5.js create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/resources/tests/SalutationImpl.componentType create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/resources/tests/SalutationImpl.js create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/resources/tests/e4x.componentType create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/resources/tests/e4x.js create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/resources/wsdl/helloworld.wsdl create mode 100644 sca-java-1.x/tags/java-M1-20060518/java/sca/containers/pom.xml (limited to 'sca-java-1.x/tags/java-M1-20060518/java/sca/containers') diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/LICENSE.txt b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/LICENSE.txt new file mode 100644 index 0000000000..d645695673 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/LICENSE.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/README.txt b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/README.txt new file mode 100644 index 0000000000..9b26d1690a --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/README.txt @@ -0,0 +1,35 @@ +Apache Tuscany M1 build (May, 2006) +=================================== + +http://incubator.apache.org/tuscany/ + +Tuscany is an effort undergoing incubation at the Apache Software Foundation +(ASF), sponsored by the Web Services PMC. + +Incubation is required of all newly accepted projects until a further review +indicates that the infrastructure, communications, and decision making process +have stabilized in a manner consistent with other successful ASF projects. + +While incubation status is not necessarily a reflection of the completeness or +stability of the code, it does indicate that the project has yet to be fully +endorsed by the ASF. + + +Support +------- + +Any problem with this release can be reported to the Tuscany mailing list +or in the JIRA issue tracker. + +Mailing list subscription: + tuscany-dev-subscribe@ws.apache.org + +Jira: + http://issues.apache.org/jira/browse/Tuscany + + +Thank you for using Tuscany! + + +The Tuscany Team. + diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/pom.xml b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/pom.xml new file mode 100644 index 0000000000..cb33cc90cf --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/pom.xml @@ -0,0 +1,52 @@ + + + + + + org.apache.tuscany.sca.containers + tuscany-sca-containers + incubating-M1 + + + 4.0.0 + tuscany-container-java + Tuscany Java IoC Container + Container for managing components as defined by the SCA implementation specification. + incubating-M1 + + + + org.apache.tuscany + tuscany-core + ${pom.version} + compile + + + org.apache.tuscany.databinding + tuscany-databinding-sdo + ${pom.version} + compile + + + + junit + junit + 3.8.1 + test + + + diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/assembly/JavaAssemblyFactory.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/assembly/JavaAssemblyFactory.java new file mode 100644 index 0000000000..90271179d1 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/assembly/JavaAssemblyFactory.java @@ -0,0 +1,30 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.assembly; + +import org.apache.tuscany.model.assembly.AssemblyFactory; + + +/** + * The Factory for the model. + */ +public interface JavaAssemblyFactory extends AssemblyFactory { + /** + * Returns a new JavaImplementation. + */ + JavaImplementation createJavaImplementation(); +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/assembly/JavaImplementation.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/assembly/JavaImplementation.java new file mode 100644 index 0000000000..a87b8ea1bb --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/assembly/JavaImplementation.java @@ -0,0 +1,39 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.assembly; + +import org.apache.tuscany.model.assembly.AtomicImplementation; + + +/** + * Represents a java implementation. + * + * @version $Rev$ $Date$ + */ +public interface JavaImplementation extends AtomicImplementation { + + /** + * Returns the implementation class. + */ + Class getImplementationClass(); + + /** + * Sets the implementation class. + */ + void setImplementationClass(Class value); + +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/assembly/impl/JavaAssemblyFactoryImpl.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/assembly/impl/JavaAssemblyFactoryImpl.java new file mode 100644 index 0000000000..3337c287ac --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/assembly/impl/JavaAssemblyFactoryImpl.java @@ -0,0 +1,45 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.assembly.impl; + +import org.osoa.sca.annotations.Service; + +import org.apache.tuscany.container.java.assembly.JavaAssemblyFactory; +import org.apache.tuscany.container.java.assembly.JavaImplementation; +import org.apache.tuscany.model.assembly.impl.AssemblyFactoryImpl; + +/** + * A factory for the model. + */ +@Service(interfaces = {JavaAssemblyFactory.class}) +public class JavaAssemblyFactoryImpl extends AssemblyFactoryImpl implements JavaAssemblyFactory { + + /** + * Constructor + */ + public JavaAssemblyFactoryImpl() { + super(); + } + + /** + * @see org.apache.tuscany.container.java.assembly.JavaAssemblyFactory#createJavaImplementation() + */ + public JavaImplementation createJavaImplementation() { + return new JavaImplementationImpl(); + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/assembly/impl/JavaImplementationImpl.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/assembly/impl/JavaImplementationImpl.java new file mode 100644 index 0000000000..57a98f4ad6 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/assembly/impl/JavaImplementationImpl.java @@ -0,0 +1,44 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.assembly.impl; + +import org.apache.tuscany.container.java.assembly.JavaImplementation; +import org.apache.tuscany.model.assembly.impl.AtomicImplementationImpl; + +/** + * An implementation of JavaImplementation. + * + * @version $Rev$ $Date$ + */ +public class JavaImplementationImpl extends AtomicImplementationImpl implements JavaImplementation { + private Class implementationClass; + + /** + * Default constructor. + */ + protected JavaImplementationImpl() { + } + + public Class getImplementationClass() { + return implementationClass; + } + + public void setImplementationClass(Class value) { + checkNotFrozen(); + implementationClass = value; + } +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/builder/JavaContextFactoryBuilder.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/builder/JavaContextFactoryBuilder.java new file mode 100644 index 0000000000..de915738f9 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/builder/JavaContextFactoryBuilder.java @@ -0,0 +1,113 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.builder; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.container.java.assembly.JavaImplementation; +import org.apache.tuscany.container.java.config.JavaContextFactory; +import org.apache.tuscany.core.extension.config.extensibility.ComponentNameExtensibilityElement; +import org.apache.tuscany.core.extension.config.extensibility.ContextExtensibilityElement; +import org.apache.tuscany.core.extension.config.extensibility.DestroyInvokerExtensibilityElement; +import org.apache.tuscany.core.extension.config.extensibility.InitInvokerExtensibilityElement; +import org.apache.tuscany.core.extension.config.InjectorExtensibilityElement; +import org.apache.tuscany.core.builder.BuilderConfigException; +import org.apache.tuscany.core.builder.BuilderException; +import org.apache.tuscany.core.builder.ContextFactory; +import org.apache.tuscany.core.config.JavaIntrospectionHelper; +import org.apache.tuscany.core.extension.ContextFactoryBuilderSupport; +import org.apache.tuscany.core.injection.EventInvoker; +import org.apache.tuscany.core.injection.Injector; +import org.apache.tuscany.core.wire.service.WireFactoryService; +import org.apache.tuscany.model.assembly.Scope; + +/** + * Builds context factories for component implementations that map to {@link + * org.apache.tuscany.container.java.assembly.JavaImplementation}. The logical model is then decorated with + * the runtime configuration. + * + * @version $Rev: 368822 $ $Date: 2006-01-13 10:54:38 -0800 (Fri, 13 Jan 2006) $ + * @see org.apache.tuscany.core.builder.ContextFactory + */ +@org.osoa.sca.annotations.Scope("MODULE") +public class JavaContextFactoryBuilder extends ContextFactoryBuilderSupport { + + /** + * Default constructor + */ + public JavaContextFactoryBuilder() { + super(); + } + + /** + * Constructs a new instance + * + * @param wireFactoryService the system service responsible for creating wire factories + */ + public JavaContextFactoryBuilder(WireFactoryService wireFactoryService) { + super(wireFactoryService); + } + + @SuppressWarnings("unchecked") + protected ContextFactory createContextFactory(String name, JavaImplementation javaImpl, Scope scope) { + Class implClass = null; + JavaContextFactory contextFactory; + try { + implClass = javaImpl.getImplementationClass(); + + contextFactory = new JavaContextFactory(name, JavaIntrospectionHelper + .getDefaultConstructor(implClass), scope); + + List injectors = new ArrayList(); + List elements = javaImpl.getComponentType().getExtensibilityElements(); + for (Object element : elements) { + if (element instanceof InitInvokerExtensibilityElement) { + InitInvokerExtensibilityElement invokerElement = (InitInvokerExtensibilityElement) element; + EventInvoker initInvoker = invokerElement.getEventInvoker(); + boolean eagerInit = invokerElement.isEager(); + contextFactory.setEagerInit(eagerInit); + contextFactory.setInitInvoker(initInvoker); + } else if (element instanceof DestroyInvokerExtensibilityElement) { + DestroyInvokerExtensibilityElement invokerElement = (DestroyInvokerExtensibilityElement) element; + EventInvoker destroyInvoker = invokerElement.getEventInvoker(); + contextFactory.setDestroyInvoker(destroyInvoker); + } else if (element instanceof ComponentNameExtensibilityElement) { + ComponentNameExtensibilityElement nameElement = (ComponentNameExtensibilityElement) element; + injectors.add(nameElement.getEventInvoker(name)); + } else if (element instanceof ContextExtensibilityElement) { + ContextExtensibilityElement contextElement = (ContextExtensibilityElement) element; + injectors.add(contextElement.getInjector(contextFactory)); + }else if (element instanceof InjectorExtensibilityElement){ + InjectorExtensibilityElement injectorElement = (InjectorExtensibilityElement)element; + injectors.add(injectorElement.getInjector(contextFactory)); + } + } + contextFactory.setSetters(injectors); + return contextFactory; + } catch (BuilderException e) { + e.addContextName(name); + throw e; + } catch (NoSuchMethodException e) { + BuilderConfigException ce = new BuilderConfigException("Class does not have a no-arg constructor", e); + ce.setIdentifier(implClass.getName()); + ce.addContextName(name); + throw ce; + } + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/builder/JavaTargetWireBuilder.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/builder/JavaTargetWireBuilder.java new file mode 100644 index 0000000000..cc66fa54f6 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/builder/JavaTargetWireBuilder.java @@ -0,0 +1,38 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package org.apache.tuscany.container.java.builder; + +import org.apache.tuscany.container.java.config.JavaContextFactory; +import org.apache.tuscany.container.java.invocation.ScopedJavaComponentInvoker; +import org.apache.tuscany.core.context.QualifiedName; +import org.apache.tuscany.core.context.ScopeContext; +import org.apache.tuscany.core.extension.WireBuilderSupport; +import org.apache.tuscany.core.wire.TargetInvoker; +import org.osoa.sca.annotations.Scope; + +import java.lang.reflect.Method; + +/** + * Completes a wire to a Java-based target component by adding a scoped java invoker to the source chain + * + * @version $Rev$ $Date$ + */ +@Scope("MODULE") +public class JavaTargetWireBuilder extends WireBuilderSupport { + + protected TargetInvoker createInvoker(QualifiedName targetName, Method operation, ScopeContext context, boolean downScope) { + boolean cacheable = !downScope; + return new ScopedJavaComponentInvoker(targetName, operation, context,cacheable); + } +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/config/JavaContextFactory.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/config/JavaContextFactory.java new file mode 100644 index 0000000000..ff498d851a --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/config/JavaContextFactory.java @@ -0,0 +1,341 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package org.apache.tuscany.container.java.config; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import commonj.sdo.DataObject; +import org.apache.tuscany.container.java.context.JavaAtomicContext; +import org.apache.tuscany.core.builder.BuilderConfigException; +import org.apache.tuscany.core.builder.ContextCreationException; +import org.apache.tuscany.core.builder.ContextFactory; +import org.apache.tuscany.core.builder.ContextResolver; +import org.apache.tuscany.core.builder.NoAccessorException; +import org.apache.tuscany.core.builder.ObjectFactory; +import org.apache.tuscany.core.builder.impl.ArrayMultiplicityObjectFactory; +import org.apache.tuscany.core.builder.impl.ListMultiplicityObjectFactory; +import org.apache.tuscany.core.builder.impl.ProxyObjectFactory; +import org.apache.tuscany.core.config.JavaIntrospectionHelper; +import org.apache.tuscany.core.context.AtomicContext; +import org.apache.tuscany.core.context.CompositeContext; +import org.apache.tuscany.core.injection.EventInvoker; +import org.apache.tuscany.core.injection.FieldInjector; +import org.apache.tuscany.core.injection.Injector; +import org.apache.tuscany.core.injection.MethodInjector; +import org.apache.tuscany.core.injection.PojoObjectFactory; +import org.apache.tuscany.core.injection.SingletonObjectFactory; +import org.apache.tuscany.core.wire.SourceWireFactory; +import org.apache.tuscany.core.wire.TargetWireFactory; +import org.apache.tuscany.databinding.sdo.SDOObjectFactory; +import org.apache.tuscany.model.assembly.Scope; +import org.osoa.sca.annotations.Property; +import org.osoa.sca.annotations.Reference; + +/** + * A ContextFactory that handles POJO component implementation types + * + * @version $Rev$ $Date$ + */ +public class JavaContextFactory implements ContextFactory, ContextResolver { + + // the component name as configured in the hosting module + private String name; + + // the parent context of the component + private CompositeContext parentContext; + + private Map targetProxyFactories = new HashMap(); + + private List sourceProxyFactories = new ArrayList(); + + // the implementation type constructor + private Constructor ctr; + + private Set fields; + + private Set methods; + + // injectors for properties, references and other metadata values such as + private List setters; + + // an invoker for a method decorated with @Init + private EventInvoker init; + + // whether the component should be eagerly initialized when its scope starts + private boolean eagerInit; + + // an invoker for a method decorated with @Destroy + private EventInvoker destroy; + + // the scope of the implementation instance + private Scope scope; + + // whether the component is stateless + private boolean stateless; + + /** + * Creates a new context factory + * + * @param name the SCDL name of the component the context refers to + * @param ctr the implementation type constructor + * @param scope the scope of the component implementation type + */ + public JavaContextFactory(String name, Constructor ctr, Scope scope) { + assert (name != null) : "Name was null"; + assert (ctr != null) : "Constructor was null"; + this.name = name; + this.ctr = ctr; + this.scope = scope; + stateless = (scope == Scope.INSTANCE); + fields = JavaIntrospectionHelper.getAllFields(ctr.getDeclaringClass()); + methods = JavaIntrospectionHelper.getAllUniqueMethods(ctr.getDeclaringClass()); + } + + public String getName() { + return name; + } + + public Scope getScope() { + return scope; + } + + public AtomicContext createContext() throws ContextCreationException { + PojoObjectFactory objectFactory = new PojoObjectFactory(ctr, null, setters); + return new JavaAtomicContext(name, objectFactory, eagerInit, init, destroy, stateless); + } + + public void addTargetWireFactory(String serviceName, TargetWireFactory factory) { + targetProxyFactories.put(serviceName, factory); + } + + public TargetWireFactory getTargetWireFactory(String serviceName) { + return targetProxyFactories.get(serviceName); + } + + public Map getTargetWireFactories() { + return targetProxyFactories; + } + + public void addProperty(String propertyName, Object value) { + setters.add(createPropertyInjector(propertyName, value)); + } + + public void addSourceWireFactory(String referenceName, SourceWireFactory factory) { + sourceProxyFactories.add(factory); + setters.add(createReferenceInjector(referenceName, factory, false)); + } + + public void addSourceWireFactories(String referenceName, Class referenceInterface, List factories, boolean multiplicity) { + sourceProxyFactories.addAll(factories); + setters.add(createReferenceInjector(referenceName, factories, multiplicity)); + } + + public List getSourceWireFactories() { + return sourceProxyFactories; + } + + public void setSetters(List setters) { + this.setters = setters; + } + + public void setEagerInit(boolean val) { + eagerInit = val; + } + + public void setInitInvoker(EventInvoker invoker) { + init = invoker; + } + + public void setDestroyInvoker(EventInvoker invoker) { + destroy = invoker; + } + + public void prepare(CompositeContext parent) { + parentContext = parent; + } + + public CompositeContext getCurrentContext() { + return parentContext; + } + + /** + * Creates an Injector for component properties + */ + private Injector createPropertyInjector(String propertyName, Object value) + throws NoAccessorException { + Class type = value.getClass(); + + // There is no efficient way to do this + Method method = null; + Field field = JavaIntrospectionHelper.findClosestMatchingField(propertyName, type, fields); + if (field == null) { + // hack for TUSCANY-322 + for (Field current : fields) { + Property annot = current.getAnnotation(Property.class); + if (annot != null) { + if (propertyName.equals(annot.name())) { + field = current; + break; + } + } + } + method = JavaIntrospectionHelper.findClosestMatchingMethod(propertyName, new Class[]{type}, methods); + if (method == null) { + // hack for TUSCANY-322 + for (Method current : methods) { + Property annot = current.getAnnotation(Property.class); + if (annot != null) { + if (propertyName.equals(annot.name())) { + method = current; + break; + } + } + } + if (method == null) { + throw new NoAccessorException(propertyName); + } + } + } + Injector injector = null; + if (value instanceof DataObject) { + if (field != null) { + injector = new FieldInjector(field, new SDOObjectFactory((DataObject) value)); + } else { + injector = new MethodInjector(method, new SDOObjectFactory((DataObject) value)); + } + } else if (JavaIntrospectionHelper.isImmutable(type)) { + if (field != null) { + injector = new FieldInjector(field, new SingletonObjectFactory(value)); + } else { + injector = new MethodInjector(method, new SingletonObjectFactory(value)); + } + } + return injector; + + } + + /** + * Creates proxy factories that represent target(s) of a reference and an Injector + * responsible for injecting them into the reference + */ + private Injector createReferenceInjector(String refName, List wireFactories, boolean multiplicity) { + Class refClass = wireFactories.get(0).getBusinessInterface(); //reference.getPort().getServiceContract().getInterface(); + // iterate through the targets + List objectFactories = new ArrayList(); + for (SourceWireFactory wireFactory : wireFactories) { + objectFactories.add(new ProxyObjectFactory(wireFactory)); + } + return createInjector(refName, refClass, multiplicity, objectFactories, fields, methods); + + } + + private Injector createReferenceInjector(String refName, SourceWireFactory wireFactory, boolean multiplicity) { + Class refClass = wireFactory.getBusinessInterface();//reference.getPort().getServiceContract().getInterface(); + List objectFactories = new ArrayList(); + objectFactories.add(new ProxyObjectFactory(wireFactory)); + return createInjector(refName, refClass, multiplicity, objectFactories, fields, methods); + + } + + /** + * Creates an Injector for a set of object factories associated with a reference. + */ + private Injector createInjector(String refName, Class refClass, boolean multiplicity, List objectFactories, + Set fields, Set methods) throws NoAccessorException, BuilderConfigException { + Field field; + Method method = null; + if (multiplicity) { + // since this is a multiplicity, we cannot match on business interface type, so scan through the fields, + // matching on name and List or Array + field = JavaIntrospectionHelper.findMultiplicityFieldByName(refName, fields); + if (field == null) { + // No fields found. Again, since this is a multiplicity, we cannot match on business interface type, so + // scan through the fields, matching on name and List or Array + method = JavaIntrospectionHelper.findMultiplicityMethodByName(refName, methods); + if (method == null) { + throw new NoAccessorException(refName); + } + } + Injector injector; + // for multiplicities, we need to inject the reference proxy or proxies using an object factory + // which first delegates to create the proxies and then returns them in the appropriate List or array type + if (field != null) { + if (field.getType().isArray()) { + injector = new FieldInjector(field, new ArrayMultiplicityObjectFactory(refClass, objectFactories)); + } else { + injector = new FieldInjector(field, new ListMultiplicityObjectFactory(objectFactories)); + } + } else { + if (method.getParameterTypes()[0].isArray()) { + injector = new MethodInjector(method, new ArrayMultiplicityObjectFactory(refClass, objectFactories)); + } else { + injector = new MethodInjector(method, new ListMultiplicityObjectFactory(objectFactories)); + } + } + return injector; + } else { + field = JavaIntrospectionHelper.findClosestMatchingField(refName, refClass, fields); + if (field == null) { + // hack for TUSCANY-300 + for (Field current : fields) { + Reference annot = current.getAnnotation(Reference.class); + if (annot != null) { + if (refName.equals(annot.name())) { + field = current; + break; + } + } + } + if (field == null) { + method = JavaIntrospectionHelper.findClosestMatchingMethod(refName, new Class[]{refClass}, methods); + if(method == null){ + // Fix for Tuscany-325 + method = JavaIntrospectionHelper.findClosestMatchingMethod("set"+refName.substring(0,1).toUpperCase()+ refName.substring(1), new Class[]{refClass}, methods); + } + if (method == null) { + // hack for TUSCANY-300 + for (Method current : methods) { + Reference annot = current.getAnnotation(Reference.class); + if (annot != null) { + if (refName.equals(annot.name())) { + method = current; + break; + } + } + } + if (method == null) { + throw new NoAccessorException(refName); + } + } + } + } + Injector injector; + if (field != null) { + injector = new FieldInjector(field, objectFactories.get(0)); + } else { + injector = new MethodInjector(method, objectFactories.get(0)); + } + return injector; + } + } + + +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/context/JavaAtomicContext.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/context/JavaAtomicContext.java new file mode 100644 index 0000000000..27581198aa --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/context/JavaAtomicContext.java @@ -0,0 +1,165 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.context; + +import org.apache.tuscany.core.builder.ObjectFactory; +import org.apache.tuscany.core.context.AtomicContext; +import org.apache.tuscany.core.context.ContextInitException; +import org.apache.tuscany.core.context.QualifiedName; +import org.apache.tuscany.core.context.TargetException; +import org.apache.tuscany.core.context.event.InstanceCreated; +import org.apache.tuscany.core.context.impl.AbstractContext; +import org.apache.tuscany.core.injection.EventInvoker; +import org.apache.tuscany.core.injection.ObjectCallbackException; +import org.apache.tuscany.core.injection.ObjectCreationException; + +/** + * Manages Java component implementation instances + * + * @version $Rev$ $Date$ + */ +public class JavaAtomicContext extends AbstractContext implements AtomicContext { + + private boolean eagerInit; + + private EventInvoker initInvoker; + + private EventInvoker destroyInvoker; + + private boolean stateless; + + // the cached target instance + private Object cachedTargetInstance; + + // creates a new implementation instance with injected references and properties + private ObjectFactory objectFactory; + + public JavaAtomicContext(String name, ObjectFactory objectFactory, boolean eagerInit, EventInvoker initInvoker, + EventInvoker destroyInvoker, boolean stateless) { + super(name); + assert (objectFactory != null) : "Object factory was null"; + if (eagerInit && initInvoker == null) { + ContextInitException e = new ContextInitException("No intialization method found for implementation"); + e.setIdentifier(getName()); + throw e; + } + this.objectFactory = objectFactory; + + this.eagerInit = eagerInit; + this.initInvoker = initInvoker; + this.destroyInvoker = destroyInvoker; + this.stateless = stateless; + } + + public void setName(String name) { + super.setName(name); + } + + protected int type; + + public int getType() { + return type; + } + + public void setType(int type) { + this.type = type; + } + + public void init() throws TargetException { + getInstance(null); + } + + public void destroy() throws TargetException { + if (cachedTargetInstance != null) { + if (destroyInvoker != null) { + try { + destroyInvoker.invokeEvent(cachedTargetInstance); + } catch (ObjectCallbackException e) { + TargetException te = new TargetException(e.getCause()); + te.setIdentifier(getName()); + throw te; + } + } + } + lifecycleState = STARTED; + } + + public synchronized Object getInstance(QualifiedName qName) throws TargetException { + //TODO implement returning of proxy and wire chain for service + if (cachedTargetInstance != null) { + return cachedTargetInstance; // already cached, just return + } + + if (getLifecycleState() == ERROR || getLifecycleState() == CONFIG_ERROR) { + return null; + } + synchronized (this) { + try { + Object instance = objectFactory.getInstance(); + // handle @Init + if (initInvoker != null) { + initInvoker.invokeEvent(instance); + } + publish(new InstanceCreated(this)); + lifecycleState = RUNNING; + if (stateless) { + return instance; + } else { + cachedTargetInstance = instance; // cache the instance + return cachedTargetInstance; + } + } catch (ObjectCreationException e) { + lifecycleState = ERROR; + TargetException te = new TargetException("Error creating component instance", e); + te.setIdentifier(getName()); + throw te; + } + } + + } + + public Object getTargetInstance() throws TargetException { + //TODO refactor when getInstance() returns a proxy + return getInstance(null); + } + + public boolean isEagerInit() { + return eagerInit; + } + + public boolean isDestroyable() { + return (destroyInvoker != null); + } + + public void start() throws ContextInitException { + if (getLifecycleState() != UNINITIALIZED && getLifecycleState() != STOPPED) { + throw new IllegalStateException("Context must be in UNINITIALIZED state [" + getLifecycleState() + "]"); + } + if (objectFactory == null) { + lifecycleState = ERROR; + ContextInitException e = new ContextInitException("Object factory not found"); + e.setIdentifier(getName()); + throw e; + } + lifecycleState = INITIALIZED; + } + + public void stop() { + lifecycleState = STOPPED; + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/invocation/AbstractJavaComponentInvoker.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/invocation/AbstractJavaComponentInvoker.java new file mode 100644 index 0000000000..33fa9238b6 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/invocation/AbstractJavaComponentInvoker.java @@ -0,0 +1,93 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.invocation; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.Set; + +import org.apache.tuscany.core.config.JavaIntrospectionHelper; +import org.apache.tuscany.core.context.TargetException; +import org.apache.tuscany.core.wire.Interceptor; +import org.apache.tuscany.core.wire.InvocationRuntimeException; +import org.apache.tuscany.core.wire.TargetInvoker; +import org.apache.tuscany.core.message.Message; + +/** + * Base class for dispatching to a Java based component implementation. Subclasses implement a strategy for resolving + * implementation instances. + * + * @version $Rev$ $Date$ + */ +public abstract class AbstractJavaComponentInvoker implements TargetInvoker { + + protected Method operation; + + public AbstractJavaComponentInvoker(Method operation) { + assert (operation != null) : "Operation method cannot be null"; + this.operation = operation; + } + + public Object invokeTarget(Object payload) throws InvocationTargetException { + try { + Object instance = getInstance(); + if (!operation.getDeclaringClass().isInstance(instance)) { + Set methods = JavaIntrospectionHelper.getAllUniqueMethods(instance.getClass()); + Method newOperation = JavaIntrospectionHelper.findClosestMatchingMethod(operation.getName(), operation + .getParameterTypes(), methods); + if (newOperation != null) + operation = newOperation; + } + if (payload != null && !payload.getClass().isArray()) { + return operation.invoke(instance, payload); + } else { + return operation.invoke(instance, (Object[]) payload); + } + } catch (IllegalAccessException e) { + throw new InvocationRuntimeException(e); + } + } + + public Message invoke(Message msg) { + try { + Object resp = invokeTarget(msg.getBody()); + msg.setBody(resp); + } catch (InvocationTargetException e) { + msg.setBody(e.getCause()); + } catch (Throwable e) { + msg.setBody(e); + } + return msg; + } + + protected abstract Object getInstance() throws TargetException; + + public void setNext(Interceptor next) { + throw new IllegalStateException("This interceptor must be the last interceptor in an interceptor chain"); + } + + @Override + public Object clone() throws CloneNotSupportedException { + try { + AbstractJavaComponentInvoker clone = (AbstractJavaComponentInvoker) super.clone(); + clone.operation = this.operation; + return clone; + } catch (CloneNotSupportedException e) { + return null; // will not happen + } + } +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/invocation/ScopedJavaComponentInvoker.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/invocation/ScopedJavaComponentInvoker.java new file mode 100644 index 0000000000..85d72b4b0d --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/invocation/ScopedJavaComponentInvoker.java @@ -0,0 +1,89 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.invocation; + +import org.apache.tuscany.core.context.QualifiedName; +import org.apache.tuscany.core.context.ScopeContext; +import org.apache.tuscany.core.context.TargetException; + +import java.lang.reflect.Method; + +/** + * Uses a scope container to resolve an implementation instance based on the current thread context + * + * @version $Rev$ $Date$ + */ +public class ScopedJavaComponentInvoker extends AbstractJavaComponentInvoker { + + private ScopeContext container; + + private QualifiedName name; + + private Object target; + + public boolean cacheable; + + + /** + * Creates a new invoker + * + * @param serviceName the name of the component/service pair to invoke + * @param operation the operation the invoker is associated with + * @param scopeContext the scope context the component is resolved in + * @param cacheable Sets whether the target service instance may be cached by the invoker. This is a possible optimization + * when a wire is configured for a "down-scope" reference, i.e. a reference from a source of a shorter + * lifetime to a source of greater lifetime. + */ + public ScopedJavaComponentInvoker(QualifiedName serviceName, Method operation, ScopeContext scopeContext, boolean cacheable) { + super(operation); + assert (serviceName != null) : "No service name specified"; + assert (scopeContext != null) : "No scope scopeContext specified"; + name = serviceName; + this.container = scopeContext; + this.cacheable = cacheable; + } + + /** + * Returns whether the target is cacheable. + */ + public boolean isCacheable() { + return cacheable; + } + + /** + * Resolves the target service instance or returns a cached one + */ + protected Object getInstance() throws TargetException { + if (!cacheable) { + return container.getInstance(name); + } else { + if (target == null) { + target = container.getInstance(name); + } + return target; + } + } + + public Object clone() throws CloneNotSupportedException { + ScopedJavaComponentInvoker invoker = (ScopedJavaComponentInvoker) super.clone(); + invoker.target = null; + invoker.cacheable = this.cacheable; + invoker.container = this.container; + invoker.name = this.name; + return invoker; + } +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/invocation/StaticJavaComponentTargetInvoker.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/invocation/StaticJavaComponentTargetInvoker.java new file mode 100644 index 0000000000..dd757137cf --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/invocation/StaticJavaComponentTargetInvoker.java @@ -0,0 +1,50 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.invocation; + +import java.lang.reflect.Method; + +/** + * Caches component instances that do not need to be resolved for every wire, e.g. an wire originating from + * a lesser scope intended for a target with a wider scope + * + * @version $Rev$ $Date$ + */ +public class StaticJavaComponentTargetInvoker extends AbstractJavaComponentInvoker { + + private Object instance; + + public StaticJavaComponentTargetInvoker(Method operation, Object instance) { + super(operation); + assert (instance != null) : "Instance cannot be null"; + this.instance = instance; + } + + protected Object getInstance() { + return instance; + } + + public boolean isCacheable() { + return true; + } + + public Object clone() throws CloneNotSupportedException { + StaticJavaComponentTargetInvoker invoker = (StaticJavaComponentTargetInvoker) super.clone(); + invoker.instance = null; + return invoker; + } +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/loader/JavaImplementationLoader.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/loader/JavaImplementationLoader.java new file mode 100644 index 0000000000..db3dd07c98 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/loader/JavaImplementationLoader.java @@ -0,0 +1,165 @@ +/** + * + * Copyright 2005 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.loader; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import javax.xml.namespace.QName; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.common.resource.ResourceLoader; +import org.apache.tuscany.container.java.assembly.JavaAssemblyFactory; +import org.apache.tuscany.container.java.assembly.JavaImplementation; +import org.apache.tuscany.core.config.ComponentTypeIntrospector; +import org.apache.tuscany.core.config.ConfigurationLoadException; +import org.apache.tuscany.core.config.InvalidRootElementException; +import org.apache.tuscany.core.config.JavaIntrospectionHelper; +import org.apache.tuscany.core.config.SidefileLoadException; +import org.apache.tuscany.core.config.processor.ProcessorUtils; +import org.apache.tuscany.core.loader.LoaderContext; +import org.apache.tuscany.core.loader.StAXElementLoader; +import org.apache.tuscany.core.loader.StAXLoaderRegistry; +import org.apache.tuscany.core.loader.assembly.AssemblyConstants; +import org.apache.tuscany.core.system.annotation.Autowire; +import org.apache.tuscany.model.assembly.ComponentType; +import org.osoa.sca.annotations.Destroy; +import org.osoa.sca.annotations.Init; +import org.osoa.sca.annotations.Scope; + +/** + * @version $Rev$ $Date$ + */ +@Scope("MODULE") +public class JavaImplementationLoader implements StAXElementLoader { + public static final QName IMPLEMENTATION_JAVA = new QName("http://www.osoa.org/xmlns/sca/0.9", "implementation.java"); + + private StAXLoaderRegistry registry; + private XMLInputFactory xmlFactory; + + private JavaAssemblyFactory factory; + private ComponentTypeIntrospector introspector; + + public JavaImplementationLoader() { + // todo make this a reference to a system service + xmlFactory = XMLInputFactory.newInstance(); + } + + @Autowire + public void setRegistry(StAXLoaderRegistry registry) { + this.registry = registry; + } + + @Autowire + public void setFactory(JavaAssemblyFactory factory) { + this.factory = factory; + //FIXME JFM HACK + introspector = ProcessorUtils.createCoreIntrospector(factory); + } + + @Init(eager = true) + public void start() { + registry.registerLoader(IMPLEMENTATION_JAVA, this); + } + + @Destroy + public void stop() { + registry.unregisterLoader(IMPLEMENTATION_JAVA, this); + } + + public JavaImplementation load(XMLStreamReader reader, LoaderContext loaderContext) throws XMLStreamException, ConfigurationLoadException { + JavaImplementation javaImpl = factory.createJavaImplementation(); + String typeName = reader.getAttributeValue(null, "class"); + Class implementationClass = getImplementationClass(loaderContext.getResourceLoader(), typeName); + javaImpl.setImplementationClass(implementationClass); + javaImpl.setComponentType(loadComponentType(loaderContext, implementationClass)); + return javaImpl; + } + + protected Class getImplementationClass(ResourceLoader resourceLoader, String typeName) throws ConfigurationLoadException { + ClassLoader oldCL = Thread.currentThread().getContextClassLoader(); + try { + // set TCCL in case the application code needs it + Thread.currentThread().setContextClassLoader(resourceLoader.getClassLoader()); + return resourceLoader.loadClass(typeName); + } catch (ClassNotFoundException e) { + throw new ConfigurationLoadException(e.getMessage(), e); + } finally { + Thread.currentThread().setContextClassLoader(oldCL); + } + } + + protected ComponentType loadComponentType(LoaderContext loaderContext, Class implClass) throws ConfigurationLoadException, XMLStreamException { + String baseName = JavaIntrospectionHelper.getBaseName(implClass); + URL sidefile = implClass.getResource(baseName + ".componentType"); + if (sidefile == null) { + return loadComponentTypeByIntrospection(implClass); + } else { + return loadComponentTypeFromSidefile(sidefile, loaderContext); + } + } + + protected ComponentType loadComponentTypeByIntrospection(Class implClass) throws ConfigurationLoadException { + return introspector.introspect(implClass); + } + + protected ComponentType loadComponentTypeFromSidefile(URL sidefile, LoaderContext loaderContext) throws SidefileLoadException { + try { + XMLStreamReader reader; + InputStream is; + is = sidefile.openStream(); + try { + reader = xmlFactory.createXMLStreamReader(is); + try { + reader.nextTag(); + if (!AssemblyConstants.COMPONENT_TYPE.equals(reader.getName())) { + InvalidRootElementException e = new InvalidRootElementException(AssemblyConstants.COMPONENT_TYPE, reader.getName()); + e.setResourceURI(sidefile.toString()); + throw e; + } + return (ComponentType) registry.load(reader, loaderContext); + } finally { + try { + reader.close(); + } catch (XMLStreamException e) { + // ignore + } + } + } finally { + try { + is.close(); + } catch (IOException e) { + // ignore + } + } + } catch (IOException e) { + SidefileLoadException sfe = new SidefileLoadException(e.getMessage()); + sfe.setResourceURI(sidefile.toString()); + throw sfe; + } catch (XMLStreamException e) { + SidefileLoadException sfe = new SidefileLoadException(e.getMessage()); + sfe.setResourceURI(sidefile.toString()); + throw sfe; + } catch (ConfigurationLoadException e) { + SidefileLoadException sfe = new SidefileLoadException(e.getMessage()); + sfe.setResourceURI(sidefile.toString()); + throw sfe; + } + } +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/main/resources/org/apache/tuscany/container/java/Messages.properties b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/main/resources/org/apache/tuscany/container/java/Messages.properties new file mode 100644 index 0000000000..4581e44bff --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/main/resources/org/apache/tuscany/container/java/Messages.properties @@ -0,0 +1,25 @@ +# Copyright (c) 2005 The Apache Software Foundation or its licensors, as applicable. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ==================================================================== +# To code developer: +# Do NOT change the properties between this line and the +# "%%% END OF TRANSLATED PROPERTIES %%%" line. +# Make a new property name, append to the end of the file and change +# the code to use the new property. +# ==================================================================== + +# ===================================================================== +# %%% END OF TRANSLATED PROPERTIES %%% +# ===================================================================== +# NLS_MESSAGEFORMAT_ALL diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/main/resources/system.fragment b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/main/resources/system.fragment new file mode 100644 index 0000000000..6aab9b8510 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/main/resources/system.fragment @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/main/test/sca.module b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/main/test/sca.module new file mode 100644 index 0000000000..1c1ddafb53 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/main/test/sca.module @@ -0,0 +1,75 @@ + + + + + + + + MyFoo + 1 + + + TestService2 + + + + + + + + + + \ No newline at end of file diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/mock/HelloWorldImpl.componentType b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/mock/HelloWorldImpl.componentType new file mode 100644 index 0000000000..784d8bf728 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/mock/HelloWorldImpl.componentType @@ -0,0 +1,23 @@ + + + + + + + + \ No newline at end of file diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/mock/HelloWorldImpl.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/mock/HelloWorldImpl.java new file mode 100644 index 0000000000..74f4c658ce --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/mock/HelloWorldImpl.java @@ -0,0 +1,36 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.assembly.mock; + +/** + * @version $Rev$ $Date$ + */ +public class HelloWorldImpl implements HelloWorldService { + + private String text; + + private int count; + + public String hello(String name) { + ++count; + return "Hello " + name; + } + + public int count() { + return count; + } +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/mock/HelloWorldService.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/mock/HelloWorldService.java new file mode 100644 index 0000000000..a7d0fe7788 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/mock/HelloWorldService.java @@ -0,0 +1,27 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.assembly.mock; + +/** + * @version $Rev$ $Date$ + */ +public interface HelloWorldService { + String hello(String name); + + public int count(); + +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/mock/HelloWorldWithFieldProperties.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/mock/HelloWorldWithFieldProperties.java new file mode 100644 index 0000000000..0801c56f44 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/mock/HelloWorldWithFieldProperties.java @@ -0,0 +1,40 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.assembly.mock; + +import org.osoa.sca.annotations.Property; + +/** + * @version $Rev$ $Date$ + */ +public class HelloWorldWithFieldProperties { + @Property + protected String text; + + @Property(required = true) + public Integer text2; + + @Property(name = "foo") + public int text3; + + @Property(name = "not exposed") + protected int field4; + + public String hello(String name) { + return "Hello " + name; + } +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/mock/NakedHelloWorld.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/mock/NakedHelloWorld.java new file mode 100644 index 0000000000..2f1ae5d17b --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/mock/NakedHelloWorld.java @@ -0,0 +1,26 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.assembly.mock; + +/** + * @version $Rev$ $Date$ + */ +public class NakedHelloWorld { + public String hello(String name) { + return "Hello " + name; + } +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/mock/NakedHelloWorldWithInterface.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/mock/NakedHelloWorldWithInterface.java new file mode 100644 index 0000000000..9d5fe5e969 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/mock/NakedHelloWorldWithInterface.java @@ -0,0 +1,28 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.assembly.mock; + +import java.io.Serializable; + +/** + * @version $Rev$ $Date$ + */ +public class NakedHelloWorldWithInterface implements Serializable { + public String hello(String name) { + return "Hello " + name; + } +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/account/AccountReport.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/account/AccountReport.java new file mode 100644 index 0000000000..1770c2b011 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/account/AccountReport.java @@ -0,0 +1,32 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.assembly.tests.bigbank.account.services.account; + +import java.util.List; + +/** + * @model + */ + +public interface AccountReport { + + /** + * @model type="services.account.AccountSummary" + */ + + List getAccountSummaries(); +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/account/AccountService.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/account/AccountService.java new file mode 100644 index 0000000000..1bb938655f --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/account/AccountService.java @@ -0,0 +1,25 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.assembly.tests.bigbank.account.services.account; + +import org.osoa.sca.annotations.Remotable; + +@Remotable +public interface AccountService { + + public AccountReport getAccountReport(String customerID); +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/account/AccountService.wsdl b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/account/AccountService.wsdl new file mode 100644 index 0000000000..022258f2c5 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/account/AccountService.wsdl @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/account/AccountServiceImpl.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/account/AccountServiceImpl.java new file mode 100644 index 0000000000..9a5ddb0005 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/account/AccountServiceImpl.java @@ -0,0 +1,42 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.assembly.tests.bigbank.account.services.account; + +import org.osoa.sca.annotations.Property; +import org.osoa.sca.annotations.Reference; + +import org.apache.tuscany.container.java.assembly.tests.bigbank.account.services.accountdata.AccountDataService; +import org.apache.tuscany.container.java.assembly.tests.bigbank.account.services.stockquote.StockQuoteService; + +public class AccountServiceImpl implements AccountService { + + @Property + public String currency = "USD"; + + @Reference + public AccountDataService accountDataService; + @Reference + public StockQuoteService stockQuoteService; + + public AccountServiceImpl() { + } + + public AccountReport getAccountReport(String customerID) { + return null; + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/account/AccountSummary.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/account/AccountSummary.java new file mode 100644 index 0000000000..2b11e23425 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/account/AccountSummary.java @@ -0,0 +1,46 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.assembly.tests.bigbank.account.services.account; + +/** + * @model + */ + +public interface AccountSummary { + + /** + * @model + */ + String getAccountNumber(); + + void setAccountNumber(String accountNumber); + + /** + * @model + */ + String getAccountType(); + + void setAccountType(String accountType); + + /** + * @model + */ + float getBalance(); + + void setBalance(float balance); +} + diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/accountdata/AccountDataService.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/accountdata/AccountDataService.java new file mode 100644 index 0000000000..56f24ea4ac --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/accountdata/AccountDataService.java @@ -0,0 +1,26 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.assembly.tests.bigbank.account.services.accountdata; + +public interface AccountDataService { + + CheckingAccount getCheckingAccount(String customerID); + + SavingsAccount getSavingsAccount(String customerID); + + StockAccount getStockAccount(String customerID); +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/accountdata/AccountDataServiceImpl.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/accountdata/AccountDataServiceImpl.java new file mode 100644 index 0000000000..a7a40f954d --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/accountdata/AccountDataServiceImpl.java @@ -0,0 +1,48 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.assembly.tests.bigbank.account.services.accountdata; + +public class AccountDataServiceImpl implements AccountDataService { + + public CheckingAccount getCheckingAccount(String customerID) { + + CheckingAccount checkingAccount = new CheckingAccount(); + checkingAccount.setAccountNumber(customerID + "_" + "CHA12345"); + checkingAccount.setBalance(1500.0f); + + return checkingAccount; + } + + public SavingsAccount getSavingsAccount(String customerID) { + + SavingsAccount savingsAccount = new SavingsAccount(); + savingsAccount.setAccountNumber(customerID + "_" + "SAA12345"); + savingsAccount.setBalance(1500.0f); + + return savingsAccount; + } + + public StockAccount getStockAccount(String customerID) { + + StockAccount stockAccount = new StockAccount(); + stockAccount.setAccountNumber(customerID + "_" + "STA12345"); + stockAccount.setSymbol("IBM"); + stockAccount.setQuantity(100); + + return stockAccount; + } +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/accountdata/CheckingAccount.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/accountdata/CheckingAccount.java new file mode 100644 index 0000000000..ff84e9968a --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/accountdata/CheckingAccount.java @@ -0,0 +1,39 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.assembly.tests.bigbank.account.services.accountdata; + +public class CheckingAccount { + + private String accountNumber; + private float balance; + + public String getAccountNumber() { + return accountNumber; + } + + public void setAccountNumber(String accountNumber) { + this.accountNumber = accountNumber; + } + + public float getBalance() { + return balance; + } + + public void setBalance(float balance) { + this.balance = balance; + } +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/accountdata/SavingsAccount.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/accountdata/SavingsAccount.java new file mode 100644 index 0000000000..b39d9051de --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/accountdata/SavingsAccount.java @@ -0,0 +1,39 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.assembly.tests.bigbank.account.services.accountdata; + +public class SavingsAccount { + + private String accountNumber; + private float balance; + + public String getAccountNumber() { + return accountNumber; + } + + public void setAccountNumber(String accountNumber) { + this.accountNumber = accountNumber; + } + + public float getBalance() { + return balance; + } + + public void setBalance(float balance) { + this.balance = balance; + } +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/accountdata/StockAccount.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/accountdata/StockAccount.java new file mode 100644 index 0000000000..bce0821b25 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/accountdata/StockAccount.java @@ -0,0 +1,48 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.assembly.tests.bigbank.account.services.accountdata; + +public class StockAccount { + + private String accountNumber; + private String symbol; + private int quantity; + + public String getAccountNumber() { + return accountNumber; + } + + public void setAccountNumber(String accountNumber) { + this.accountNumber = accountNumber; + } + + public int getQuantity() { + return quantity; + } + + public void setQuantity(int quantity) { + this.quantity = quantity; + } + + public String getSymbol() { + return symbol; + } + + public void setSymbol(String symbol) { + this.symbol = symbol; + } +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/stockquote/StockQuoteService.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/stockquote/StockQuoteService.java new file mode 100644 index 0000000000..78ece12b41 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/stockquote/StockQuoteService.java @@ -0,0 +1,24 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.assembly.tests.bigbank.account.services.stockquote; + +public interface StockQuoteService { + + public float getQuote(String symbol); +} + + \ No newline at end of file diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/stockquote/StockQuoteServiceImpl.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/stockquote/StockQuoteServiceImpl.java new file mode 100644 index 0000000000..fa180d0ceb --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/stockquote/StockQuoteServiceImpl.java @@ -0,0 +1,28 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.assembly.tests.bigbank.account.services.stockquote; + +/* Dummy'd up StockQuoteService, override webservice for now */ + +public class StockQuoteServiceImpl implements StockQuoteService { + + public float getQuote(String symbol) { + // Just hardcode for now + return 83.00f; + } + +} \ No newline at end of file diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/stockquote/StockQuoteWebService.wsdl b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/stockquote/StockQuoteWebService.wsdl new file mode 100644 index 0000000000..6af61ef80e --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/assembly/tests/bigbank/account/services/stockquote/StockQuoteWebService.wsdl @@ -0,0 +1,98 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/builder/JavaContextFactoryBuilderTestCase.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/builder/JavaContextFactoryBuilderTestCase.java new file mode 100644 index 0000000000..fcfd320e0e --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/builder/JavaContextFactoryBuilderTestCase.java @@ -0,0 +1,112 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.builder; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.apache.tuscany.container.java.invocation.mock.MockSyncInterceptor; +import org.apache.tuscany.container.java.mock.MockFactory; +import org.apache.tuscany.container.java.mock.components.GenericComponent; +import org.apache.tuscany.container.java.mock.components.ModuleScopeComponent; +import org.apache.tuscany.core.builder.ContextFactory; +import org.apache.tuscany.core.builder.system.PolicyBuilderRegistry; +import org.apache.tuscany.core.builder.system.DefaultPolicyBuilderRegistry; +import org.apache.tuscany.core.builder.impl.DefaultWireBuilder; +import org.apache.tuscany.core.context.impl.EventContextImpl; +import org.apache.tuscany.core.context.scope.DefaultScopeStrategy; +import org.apache.tuscany.core.context.scope.ModuleScopeContext; +import org.apache.tuscany.core.context.ScopeStrategy; +import org.apache.tuscany.core.context.EventContext; +import org.apache.tuscany.core.context.ScopeContext; +import org.apache.tuscany.core.context.Context; +import org.apache.tuscany.core.context.event.ModuleStart; +import org.apache.tuscany.core.wire.WireConfiguration; +import org.apache.tuscany.core.wire.jdk.JDKWireFactoryFactory; +import org.apache.tuscany.core.wire.SourceWireFactory; +import org.apache.tuscany.core.wire.service.WireFactoryService; +import org.apache.tuscany.core.wire.service.DefaultWireFactoryService; +import org.apache.tuscany.core.message.impl.MessageFactoryImpl; +import org.apache.tuscany.model.assembly.Component; +import org.apache.tuscany.model.assembly.Module; + +public class JavaContextFactoryBuilderTestCase extends TestCase { + + public JavaContextFactoryBuilderTestCase() { + } + + public void testBuilder() throws Exception { + MockSyncInterceptor mockInterceptor = new MockSyncInterceptor(); + MockInterceptorBuilder interceptorBuilder = new MockInterceptorBuilder(mockInterceptor, true); + PolicyBuilderRegistry policyRegistry = new DefaultPolicyBuilderRegistry(); + policyRegistry.registerSourceBuilder(interceptorBuilder); + WireFactoryService wireService = new DefaultWireFactoryService(new MessageFactoryImpl(), new JDKWireFactoryFactory(), policyRegistry); + JavaContextFactoryBuilder builder = new JavaContextFactoryBuilder(wireService); + + JavaTargetWireBuilder javaWireBuilder = new JavaTargetWireBuilder(); + ScopeStrategy strategy = new DefaultScopeStrategy(); + DefaultWireBuilder wireBuilder = new DefaultWireBuilder(); + wireBuilder.addWireBuilder(javaWireBuilder); + Module module = MockFactory.createModule(); + EventContext eCtx = new EventContextImpl(); + ScopeContext scopeContext = new ModuleScopeContext(eCtx); + scopeContext.start(); + scopeContext.onEvent(new ModuleStart(this)); + List components = module.getComponents(); + Map compMap = new HashMap(components.size()); + + for (Component component : components) { + compMap.put(component.getName(), component); + builder.build(component); + ContextFactory contextFactory = (ContextFactory) component.getContextFactory(); + Assert.assertNotNull(contextFactory); + } + for (Component component : components) { + ContextFactory source = (ContextFactory) component.getContextFactory(); + Assert.assertNotNull(source); + for (SourceWireFactory pFactory : source.getSourceWireFactories()) { + WireConfiguration pConfig = pFactory.getConfiguration(); + Component target = compMap.get(pConfig.getTargetName().getPartName()); + + if (target != null) { + ContextFactory targetConfig = (ContextFactory) target.getContextFactory(); + boolean downScope = strategy.downScopeReference(source.getScope(), targetConfig.getScope()); + wireBuilder.connect(pFactory, targetConfig.getTargetWireFactory(pFactory.getConfiguration().getTargetName() + .getPortName()), targetConfig.getClass(), downScope, scopeContext); + } + pFactory.initialize(); + } + scopeContext.registerFactory(source); + } + for (Component component : components) { + ContextFactory config = (ContextFactory) component.getContextFactory(); + Context context = config.createContext(); + if ("source".equals(component.getName())) { + ModuleScopeComponent source = (ModuleScopeComponent) context.getInstance(null); + Assert.assertNotNull(source); + GenericComponent gComp = source.getGenericComponent(); + gComp.getString(); + } + } + } + + +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/builder/JavaTargetWireBuilderTestCase.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/builder/JavaTargetWireBuilderTestCase.java new file mode 100644 index 0000000000..5a0ee8e14c --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/builder/JavaTargetWireBuilderTestCase.java @@ -0,0 +1,132 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.builder; + +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.Map; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.apache.tuscany.container.java.config.JavaContextFactory; +import org.apache.tuscany.container.java.invocation.mock.MockHandler; +import org.apache.tuscany.container.java.invocation.mock.MockSyncInterceptor; +import org.apache.tuscany.container.java.invocation.mock.SimpleTarget; +import org.apache.tuscany.container.java.invocation.mock.SimpleTargetImpl; +import org.apache.tuscany.container.java.mock.MockScopeContext; +import org.apache.tuscany.core.builder.impl.DefaultWireBuilder; +import org.apache.tuscany.core.context.QualifiedName; +import org.apache.tuscany.core.wire.MethodHashMap; +import org.apache.tuscany.core.wire.impl.InvokerInterceptor; +import org.apache.tuscany.core.wire.jdk.JDKWireFactoryFactory; +import org.apache.tuscany.core.wire.WireSourceConfiguration; +import org.apache.tuscany.core.wire.WireTargetConfiguration; +import org.apache.tuscany.core.wire.SourceInvocationConfiguration; +import org.apache.tuscany.core.wire.TargetInvocationConfiguration; +import org.apache.tuscany.core.wire.TargetWireFactory; +import org.apache.tuscany.core.wire.SourceWireFactory; +import org.apache.tuscany.core.message.Message; +import org.apache.tuscany.core.message.MessageFactory; +import org.apache.tuscany.core.message.impl.MessageFactoryImpl; + +public class JavaTargetWireBuilderTestCase extends TestCase { + + private Method hello; + + public JavaTargetWireBuilderTestCase() { + } + + public JavaTargetWireBuilderTestCase(String arg0) { + super(arg0); + } + + public void setUp() throws Exception { + hello = SimpleTarget.class.getMethod("hello", String.class); + } + + + /** + * Tests basic wiring of a source to a target, including handlers and interceptors + */ + public void testInvocation() throws Exception { + MessageFactory msgFactory = new MessageFactoryImpl(); + + SourceInvocationConfiguration source = new SourceInvocationConfiguration(hello); + MockHandler sourceRequestHandler = new MockHandler(); + MockHandler sourceResponseHandler = new MockHandler(); + MockSyncInterceptor sourceInterceptor = new MockSyncInterceptor(); + source.addRequestHandler(sourceRequestHandler); + source.addResponseHandler(sourceResponseHandler); + source.addInterceptor(sourceInterceptor); + + SourceWireFactory sourceFactory = new JDKWireFactoryFactory().createSourceWireFactory(); + Map sourceInvocationConfigs = new MethodHashMap(); + sourceInvocationConfigs.put(hello, source); + WireSourceConfiguration sourceConfig = new WireSourceConfiguration("foo",new QualifiedName("target/SimpleTarget"), + sourceInvocationConfigs, Thread.currentThread().getContextClassLoader(), msgFactory); + sourceFactory.setConfiguration(sourceConfig); + sourceFactory.setBusinessInterface(SimpleTarget.class); + + TargetInvocationConfiguration target = new TargetInvocationConfiguration(hello); + MockHandler targetRequestHandler = new MockHandler(); + MockHandler targetResponseHandler = new MockHandler(); + MockSyncInterceptor targetInterceptor = new MockSyncInterceptor(); + target.addRequestHandler(targetRequestHandler); + target.addResponseHandler(targetResponseHandler); + target.addInterceptor(targetInterceptor); + target.addInterceptor(new InvokerInterceptor()); + + TargetWireFactory targetFactory = new JDKWireFactoryFactory().createTargetWireFactory(); + Map targetInvocationConfigs = new MethodHashMap(); + targetInvocationConfigs.put(hello, target); + WireTargetConfiguration targetConfig = new WireTargetConfiguration(new QualifiedName("target/SimpleTarget"), + targetInvocationConfigs, Thread.currentThread().getContextClassLoader(), msgFactory); + targetFactory.setConfiguration(targetConfig); + targetFactory.setBusinessInterface(SimpleTarget.class); + + // bootstrap a scope container with the target in it + Map instances = new HashMap(); + SimpleTarget simpleTarget = new SimpleTargetImpl(); + instances.put("target",simpleTarget); + MockScopeContext scopeCtx = new MockScopeContext(instances); + + // connect the source to the target + DefaultWireBuilder builder = new DefaultWireBuilder(); + builder.addWireBuilder(new JavaTargetWireBuilder()); + + builder.connect(sourceFactory, targetFactory, JavaContextFactory.class, true, scopeCtx); + source.build(); + target.build(); + Assert.assertNotNull(source.getTargetInvoker()); + + Message msg = msgFactory.createMessage(); + msg.setBody("foo"); + msg.setTargetInvoker(source.getTargetInvoker()); + Message response = source.getHeadInterceptor().invoke(msg); + Assert.assertEquals("foo", response.getBody()); + Assert.assertEquals(1, sourceRequestHandler.getCount()); + Assert.assertEquals(1, sourceResponseHandler.getCount()); + Assert.assertEquals(1, sourceInterceptor.getCount()); + Assert.assertEquals(1, targetRequestHandler.getCount()); + Assert.assertEquals(1, targetResponseHandler.getCount()); + Assert.assertEquals(1, targetInterceptor.getCount()); + } + + +} + diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/builder/MockHandlerBuilder.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/builder/MockHandlerBuilder.java new file mode 100644 index 0000000000..bd1c13c4ac --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/builder/MockHandlerBuilder.java @@ -0,0 +1,120 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package org.apache.tuscany.container.java.builder; + +import org.apache.tuscany.core.builder.BuilderException; +import org.apache.tuscany.core.builder.SourcePolicyBuilder; +import org.apache.tuscany.core.builder.TargetPolicyBuilder; +import org.apache.tuscany.core.wire.InvocationConfiguration; +import org.apache.tuscany.core.wire.MessageHandler; +import org.apache.tuscany.core.wire.SourceInvocationConfiguration; +import org.apache.tuscany.core.wire.SourceWireFactory; +import org.apache.tuscany.core.wire.TargetInvocationConfiguration; +import org.apache.tuscany.core.wire.TargetWireFactory; +import org.apache.tuscany.core.wire.WireSourceConfiguration; +import org.apache.tuscany.core.wire.WireTargetConfiguration; +import org.apache.tuscany.model.assembly.AssemblyObject; +import org.apache.tuscany.model.assembly.ConfiguredReference; +import org.apache.tuscany.model.assembly.ConfiguredService; + +import java.util.List; + +/** + * Adds a handler to a source or target proxy configuration + * + * @version $Rev$ $Date$ + */ +public class MockHandlerBuilder implements SourcePolicyBuilder, TargetPolicyBuilder { + + + private MessageHandler handler; + + private boolean source; + + private boolean request; + + /** + * Creates the builder. + * + * @param handler the handler to add to the source or target proxy configuration + * @param source true if the handler should be added on the source side; false if the handler should be added to the target + * side + * @param request true if the handler is a request handler; false if the handler is a response handler + */ + public MockHandlerBuilder(MessageHandler handler, boolean source, boolean request) { + this.handler = handler; + this.source = source; + this.request = request; + } + + public void build(AssemblyObject modelObject) throws BuilderException { + if (source) { + if (!(modelObject instanceof ConfiguredReference)) { + return; + } else { + ConfiguredReference cref = (ConfiguredReference) modelObject; + // /xcv WireFactory pFactory = (WireFactory) cref.getProxyFactory(); + for (ConfiguredService configuredService : cref.getTargetConfiguredServices()) { + SourceWireFactory pFactory = (SourceWireFactory) configuredService.getProxyFactory(); + for (InvocationConfiguration config : pFactory.getConfiguration().getInvocationConfigurations().values()) { + if (request) { + config.addRequestHandler(handler); + } else { + config.addResponseHandler(handler); + } + } + } + } + } else { + if (!(modelObject instanceof ConfiguredService)) { + return; + } else { + ConfiguredService cservice = (ConfiguredService) modelObject; + TargetWireFactory pFactory = (TargetWireFactory) cservice.getProxyFactory(); + for (InvocationConfiguration config : pFactory.getConfiguration().getInvocationConfigurations().values()) { + if (request) { + config.addRequestHandler(handler); + } else { + config.addResponseHandler(handler); + } + } + } + + } + } + + public void build(ConfiguredReference reference, List configurations) throws BuilderException { + for (WireSourceConfiguration wireSourceConfiguration : configurations) { + for (SourceInvocationConfiguration configuration : wireSourceConfiguration.getInvocationConfigurations().values()) { + if (request) { + configuration.addRequestHandler(handler); + } else { + configuration.addResponseHandler(handler); + } + + } + + } + } + + public void build(ConfiguredService service, WireTargetConfiguration configuration) throws BuilderException { + for (TargetInvocationConfiguration config : configuration.getInvocationConfigurations().values()) { + if (request) { + config.addRequestHandler(handler); + } else { + config.addResponseHandler(handler); + } + } + } +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/builder/MockInterceptorBuilder.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/builder/MockInterceptorBuilder.java new file mode 100644 index 0000000000..d3ad8a53b5 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/builder/MockInterceptorBuilder.java @@ -0,0 +1,66 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package org.apache.tuscany.container.java.builder; + +import org.apache.tuscany.core.builder.BuilderException; +import org.apache.tuscany.core.builder.SourcePolicyBuilder; +import org.apache.tuscany.core.builder.TargetPolicyBuilder; +import org.apache.tuscany.core.wire.Interceptor; +import org.apache.tuscany.core.wire.SourceInvocationConfiguration; +import org.apache.tuscany.core.wire.SourceWireFactory; +import org.apache.tuscany.core.wire.TargetInvocationConfiguration; +import org.apache.tuscany.core.wire.TargetWireFactory; +import org.apache.tuscany.core.wire.WireFactory; +import org.apache.tuscany.core.wire.WireSourceConfiguration; +import org.apache.tuscany.core.wire.WireTargetConfiguration; +import org.apache.tuscany.model.assembly.AssemblyObject; +import org.apache.tuscany.model.assembly.ConfiguredReference; +import org.apache.tuscany.model.assembly.ConfiguredService; + +import java.util.List; + +/** + * Adds an interceptor to a source or target proxy configuration + * + * @version $Rev$ $Date$ + */ +public class MockInterceptorBuilder implements SourcePolicyBuilder, TargetPolicyBuilder { + + private Interceptor interceptor; + + /** + * Creates the builder + * + * @param interceptor the interceptor ot add + * @param source true if the interceptor should be added to the source side; false if the interceptor should be added to + * the target side + */ + public MockInterceptorBuilder(Interceptor interceptor, boolean source) { + this.interceptor = interceptor; + } + + public void build(ConfiguredReference reference, List configurations) throws BuilderException { + for (WireSourceConfiguration wireSourceConfiguration : configurations) { + for (SourceInvocationConfiguration configuration : wireSourceConfiguration.getInvocationConfigurations().values()) { + configuration.addInterceptor(interceptor); + } + } + } + + public void build(ConfiguredService service, WireTargetConfiguration configuration) throws BuilderException { + for (TargetInvocationConfiguration config : configuration.getInvocationConfigurations().values()) { + config.addInterceptor(interceptor); + } + } +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/context/DifferentInterfaceWireTestCase.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/context/DifferentInterfaceWireTestCase.java new file mode 100644 index 0000000000..ed91b9cb9b --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/context/DifferentInterfaceWireTestCase.java @@ -0,0 +1,81 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package org.apache.tuscany.container.java.context; + +import java.util.ArrayList; +import java.util.List; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.apache.tuscany.container.java.builder.JavaContextFactoryBuilder; +import org.apache.tuscany.container.java.builder.JavaTargetWireBuilder; +import org.apache.tuscany.container.java.mock.MockConfigContext; +import org.apache.tuscany.container.java.mock.MockFactory; +import org.apache.tuscany.container.java.mock.components.OtherTarget; +import org.apache.tuscany.container.java.mock.components.Source; +import org.apache.tuscany.container.java.mock.components.Target; +import org.apache.tuscany.core.builder.ContextFactoryBuilder; +import org.apache.tuscany.core.builder.WireBuilder; +import org.apache.tuscany.core.builder.system.DefaultPolicyBuilderRegistry; +import org.apache.tuscany.core.context.CompositeContext; +import org.apache.tuscany.core.context.AtomicContext; +import org.apache.tuscany.core.context.event.ModuleStart; +import org.apache.tuscany.core.context.impl.CompositeContextImpl; +import org.apache.tuscany.core.wire.jdk.JDKWireFactoryFactory; +import org.apache.tuscany.core.wire.service.WireFactoryService; +import org.apache.tuscany.core.wire.service.DefaultWireFactoryService; +import org.apache.tuscany.core.message.impl.MessageFactoryImpl; +import org.apache.tuscany.model.assembly.Scope; + +/** + * Tests wires that have different interfaces on the source and target side + * + * @version $Rev$ $Date$ + */ +public class DifferentInterfaceWireTestCase extends TestCase { + + public void testMultiplicity() throws Exception { + + CompositeContext context = createContext(); + context.start(); + context.registerModelObject(MockFactory.createModuleWithWiredComponentsOfDifferentInterface(Scope.MODULE, Scope.MODULE)); + context.publish(new ModuleStart(this)); + Source source = (Source) ((AtomicContext) context.getContext("source")).getTargetInstance(); + Assert.assertNotNull(source); + OtherTarget target = (OtherTarget) ((AtomicContext)context.getContext("target")).getTargetInstance(); + Assert.assertNotNull(target); + // test setter injection + List targets = source.getTargets(); + Assert.assertEquals(1, targets.size()); + + // test field injection + targets = source.getTargetsThroughField(); + Assert.assertEquals(1, targets.size()); + targets.get(0).setString("foo"); + Assert.assertEquals("foo",target.getString()); + } + + private CompositeContext createContext() { + CompositeContextImpl context = new CompositeContextImpl(); + context.setName("system.context"); + Listbuilders = MockFactory.createSystemBuilders(); + WireFactoryService wireService = new DefaultWireFactoryService(new MessageFactoryImpl(), new JDKWireFactoryFactory(), new DefaultPolicyBuilderRegistry()); + builders.add(new JavaContextFactoryBuilder(wireService)); + List wireBuilders = new ArrayList(); + wireBuilders.add(new JavaTargetWireBuilder()); + context.setConfigurationContext(new MockConfigContext(builders,wireBuilders)); + return context; + } +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/context/JavaAtomicContextLifecycleTestCase.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/context/JavaAtomicContextLifecycleTestCase.java new file mode 100644 index 0000000000..c257a1f892 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/context/JavaAtomicContextLifecycleTestCase.java @@ -0,0 +1,59 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.context; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.apache.tuscany.container.java.mock.MockFactory; +import org.apache.tuscany.container.java.mock.components.ModuleScopeInitOnlyComponent; +import org.apache.tuscany.container.java.mock.components.ModuleScopeInitDestroyComponent; +import org.apache.tuscany.core.context.CompositeContext; +import org.apache.tuscany.core.context.impl.CompositeContextImpl; +import org.apache.tuscany.model.assembly.Scope; + +/** + * Tests init and destroy lifecycle callbacks are handled properly + * + * @version $Rev$ $Date$ + */ +public class JavaAtomicContextLifecycleTestCase extends TestCase { + + public void testComponentNameSet() throws Exception { + CompositeContext mc = new CompositeContextImpl(); + mc.setName("mc"); + JavaAtomicContext context = MockFactory.createPojoContext("TestServiceInit", + ModuleScopeInitOnlyComponent.class, Scope.MODULE, mc); + context.start(); + ModuleScopeInitOnlyComponent instance = (ModuleScopeInitOnlyComponent) context.getInstance(null); + Assert.assertNotNull(instance); + Assert.assertEquals("TestServiceInit", instance.getName()); + context.stop(); + } + + public void testModuleContextSet() throws Exception { + CompositeContext mc = new CompositeContextImpl(); + mc.setName("mc"); + JavaAtomicContext context = MockFactory.createPojoContext("TestServiceInit", + ModuleScopeInitOnlyComponent.class, Scope.MODULE, mc); + context.start(); + ModuleScopeInitOnlyComponent instance = (ModuleScopeInitOnlyComponent) context.getInstance(null); + Assert.assertNotNull(instance); + Assert.assertEquals(mc, instance.getModuleContext()); + context.stop(); + } +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/context/JavaAtomicContextMetadataInjectionTestCase.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/context/JavaAtomicContextMetadataInjectionTestCase.java new file mode 100644 index 0000000000..a79a04f5ab --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/context/JavaAtomicContextMetadataInjectionTestCase.java @@ -0,0 +1,58 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.context; + +import junit.framework.TestCase; +import junit.framework.Assert; +import org.apache.tuscany.core.context.CompositeContext; +import org.apache.tuscany.core.context.impl.CompositeContextImpl; +import org.apache.tuscany.container.java.mock.MockFactory; +import org.apache.tuscany.container.java.mock.components.ModuleScopeInitOnlyComponent; +import org.apache.tuscany.container.java.mock.components.ModuleScopeInitDestroyComponent; +import org.apache.tuscany.model.assembly.Scope; + +/** + * Tests SCA metadata such as @ComponentName and @Context are handled properly + * + * @version $Rev: 394173 $ $Date: 2006-04-14 11:54:59 -0700 (Fri, 14 Apr 2006) $ + */ +public class JavaAtomicContextMetadataInjectionTestCase extends TestCase { + + public void testComponentNameSet() throws Exception { + CompositeContext mc = new CompositeContextImpl(); + mc.setName("mc"); + JavaAtomicContext context = MockFactory.createPojoContext("TestServiceInit", + ModuleScopeInitOnlyComponent.class, Scope.MODULE, mc); + context.start(); + ModuleScopeInitOnlyComponent instance = (ModuleScopeInitOnlyComponent) context.getInstance(null); + Assert.assertNotNull(instance); + Assert.assertEquals("TestServiceInit", instance.getName()); + context.stop(); + } + + public void testModuleContextSet() throws Exception { + CompositeContext mc = new CompositeContextImpl(); + mc.setName("mc"); + JavaAtomicContext context = MockFactory.createPojoContext("TestServiceInit", + ModuleScopeInitOnlyComponent.class, Scope.MODULE, mc); + context.start(); + ModuleScopeInitOnlyComponent instance = (ModuleScopeInitOnlyComponent) context.getInstance(null); + Assert.assertNotNull(instance); + Assert.assertEquals(mc, instance.getModuleContext()); + context.stop(); + } +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/context/JavaAtomicContextNegativeMetadataTestCase.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/context/JavaAtomicContextNegativeMetadataTestCase.java new file mode 100644 index 0000000000..0a4527f405 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/context/JavaAtomicContextNegativeMetadataTestCase.java @@ -0,0 +1,73 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.context; + +import junit.framework.TestCase; + +import org.apache.tuscany.container.java.mock.MockFactory; +import org.apache.tuscany.container.java.mock.components.BadContextPojo; +import org.apache.tuscany.container.java.mock.components.BadNamePojo; +import org.apache.tuscany.core.context.CompositeContext; +import org.apache.tuscany.core.context.impl.CompositeContextImpl; +import org.apache.tuscany.model.assembly.Scope; + +/** + * Performs rudimentary negative testing by using malformed metadata on a POJO + * + * @version $Rev $Date + */ +public class JavaAtomicContextNegativeMetadataTestCase extends TestCase { + + /** + * Tests that a pojo with @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 { + CompositeContext mc = new CompositeContextImpl(); + mc.setName("mc"); + try { + MockFactory.createPojoContext("BadNamePojo", BadNamePojo.class, Scope.MODULE, mc); + } catch (NoSuchMethodException e) { + if (e.getMessage().indexOf("@ComponentName") < 0) { + throw e; + } + } + + } + + /** + * Tests that a pojo with @Context specified on a non-ModuleContext type generates an error. + *

+ * NB: the test assumes an error with a message containing + * "@Context" is generated + */ + public void testContextType() throws Exception { + CompositeContext mc = new CompositeContextImpl(); + mc.setName("mc"); + try { + MockFactory.createPojoContext("BadContextPojo", BadContextPojo.class, Scope.MODULE, mc); + } catch (NoSuchMethodException e) { + if (e.getMessage().indexOf("@Context") < 0) { + throw e; + } + } + + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/context/JavaAtomicContextScopeTestCase.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/context/JavaAtomicContextScopeTestCase.java new file mode 100644 index 0000000000..96bff0cf2e --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/context/JavaAtomicContextScopeTestCase.java @@ -0,0 +1,95 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.context; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.apache.tuscany.container.java.assembly.JavaAssemblyFactory; +import org.apache.tuscany.container.java.assembly.impl.JavaAssemblyFactoryImpl; +import org.apache.tuscany.container.java.mock.components.GenericComponent; +import org.apache.tuscany.container.java.mock.components.ModuleScopeComponentImpl; +import org.apache.tuscany.container.java.mock.components.RequestScopeComponentImpl; +import org.apache.tuscany.container.java.mock.components.SessionScopeComponentImpl; +import org.apache.tuscany.container.java.mock.components.StatelessComponentImpl; +import org.apache.tuscany.core.config.JavaIntrospectionHelper; +import org.apache.tuscany.core.context.CompositeContext; +import org.apache.tuscany.core.context.impl.CompositeContextImpl; +import org.apache.tuscany.core.injection.PojoObjectFactory; + +/** + * Tests {@link JavaAtomicContext} to ensure it handles component scopes properly + * + * @version $Rev$ $Date$ + */ +public class JavaAtomicContextScopeTestCase extends TestCase { + + JavaAssemblyFactory factory = new JavaAssemblyFactoryImpl(); + + public void testGetModuleInstance() throws Exception { + CompositeContext mc = new CompositeContextImpl(); + mc.setName("mc"); + JavaAtomicContext c = new JavaAtomicContext("foo", new PojoObjectFactory(JavaIntrospectionHelper + .getDefaultConstructor(ModuleScopeComponentImpl.class), null, null), false, null, null, false); + GenericComponent service = (GenericComponent) c.getInstance(null); + Assert.assertNotNull(service); + service.setString("foo"); + GenericComponent service2 = (GenericComponent) c.getInstance(null); + Assert.assertNotNull(service2); + Assert.assertSame(service, service2); + } + + public void testGetSessionInstance() throws Exception { + CompositeContext mc = new CompositeContextImpl(); + mc.setName("mc"); + JavaAtomicContext c = new JavaAtomicContext("foo", new PojoObjectFactory(JavaIntrospectionHelper + .getDefaultConstructor(SessionScopeComponentImpl.class), null, null), false, null, null, false); + GenericComponent service = (GenericComponent) c.getInstance(null); + Assert.assertNotNull(service); + service.setString("foo"); + GenericComponent service2 = (GenericComponent) c.getInstance(null); + Assert.assertNotNull(service2); + Assert.assertSame(service, service2); + } + + public void testGetRequestInstance() throws Exception { + CompositeContext mc = new CompositeContextImpl(); + mc.setName("mc"); + JavaAtomicContext c = new JavaAtomicContext("foo", new PojoObjectFactory(JavaIntrospectionHelper + .getDefaultConstructor(RequestScopeComponentImpl.class), null, null), false, null, null, false); + GenericComponent service = (GenericComponent) c.getInstance(null); + Assert.assertNotNull(service); + service.setString("foo"); + GenericComponent service2 = (GenericComponent) c.getInstance(null); + Assert.assertNotNull(service2); + Assert.assertSame(service, service2); + } + + public void testGetStatelessInstance() throws Exception { + CompositeContext mc = new CompositeContextImpl(); + mc.setName("fooContext"); + JavaAtomicContext c = new JavaAtomicContext("foo", new PojoObjectFactory(JavaIntrospectionHelper + .getDefaultConstructor(StatelessComponentImpl.class), null, null), false, null, null, true); + GenericComponent service = (GenericComponent) c.getInstance(null); + Assert.assertNotNull(service); + service.setString("foo"); + GenericComponent service2 = (GenericComponent) c.getInstance(null); + Assert.assertNotNull(service2); + Assert.assertTrue(!"foo".equals(service2.getString())); + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/context/MultiplicityTestCase.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/context/MultiplicityTestCase.java new file mode 100644 index 0000000000..a22a8dfce2 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/context/MultiplicityTestCase.java @@ -0,0 +1,77 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package org.apache.tuscany.container.java.context; + +import java.util.ArrayList; +import java.util.List; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.apache.tuscany.container.java.builder.JavaContextFactoryBuilder; +import org.apache.tuscany.container.java.builder.JavaTargetWireBuilder; +import org.apache.tuscany.container.java.mock.MockConfigContext; +import org.apache.tuscany.container.java.mock.MockFactory; +import org.apache.tuscany.container.java.mock.components.Source; +import org.apache.tuscany.container.java.mock.components.Target; +import org.apache.tuscany.core.builder.ContextFactoryBuilder; +import org.apache.tuscany.core.builder.WireBuilder; +import org.apache.tuscany.core.builder.system.DefaultPolicyBuilderRegistry; +import org.apache.tuscany.core.context.CompositeContext; +import org.apache.tuscany.core.context.AtomicContext; +import org.apache.tuscany.core.context.event.ModuleStart; +import org.apache.tuscany.core.context.impl.CompositeContextImpl; +import org.apache.tuscany.core.wire.jdk.JDKWireFactoryFactory; +import org.apache.tuscany.core.wire.service.WireFactoryService; +import org.apache.tuscany.core.wire.service.DefaultWireFactoryService; +import org.apache.tuscany.core.message.impl.MessageFactoryImpl; +import org.apache.tuscany.model.assembly.Scope; + +/** + * Tests wires that are configured with a multiplicity + * + * @version $Rev$ $Date$ + */ +public class MultiplicityTestCase extends TestCase { + + public void testMultiplicity() throws Exception { + CompositeContext context = createContext(); + context.start(); + context.registerModelObject(MockFactory.createModuleWithWiredComponents(Scope.MODULE, Scope.MODULE)); + context.publish(new ModuleStart(this)); + Source source = (Source) ((AtomicContext) context.getContext("source")).getTargetInstance(); + Assert.assertNotNull(source); + Target target = (Target) ((AtomicContext)context.getContext("target")).getTargetInstance(); + Assert.assertNotNull(target); + // test setter injection + List targets = source.getTargets(); + Assert.assertEquals(1, targets.size()); + + // test field injection + targets = source.getTargetsThroughField(); + Assert.assertEquals(1, targets.size()); + } + + private CompositeContext createContext() { + CompositeContextImpl context = new CompositeContextImpl(); + context.setName("system.context"); + Listbuilders = MockFactory.createSystemBuilders(); + WireFactoryService wireService = new DefaultWireFactoryService(new MessageFactoryImpl(), new JDKWireFactoryFactory(), new DefaultPolicyBuilderRegistry()); + builders.add(new JavaContextFactoryBuilder(wireService)); + List wireBuilders = new ArrayList(); + wireBuilders.add(new JavaTargetWireBuilder()); + context.setConfigurationContext(new MockConfigContext(builders,wireBuilders)); + return context; + } +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/GreetingProvider.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/GreetingProvider.java new file mode 100644 index 0000000000..58180674b3 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/GreetingProvider.java @@ -0,0 +1,24 @@ +/** + * + * Copyright 2005 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.integration; + +/** + * @version $Rev$ $Date$ + */ +public interface GreetingProvider { + String getGreeting(String name, String locale); +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/GreetingProviderImpl.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/GreetingProviderImpl.java new file mode 100644 index 0000000000..fef068c22e --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/GreetingProviderImpl.java @@ -0,0 +1,42 @@ +/** + * + * Copyright 2005 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.integration; + +import org.osoa.sca.annotations.Property; +import org.osoa.sca.annotations.Service; + +/** + * @version $Rev$ $Date$ + */ +@Service(GreetingProvider.class) +public class GreetingProviderImpl implements GreetingProvider { + + public String greeting; + + @Property + public void setGreeting(String greeting) { + this.greeting = greeting; + } + + public String getGreeting(String name, String locale) { + if ("fr".equals(locale)) { + return "Bonjour " + name; + } else { + return greeting + name; + } + } +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/HelloWorldImpl.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/HelloWorldImpl.java new file mode 100644 index 0000000000..9ff58f2d8d --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/HelloWorldImpl.java @@ -0,0 +1,29 @@ +/** + * + * Copyright 2005 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.integration; + +import org.osoa.sca.annotations.Service; + +/** + * @version $Rev$ $Date$ + */ +@Service(HelloWorldService.class) +public class HelloWorldImpl implements HelloWorldService { + public String getGreetings(String name) { + return "Hello " + name; + } +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/HelloWorldMCImpl.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/HelloWorldMCImpl.java new file mode 100644 index 0000000000..aa5069c232 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/HelloWorldMCImpl.java @@ -0,0 +1,61 @@ +/** + * + * Copyright 2005 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.integration; + +import org.osoa.sca.annotations.Property; +import org.osoa.sca.annotations.Reference; +import org.osoa.sca.annotations.Service; +import org.apache.tuscany.core.sdo.helper.SDOHelper; +import commonj.sdo.helper.TypeHelper; +import commonj.sdo.helper.DataFactory; + +/** + * @version $Rev$ $Date$ + */ +@Service(HelloWorldService.class) +public class HelloWorldMCImpl implements HelloWorldService { + + @Property + public String locale; + + public String getBar() { + return bar; + } + + @Property(name= "bar", required=true) + public void setXBar(String bar) { + this.bar = bar; + } + + public String bar; + + @Reference(name="greetingProvider") + public void setGreetingProvider(GreetingProvider greetingProvider) { + this.greetingProvider2 = greetingProvider; + } + + public GreetingProvider greetingProvider2; + + @Reference(required=false) + public GreetingProvider foo; + + public String getGreetings(String name) { + return greetingProvider2.getGreeting(name, locale); + } + + +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/HelloWorldMCTestCase.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/HelloWorldMCTestCase.java new file mode 100644 index 0000000000..5a73abd45a --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/HelloWorldMCTestCase.java @@ -0,0 +1,59 @@ +/** + * + * Copyright 2005 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.integration; + +import java.net.URL; +import java.net.URLClassLoader; + +import junit.framework.TestCase; +import org.apache.tuscany.core.client.TuscanyRuntime; +import org.osoa.sca.CurrentModuleContext; +import org.osoa.sca.ModuleContext; + +/** + * @version $Rev$ $Date$ + */ +public class HelloWorldMCTestCase extends TestCase { + private ClassLoader oldCL; + + public void testHelloWorld() throws Exception { + TuscanyRuntime tuscany = new TuscanyRuntime("test", "foo"); + tuscany.start(); + ModuleContext moduleContext = CurrentModuleContext.getContext(); + assertNotNull(moduleContext); + assertEquals("foo", moduleContext.getURI()); + HelloWorldService helloworldService = (HelloWorldService) moduleContext.locateService("HelloWorld"); + assertNotNull(helloworldService); + + String value = helloworldService .getGreetings("World"); + assertEquals("Hello World", value); + tuscany.stop(); + } + + protected void setUp() throws Exception { + super.setUp(); + URL url = getClass().getResource("/helloworldmc/"); + ClassLoader cl = new URLClassLoader(new URL[]{url}, getClass().getClassLoader()); + oldCL = Thread.currentThread().getContextClassLoader(); + Thread.currentThread().setContextClassLoader(cl); + } + + protected void tearDown() throws Exception { + Thread.currentThread().setContextClassLoader(oldCL); + super.tearDown(); + } +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/HelloWorldService.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/HelloWorldService.java new file mode 100644 index 0000000000..3abb99d7e0 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/HelloWorldService.java @@ -0,0 +1,24 @@ +/** + * + * Copyright 2005 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.integration; + +/** + * @version $Rev$ $Date$ + */ +public interface HelloWorldService { + public String getGreetings(String name); +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/HelloWorldTestCase.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/HelloWorldTestCase.java new file mode 100644 index 0000000000..c714b416e4 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/HelloWorldTestCase.java @@ -0,0 +1,61 @@ +/** + * + * Copyright 2005 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.integration; + +import java.net.URL; +import java.net.URLClassLoader; + +import junit.framework.TestCase; +import org.osoa.sca.CurrentModuleContext; +import org.osoa.sca.ModuleContext; + +import org.apache.tuscany.core.client.TuscanyRuntime; + +/** + * @version $Rev$ $Date$ + */ +public class HelloWorldTestCase extends TestCase { + private ClassLoader oldCL; + + public void testHelloWorld() throws Exception { + TuscanyRuntime tuscany = new TuscanyRuntime("test", null); + tuscany.start(); + ModuleContext moduleContext = CurrentModuleContext.getContext(); + assertNotNull(moduleContext); + + HelloWorldService helloworldService = (HelloWorldService) moduleContext.locateService("HelloWorld"); + assertNotNull(helloworldService); + + String value = helloworldService .getGreetings("World"); + assertEquals("Hello World", value); + + tuscany.stop(); + } + + protected void setUp() throws Exception { + super.setUp(); + URL url = getClass().getResource("/helloworld/"); + ClassLoader cl = new URLClassLoader(new URL[]{url}, getClass().getClassLoader()); + oldCL = Thread.currentThread().getContextClassLoader(); + Thread.currentThread().setContextClassLoader(cl); + } + + protected void tearDown() throws Exception { + Thread.currentThread().setContextClassLoader(oldCL); + super.tearDown(); + } +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/JavaBuilderContextIntegrationTestCase.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/JavaBuilderContextIntegrationTestCase.java new file mode 100644 index 0000000000..f7cc2ed149 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/JavaBuilderContextIntegrationTestCase.java @@ -0,0 +1,189 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package org.apache.tuscany.container.java.integration; + +import junit.framework.Assert; +import junit.framework.TestCase; +import org.apache.tuscany.common.monitor.impl.NullMonitorFactory; +import org.apache.tuscany.container.java.builder.JavaContextFactoryBuilder; +import org.apache.tuscany.container.java.builder.JavaTargetWireBuilder; +import org.apache.tuscany.container.java.builder.MockHandlerBuilder; +import org.apache.tuscany.container.java.builder.MockInterceptorBuilder; +import org.apache.tuscany.container.java.invocation.mock.MockHandler; +import org.apache.tuscany.container.java.invocation.mock.MockSyncInterceptor; +import org.apache.tuscany.container.java.mock.MockFactory; +import org.apache.tuscany.container.java.mock.components.GenericComponent; +import org.apache.tuscany.core.builder.ContextFactoryBuilderRegistry; +import org.apache.tuscany.core.builder.impl.DefaultWireBuilder; +import org.apache.tuscany.core.builder.system.DefaultPolicyBuilderRegistry; +import org.apache.tuscany.core.builder.system.PolicyBuilderRegistry; +import org.apache.tuscany.core.client.BootstrapHelper; +import org.apache.tuscany.core.context.CompositeContext; +import org.apache.tuscany.core.context.event.ModuleStart; +import org.apache.tuscany.core.context.event.ModuleStop; +import org.apache.tuscany.core.message.impl.MessageFactoryImpl; +import org.apache.tuscany.core.runtime.RuntimeContext; +import org.apache.tuscany.core.runtime.RuntimeContextImpl; +import org.apache.tuscany.core.wire.jdk.JDKWireFactoryFactory; +import org.apache.tuscany.core.wire.service.DefaultWireFactoryService; +import org.apache.tuscany.core.wire.service.WireFactoryService; + +/** + * Verifies that the composite context implementation and java component builders construct references properly + * + * @version $Rev$ $Date$ + */ +public class JavaBuilderContextIntegrationTestCase extends TestCase { + private ContextFactoryBuilderRegistry builderRegistry; + private DefaultWireBuilder defaultWireBuilder; + private NullMonitorFactory monitorFactory; + + public JavaBuilderContextIntegrationTestCase(String arg0) { + super(arg0); + } + + protected void setUp() throws Exception { + super.setUp(); + monitorFactory = new NullMonitorFactory(); + builderRegistry = BootstrapHelper.bootstrapContextFactoryBuilders(monitorFactory); + defaultWireBuilder = new DefaultWireBuilder(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public void testRefWithSourceInterceptor() throws Exception { + MockSyncInterceptor mockInterceptor = new MockSyncInterceptor(); + MockInterceptorBuilder interceptorBuilder = new MockInterceptorBuilder(mockInterceptor, true); + PolicyBuilderRegistry policyRegistry = new DefaultPolicyBuilderRegistry(); + policyRegistry.registerSourceBuilder(interceptorBuilder); + WireFactoryService wireFactory = new DefaultWireFactoryService(new MessageFactoryImpl(), new JDKWireFactoryFactory(), policyRegistry); + JavaContextFactoryBuilder javaBuilder = new JavaContextFactoryBuilder(wireFactory); + + builderRegistry.register(javaBuilder); + + RuntimeContext runtime = new RuntimeContextImpl(monitorFactory, builderRegistry, defaultWireBuilder); + runtime.addBuilder(new JavaTargetWireBuilder()); + runtime.start(); + runtime.getRootContext().registerModelObject( + MockFactory.createCompositeComponent("test.module")); + CompositeContext child = (CompositeContext) runtime.getRootContext().getContext("test.module"); + child.registerModelObject(MockFactory.createModule()); + child.publish(new ModuleStart(this)); + GenericComponent source = (GenericComponent) child.getContext("source").getInstance(null); + Assert.assertNotNull(source); + source.getGenericComponent().getString(); + Assert.assertEquals(1, mockInterceptor.getCount()); + source.getGenericComponent().getString(); + Assert.assertEquals(2, mockInterceptor.getCount()); + child.publish(new ModuleStop(this)); + runtime.stop(); + } + + public void testRefWithSourceInterceptorHandler() throws Exception { + MockSyncInterceptor mockInterceptor = new MockSyncInterceptor(); + MockInterceptorBuilder interceptorBuilder = new MockInterceptorBuilder(mockInterceptor, true); + MockHandler mockHandler = new MockHandler(); + MockHandlerBuilder handlerBuilder = new MockHandlerBuilder(mockHandler, true, true); + PolicyBuilderRegistry policyRegistry = new DefaultPolicyBuilderRegistry(); + policyRegistry.registerSourceBuilder(interceptorBuilder); + policyRegistry.registerSourceBuilder(handlerBuilder); + WireFactoryService wireFactory = new DefaultWireFactoryService(new MessageFactoryImpl(), new JDKWireFactoryFactory(), policyRegistry); + JavaContextFactoryBuilder javaBuilder = new JavaContextFactoryBuilder(wireFactory); + + builderRegistry.register(javaBuilder); + RuntimeContext runtime = new RuntimeContextImpl(monitorFactory, builderRegistry, defaultWireBuilder); + runtime.addBuilder(new JavaTargetWireBuilder()); + runtime.start(); + runtime.getRootContext().registerModelObject( + MockFactory.createCompositeComponent("test.module")); + CompositeContext child = (CompositeContext) runtime.getRootContext().getContext("test.module"); + child.registerModelObject(MockFactory.createModule()); + child.publish(new ModuleStart(this)); + GenericComponent source = (GenericComponent) child.getContext("source").getInstance(null); + Assert.assertNotNull(source); + source.getGenericComponent().getString(); + Assert.assertEquals(1, mockInterceptor.getCount()); + Assert.assertEquals(1, mockHandler.getCount()); + source.getGenericComponent().getString(); + Assert.assertEquals(2, mockInterceptor.getCount()); + Assert.assertEquals(2, mockHandler.getCount()); + child.publish(new ModuleStop(this)); + runtime.stop(); + } + + public void testRefWithTargetInterceptorHandler() throws Exception { + MockSyncInterceptor mockInterceptor = new MockSyncInterceptor(); + MockInterceptorBuilder interceptorBuilder = new MockInterceptorBuilder(mockInterceptor, false); + MockHandler mockHandler = new MockHandler(); + MockHandlerBuilder handlerBuilder = new MockHandlerBuilder(mockHandler, false, true); + PolicyBuilderRegistry policyRegistry = new DefaultPolicyBuilderRegistry(); + policyRegistry.registerSourceBuilder(interceptorBuilder); + policyRegistry.registerSourceBuilder(handlerBuilder); + WireFactoryService wireFactory = new DefaultWireFactoryService(new MessageFactoryImpl(), new JDKWireFactoryFactory(), policyRegistry); + JavaContextFactoryBuilder javaBuilder = new JavaContextFactoryBuilder(wireFactory); + + builderRegistry.register(javaBuilder); + + RuntimeContext runtime = new RuntimeContextImpl(monitorFactory, builderRegistry, defaultWireBuilder); + runtime.addBuilder(new JavaTargetWireBuilder()); + runtime.start(); + runtime.getRootContext().registerModelObject( + MockFactory.createCompositeComponent("test.module")); + CompositeContext child = (CompositeContext) runtime.getRootContext().getContext("test.module"); + child.registerModelObject(MockFactory.createModule()); + child.publish(new ModuleStart(this)); + GenericComponent source = (GenericComponent) child.getContext("source").getInstance(null); + Assert.assertNotNull(source); + source.getGenericComponent().getString(); + Assert.assertEquals(1, mockInterceptor.getCount()); + Assert.assertEquals(1, mockHandler.getCount()); + source.getGenericComponent().getString(); + Assert.assertEquals(2, mockInterceptor.getCount()); + Assert.assertEquals(2, mockHandler.getCount()); + child.publish(new ModuleStop(this)); + runtime.stop(); + } + + public void testRefWithTargetInterceptor() throws Exception { + MockSyncInterceptor mockInterceptor = new MockSyncInterceptor(); + MockInterceptorBuilder interceptorBuilder = new MockInterceptorBuilder(mockInterceptor, false); + PolicyBuilderRegistry policyRegistry = new DefaultPolicyBuilderRegistry(); + policyRegistry.registerSourceBuilder(interceptorBuilder); + WireFactoryService wireFactory = new DefaultWireFactoryService(new MessageFactoryImpl(), new JDKWireFactoryFactory(), policyRegistry); + JavaContextFactoryBuilder javaBuilder = new JavaContextFactoryBuilder(wireFactory); + + builderRegistry.register(javaBuilder); + + RuntimeContext runtime = new RuntimeContextImpl(monitorFactory, builderRegistry, defaultWireBuilder); + runtime.addBuilder(new JavaTargetWireBuilder()); + + runtime.start(); + runtime.getRootContext().registerModelObject( + MockFactory.createCompositeComponent("test.module")); + CompositeContext child = (CompositeContext) runtime.getRootContext().getContext("test.module"); + child.registerModelObject(MockFactory.createModule()); + child.publish(new ModuleStart(this)); + GenericComponent source = (GenericComponent) child.getContext("source").getInstance(null); + Assert.assertNotNull(source); + source.getGenericComponent().getString(); + Assert.assertEquals(1, mockInterceptor.getCount()); + source.getGenericComponent().getString(); + Assert.assertEquals(2, mockInterceptor.getCount()); + child.publish(new ModuleStop(this)); + runtime.stop(); + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/JavaIntegrationTestCase.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/JavaIntegrationTestCase.java new file mode 100644 index 0000000000..a5ec39480f --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/JavaIntegrationTestCase.java @@ -0,0 +1,68 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.integration; + +import junit.framework.TestCase; + +import org.apache.tuscany.common.monitor.MonitorFactory; +import org.apache.tuscany.common.monitor.impl.NullMonitorFactory; +import org.apache.tuscany.container.java.assembly.JavaAssemblyFactory; +import org.apache.tuscany.container.java.assembly.impl.JavaAssemblyFactoryImpl; +import org.apache.tuscany.core.builder.ContextFactoryBuilderRegistry; +import org.apache.tuscany.core.builder.impl.DefaultWireBuilder; +import org.apache.tuscany.core.client.BootstrapHelper; +import org.apache.tuscany.core.runtime.RuntimeContext; +import org.apache.tuscany.core.runtime.RuntimeContextImpl; +import org.apache.tuscany.model.assembly.Module; +import org.apache.tuscany.model.assembly.ModuleComponent; + +/** + * Integration test that verifies container.java can be used to host components. + * + * @version $Rev$ $Date$ + */ +public class JavaIntegrationTestCase extends TestCase { + private JavaAssemblyFactory factory; + private RuntimeContext runtime; + + public void testModuleWithOneComponent() throws Exception { + Module module = factory.createModule(); + ModuleComponent moduleComponent = factory.createModuleComponent(); + moduleComponent.setImplementation(module); + +// runtime.registerModelObject(moduleComponent); + } + + protected void setUp() throws Exception { + super.setUp(); + + // Create a factory for model objects + factory = new JavaAssemblyFactoryImpl(); + + // Create and bootstrap an empty Tuscany runtime + MonitorFactory monitorFactory = new NullMonitorFactory(); + ContextFactoryBuilderRegistry builderRegistry = BootstrapHelper.bootstrapContextFactoryBuilders(monitorFactory); + DefaultWireBuilder wireBuilder = new DefaultWireBuilder(); + runtime = new RuntimeContextImpl(monitorFactory, builderRegistry, wireBuilder); + runtime.start(); + } + + protected void tearDown() throws Exception { + runtime.stop(); + super.tearDown(); + } +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/JavaRuntimeBootstrapTestCase.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/JavaRuntimeBootstrapTestCase.java new file mode 100644 index 0000000000..6a9fca90c9 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/JavaRuntimeBootstrapTestCase.java @@ -0,0 +1,53 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package org.apache.tuscany.container.java.integration; + +import org.apache.tuscany.container.java.mock.MockFactory; +import org.apache.tuscany.container.java.mock.components.GenericComponent; +import org.apache.tuscany.core.context.CompositeContext; +import org.apache.tuscany.core.context.Context; +import org.apache.tuscany.core.context.event.ModuleStart; +import org.apache.tuscany.core.runtime.RuntimeContext; + +import junit.framework.Assert; +import junit.framework.TestCase; + +/** + * Ensures basic runtime with Java support boots properly + * + * @version $Rev$ $Date$ + */ +public class JavaRuntimeBootstrapTestCase extends TestCase { + + /** + * Tests the runtime can be bootstrapped with Java builders and two module-scoped Java-based components can be wired + */ + public void testRuntimeBoot() throws Exception{ + RuntimeContext runtime = MockFactory.createJavaRuntime(); + Context ctx = runtime.getSystemContext().getContext(MockFactory.SYSTEM_CHILD); + Assert.assertNotNull(ctx); + runtime.getRootContext().registerModelObject(MockFactory.createCompositeComponent("test")); + CompositeContext testCtx = (CompositeContext) runtime.getRootContext().getContext("test"); + Assert.assertNotNull(testCtx); + testCtx.registerModelObject(MockFactory.createModule()); + testCtx.publish(new ModuleStart(this)); + GenericComponent source = (GenericComponent)testCtx.getContext("source").getInstance(null); + Assert.assertNotNull(source); + GenericComponent target = (GenericComponent)testCtx.getContext("target").getInstance(null); + Assert.assertNotNull(target); + source.getGenericComponent().getString(); + } + +} + diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/StartStopTestCase.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/StartStopTestCase.java new file mode 100644 index 0000000000..8b7ed342c4 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/StartStopTestCase.java @@ -0,0 +1,68 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.integration; + +import java.net.URL; +import java.net.URLClassLoader; + +import junit.framework.TestCase; +import org.apache.tuscany.core.client.TuscanyRuntime; +import org.osoa.sca.ModuleContext; +import org.osoa.sca.CurrentModuleContext; + +/** + * @version $Rev$ $Date$ + */ +public class StartStopTestCase extends TestCase { + private ClassLoader oldCL; + + public void testHelloWorld() throws Exception { + TuscanyRuntime tuscany = new TuscanyRuntime("test", null); + tuscany.start(); + ModuleContext moduleContext = CurrentModuleContext.getContext(); + assertNotNull(moduleContext); + + HelloWorldService helloworldService = (HelloWorldService) moduleContext.locateService("HelloWorld"); + assertNotNull(helloworldService); + + String value = helloworldService .getGreetings("World"); + assertEquals("Hello World", value); + tuscany.stop(); + tuscany = new TuscanyRuntime("test", null); + tuscany.start(); + moduleContext = CurrentModuleContext.getContext(); + assertNotNull(moduleContext); + helloworldService = (HelloWorldService) moduleContext.locateService("HelloWorld"); + assertNotNull(helloworldService); + value = helloworldService .getGreetings("World"); + assertEquals("Hello World", value); + tuscany.stop(); + } + + protected void setUp() throws Exception { + super.setUp(); + URL url = getClass().getResource("/helloworldmc/"); + ClassLoader cl = new URLClassLoader(new URL[]{url}, getClass().getClassLoader()); + oldCL = Thread.currentThread().getContextClassLoader(); + Thread.currentThread().setContextClassLoader(cl); + } + + protected void tearDown() throws Exception { + Thread.currentThread().setContextClassLoader(oldCL); + super.tearDown(); + } +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/binding/EPtoExternalServiceTestCase.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/binding/EPtoExternalServiceTestCase.java new file mode 100644 index 0000000000..17424669bc --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/binding/EPtoExternalServiceTestCase.java @@ -0,0 +1,99 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.integration.binding; + +import junit.framework.Assert; +import junit.framework.TestCase; +import org.apache.tuscany.container.java.assembly.mock.HelloWorldService; +import org.apache.tuscany.container.java.builder.MockInterceptorBuilder; +import org.apache.tuscany.container.java.invocation.mock.MockSyncInterceptor; +import org.apache.tuscany.container.java.mock.MockFactory; +import org.apache.tuscany.core.builder.system.PolicyBuilderRegistry; +import org.apache.tuscany.core.context.CompositeContext; +import org.apache.tuscany.core.context.EntryPointContext; +import org.apache.tuscany.core.context.event.ModuleStart; +import org.apache.tuscany.core.context.event.ModuleStop; +import org.apache.tuscany.core.context.event.RequestEnd; +import org.apache.tuscany.core.context.event.RequestStart; +import org.apache.tuscany.core.runtime.RuntimeContext; + +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; + +/** + * @version $$Rev$$ $$Date$$ + */ +public class EPtoExternalServiceTestCase extends TestCase { + private Method hello; + + /** + * Tests wiring of an entry point directly to an external service + */ + public void testEPtoESInvocation() throws Throwable { + RuntimeContext runtime = MockFactory.registerFooBinding(MockFactory.createJavaRuntime()); + PolicyBuilderRegistry registry = (PolicyBuilderRegistry) ((CompositeContext) runtime.getSystemContext().getContext(MockFactory.SYSTEM_CHILD)) + .getContext(MockFactory.POLICY_BUILDER_REGISTRY).getInstance(null); + MockSyncInterceptor mockInterceptor = new MockSyncInterceptor(); + MockInterceptorBuilder interceptorBuilder = new MockInterceptorBuilder(mockInterceptor, false); + registry.registerTargetBuilder(interceptorBuilder); + runtime.getRootContext().registerModelObject(MockFactory.createCompositeComponent("test.module")); + CompositeContext child = (CompositeContext) runtime.getRootContext().getContext("test.module"); + child.registerModelObject(MockFactory.createModuleWithEntryPointToExternalService()); + child.publish(new ModuleStart(this)); + Object id = new Object(); + child.publish(new RequestStart(this, id)); + EntryPointContext ctx = (EntryPointContext) child.getContext("source"); + Assert.assertNotNull(ctx); + InvocationHandler handler = (InvocationHandler) ctx.getHandler(); + Assert.assertEquals(0, mockInterceptor.getCount()); + Object response = handler.invoke(null, hello, new Object[]{"foo"}); + Assert.assertEquals("foo", response); + Assert.assertEquals(1, mockInterceptor.getCount()); + + ctx = (EntryPointContext) child.getContext("source"); + Assert.assertNotNull(ctx); + handler = (InvocationHandler) ctx.getHandler(); + response = handler.invoke(null, hello, new Object[]{"foo"}); + Assert.assertEquals("foo", response); + child.publish(new RequestEnd(this, id)); + + // second request + Object id2 = new Object(); + child.publish(new RequestStart(this, id2)); + ctx = (EntryPointContext) child.getContext("source"); + Assert.assertNotNull(ctx); + handler = (InvocationHandler) ctx.getHandler(); + Assert.assertEquals(2, mockInterceptor.getCount()); + response = handler.invoke(null, hello, new Object[]{"foo"}); + Assert.assertEquals("foo", response); + Assert.assertEquals(3, mockInterceptor.getCount()); + child.publish(new RequestEnd(this, id2)); + + child.publish(new ModuleStop(this)); + runtime.stop(); + + } + + protected void setUp() throws Exception { + super.setUp(); + hello = HelloWorldService.class.getMethod("hello", String.class); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/binding/EntryPointToJavaTestCase.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/binding/EntryPointToJavaTestCase.java new file mode 100644 index 0000000000..f8ba1e2192 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/binding/EntryPointToJavaTestCase.java @@ -0,0 +1,261 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package org.apache.tuscany.container.java.integration.binding; + +import junit.framework.Assert; +import junit.framework.TestCase; +import org.apache.tuscany.container.java.assembly.mock.HelloWorldService; +import org.apache.tuscany.container.java.builder.MockInterceptorBuilder; +import org.apache.tuscany.container.java.invocation.mock.MockSyncInterceptor; +import org.apache.tuscany.container.java.mock.MockFactory; +import org.apache.tuscany.core.builder.system.PolicyBuilderRegistry; +import org.apache.tuscany.core.context.CompositeContext; +import org.apache.tuscany.core.context.EntryPointContext; +import org.apache.tuscany.core.context.event.HttpSessionBound; +import org.apache.tuscany.core.context.event.HttpSessionEnd; +import org.apache.tuscany.core.context.event.ModuleStart; +import org.apache.tuscany.core.context.event.ModuleStop; +import org.apache.tuscany.core.context.event.RequestEnd; +import org.apache.tuscany.core.context.event.RequestStart; +import org.apache.tuscany.core.runtime.RuntimeContext; +import org.apache.tuscany.model.assembly.Scope; + +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; + +/** + * Tests basic entry point functionality with Java components + * + * @version $Rev$ $Date$ + */ +public class EntryPointToJavaTestCase extends TestCase { + + private Method hello; + + public void setUp() throws Exception { + hello = HelloWorldService.class.getMethod("hello", String.class); + } + + /** + * Tests creation and wire of an entry point wired to a module-scoped service offered by a Java component + */ + public void testEPtoJavaModuleScopeInvoke() throws Throwable { + RuntimeContext runtime = MockFactory.registerFooBinding(MockFactory.createJavaRuntime()); + PolicyBuilderRegistry registry = (PolicyBuilderRegistry) ((CompositeContext) runtime.getSystemContext().getContext(MockFactory.SYSTEM_CHILD)) + .getContext(MockFactory.POLICY_BUILDER_REGISTRY).getInstance(null); + + MockSyncInterceptor mockInterceptor = new MockSyncInterceptor(); + MockInterceptorBuilder interceptorBuilder = new MockInterceptorBuilder(mockInterceptor, false); + registry.registerTargetBuilder(interceptorBuilder); + runtime.getRootContext().registerModelObject(MockFactory.createCompositeComponent("test.module")); + CompositeContext child = (CompositeContext) runtime.getRootContext().getContext("test.module"); + child.registerModelObject(MockFactory.createModuleWithEntryPoint(Scope.MODULE)); + child.publish(new ModuleStart(this)); + Object id = new Object(); + child.publish(new RequestStart(this, id)); + EntryPointContext ctx = (EntryPointContext) child.getContext("source"); + Assert.assertNotNull(ctx); + InvocationHandler handler = (InvocationHandler) ctx.getHandler(); + Assert.assertEquals(0, mockInterceptor.getCount()); + Object response = handler.invoke(null, hello, new Object[]{"foo"}); + Assert.assertEquals("Hello foo", response); + Assert.assertEquals(1, mockInterceptor.getCount()); + Object id2 = new Object(); + child.publish(new RequestStart(this, id2)); + + // second request + Object id3 = new Object(); + child.publish(new RequestStart(this, id3)); + ctx = (EntryPointContext) child.getContext("source"); + Assert.assertNotNull(ctx); + handler = (InvocationHandler) ctx.getHandler(); + Assert.assertEquals(1, mockInterceptor.getCount()); + response = handler.invoke(null, hello, new Object[]{"foo"}); + Assert.assertEquals("Hello foo", response); + Assert.assertEquals(2, mockInterceptor.getCount()); + HelloWorldService service1 = (HelloWorldService) child.getContext("target").getInstance(null); + Assert.assertEquals(2, service1.count()); + child.publish(new RequestEnd(this, id3)); + + child.publish(new ModuleStop(this)); + runtime.stop(); + } + + /** + * Tests creation and wire of an entry point wired to a session-scoped service offered by a Java component + */ + public void testEPtoJavaSessionScopeInvoke() throws Throwable { + RuntimeContext runtime = MockFactory.registerFooBinding(MockFactory.createJavaRuntime()); + PolicyBuilderRegistry registry = (PolicyBuilderRegistry) ((CompositeContext) runtime.getSystemContext().getContext(MockFactory.SYSTEM_CHILD)) + .getContext(MockFactory.POLICY_BUILDER_REGISTRY).getInstance(null); + MockSyncInterceptor mockInterceptor = new MockSyncInterceptor(); + MockInterceptorBuilder interceptorBuilder = new MockInterceptorBuilder(mockInterceptor, false); + registry.registerTargetBuilder(interceptorBuilder); + runtime.getRootContext().registerModelObject(MockFactory.createCompositeComponent("test.module")); + CompositeContext child = (CompositeContext) runtime.getRootContext().getContext("test.module"); + child.registerModelObject(MockFactory.createModuleWithEntryPoint(Scope.SESSION)); + child.publish(new ModuleStart(this)); + + // first session + Object session = new Object(); + Object id = new Object(); + child.publish(new RequestStart(this, id)); + child.publish(new HttpSessionBound(this, session)); + + EntryPointContext ctx = (EntryPointContext) child.getContext("source"); + Assert.assertNotNull(ctx); + InvocationHandler handler = (InvocationHandler) ctx.getHandler(); + Assert.assertEquals(0, mockInterceptor.getCount()); + Object response = handler.invoke(null, hello, new Object[]{"foo"}); + Assert.assertEquals("Hello foo", response); + Assert.assertEquals(1, mockInterceptor.getCount()); + child.publish(new RequestEnd(this, id)); + + Object id2 = new Object(); + child.publish(new RequestStart(this, id2)); + child.publish(new HttpSessionBound(this, session)); + EntryPointContext ctx2 = (EntryPointContext) child.getContext("source"); + Assert.assertNotNull(ctx2); + response = handler.invoke(null, hello, new Object[]{"foo"}); + Assert.assertEquals("Hello foo", response); + Assert.assertEquals(2, mockInterceptor.getCount()); + HelloWorldService service1 = (HelloWorldService) child.getContext("target").getInstance(null); + Assert.assertEquals(2, service1.count()); + child.publish(new RequestEnd(this, id2)); + child.publish(new HttpSessionEnd(this, session)); + + // second session + Object session2 = new Object(); + child.publish(new RequestStart(this, new Object())); + child.publish(new HttpSessionBound(this, session2)); + + ctx = (EntryPointContext) child.getContext("source"); + Assert.assertNotNull(ctx); + Assert.assertEquals(2, mockInterceptor.getCount()); + response = handler.invoke(null, hello, new Object[]{"foo"}); + Assert.assertEquals("Hello foo", response); + Assert.assertEquals(3, mockInterceptor.getCount()); + child.publish(new HttpSessionBound(this, session2)); + + Object id3 = new Object(); + child.publish(new RequestStart(this, id3)); + child.publish(new HttpSessionBound(this, session2)); + ctx2 = (EntryPointContext) child.getContext("source"); + Assert.assertNotNull(ctx2); + response = handler.invoke(null, hello, new Object[]{"foo"}); + Assert.assertEquals("Hello foo", response); + Assert.assertEquals(4, mockInterceptor.getCount()); + HelloWorldService service2 = (HelloWorldService) child.getContext("target").getInstance(null); + Assert.assertEquals(2, service2.count()); + Assert.assertEquals(2, service1.count()); //ensure sessions not crossed + child.publish(new RequestEnd(this, session2)); + child.publish(new HttpSessionBound(this, session2)); + + child.publish(new ModuleStop(this)); + runtime.stop(); + } + + + /** + * Tests creation and wire of an entry point wired to a module-scoped service offered by a Java component + */ + public void testEPtoJavaStatelessInvoke() throws Throwable { + RuntimeContext runtime = MockFactory.registerFooBinding(MockFactory.createJavaRuntime()); + PolicyBuilderRegistry registry = (PolicyBuilderRegistry) ((CompositeContext) runtime.getSystemContext().getContext(MockFactory.SYSTEM_CHILD)) + .getContext(MockFactory.POLICY_BUILDER_REGISTRY).getInstance(null); + MockSyncInterceptor mockInterceptor = new MockSyncInterceptor(); + MockInterceptorBuilder interceptorBuilder = new MockInterceptorBuilder(mockInterceptor, false); + registry.registerTargetBuilder(interceptorBuilder); + runtime.getRootContext().registerModelObject(MockFactory.createCompositeComponent("test.module")); + CompositeContext child = (CompositeContext) runtime.getRootContext().getContext("test.module"); + child.registerModelObject(MockFactory.createModuleWithEntryPoint(Scope.INSTANCE)); + child.publish(new ModuleStart(this)); + Object id = new Object(); + child.publish(new RequestStart(this, id)); + EntryPointContext ctx = (EntryPointContext) child.getContext("source"); + Assert.assertNotNull(ctx); + InvocationHandler handler = (InvocationHandler) ctx.getHandler(); + Assert.assertEquals(0, mockInterceptor.getCount()); + Object response = handler.invoke(null, hello, new Object[]{"foo"}); + Assert.assertEquals("Hello foo", response); + Assert.assertEquals(1, mockInterceptor.getCount()); + child.publish(new RequestEnd(this, id)); + + // second request + Object id2 = new Object(); + child.publish(new RequestStart(this, id2)); + ctx = (EntryPointContext) child.getContext("source"); + Assert.assertNotNull(ctx); + handler = (InvocationHandler) ctx.getHandler(); + Assert.assertEquals(1, mockInterceptor.getCount()); + response = handler.invoke(null, hello, new Object[]{"foo"}); + Assert.assertEquals("Hello foo", response); + Assert.assertEquals(2, mockInterceptor.getCount()); + HelloWorldService service1 = (HelloWorldService) child.getContext("target").getInstance(null); + Assert.assertEquals(0, service1.count()); + child.publish(new RequestEnd(this, id)); + + child.publish(new ModuleStop(this)); + runtime.stop(); + } + + public void testEPtoJavaRequestInvoke() throws Throwable { + RuntimeContext runtime = MockFactory.registerFooBinding(MockFactory.createJavaRuntime()); + PolicyBuilderRegistry registry = (PolicyBuilderRegistry) ((CompositeContext) runtime.getSystemContext().getContext(MockFactory.SYSTEM_CHILD)) + .getContext(MockFactory.POLICY_BUILDER_REGISTRY).getInstance(null); + MockSyncInterceptor mockInterceptor = new MockSyncInterceptor(); + MockInterceptorBuilder interceptorBuilder = new MockInterceptorBuilder(mockInterceptor, false); + registry.registerTargetBuilder(interceptorBuilder); + runtime.getRootContext().registerModelObject(MockFactory.createCompositeComponent("test.module")); + CompositeContext child = (CompositeContext) runtime.getRootContext().getContext("test.module"); + child.registerModelObject(MockFactory.createModuleWithEntryPoint(Scope.REQUEST)); + child.publish(new ModuleStart(this)); + Object id = new Object(); + child.publish(new RequestStart(this, id)); + EntryPointContext ctx = (EntryPointContext) child.getContext("source"); + Assert.assertNotNull(ctx); + InvocationHandler handler = (InvocationHandler) ctx.getHandler(); + Assert.assertEquals(0, mockInterceptor.getCount()); + Object response = handler.invoke(null, hello, new Object[]{"foo"}); + Assert.assertEquals("Hello foo", response); + Assert.assertEquals(1, mockInterceptor.getCount()); + + ctx = (EntryPointContext) child.getContext("source"); + Assert.assertNotNull(ctx); + handler = (InvocationHandler) ctx.getHandler(); + response = handler.invoke(null, hello, new Object[]{"foo"}); + HelloWorldService service1 = (HelloWorldService) child.getContext("target").getInstance(null); + Assert.assertEquals(2, service1.count()); + + child.publish(new RequestEnd(this, id)); + + // second request + Object id2 = new Object(); + child.publish(new RequestStart(this, id2)); + ctx = (EntryPointContext) child.getContext("source"); + Assert.assertNotNull(ctx); + handler = (InvocationHandler) ctx.getHandler(); + Assert.assertEquals(2, mockInterceptor.getCount()); + response = handler.invoke(null, hello, new Object[]{"foo"}); + Assert.assertEquals("Hello foo", response); + Assert.assertEquals(3, mockInterceptor.getCount()); + HelloWorldService service2 = (HelloWorldService) child.getContext("target").getInstance(null); + Assert.assertEquals(1, service2.count()); + child.publish(new RequestEnd(this, id2)); + + child.publish(new ModuleStop(this)); + runtime.stop(); + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/binding/ExternalServiceProxyInvokeTestCase.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/binding/ExternalServiceProxyInvokeTestCase.java new file mode 100644 index 0000000000..7357f973f7 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/binding/ExternalServiceProxyInvokeTestCase.java @@ -0,0 +1,73 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.integration.binding; + +import junit.framework.Assert; +import junit.framework.TestCase; +import org.apache.tuscany.container.java.assembly.mock.HelloWorldService; +import org.apache.tuscany.container.java.builder.MockInterceptorBuilder; +import org.apache.tuscany.container.java.invocation.mock.MockSyncInterceptor; +import org.apache.tuscany.container.java.mock.MockFactory; +import org.apache.tuscany.core.builder.system.PolicyBuilderRegistry; +import org.apache.tuscany.core.context.CompositeContext; +import org.apache.tuscany.core.context.event.ModuleStart; +import org.apache.tuscany.core.context.event.ModuleStop; +import org.apache.tuscany.core.context.event.RequestEnd; +import org.apache.tuscany.core.context.event.RequestStart; +import org.apache.tuscany.core.runtime.RuntimeContext; + +/** + * @version $$Rev$$ $$Date$$ + */ +public class ExternalServiceProxyInvokeTestCase extends TestCase { + + /** + * Tests that an external service can be invoked by locating a proxy to it as opposed to invoking it over a wire from another + * source such as an entry point or external service. + * + * @throws Throwable + */ + public void testProxyInvocation() throws Throwable { + RuntimeContext runtime = MockFactory.registerFooBinding(MockFactory.createJavaRuntime()); + PolicyBuilderRegistry registry = (PolicyBuilderRegistry) ((CompositeContext) runtime.getSystemContext().getContext(MockFactory.SYSTEM_CHILD)) + .getContext(MockFactory.POLICY_BUILDER_REGISTRY).getInstance(null); + MockSyncInterceptor mockInterceptor = new MockSyncInterceptor(); + MockInterceptorBuilder interceptorBuilder = new MockInterceptorBuilder(mockInterceptor, false); + registry.registerTargetBuilder(interceptorBuilder); + runtime.getRootContext().registerModelObject(MockFactory.createCompositeComponent("test.module")); + CompositeContext child = (CompositeContext) runtime.getRootContext().getContext("test.module"); + child.registerModelObject(MockFactory.createModuleWithEntryPointToExternalService()); + child.publish(new ModuleStart(this)); + Object id = new Object(); + child.publish(new RequestStart(this, id)); + HelloWorldService service1 = (HelloWorldService) child.getContext("target").getInstance(null); + Assert.assertEquals("foo", service1.hello("foo")); + + child.publish(new RequestEnd(this, id)); + child.publish(new ModuleStop(this)); + runtime.stop(); + + } + + protected void setUp() throws Exception { + super.setUp(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/binding/JavaToExternalServiceTestCase.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/binding/JavaToExternalServiceTestCase.java new file mode 100644 index 0000000000..90acb1c591 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/binding/JavaToExternalServiceTestCase.java @@ -0,0 +1,61 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package org.apache.tuscany.container.java.integration.binding; + +import junit.framework.Assert; +import junit.framework.TestCase; +import org.apache.tuscany.container.java.assembly.mock.HelloWorldService; +import org.apache.tuscany.container.java.builder.MockInterceptorBuilder; +import org.apache.tuscany.container.java.invocation.mock.MockSyncInterceptor; +import org.apache.tuscany.container.java.mock.MockFactory; +import org.apache.tuscany.core.builder.system.PolicyBuilderRegistry; +import org.apache.tuscany.core.context.CompositeContext; +import org.apache.tuscany.core.context.event.ModuleStart; +import org.apache.tuscany.core.context.event.ModuleStop; +import org.apache.tuscany.core.runtime.RuntimeContext; + +/** + * Tests basic Java to external service interaction + * + * @version $Rev$ $Date$ + */ +public class JavaToExternalServiceTestCase extends TestCase { + + /** + * Tests an wire of an external service configured with the {@link org.apache.tuscany.container.java.mock.binding.foo.FooBinding} + * from a Java component + * + * @throws Exception + */ + public void testJavaToESInvoke() throws Exception { + RuntimeContext runtime = MockFactory.registerFooBinding(MockFactory.createJavaRuntime()); + PolicyBuilderRegistry registry = (PolicyBuilderRegistry) ((CompositeContext) runtime.getSystemContext().getContext( + MockFactory.SYSTEM_CHILD)).getContext(MockFactory.POLICY_BUILDER_REGISTRY).getInstance(null); + MockSyncInterceptor mockInterceptor = new MockSyncInterceptor(); + MockInterceptorBuilder interceptorBuilder = new MockInterceptorBuilder(mockInterceptor, false); + registry.registerTargetBuilder(interceptorBuilder); + runtime.getRootContext().registerModelObject(MockFactory.createCompositeComponent("test.module")); + CompositeContext child = (CompositeContext) runtime.getRootContext().getContext("test.module"); + child.registerModelObject(MockFactory.createModuleWithExternalService()); + child.publish(new ModuleStart(this)); + HelloWorldService source = (HelloWorldService) child.getContext("source").getInstance(null); + Assert.assertNotNull(source); + Assert.assertEquals(0, mockInterceptor.getCount()); + Assert.assertEquals("foo", source.hello("foo")); + Assert.assertEquals(1, mockInterceptor.getCount()); + child.publish(new ModuleStop(this)); + runtime.stop(); + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/context/ScopeReferenceTestCase.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/context/ScopeReferenceTestCase.java new file mode 100644 index 0000000000..89320f60e5 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/context/ScopeReferenceTestCase.java @@ -0,0 +1,741 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package org.apache.tuscany.container.java.integration.context; + +import org.apache.tuscany.container.java.mock.MockFactory; +import org.apache.tuscany.container.java.mock.components.GenericComponent; +import org.apache.tuscany.core.context.CompositeContext; +import org.apache.tuscany.core.context.Context; +import org.apache.tuscany.core.context.event.ModuleStart; +import org.apache.tuscany.core.context.event.RequestStart; +import org.apache.tuscany.core.context.event.HttpSessionBound; +import org.apache.tuscany.core.context.event.RequestEnd; +import org.apache.tuscany.core.runtime.RuntimeContext; +import org.apache.tuscany.model.assembly.Scope; + +import junit.framework.Assert; +import junit.framework.TestCase; + +/** + * Tests scoping is properly handled for service references + * + * @version $Rev$ $Date$ + */ +public class ScopeReferenceTestCase extends TestCase { + + /** + * Tests a module-to-module scoped wire is setup properly by the runtime + */ + public void testModuleToModule() throws Exception{ + RuntimeContext runtime = MockFactory.createJavaRuntime(); + Context ctx = runtime.getSystemContext().getContext("tuscany.system.child"); + Assert.assertNotNull(ctx); + runtime.getRootContext().registerModelObject(MockFactory.createCompositeComponent("test")); + CompositeContext testCtx = (CompositeContext) runtime.getRootContext().getContext("test"); + Assert.assertNotNull(testCtx); + testCtx.registerModelObject(MockFactory.createModule()); + testCtx.publish(new ModuleStart(this)); + GenericComponent source = (GenericComponent)testCtx.getContext("source").getInstance(null); + Assert.assertNotNull(source); + GenericComponent target = (GenericComponent)testCtx.getContext("target").getInstance(null); + Assert.assertNotNull(target); + source.getGenericComponent().getString(); + } + + /** + * Tests a module-to-session scoped wire is setup properly by the runtime + */ + public void testModuleToSession() throws Exception{ + RuntimeContext runtime = MockFactory.createJavaRuntime(); + Context ctx = runtime.getSystemContext().getContext("tuscany.system.child"); + Assert.assertNotNull(ctx); + runtime.getRootContext().registerModelObject(MockFactory.createCompositeComponent("test")); + CompositeContext testCtx = (CompositeContext) runtime.getRootContext().getContext("test"); + Assert.assertNotNull(testCtx); + testCtx.registerModelObject(MockFactory.createModule(Scope.MODULE,Scope.SESSION)); + testCtx.publish(new ModuleStart(this)); + + // first session + Object session = new Object(); + Object id = new Object(); + testCtx.publish(new RequestStart(this,id)); + testCtx.publish(new HttpSessionBound(this,session)); + GenericComponent source = (GenericComponent)testCtx.getContext("source").getInstance(null); + Assert.assertNotNull(source); + GenericComponent target = (GenericComponent)testCtx.getContext("target").getInstance(null); + Assert.assertNotNull(target); + source.getGenericComponent().setString("foo"); + Assert.assertEquals("foo",target.getString()); + testCtx.publish(new RequestEnd(this,id)); + + //second session + Object session2 = new Object(); + Object id2 = new Object(); + testCtx.publish(new RequestStart(this,id2)); + testCtx.publish(new HttpSessionBound(this,session2)); + GenericComponent target2 = (GenericComponent)testCtx.getContext("target").getInstance(null); + Assert.assertNotNull(target2); + Assert.assertTrue(!"foo".equals(target2.getString())); + + Assert.assertTrue(!"foo".equals(source.getGenericComponent().getString())); + source.getGenericComponent().setString("bar"); + Assert.assertEquals("bar",target2.getString()); + Assert.assertEquals("bar",source.getGenericComponent().getString()); + //testCtx.fireEvent(EventContext.SESSION_NOTIFY,session); + + } + + /** + * Tests a module-to-request scoped wire is setup properly by the runtime + */ + public void testModuleToRequest() throws Exception{ + RuntimeContext runtime = MockFactory.createJavaRuntime(); + Context ctx = runtime.getSystemContext().getContext("tuscany.system.child"); + Assert.assertNotNull(ctx); + runtime.getRootContext().registerModelObject(MockFactory.createCompositeComponent("test")); + CompositeContext testCtx = (CompositeContext) runtime.getRootContext().getContext("test"); + Assert.assertNotNull(testCtx); + testCtx.registerModelObject(MockFactory.createModule(Scope.MODULE,Scope.REQUEST)); + testCtx.publish(new ModuleStart(this)); + + // first request + Object id = new Object(); + testCtx.publish(new RequestStart(this,id)); + GenericComponent source = (GenericComponent)testCtx.getContext("source").getInstance(null); + Assert.assertNotNull(source); + GenericComponent target = (GenericComponent)testCtx.getContext("target").getInstance(null); + Assert.assertNotNull(target); + source.getGenericComponent().setString("foo"); + Assert.assertEquals("foo",target.getString()); + testCtx.publish(new RequestEnd(this,id)); + + //second request + Object id2 = new Object(); + testCtx.publish(new RequestStart(this,id2)); + GenericComponent target2 = (GenericComponent)testCtx.getContext("target").getInstance(null); + Assert.assertNotNull(target2); + Assert.assertTrue(!"foo".equals(target2.getString())); + + Assert.assertTrue(!"foo".equals(source.getGenericComponent().getString())); + source.getGenericComponent().setString("bar"); + Assert.assertEquals("bar",target2.getString()); + Assert.assertEquals("bar",source.getGenericComponent().getString()); + + } + + /** + * Tests a module-to-stateless scoped wire is setup properly by the runtime + */ + public void testModuleToStateless() throws Exception{ + RuntimeContext runtime = MockFactory.createJavaRuntime(); + Context ctx = runtime.getSystemContext().getContext("tuscany.system.child"); + Assert.assertNotNull(ctx); + runtime.getRootContext().registerModelObject(MockFactory.createCompositeComponent("test")); + CompositeContext testCtx = (CompositeContext) runtime.getRootContext().getContext("test"); + Assert.assertNotNull(testCtx); + testCtx.registerModelObject(MockFactory.createModule(Scope.MODULE,Scope.INSTANCE)); + testCtx.publish(new ModuleStart(this)); + + // first request + Object id = new Object(); + testCtx.publish(new RequestStart(this,id)); + GenericComponent source = (GenericComponent)testCtx.getContext("source").getInstance(null); + Assert.assertNotNull(source); + GenericComponent target = (GenericComponent)testCtx.getContext("target").getInstance(null); + Assert.assertNotNull(target); + source.getGenericComponent().setString("foo"); + Assert.assertTrue(!"foo".equals(target.getString())); + testCtx.publish(new RequestEnd(this,id)); + + //second request + Object id2 = new Object(); + testCtx.publish(new RequestStart(this,id2)); + GenericComponent target2 = (GenericComponent)testCtx.getContext("target").getInstance(null); + Assert.assertNotNull(target2); + Assert.assertTrue(!"foo".equals(target2.getString())); + + Assert.assertTrue(!"foo".equals(source.getGenericComponent().getString())); + source.getGenericComponent().setString("bar"); + Assert.assertTrue(!"bar".equals(target2.getString())); + } + + /** + * Tests a session-to-session scoped wire is setup properly by the runtime + */ + public void testSessionToSession() throws Exception{ + RuntimeContext runtime = MockFactory.createJavaRuntime(); + Context ctx = runtime.getSystemContext().getContext("tuscany.system.child"); + Assert.assertNotNull(ctx); + runtime.getRootContext().registerModelObject(MockFactory.createCompositeComponent("test")); + CompositeContext testCtx = (CompositeContext) runtime.getRootContext().getContext("test"); + Assert.assertNotNull(testCtx); + testCtx.registerModelObject(MockFactory.createModule(Scope.SESSION,Scope.SESSION)); + testCtx.publish(new ModuleStart(this)); + + // first session + Object session = new Object(); + Object id = new Object(); + testCtx.publish(new RequestStart(this,id)); + testCtx.publish(new HttpSessionBound(this,session)); + GenericComponent source = (GenericComponent)testCtx.getContext("source").getInstance(null); + Assert.assertNotNull(source); + GenericComponent target = (GenericComponent)testCtx.getContext("target").getInstance(null); + Assert.assertNotNull(target); + source.getGenericComponent().setString("foo"); + source.getGenericComponent().setString("foo"); + Assert.assertEquals("foo",target.getString()); + testCtx.publish(new RequestEnd(this,id)); + + //second session + Object session2 = new Object(); + Object id2 = new Object(); + testCtx.publish(new RequestStart(this,id2)); + testCtx.publish(new HttpSessionBound(this,session2)); + GenericComponent source2 = (GenericComponent)testCtx.getContext("source").getInstance(null); + Assert.assertNotNull(source2); + GenericComponent target2 = (GenericComponent)testCtx.getContext("target").getInstance(null); + + Assert.assertNotNull(target2); + Assert.assertEquals(null,target2.getString()); + Assert.assertEquals(null,source2.getGenericComponent().getString()); + source2.getGenericComponent().setString("baz"); + Assert.assertEquals("baz",source2.getGenericComponent().getString()); + Assert.assertEquals("baz",target2.getString()); + + testCtx.publish(new RequestEnd(this,id2)); + + } + + + /** + * Tests a session-to-module scoped wire is setup properly by the runtime + */ + public void testSessionToModule() throws Exception{ + RuntimeContext runtime = MockFactory.createJavaRuntime(); + Context ctx = runtime.getSystemContext().getContext("tuscany.system.child"); + Assert.assertNotNull(ctx); + runtime.getRootContext().registerModelObject(MockFactory.createCompositeComponent("test")); + CompositeContext testCtx = (CompositeContext) runtime.getRootContext().getContext("test"); + Assert.assertNotNull(testCtx); + testCtx.registerModelObject(MockFactory.createModule(Scope.SESSION,Scope.MODULE)); + testCtx.publish(new ModuleStart(this)); + + // first session + Object session = new Object(); + Object id = new Object(); + testCtx.publish(new RequestStart(this,id)); + testCtx.publish(new HttpSessionBound(this,session)); + GenericComponent source = (GenericComponent)testCtx.getContext("source").getInstance(null); + Assert.assertNotNull(source); + GenericComponent target = (GenericComponent)testCtx.getContext("target").getInstance(null); + Assert.assertNotNull(target); + source.getGenericComponent().setString("foo"); + source.getGenericComponent().setString("foo"); + Assert.assertEquals("foo",target.getString()); + testCtx.publish(new RequestEnd(this,id)); + + //second session + Object session2 = new Object(); + Object id2 = new Object(); + testCtx.publish(new RequestStart(this,id2)); + testCtx.publish(new HttpSessionBound(this,session2)); + GenericComponent source2 = (GenericComponent)testCtx.getContext("source").getInstance(null); + Assert.assertNotNull(source2); + GenericComponent target2 = (GenericComponent)testCtx.getContext("target").getInstance(null); + + Assert.assertNotNull(target2); + Assert.assertEquals("foo",target2.getString()); + Assert.assertEquals("foo",source2.getGenericComponent().getString()); + source2.getGenericComponent().setString("baz"); + Assert.assertEquals("baz",source2.getGenericComponent().getString()); + Assert.assertEquals("baz",target2.getString()); + Assert.assertEquals("baz",target.getString()); + + testCtx.publish(new RequestEnd(this,session2)); + + } + + /** + * Tests a session-to-request scoped wire is setup properly by the runtime + */ + public void testSessionToRequest() throws Exception{ + RuntimeContext runtime = MockFactory.createJavaRuntime(); + Context ctx = runtime.getSystemContext().getContext("tuscany.system.child"); + Assert.assertNotNull(ctx); + runtime.getRootContext().registerModelObject(MockFactory.createCompositeComponent("test")); + CompositeContext testCtx = (CompositeContext) runtime.getRootContext().getContext("test"); + Assert.assertNotNull(testCtx); + testCtx.registerModelObject(MockFactory.createModule(Scope.SESSION,Scope.REQUEST)); + testCtx.publish(new ModuleStart(this)); + + // first session + Object session = new Object(); + Object id = new Object(); + testCtx.publish(new RequestStart(this,id)); + testCtx.publish(new HttpSessionBound(this,session)); + GenericComponent source = (GenericComponent)testCtx.getContext("source").getInstance(null); + Assert.assertNotNull(source); + GenericComponent target = (GenericComponent)testCtx.getContext("target").getInstance(null); + Assert.assertNotNull(target); + source.getGenericComponent().setString("foo"); + Assert.assertEquals("foo",target.getString()); + testCtx.publish(new RequestEnd(this,session)); + + //second session + Object session2 = new Object(); + Object id2 = new Object(); + testCtx.publish(new RequestStart(this,id2)); + testCtx.publish(new HttpSessionBound(this,session2)); + GenericComponent source2 = (GenericComponent)testCtx.getContext("source").getInstance(null); + Assert.assertNotNull(source); + GenericComponent target2 = (GenericComponent)testCtx.getContext("target").getInstance(null); + + Assert.assertNotNull(target2); + Assert.assertEquals(null,target2.getString()); + source2.getGenericComponent().setString("baz"); + Assert.assertEquals("baz",target2.getString()); + Assert.assertEquals("baz",source2.getGenericComponent().getString()); + + Assert.assertEquals("foo",target.getString()); + testCtx.publish(new RequestEnd(this,session)); + + } + + + /** + * Tests a session-to-stateless scoped wire is setup properly by the runtime + */ + public void testSessionToStateless() throws Exception{ + RuntimeContext runtime = MockFactory.createJavaRuntime(); + Context ctx = runtime.getSystemContext().getContext("tuscany.system.child"); + Assert.assertNotNull(ctx); + runtime.getRootContext().registerModelObject(MockFactory.createCompositeComponent("test")); + CompositeContext testCtx = (CompositeContext) runtime.getRootContext().getContext("test"); + Assert.assertNotNull(testCtx); + testCtx.registerModelObject(MockFactory.createModule(Scope.SESSION,Scope.INSTANCE)); + testCtx.publish(new ModuleStart(this)); + + // first session + Object session = new Object(); + Object id = new Object(); + testCtx.publish(new RequestStart(this,id)); + testCtx.publish(new HttpSessionBound(this,session)); + GenericComponent source = (GenericComponent)testCtx.getContext("source").getInstance(null); + Assert.assertNotNull(source); + GenericComponent target = (GenericComponent)testCtx.getContext("target").getInstance(null); + Assert.assertNotNull(target); + source.getGenericComponent().setString("foo"); + Assert.assertEquals(null,target.getString()); + testCtx.publish(new RequestEnd(this,session)); + + //second session + Object session2 = new Object(); + Object id2 = new Object(); + testCtx.publish(new RequestStart(this,id2)); + testCtx.publish(new HttpSessionBound(this,session2)); + GenericComponent source2 = (GenericComponent)testCtx.getContext("source").getInstance(null); + Assert.assertNotNull(source); + GenericComponent target2 = (GenericComponent)testCtx.getContext("target").getInstance(null); + + Assert.assertNotNull(target2); + Assert.assertEquals(null,target2.getString()); + source2.getGenericComponent().setString("baz"); + Assert.assertEquals(null,target2.getString()); //Note assumes no pooling + Assert.assertEquals(null,source2.getGenericComponent().getString()); + + Assert.assertEquals(null,target.getString()); //Note assumes no pooling + testCtx.publish(new RequestEnd(this,session)); + + } + + /** + * Tests a request-to-request scoped wire is setup properly by the runtime + */ + public void testRequestToRequest() throws Exception{ + RuntimeContext runtime = MockFactory.createJavaRuntime(); + Context ctx = runtime.getSystemContext().getContext("tuscany.system.child"); + Assert.assertNotNull(ctx); + runtime.getRootContext().registerModelObject(MockFactory.createCompositeComponent("test")); + CompositeContext testCtx = (CompositeContext) runtime.getRootContext().getContext("test"); + Assert.assertNotNull(testCtx); + testCtx.registerModelObject(MockFactory.createModule(Scope.REQUEST,Scope.REQUEST)); + testCtx.publish(new ModuleStart(this)); + + // first request + Object id = new Object(); + testCtx.publish(new RequestStart(this,id)); + GenericComponent source = (GenericComponent)testCtx.getContext("source").getInstance(null); + Assert.assertNotNull(source); + GenericComponent target = (GenericComponent)testCtx.getContext("target").getInstance(null); + Assert.assertNotNull(target); + source.getGenericComponent().setString("foo"); + Assert.assertEquals("foo",target.getString()); + testCtx.publish(new RequestEnd(this,new Object())); + + //second request + Object id2 = new Object(); + testCtx.publish(new RequestStart(this,id2)); + GenericComponent source2 = (GenericComponent)testCtx.getContext("source").getInstance(null); + Assert.assertNotNull(source2); + GenericComponent target2 = (GenericComponent)testCtx.getContext("target").getInstance(null); + + Assert.assertNotNull(target2); + Assert.assertEquals(null,target2.getString()); + Assert.assertEquals(null,source2.getGenericComponent().getString()); + source2.getGenericComponent().setString("baz"); + Assert.assertEquals("baz",source2.getGenericComponent().getString()); + Assert.assertEquals("baz",target2.getString()); + + testCtx.publish(new RequestEnd(this,new Object())); + } + + /** + * Tests a request-to-module scoped wire is setup properly by the runtime + */ + public void testRequestToModule() throws Exception{ + RuntimeContext runtime = MockFactory.createJavaRuntime(); + Context ctx = runtime.getSystemContext().getContext("tuscany.system.child"); + Assert.assertNotNull(ctx); + runtime.getRootContext().registerModelObject(MockFactory.createCompositeComponent("test")); + CompositeContext testCtx = (CompositeContext) runtime.getRootContext().getContext("test"); + Assert.assertNotNull(testCtx); + testCtx.registerModelObject(MockFactory.createModule(Scope.REQUEST,Scope.MODULE)); + testCtx.publish(new ModuleStart(this)); + + // first request + Object id = new Object(); + testCtx.publish(new RequestStart(this,id)); + GenericComponent source = (GenericComponent)testCtx.getContext("source").getInstance(null); + Assert.assertNotNull(source); + GenericComponent target = (GenericComponent)testCtx.getContext("target").getInstance(null); + Assert.assertNotNull(target); + source.getGenericComponent().setString("foo"); + Assert.assertEquals("foo",target.getString()); + testCtx.publish(new RequestEnd(this,new Object())); + + //second request + Object id2 = new Object(); + testCtx.publish(new RequestStart(this,id2)); + GenericComponent source2 = (GenericComponent)testCtx.getContext("source").getInstance(null); + Assert.assertNotNull(source2); + GenericComponent target2 = (GenericComponent)testCtx.getContext("target").getInstance(null); + + Assert.assertNotNull(target2); + Assert.assertEquals("foo",target2.getString()); + Assert.assertEquals("foo",source2.getGenericComponent().getString()); + source2.getGenericComponent().setString("baz"); + Assert.assertEquals("baz",source2.getGenericComponent().getString()); + Assert.assertEquals("baz",target2.getString()); + Assert.assertEquals("baz",target.getString()); + + testCtx.publish(new RequestEnd(this,new Object())); + } + + /** + * Tests a request-to-session scoped wire is setup properly by the runtime + */ + public void testRequestToSession() throws Exception{ + RuntimeContext runtime = MockFactory.createJavaRuntime(); + Context ctx = runtime.getSystemContext().getContext("tuscany.system.child"); + Assert.assertNotNull(ctx); + runtime.getRootContext().registerModelObject(MockFactory.createCompositeComponent("test")); + CompositeContext testCtx = (CompositeContext) runtime.getRootContext().getContext("test"); + Assert.assertNotNull(testCtx); + testCtx.registerModelObject(MockFactory.createModule(Scope.REQUEST,Scope.SESSION)); + testCtx.publish(new ModuleStart(this)); + + // first session + Object session = new Object(); + Object id = new Object(); + testCtx.publish(new RequestStart(this,id)); + testCtx.publish(new HttpSessionBound(this,session)); + GenericComponent source = (GenericComponent)testCtx.getContext("source").getInstance(null); + Assert.assertNotNull(source); + GenericComponent target = (GenericComponent)testCtx.getContext("target").getInstance(null); + Assert.assertNotNull(target); + source.getGenericComponent().setString("foo"); + Assert.assertEquals("foo",target.getString()); + testCtx.publish(new RequestEnd(this,new Object())); + + //second request for session + Object id2 = new Object(); + testCtx.publish(new RequestStart(this,id2)); + testCtx.publish(new HttpSessionBound(this,session)); + GenericComponent targetR2 = (GenericComponent)testCtx.getContext("target").getInstance(null); + Assert.assertEquals("foo",targetR2.getString()); + GenericComponent sourceR2 = (GenericComponent)testCtx.getContext("source").getInstance(null); + Assert.assertNotNull(sourceR2); + Assert.assertEquals("foo",sourceR2.getGenericComponent().getString()); + + testCtx.publish(new RequestEnd(this,new Object())); + + //second session + Object session2 = new Object(); + Object id3 = new Object(); + testCtx.publish(new RequestStart(this,id3)); + testCtx.publish(new HttpSessionBound(this,session2)); + GenericComponent source2 = (GenericComponent)testCtx.getContext("source").getInstance(null); + Assert.assertNotNull(source2); + GenericComponent target2 = (GenericComponent)testCtx.getContext("target").getInstance(null); + + Assert.assertNotNull(target2); + Assert.assertEquals(null,target2.getString()); + Assert.assertEquals(null,source2.getGenericComponent().getString()); + source2.getGenericComponent().setString("baz"); + Assert.assertEquals("baz",source2.getGenericComponent().getString()); + Assert.assertEquals("baz",target2.getString()); + + testCtx.publish(new RequestEnd(this,session2)); + Object id4 = new Object(); + testCtx.publish(new RequestStart(this,id4)); + testCtx.publish(new HttpSessionBound(this,session)); + testCtx.publish(new RequestEnd(this,session)); + + } + + + /** + * Tests a request-to-stateless scoped wire is setup properly by the runtime + */ + public void testRequestToStateless() throws Exception{ + RuntimeContext runtime = MockFactory.createJavaRuntime(); + Context ctx = runtime.getSystemContext().getContext("tuscany.system.child"); + Assert.assertNotNull(ctx); + runtime.getRootContext().registerModelObject(MockFactory.createCompositeComponent("test")); + CompositeContext testCtx = (CompositeContext) runtime.getRootContext().getContext("test"); + Assert.assertNotNull(testCtx); + testCtx.registerModelObject(MockFactory.createModule(Scope.REQUEST,Scope.INSTANCE)); + testCtx.publish(new ModuleStart(this)); + + // first request + Object id = new Object(); + testCtx.publish(new RequestStart(this,id)); + GenericComponent source = (GenericComponent)testCtx.getContext("source").getInstance(null); + Assert.assertNotNull(source); + GenericComponent target = (GenericComponent)testCtx.getContext("target").getInstance(null); + Assert.assertNotNull(target); + source.getGenericComponent().setString("foo"); + Assert.assertEquals(null,target.getString()); + testCtx.publish(new RequestEnd(this,new Object())); + + //second request + Object id2 = new Object(); + testCtx.publish(new RequestStart(this,id2)); + GenericComponent source2 = (GenericComponent)testCtx.getContext("source").getInstance(null); + Assert.assertNotNull(source2); + GenericComponent target2 = (GenericComponent)testCtx.getContext("target").getInstance(null); + + Assert.assertNotNull(target2); + Assert.assertEquals(null,target2.getString()); + Assert.assertEquals(null,source2.getGenericComponent().getString()); + source2.getGenericComponent().setString("baz"); + Assert.assertEquals(null,source2.getGenericComponent().getString()); + Assert.assertEquals(null,target2.getString()); + + testCtx.publish(new RequestEnd(this,new Object())); + } + + + /** + * Tests a stateless-to-stateless scoped wire is setup properly by the runtime + */ + public void testStatelessToStateless() throws Exception{ + RuntimeContext runtime = MockFactory.createJavaRuntime(); + Context ctx = runtime.getSystemContext().getContext("tuscany.system.child"); + Assert.assertNotNull(ctx); + runtime.getRootContext().registerModelObject(MockFactory.createCompositeComponent("test")); + CompositeContext testCtx = (CompositeContext) runtime.getRootContext().getContext("test"); + Assert.assertNotNull(testCtx); + testCtx.registerModelObject(MockFactory.createModule(Scope.INSTANCE,Scope.INSTANCE)); + testCtx.publish(new ModuleStart(this)); + + // first request + Object id = new Object(); + testCtx.publish(new RequestStart(this,id)); + GenericComponent source = (GenericComponent)testCtx.getContext("source").getInstance(null); + Assert.assertNotNull(source); + GenericComponent target = (GenericComponent)testCtx.getContext("target").getInstance(null); + Assert.assertNotNull(target); + source.getGenericComponent().setString("foo"); + Assert.assertEquals(null,target.getString()); + testCtx.publish(new RequestEnd(this,new Object())); + + //second request + Object id2 = new Object(); + testCtx.publish(new RequestStart(this,id2)); + GenericComponent source2 = (GenericComponent)testCtx.getContext("source").getInstance(null); + Assert.assertNotNull(source2); + GenericComponent target2 = (GenericComponent)testCtx.getContext("target").getInstance(null); + + Assert.assertNotNull(target2); + Assert.assertEquals(null,target2.getString()); + Assert.assertEquals(null,source2.getGenericComponent().getString()); + source2.getGenericComponent().setString("baz"); + Assert.assertEquals(null,source2.getGenericComponent().getString()); + Assert.assertEquals(null,target2.getString()); + + testCtx.publish(new RequestEnd(this,new Object())); + } + + /** + * Tests a stateless-to-request scoped wire is setup properly by the runtime + */ + public void testStatelessToRequest() throws Exception{ + RuntimeContext runtime = MockFactory.createJavaRuntime(); + Context ctx = runtime.getSystemContext().getContext("tuscany.system.child"); + Assert.assertNotNull(ctx); + runtime.getRootContext().registerModelObject(MockFactory.createCompositeComponent("test")); + CompositeContext testCtx = (CompositeContext) runtime.getRootContext().getContext("test"); + Assert.assertNotNull(testCtx); + testCtx.registerModelObject(MockFactory.createModule(Scope.INSTANCE,Scope.REQUEST)); + testCtx.publish(new ModuleStart(this)); + + // first request + Object id = new Object(); + testCtx.publish(new RequestStart(this,id)); + GenericComponent source = (GenericComponent)testCtx.getContext("source").getInstance(null); + Assert.assertNotNull(source); + GenericComponent target = (GenericComponent)testCtx.getContext("target").getInstance(null); + Assert.assertNotNull(target); + source.getGenericComponent().setString("foo"); + Assert.assertEquals("foo",target.getString()); + testCtx.publish(new RequestEnd(this,new Object())); + + GenericComponent targetR1 = (GenericComponent)testCtx.getContext("target").getInstance(null); + Assert.assertNotNull(targetR1); + Assert.assertEquals("foo",target.getString()); + + //second request + Object id2 = new Object(); + testCtx.publish(new RequestStart(this,id2)); + GenericComponent source2 = (GenericComponent)testCtx.getContext("source").getInstance(null); + Assert.assertNotNull(source2); + GenericComponent target2 = (GenericComponent)testCtx.getContext("target").getInstance(null); + + Assert.assertNotNull(target2); + Assert.assertEquals(null,target2.getString()); + Assert.assertEquals(null,source2.getGenericComponent().getString()); + source2.getGenericComponent().setString("baz"); + Assert.assertEquals("baz",source2.getGenericComponent().getString()); + Assert.assertEquals("baz",target2.getString()); + + testCtx.publish(new RequestEnd(this,new Object())); + } + + /** + * Tests a stateless-to-session scoped wire is setup properly by the runtime + */ + public void testStatelessToSession() throws Exception{ + RuntimeContext runtime = MockFactory.createJavaRuntime(); + Context ctx = runtime.getSystemContext().getContext("tuscany.system.child"); + Assert.assertNotNull(ctx); + runtime.getRootContext().registerModelObject(MockFactory.createCompositeComponent("test")); + CompositeContext testCtx = (CompositeContext) runtime.getRootContext().getContext("test"); + Assert.assertNotNull(testCtx); + testCtx.registerModelObject(MockFactory.createModule(Scope.INSTANCE,Scope.SESSION)); + testCtx.publish(new ModuleStart(this)); + + // first session + Object session = new Object(); + Object id = new Object(); + testCtx.publish(new RequestStart(this,id)); + testCtx.publish(new HttpSessionBound(this,session)); + GenericComponent source = (GenericComponent)testCtx.getContext("source").getInstance(null); + Assert.assertNotNull(source); + GenericComponent target = (GenericComponent)testCtx.getContext("target").getInstance(null); + Assert.assertNotNull(target); + source.getGenericComponent().setString("foo"); + Assert.assertEquals("foo",target.getString()); + testCtx.publish(new RequestEnd(this,new Object())); + + //second request for session + Object id2 = new Object(); + testCtx.publish(new RequestStart(this,id2)); + testCtx.publish(new HttpSessionBound(this,session)); + GenericComponent targetR2 = (GenericComponent)testCtx.getContext("target").getInstance(null); + Assert.assertEquals("foo",targetR2.getString()); + GenericComponent sourceR2 = (GenericComponent)testCtx.getContext("source").getInstance(null); + Assert.assertNotNull(sourceR2); + Assert.assertEquals("foo",sourceR2.getGenericComponent().getString()); + + testCtx.publish(new RequestEnd(this,new Object())); + + //second session + Object session2 = new Object(); + Object id3 = new Object(); + testCtx.publish(new RequestStart(this,id3)); + testCtx.publish(new HttpSessionBound(this,session2)); + GenericComponent source2 = (GenericComponent)testCtx.getContext("source").getInstance(null); + Assert.assertNotNull(source2); + GenericComponent target2 = (GenericComponent)testCtx.getContext("target").getInstance(null); + + Assert.assertNotNull(target2); + Assert.assertEquals(null,target2.getString()); + Assert.assertEquals(null,source2.getGenericComponent().getString()); + source2.getGenericComponent().setString("baz"); + Assert.assertEquals("baz",source2.getGenericComponent().getString()); + Assert.assertEquals("baz",target2.getString()); + + testCtx.publish(new RequestEnd(this,session2)); + Object id4 = new Object(); + testCtx.publish(new RequestStart(this,id4)); + testCtx.publish(new HttpSessionBound(this,session)); + testCtx.publish(new RequestEnd(this,session)); + + } + + + /** + * Tests a stateless-to-module scoped wire is setup properly by the runtime + */ + public void testStatelessToModule() throws Exception{ + RuntimeContext runtime = MockFactory.createJavaRuntime(); + Context ctx = runtime.getSystemContext().getContext("tuscany.system.child"); + Assert.assertNotNull(ctx); + runtime.getRootContext().registerModelObject(MockFactory.createCompositeComponent("test")); + CompositeContext testCtx = (CompositeContext) runtime.getRootContext().getContext("test"); + Assert.assertNotNull(testCtx); + testCtx.registerModelObject(MockFactory.createModule(Scope.INSTANCE,Scope.MODULE)); + testCtx.publish(new ModuleStart(this)); + + Object id = new Object(); + testCtx.publish(new RequestStart(this,id)); + GenericComponent source = (GenericComponent)testCtx.getContext("source").getInstance(null); + Assert.assertNotNull(source); + GenericComponent target = (GenericComponent)testCtx.getContext("target").getInstance(null); + Assert.assertNotNull(target); + source.getGenericComponent().setString("foo"); + Assert.assertEquals("foo",target.getString()); + testCtx.publish(new RequestEnd(this,new Object())); + + //second session + Object id2 = new Object(); + testCtx.publish(new RequestStart(this,id2)); + GenericComponent source2 = (GenericComponent)testCtx.getContext("source").getInstance(null); + Assert.assertNotNull(source2); + GenericComponent target2 = (GenericComponent)testCtx.getContext("target").getInstance(null); + + Assert.assertNotNull(target2); + Assert.assertEquals("foo",target2.getString()); + Assert.assertEquals("foo",source2.getGenericComponent().getString()); + source2.getGenericComponent().setString("baz"); + Assert.assertEquals("baz",source2.getGenericComponent().getString()); + Assert.assertEquals("baz",target2.getString()); + + testCtx.publish(new RequestEnd(this,new Object())); + + } + +} + diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/invocation/MediationTestCase.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/invocation/MediationTestCase.java new file mode 100644 index 0000000000..e560af6fd3 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/invocation/MediationTestCase.java @@ -0,0 +1,53 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package org.apache.tuscany.container.java.invocation; + +import java.lang.reflect.Method; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.apache.tuscany.container.java.invocation.mock.SimpleTargetImpl; +import org.apache.tuscany.core.message.Message; +import org.apache.tuscany.core.message.MessageFactory; +import org.apache.tuscany.core.message.impl.MessageFactoryImpl; + +/** + * Tests invoking on a different interface from the one actually implemented by the target + * + * @version $Rev$ $Date$ + */ +public class MediationTestCase extends TestCase { + + private Method hello; + + private MessageFactory msgFactory = new MessageFactoryImpl(); + + public void setUp() throws Exception { + hello = Hello.class.getMethod("hello", String.class); + } + + public void testMediation() throws Exception { + StaticJavaComponentTargetInvoker invoker = new StaticJavaComponentTargetInvoker(hello, new SimpleTargetImpl()); + Message msg = msgFactory.createMessage(); + msg.setBody("foo"); + Assert.assertEquals("foo", invoker.invoke(msg).getBody()); + } + + public interface Hello { + + public String hello(String message) throws Exception; + + } +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/invocation/ScopedPojoInvokerTestCase.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/invocation/ScopedPojoInvokerTestCase.java new file mode 100644 index 0000000000..f4337fe3cb --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/invocation/ScopedPojoInvokerTestCase.java @@ -0,0 +1,53 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.invocation; + +import java.lang.reflect.Method; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.apache.tuscany.container.java.invocation.mock.SimpleTarget; +import org.apache.tuscany.container.java.mock.MockScopeContext; +import org.apache.tuscany.core.context.QualifiedName; +import org.apache.tuscany.core.context.ScopeContext; + +public class ScopedPojoInvokerTestCase extends TestCase { + + private Method echoMethod; + + public ScopedPojoInvokerTestCase() { + super(); + } + + public ScopedPojoInvokerTestCase(String arg0) { + super(arg0); + } + + public void setUp() throws Exception { + echoMethod = SimpleTarget.class.getDeclaredMethod("echo", String.class); + Assert.assertNotNull(echoMethod); + } + + public void testScopedInvoke() throws Exception { + ScopeContext container = new MockScopeContext(); + ScopedJavaComponentInvoker invoker = new ScopedJavaComponentInvoker(new QualifiedName("foo"), echoMethod, container,false); + Object ret = invoker.invokeTarget("foo"); + Assert.assertEquals("foo", ret); + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/invocation/StaticPojoInvokerTestCase.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/invocation/StaticPojoInvokerTestCase.java new file mode 100644 index 0000000000..31e7e3c64e --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/invocation/StaticPojoInvokerTestCase.java @@ -0,0 +1,154 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.invocation; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import static java.lang.Integer.*; + +import junit.framework.Assert; +import junit.framework.TestCase; + +public class StaticPojoInvokerTestCase extends TestCase { + + private Method echoMethod; + private Method arrayMethod; + private Method nullParamMethod; + private Method primitiveMethod; + private Method checkedMethod; + private Method runtimeMethod; + + public StaticPojoInvokerTestCase() { + + } + + public StaticPojoInvokerTestCase(String arg0) { + super(arg0); + } + + public void setUp() throws Exception { + echoMethod = TestBean.class.getDeclaredMethod("echo", String.class); + arrayMethod = TestBean.class.getDeclaredMethod("arrayEcho", String[].class); + nullParamMethod = TestBean.class.getDeclaredMethod("nullParam", (Class[]) null); + primitiveMethod = TestBean.class.getDeclaredMethod("primitiveEcho", TYPE); + checkedMethod = TestBean.class.getDeclaredMethod("checkedException", (Class[]) null); + runtimeMethod = TestBean.class.getDeclaredMethod("runtimeException", (Class[]) null); + Assert.assertNotNull(echoMethod); + Assert.assertNotNull(checkedMethod); + Assert.assertNotNull(runtimeMethod); + } + + public void testObjectInvoke() throws Throwable { + TestBean bean = new TestBean(); + StaticJavaComponentTargetInvoker invoker = new StaticJavaComponentTargetInvoker(echoMethod, bean); + Object ret = invoker.invokeTarget("foo"); + Assert.assertEquals("foo", ret); + } + + public void testArrayInvoke() throws Throwable { + TestBean bean = new TestBean(); + StaticJavaComponentTargetInvoker invoker = new StaticJavaComponentTargetInvoker(arrayMethod, bean); + String[] args = new String[]{"foo", "bar"}; + Object ret = invoker.invokeTarget(new Object[]{args}); + String[] retA = (String[]) ret; + Assert.assertNotNull(retA); + Assert.assertEquals(2, retA.length); + Assert.assertEquals("foo", retA[0]); + Assert.assertEquals("bar", retA[1]); + } + + public void testNullInvoke() throws Throwable { + TestBean bean = new TestBean(); + StaticJavaComponentTargetInvoker invoker = new StaticJavaComponentTargetInvoker(nullParamMethod, bean); + Object ret = invoker.invokeTarget(null); + String retS = (String) ret; + Assert.assertEquals("foo", retS); + } + + public void testPrimitiveInvoke() throws Throwable { + TestBean bean = new TestBean(); + StaticJavaComponentTargetInvoker invoker = new StaticJavaComponentTargetInvoker(primitiveMethod, bean); + Object ret = invoker.invokeTarget(new Integer[]{1}); + Integer retI = (Integer) ret; + Assert.assertEquals(1, retI.intValue()); + } + + public void testInvokeCheckedException() throws Throwable { + TestBean bean = new TestBean(); + StaticJavaComponentTargetInvoker invoker = new StaticJavaComponentTargetInvoker(checkedMethod, bean); + try { + invoker.invokeTarget(null); + } catch (InvocationTargetException e) { + if (e.getCause() != null && TestException.class.equals(e.getCause().getClass())) { + return; + } + } catch (Throwable e) { + } + fail(TestException.class.getName() + " should have been thrown"); + } + + public void testInvokeRuntimeException() throws Throwable { + TestBean bean = new TestBean(); + StaticJavaComponentTargetInvoker invoker = new StaticJavaComponentTargetInvoker(runtimeMethod, bean); + try { + invoker.invokeTarget(null); + } catch (InvocationTargetException e) { + if (e.getCause() != null && e.getCause() instanceof TestRuntimeException) { + return; + } + } + fail(TestException.class.getName() + " should have been thrown"); + } + + private class TestBean { + + public String echo(String msg) throws Exception { + Assert.assertEquals("foo", msg); + return msg; + } + + public String[] arrayEcho(String[] msg) throws Exception { + Assert.assertNotNull(msg); + Assert.assertEquals(2, msg.length); + Assert.assertEquals("foo", msg[0]); + Assert.assertEquals("bar", msg[1]); + return msg; + } + + public String nullParam() throws Exception { + return "foo"; + } + + public int primitiveEcho(int i) throws Exception { + return i; + } + + public void checkedException() throws TestException { + throw new TestException(); + } + + public void runtimeException() throws TestRuntimeException { + throw new TestRuntimeException(); + } + } + + public class TestException extends Exception { + } + + public class TestRuntimeException extends RuntimeException { + } +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/invocation/mock/MockHandler.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/invocation/mock/MockHandler.java new file mode 100644 index 0000000000..cda09e8540 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/invocation/mock/MockHandler.java @@ -0,0 +1,38 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.invocation.mock; + +import org.apache.tuscany.core.wire.MessageHandler; +import org.apache.tuscany.core.message.Message; + +/** + * + */ +public class MockHandler implements MessageHandler { + + private int count =0; + + public boolean processMessage(Message message) { + //System.out.println("Invoking handler"); + count++; + return true; + } + + public int getCount(){ + return count; + } +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/invocation/mock/MockSyncInterceptor.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/invocation/mock/MockSyncInterceptor.java new file mode 100644 index 0000000000..24b22a641a --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/invocation/mock/MockSyncInterceptor.java @@ -0,0 +1,45 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.invocation.mock; + +import org.apache.tuscany.core.wire.Interceptor; +import org.apache.tuscany.core.message.Message; + +public class MockSyncInterceptor implements Interceptor { + + private int count; + + private Interceptor next; + + public MockSyncInterceptor() { + } + + public Message invoke(Message msg) { + ++count; + //System.out.println("Invoking interceptor"); + return next.invoke(msg); + } + + public int getCount() { + return count; + } + + public void setNext(Interceptor next) { + this.next=next; + } +} + diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/invocation/mock/SimpleSource.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/invocation/mock/SimpleSource.java new file mode 100644 index 0000000000..213caab7e9 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/invocation/mock/SimpleSource.java @@ -0,0 +1,25 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.invocation.mock; + +public interface SimpleSource { + + public void invokeHello() throws Exception; + + public void invokeGoodbye() throws Exception; +} + diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/invocation/mock/SimpleSourceImpl.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/invocation/mock/SimpleSourceImpl.java new file mode 100644 index 0000000000..2e7bd75f11 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/invocation/mock/SimpleSourceImpl.java @@ -0,0 +1,36 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.invocation.mock; + +public class SimpleSourceImpl implements SimpleSource { + + private SimpleTarget proxy; + + public SimpleSourceImpl(SimpleTarget proxy) { + this.proxy = proxy; + } + + public void invokeHello() throws Exception { + proxy.hello("hello"); + } + + public void invokeGoodbye() throws Exception { + proxy.goodbye("hello"); + } + +} + diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/invocation/mock/SimpleTarget.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/invocation/mock/SimpleTarget.java new file mode 100644 index 0000000000..cbd3037529 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/invocation/mock/SimpleTarget.java @@ -0,0 +1,28 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.invocation.mock; + +public interface SimpleTarget { + + public String hello(String message) throws Exception; + + public String goodbye(String message) throws Exception; + + public String echo(String message) throws Exception; + +} + diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/invocation/mock/SimpleTargetImpl.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/invocation/mock/SimpleTargetImpl.java new file mode 100644 index 0000000000..18abf6108a --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/invocation/mock/SimpleTargetImpl.java @@ -0,0 +1,39 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.invocation.mock; + +public class SimpleTargetImpl implements SimpleTarget { + + public SimpleTargetImpl() { + super(); + } + + public String hello(String message) throws Exception { + return message; + } + + public String goodbye(String message) throws Exception { + return message; + } + + public String echo(String message) throws Exception { + return message; + } + + +} + diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/loader/JavaImplementationLoaderTestCase.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/loader/JavaImplementationLoaderTestCase.java new file mode 100644 index 0000000000..85e79d8780 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/loader/JavaImplementationLoaderTestCase.java @@ -0,0 +1,134 @@ +/** + * + * Copyright 2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.loader; + +import java.net.URL; +import java.util.List; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.namespace.QName; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.apache.tuscany.container.java.assembly.JavaAssemblyFactory; +import org.apache.tuscany.container.java.assembly.impl.JavaAssemblyFactoryImpl; +import org.apache.tuscany.container.java.assembly.mock.HelloWorldImpl; +import org.apache.tuscany.container.java.assembly.mock.HelloWorldWithFieldProperties; +import org.apache.tuscany.container.java.assembly.mock.NakedHelloWorld; +import org.apache.tuscany.core.config.ConfigurationLoadException; +import org.apache.tuscany.core.loader.StAXElementLoader; +import org.apache.tuscany.core.loader.StAXLoaderRegistry; +import org.apache.tuscany.core.loader.LoaderContext; +import org.apache.tuscany.core.loader.assembly.AssemblyConstants; +import org.apache.tuscany.model.assembly.AssemblyContext; +import org.apache.tuscany.model.assembly.AssemblyObject; +import org.apache.tuscany.model.assembly.ComponentType; +import org.apache.tuscany.model.assembly.Property; +import org.apache.tuscany.model.assembly.Service; + +/** + * @version $Rev$ $Date$ + */ +public class JavaImplementationLoaderTestCase extends TestCase { + private JavaImplementationLoader loader; + private ComponentType mockType; + + public void testNakedHelloWorld() throws ConfigurationLoadException { + ComponentType type = loader.loadComponentTypeByIntrospection(NakedHelloWorld.class); + Assert.assertNotNull(type); + Assert.assertEquals(1,type.getProperties().size()); + Assert.assertTrue(type.getReferences().isEmpty()); + List services = type.getServices(); + Assert.assertEquals(1, services.size()); + Assert.assertEquals("NakedHelloWorld", services.get(0).getName()); + } + + public void testHelloWorldWithSidefile() throws XMLStreamException, ConfigurationLoadException { + StAXLoaderRegistry mockRegistry = new MockRegistry(mockType); + loader.setRegistry(mockRegistry); + URL sidefile = HelloWorldImpl.class.getResource("HelloWorldImpl.componentType"); + ComponentType type = loader.loadComponentTypeFromSidefile(sidefile, null); + assertSame(mockType, type); + } + + public void testHelloWorldWithFieldProperties() throws ConfigurationLoadException { + ComponentType type = loader.loadComponentTypeByIntrospection(HelloWorldWithFieldProperties.class); + type.initialize(null); + Assert.assertNotNull(type); + List props = type.getProperties(); + Assert.assertEquals(5, props.size()); + + Property prop = type.getProperty("text"); + Assert.assertNotNull(prop); + Assert.assertEquals("text", prop.getName()); + Assert.assertEquals(false, prop.isRequired()); + Assert.assertEquals(String.class, prop.getType()); + + prop = type.getProperty("text2"); + Assert.assertNotNull(prop); + Assert.assertEquals("text2", prop.getName()); + Assert.assertEquals(true, prop.isRequired()); + Assert.assertEquals(Integer.class, prop.getType()); + + prop = type.getProperty("foo"); + Assert.assertNotNull(prop); + Assert.assertEquals("foo", prop.getName()); + Assert.assertEquals(false, prop.isRequired()); + Assert.assertEquals(Integer.TYPE, prop.getType()); + } + + protected void setUp() throws Exception { + super.setUp(); + JavaAssemblyFactory factory = new JavaAssemblyFactoryImpl(); + mockType = factory.createComponentType(); + + loader = new JavaImplementationLoader(); + loader.setFactory(factory); + } + + private static class MockRegistry implements StAXLoaderRegistry { + private final ComponentType mockType; + + public MockRegistry(ComponentType mockType) { + this.mockType = mockType; + } + + public AssemblyObject load(XMLStreamReader reader, LoaderContext loaderContext) throws XMLStreamException, ConfigurationLoadException { + assertEquals(AssemblyConstants.COMPONENT_TYPE, reader.getName()); + return mockType; + } + + public void registerLoader(QName element, StAXElementLoader loader) { + throw new UnsupportedOperationException(); + } + + public void unregisterLoader(QName element, StAXElementLoader loader) { + throw new UnsupportedOperationException(); + } + + @Deprecated + public AssemblyContext getContext() { + throw new UnsupportedOperationException(); + } + + @Deprecated + public void setContext(AssemblyContext context) { + throw new UnsupportedOperationException(); + } + } +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/MockConfigContext.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/MockConfigContext.java new file mode 100644 index 0000000000..9cb1998d68 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/MockConfigContext.java @@ -0,0 +1,64 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package org.apache.tuscany.container.java.mock; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.core.builder.BuilderConfigException; +import org.apache.tuscany.core.builder.ContextFactoryBuilder; +import org.apache.tuscany.core.builder.WireBuilder; +import org.apache.tuscany.core.builder.impl.AssemblyVisitorImpl; +import org.apache.tuscany.core.builder.impl.DefaultWireBuilder; +import org.apache.tuscany.core.context.ConfigurationContext; +import org.apache.tuscany.core.context.ScopeContext; +import org.apache.tuscany.core.wire.TargetWireFactory; +import org.apache.tuscany.core.wire.SourceWireFactory; +import org.apache.tuscany.model.assembly.AssemblyObject; + +/** + * A mock configuration context + * + * @version $Rev: 368822 $ $Date: 2006-01-13 10:54:38 -0800 (Fri, 13 Jan 2006) $ + */ +public class MockConfigContext implements ConfigurationContext { + + private List builders; + + private DefaultWireBuilder wireBuilder = new DefaultWireBuilder(); + + public MockConfigContext(List builders, List wireBuilders) { + this.builders = (builders == null) ? new ArrayList(1) : builders; + if (wireBuilders != null){ + for (WireBuilder builder : wireBuilders) { + wireBuilder.addWireBuilder(builder); + } + } + } + + public void build(AssemblyObject model) throws BuilderConfigException { + AssemblyVisitorImpl visitor = new AssemblyVisitorImpl(builders); + visitor.start(model); + } + + public void connect(SourceWireFactory sourceFactory, TargetWireFactory targetFactory, Class targetType, boolean downScope, + ScopeContext targetScopeContext) throws BuilderConfigException { + wireBuilder.connect(sourceFactory, targetFactory, targetType, downScope, targetScopeContext); + } + + public void completeTargetChain(TargetWireFactory targetFactory, Class targetType, ScopeContext targetScopeContext) throws BuilderConfigException { + wireBuilder.completeTargetChain(targetFactory, targetType, targetScopeContext); + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/MockContextFactory.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/MockContextFactory.java new file mode 100644 index 0000000000..4e00e4c236 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/MockContextFactory.java @@ -0,0 +1,92 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.mock; + +import org.apache.tuscany.container.java.assembly.JavaAssemblyFactory; +import org.apache.tuscany.container.java.assembly.impl.JavaAssemblyFactoryImpl; +import org.apache.tuscany.container.java.config.JavaContextFactory; +import org.apache.tuscany.container.java.scopes.OrderedDependentPojo; +import org.apache.tuscany.core.builder.ContextFactory; +import org.apache.tuscany.core.builder.ObjectFactory; +import org.apache.tuscany.core.config.JavaIntrospectionHelper; +import org.apache.tuscany.core.context.Context; +import org.apache.tuscany.core.context.ScopeContext; +import org.apache.tuscany.core.injection.Injector; +import org.apache.tuscany.core.injection.MethodInjector; +import org.apache.tuscany.core.injection.ObjectCreationException; +import org.apache.tuscany.core.injection.EventInvoker; +import org.apache.tuscany.core.injection.MethodEventInvoker; +import org.apache.tuscany.model.assembly.AssemblyContext; +import org.apache.tuscany.model.assembly.Scope; +import org.apache.tuscany.model.assembly.impl.AssemblyContextImpl; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.List; + +/** + * @version $$Rev$$ $$Date$$ + */ +public class MockContextFactory { + + private MockContextFactory(){} + + /** + * Wires together a source and target + * @throws NoSuchMethodException + */ + public static List> createWiredContexts(Scope scope, ScopeContext context) throws NoSuchMethodException{ + + Constructor constructor = JavaIntrospectionHelper.getDefaultConstructor(OrderedDependentPojo.class); + Method getPojo = OrderedDependentPojo.class.getMethod("setPojo",OrderedDependentPojo.class); + Method init = OrderedDependentPojo.class.getMethod("init",(Class[])null); + EventInvoker initInvoker = new MethodEventInvoker(init); + Method destroy = OrderedDependentPojo.class.getMethod("destroy",(Class[])null); + EventInvoker destroyInvoker = new MethodEventInvoker(destroy); + + JavaContextFactory source = new JavaContextFactory("source",constructor,scope); + source.setInitInvoker(initInvoker); + source.setDestroyInvoker(destroyInvoker); + JavaContextFactory target = new JavaContextFactory("target",constructor,scope); + target.setInitInvoker(initInvoker); + target.setDestroyInvoker(destroyInvoker); + List injectors = new ArrayList(); + injectors.add(new MethodInjector(getPojo, new MockTargetFactory("target",context))); + source.setSetters(injectors); + List> list = new ArrayList>(); + list.add((ContextFactory)source); + list.add((ContextFactory)target); + return list; + } + + private static class MockTargetFactory implements ObjectFactory{ + + private String name; + private ScopeContext context; + + public MockTargetFactory (String name, ScopeContext context){ + this.name = name; + this.context = context; + } + + public Object getInstance() throws ObjectCreationException { + return context.getContext(name).getInstance(null); + } + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/MockFactory.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/MockFactory.java new file mode 100644 index 0000000000..3b45352865 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/MockFactory.java @@ -0,0 +1,819 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.mock; + +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +import junit.framework.Assert; +import org.apache.tuscany.common.monitor.MonitorFactory; +import org.apache.tuscany.common.monitor.impl.NullMonitorFactory; +import org.apache.tuscany.container.java.assembly.JavaAssemblyFactory; +import org.apache.tuscany.container.java.assembly.JavaImplementation; +import org.apache.tuscany.container.java.assembly.impl.JavaAssemblyFactoryImpl; +import org.apache.tuscany.container.java.assembly.mock.HelloWorldImpl; +import org.apache.tuscany.container.java.assembly.mock.HelloWorldService; +import org.apache.tuscany.container.java.builder.JavaContextFactoryBuilder; +import org.apache.tuscany.container.java.builder.JavaTargetWireBuilder; +import org.apache.tuscany.container.java.context.JavaAtomicContext; +import org.apache.tuscany.container.java.mock.binding.foo.FooBinding; +import org.apache.tuscany.container.java.mock.binding.foo.FooBindingBuilder; +import org.apache.tuscany.container.java.mock.binding.foo.FooBindingWireBuilder; +import org.apache.tuscany.container.java.mock.components.GenericComponent; +import org.apache.tuscany.container.java.mock.components.HelloWorldClient; +import org.apache.tuscany.container.java.mock.components.ModuleScopeComponent; +import org.apache.tuscany.container.java.mock.components.ModuleScopeComponentImpl; +import org.apache.tuscany.container.java.mock.components.OtherTarget; +import org.apache.tuscany.container.java.mock.components.OtherTargetImpl; +import org.apache.tuscany.container.java.mock.components.Source; +import org.apache.tuscany.container.java.mock.components.SourceImpl; +import org.apache.tuscany.container.java.mock.components.Target; +import org.apache.tuscany.container.java.mock.components.TargetImpl; +import org.apache.tuscany.core.builder.BuilderException; +import org.apache.tuscany.core.builder.ContextFactory; +import org.apache.tuscany.core.builder.ContextFactoryBuilder; +import org.apache.tuscany.core.builder.ContextFactoryBuilderRegistry; +import org.apache.tuscany.core.builder.WireBuilder; +import org.apache.tuscany.core.builder.impl.DefaultWireBuilder; +import org.apache.tuscany.core.builder.system.DefaultPolicyBuilderRegistry; +import org.apache.tuscany.core.builder.system.PolicyBuilderRegistry; +import org.apache.tuscany.core.client.BootstrapHelper; +import org.apache.tuscany.core.config.ComponentTypeIntrospector; +import org.apache.tuscany.core.config.ConfigurationException; +import org.apache.tuscany.core.config.ConfigurationLoadException; +import org.apache.tuscany.core.config.JavaIntrospectionHelper; +import org.apache.tuscany.core.config.processor.ProcessorUtils; +import org.apache.tuscany.core.context.CompositeContext; +import org.apache.tuscany.core.context.Context; +import org.apache.tuscany.core.context.SystemCompositeContext; +import org.apache.tuscany.core.context.event.ModuleStart; +import org.apache.tuscany.core.context.impl.CompositeContextImpl; +import org.apache.tuscany.core.injection.EventInvoker; +import org.apache.tuscany.core.injection.FieldInjector; +import org.apache.tuscany.core.injection.Injector; +import org.apache.tuscany.core.injection.MethodEventInvoker; +import org.apache.tuscany.core.injection.MethodInjector; +import org.apache.tuscany.core.injection.PojoObjectFactory; +import org.apache.tuscany.core.injection.SingletonObjectFactory; +import org.apache.tuscany.core.message.MessageFactory; +import org.apache.tuscany.core.message.impl.MessageFactoryImpl; +import org.apache.tuscany.core.runtime.RuntimeContext; +import org.apache.tuscany.core.runtime.RuntimeContextImpl; +import org.apache.tuscany.core.system.assembly.SystemAssemblyFactory; +import org.apache.tuscany.core.system.assembly.SystemBinding; +import org.apache.tuscany.core.system.assembly.impl.SystemAssemblyFactoryImpl; +import org.apache.tuscany.core.system.builder.SystemContextFactoryBuilder; +import org.apache.tuscany.core.system.builder.SystemEntryPointBuilder; +import org.apache.tuscany.core.system.builder.SystemExternalServiceBuilder; +import org.apache.tuscany.core.system.context.SystemCompositeContextImpl; +import org.apache.tuscany.core.wire.WireFactoryFactory; +import org.apache.tuscany.core.wire.jdk.JDKWireFactoryFactory; +import org.apache.tuscany.core.wire.service.DefaultWireFactoryService; +import org.apache.tuscany.model.assembly.AssemblyContext; +import org.apache.tuscany.model.assembly.AtomicComponent; +import org.apache.tuscany.model.assembly.Component; +import org.apache.tuscany.model.assembly.ComponentType; +import org.apache.tuscany.model.assembly.ConfiguredReference; +import org.apache.tuscany.model.assembly.ConfiguredService; +import org.apache.tuscany.model.assembly.EntryPoint; +import org.apache.tuscany.model.assembly.ExternalService; +import org.apache.tuscany.model.assembly.Module; +import org.apache.tuscany.model.assembly.Multiplicity; +import org.apache.tuscany.model.assembly.Reference; +import org.apache.tuscany.model.assembly.Scope; +import org.apache.tuscany.model.assembly.Service; +import org.apache.tuscany.model.assembly.impl.AssemblyContextImpl; +import org.apache.tuscany.model.types.java.JavaServiceContract; +import org.osoa.sca.annotations.ComponentName; +import org.osoa.sca.annotations.Destroy; +import org.osoa.sca.annotations.Init; + +/** + * Generates test components, modules, and runtime artifacts + * + * @version $Rev$ $Date$ + */ +public class MockFactory { + + public static final String JAVA_BUILDER = "java.runtime.builder"; + public static final String MESSAGE_FACTORY = "java.runtime.messageFactory"; + public static final String PROXY_FACTORY_FACTORY = "java.runtime.wireFactoryFactory"; + public static final String WIRE_FACTORY_SERVICE = "java.runtime.wireFactoryservice"; + public static final String JAVA_WIRE_BUILDER = "java.wire.builder"; + public static final String FOO_BUILDER = "foo.binding.builder"; + public static final String FOO_WIRE_BUILDER = "foo.binding.wire.builder"; + public static final String POLICY_BUILDER_REGISTRY = "foo.binding.policy.registry"; + public static final String SYSTEM_CHILD = "tuscany.system.child"; + + private static JavaAssemblyFactory factory = new JavaAssemblyFactoryImpl(); + private static SystemAssemblyFactory systemFactory = new SystemAssemblyFactoryImpl(); + private static AssemblyContext assemblyContext = new AssemblyContextImpl(null, null); + private static ComponentTypeIntrospector introspector; + private static ComponentType systemComponentType; + private static ComponentType compositeComponentType; + + public static ComponentType getComponentType() throws ConfigurationLoadException { + if (systemComponentType == null) { + systemComponentType = getIntrospector().introspect(SystemCompositeContextImpl.class); + } + return systemComponentType; + } + + public static ComponentType getCompositeComponentType() throws ConfigurationLoadException { + if (compositeComponentType == null) { + compositeComponentType = getIntrospector().introspect(CompositeContextImpl.class); + } + return compositeComponentType; + } + + public static ComponentTypeIntrospector getIntrospector() { + if (introspector == null) { + introspector = ProcessorUtils.createCoreIntrospector(systemFactory); + } + return introspector; + } + + /** + * Creates an initialized simple component + * + * @param name the component name + * @param type the implementation type + * @param scope the component scope + */ + public static AtomicComponent createComponent(String name, Class type, Scope scope) throws ConfigurationLoadException { + AtomicComponent sc = factory.createSimpleComponent(); + JavaImplementation impl = factory.createJavaImplementation(); + impl.setComponentType(getIntrospector().introspect(type)); + impl.setImplementationClass(type); + sc.setImplementation(impl); + Service s = factory.createService(); + JavaServiceContract ji = factory.createJavaServiceContract(); + ji.setInterface(type); + s.setServiceContract(ji); + ji.setScope(scope); + impl.getComponentType().getServices().add(s); + sc.setName(name); + sc.setImplementation(impl); + return sc; + } + + public static AtomicComponent createNonIntrospectedComponent(String name, Class service, Class type, Scope scope) throws ConfigurationLoadException { + AtomicComponent sc = factory.createSimpleComponent(); + JavaImplementation impl = factory.createJavaImplementation(); + impl.setComponentType(factory.createComponentType()); + impl.setImplementationClass(type); + sc.setImplementation(impl); + Service s = factory.createService(); + JavaServiceContract ji = factory.createJavaServiceContract(); + ji.setInterface(service); + s.setServiceContract(ji); + ji.setScope(scope); + impl.getComponentType().getServices().add(s); + sc.setName(name); + sc.setImplementation(impl); + return sc; + } + + + /** + * Creates an composite component with the given name + */ + public static Component createCompositeComponent(String name) throws ConfigurationLoadException { + Component sc = systemFactory.createModuleComponent(); + Module impl = systemFactory.createModule(); + impl.setName(name); + //impl.setImplementationClass(CompositeContextImpl.class); + sc.setImplementation(impl); + Service s = systemFactory.createService(); + JavaServiceContract ji = systemFactory.createJavaServiceContract(); + s.setServiceContract(ji); + ji.setScope(Scope.AGGREGATE); + //impl.setComponentType(systemFactory.createComponentType()); + impl.setImplementationClass(CompositeContextImpl.class); + impl.setComponentType(getCompositeComponentType()); + impl.getComponentType().getServices().add(s); + sc.setName(name); + sc.setImplementation(impl); + + return sc; + } + + /** + * Creates a system composite component with the given name + */ + public static Component createSystemCompositeComponent(String name) throws ConfigurationLoadException { + Component sc = systemFactory.createModuleComponent(); + Module impl = systemFactory.createSystemModule(); + impl.setName(name); + //impl.setImplementationClass(SystemCompositeContextImpl.class); + sc.setImplementation(impl); + Service s = systemFactory.createService(); + JavaServiceContract ji = systemFactory.createJavaServiceContract(); + s.setServiceContract(ji); + ji.setScope(Scope.AGGREGATE); + impl.setComponentType(getComponentType()); + //impl.setComponentType(systemFactory.createComponentType()); + impl.getComponentType().getServices().add(s); + sc.setName(name); + sc.setImplementation(impl); + return sc; + } + + /** + * Creates an external service configured with the 'Foo' test binding + */ + public static ExternalService createFooBindingExternalService(String name, Class interfaz) { + ExternalService es = factory.createExternalService(); + es.setName(name); + Service s = factory.createService(); + JavaServiceContract ji = factory.createJavaServiceContract(); + ji.setScope(Scope.MODULE); + ji.setInterface(interfaz); + s.setServiceContract(ji); + ConfiguredService configuredService = factory.createConfiguredService(); + es.setConfiguredService(configuredService); + + FooBinding binding = new FooBinding(); + es.getBindings().add(binding); + return es; + } + + /** + * Creates an entry point with the given name configured with the given interface and the {@link + * FooBinding} + */ + public static EntryPoint createFooBindingEntryPoint(String name, Class interfaz) { + EntryPoint ep = factory.createEntryPoint(); + ep.setName(name); + Service s = factory.createService(); + JavaServiceContract ji = factory.createJavaServiceContract(); + ji.setScope(Scope.MODULE); + ji.setInterface(interfaz); + s.setServiceContract(ji); + ConfiguredService configuredService = factory.createConfiguredService(); + configuredService.setPort(s); + ep.setConfiguredService(configuredService); + FooBinding binding = new FooBinding(); + ep.getBindings().add(binding); + return ep; + } + + /** + * Creates an external service configured with a {@link SystemBinding} + */ + public static ExternalService createESSystemBinding(String name, String refName) { + ExternalService es = systemFactory.createExternalService(); + es.setName(name); + ConfiguredService configuredService = systemFactory.createConfiguredService(); + es.setConfiguredService(configuredService); + SystemBinding binding = systemFactory.createSystemBinding(); + binding.setTargetName(refName); + es.getBindings().add(binding); + es.initialize(null); + return es; + } + + /** + * Creates a module with a Java-based "target" module-scoped component wired to a module-scoped "source" + */ + public static Module createModule() throws ConfigurationLoadException { + return createModule(Scope.MODULE, Scope.MODULE); + } + + /** + * Creates a module with a Java-based "target" component wired to a "source" + */ + public static Module createModule(Scope sourceScope, Scope targetScope) throws ConfigurationLoadException { + Component sourceComponent = createNonIntrospectedComponent("source", ModuleScopeComponent.class, ModuleScopeComponentImpl.class, sourceScope); + Component targetComponent = createNonIntrospectedComponent("target", ModuleScopeComponent.class, ModuleScopeComponentImpl.class, targetScope); + + Service targetService = factory.createService(); + JavaServiceContract targetContract = factory.createJavaServiceContract(); + targetContract.setInterface(GenericComponent.class); + targetService.setServiceContract(targetContract); + targetService.setName("GenericComponent"); + targetContract.setScope(targetScope); + ConfiguredService cTargetService = factory.createConfiguredService(); + cTargetService.setPort(targetService); + cTargetService.initialize(assemblyContext); + targetComponent.getConfiguredServices().add(cTargetService); + targetComponent.initialize(assemblyContext); + + Reference ref = factory.createReference(); + ref.setName("setGenericComponent"); + JavaServiceContract inter = factory.createJavaServiceContract(); + inter.setInterface(GenericComponent.class); + ref.setServiceContract(inter); + sourceComponent.getImplementation().getComponentType().getReferences().add(ref); + + ConfiguredReference cref = factory.createConfiguredReference("setGenericComponent", "target"); + cref.initialize(assemblyContext); + sourceComponent.getConfiguredReferences().add(cref); + sourceComponent.initialize(assemblyContext); + + Module module = factory.createModule(); + module.setName("test.module"); + module.getComponents().add(sourceComponent); + module.getComponents().add(targetComponent); + module.initialize(assemblyContext); + return module; + } + + /** + * Creates a module with a Java-based source component wired to a "target" external service configured + * with the {@link FooBinding} + */ + public static Module createModuleWithExternalService() throws ConfigurationLoadException { + Component sourceComponent = createComponent("source", HelloWorldClient.class, Scope.MODULE); + ExternalService targetES = createFooBindingExternalService("target", HelloWorldService.class); + + Service targetService = factory.createService(); + JavaServiceContract targetContract = factory.createJavaServiceContract(); + targetContract.setInterface(HelloWorldService.class); + targetService.setServiceContract(targetContract); + targetService.setName("HelloWorld"); + ConfiguredService cTargetService = factory.createConfiguredService(); + cTargetService.setPort(targetService); + targetES.setConfiguredService(cTargetService); + targetES.initialize(assemblyContext); + + Reference ref = factory.createReference(); + ref.setName("setHelloWorldService"); + JavaServiceContract inter = factory.createJavaServiceContract(); + inter.setInterface(HelloWorldService.class); + ref.setServiceContract(inter); + sourceComponent.getImplementation().getComponentType().getReferences().add(ref); + + ConfiguredReference cref = factory.createConfiguredReference(ref.getName(), "target"); + cref.initialize(assemblyContext); + sourceComponent.getConfiguredReferences().add(cref); + sourceComponent.initialize(assemblyContext); + + Module module = factory.createModule(); + module.setName("test.module"); + module.getComponents().add(sourceComponent); + module.getExternalServices().add(targetES); + module.initialize(assemblyContext); + return module; + } + + /** + * Creates a module with an entry point named "source" configured with the {@link FooBinding} wired to a + * service offered by a Java-based component named "target" + * + * @param scope the scope of the target service + */ + public static Module createModuleWithEntryPoint(Scope scope) throws ConfigurationLoadException { + Component targetComponent = createComponent("target", HelloWorldImpl.class, scope); + + Service targetService = factory.createService(); + JavaServiceContract targetContract = factory.createJavaServiceContract(); + targetContract.setInterface(HelloWorldService.class); + targetService.setServiceContract(targetContract); + targetService.setName("HelloWorldService"); + ConfiguredService cTargetService = factory.createConfiguredService(); + cTargetService.setPort(targetService); + targetComponent.getConfiguredServices().add(cTargetService); + targetComponent.initialize(assemblyContext); + + Reference ref = factory.createReference(); + ConfiguredReference cref = factory.createConfiguredReference(); + ref.setName("setHelloWorldService"); + JavaServiceContract inter = factory.createJavaServiceContract(); + inter.setInterface(HelloWorldService.class); + ref.setServiceContract(inter); + cref.setPort(ref); + cref.getTargetConfiguredServices().add(cTargetService); + cref.initialize(assemblyContext); + + EntryPoint sourceEP = createFooBindingEntryPoint("source", HelloWorldService.class); + sourceEP.setConfiguredReference(cref); + sourceEP.getConfiguredService().getPort().setName("HelloWorldService"); + sourceEP.initialize(assemblyContext); + + Module module = factory.createModule(); + module.setName("test.module"); + module.getEntryPoints().add(sourceEP); + module.getComponents().add(targetComponent); + module.setImplementationClass(CompositeContextImpl.class); + module.setComponentType(getCompositeComponentType()); + module.initialize(assemblyContext); + return module; + } + + /** + * Creates a module with an entry point wired to a "target" external service configured with the {@link + * FooBinding} + */ + public static Module createModuleWithEntryPointToExternalService() { + //Component sourceComponent = createComponent("source", HelloWorldClient.class, Scope.MODULE); + + EntryPoint sourceEP = createFooBindingEntryPoint("source", HelloWorldService.class); + sourceEP.getConfiguredService().getPort().setName("HelloWorldService"); + sourceEP.initialize(assemblyContext); + + + ExternalService targetES = createFooBindingExternalService("target", HelloWorldService.class); + + Service targetService = factory.createService(); + JavaServiceContract targetContract = factory.createJavaServiceContract(); + targetContract.setInterface(HelloWorldService.class); + targetService.setServiceContract(targetContract); + targetService.setName("HelloWorld"); + ConfiguredService cTargetService = factory.createConfiguredService(); + cTargetService.setPort(targetService); + targetES.setConfiguredService(cTargetService); + targetES.initialize(assemblyContext); + + Reference ref = factory.createReference(); + ref.setName("setHelloWorldService"); + JavaServiceContract inter = factory.createJavaServiceContract(); + inter.setInterface(HelloWorldService.class); + ref.setServiceContract(inter); + + + ConfiguredReference cref = factory.createConfiguredReference(ref.getName(), "target"); + cref.setPort(ref); + cref.initialize(assemblyContext); + sourceEP.setConfiguredReference(cref); + sourceEP.initialize(assemblyContext); + + Module module = factory.createModule(); + module.setName("test.module"); + module.getEntryPoints().add(sourceEP); + module.getExternalServices().add(targetES); + module.initialize(assemblyContext); + return module; + } + + + /** + * Creates a test system module with source and target components wired together. + * + * @see org.apache.tuscany.core.mock.component.Source + * @see org.apache.tuscany.core.mock.component.Target + */ + + public static Module createModuleWithWiredComponents(Scope sourceScope, Scope targetScope) { + + // create the target component + AtomicComponent target = factory.createSimpleComponent(); + target.setName("target"); + JavaImplementation targetImpl = factory.createJavaImplementation(); + targetImpl.setComponentType(factory.createComponentType()); + targetImpl.setImplementationClass(TargetImpl.class); + target.setImplementation(targetImpl); + Service targetService = factory.createService(); + JavaServiceContract targetContract = factory.createJavaServiceContract(); + targetContract.setInterface(Target.class); + targetService.setServiceContract(targetContract); + targetService.setName("Target"); + targetImpl.getComponentType().getServices().add(targetService); + targetContract.setScope(targetScope); + ConfiguredService cTargetService = factory.createConfiguredService(); + cTargetService.setPort(targetService); + cTargetService.initialize(assemblyContext); + target.getConfiguredServices().add(cTargetService); + target.initialize(assemblyContext); + + // create the source component + AtomicComponent source = factory.createSimpleComponent(); + ComponentType componentType = factory.createComponentType(); + source.setName("source"); + JavaImplementation impl = factory.createJavaImplementation(); + impl.setComponentType(componentType); + impl.setImplementationClass(SourceImpl.class); + source.setImplementation(impl); + Service s = systemFactory.createService(); + JavaServiceContract contract = systemFactory.createJavaServiceContract(); + contract.setInterface(Source.class); + s.setServiceContract(contract); + contract.setScope(sourceScope); + impl.getComponentType().getServices().add(s); + source.setImplementation(impl); + + // wire source to target + JavaServiceContract refContract = systemFactory.createJavaServiceContract(); + refContract.setInterface(Target.class); + Reference reference = systemFactory.createReference(); + reference.setName("setTarget"); + reference.setServiceContract(refContract); + componentType.getReferences().add(reference); + ConfiguredReference cReference = systemFactory.createConfiguredReference(reference.getName(), "target"); + cReference.initialize(assemblyContext); + source.getConfiguredReferences().add(cReference); + + // wire multiplicity using a setter + JavaServiceContract refContract2 = systemFactory.createJavaServiceContract(); + refContract2.setInterface(Target.class); + Reference reference2 = systemFactory.createReference(); + reference2.setName("setTargets"); + reference2.setServiceContract(refContract2); + reference2.setMultiplicity(Multiplicity.ONE_N); + componentType.getReferences().add(reference2); + ConfiguredReference cReference2 = systemFactory.createConfiguredReference(reference2.getName(), "target"); + cReference2.initialize(assemblyContext); + source.getConfiguredReferences().add(cReference2); + + // wire multiplicity using a field + JavaServiceContract refContract3 = systemFactory.createJavaServiceContract(); + refContract3.setInterface(Target.class); + Reference reference3 = systemFactory.createReference(); + reference3.setName("targetsThroughField"); + reference3.setServiceContract(refContract3); + reference3.setMultiplicity(Multiplicity.ONE_N); + componentType.getReferences().add(reference3); + ConfiguredReference cReference3 = systemFactory.createConfiguredReference(reference3.getName(), "target"); + cReference3.initialize(assemblyContext); + source.getConfiguredReferences().add(cReference3); + + // wire multiplicity using a array + JavaServiceContract refContract4 = systemFactory.createJavaServiceContract(); + refContract4.setInterface(Target.class); + Reference reference4 = systemFactory.createReference(); + reference4.setName("setArrayOfTargets"); + reference4.setServiceContract(refContract4); + reference4.setMultiplicity(Multiplicity.ONE_N); + componentType.getReferences().add(reference4); + ConfiguredReference cReference4 = systemFactory.createConfiguredReference(reference4.getName(), "target"); + cReference4.initialize(assemblyContext); + source.getConfiguredReferences().add(cReference4); + + source.initialize(assemblyContext); + + Module module = systemFactory.createModule(); + module.setName("system.module"); + + module.getComponents().add(source); + module.getComponents().add(target); + module.initialize(assemblyContext); + return module; + } + + + /** + * Creates a test system module with source and target components wired together. + * + * @see org.apache.tuscany.core.mock.component.Source + * @see org.apache.tuscany.core.mock.component.Target + */ + + public static Module createModuleWithWiredComponentsOfDifferentInterface(Scope sourceScope, Scope targetScope) { + + // create the target component + AtomicComponent target = factory.createSimpleComponent(); + target.setName("target"); + JavaImplementation targetImpl = factory.createJavaImplementation(); + targetImpl.setComponentType(factory.createComponentType()); + targetImpl.setImplementationClass(OtherTargetImpl.class); + target.setImplementation(targetImpl); + Service targetService = factory.createService(); + JavaServiceContract targetContract = factory.createJavaServiceContract(); + targetContract.setInterface(OtherTarget.class); + targetService.setServiceContract(targetContract); + targetService.setName("Target"); + targetImpl.getComponentType().getServices().add(targetService); + targetContract.setScope(targetScope); + ConfiguredService cTargetService = factory.createConfiguredService(); + cTargetService.setPort(targetService); + cTargetService.initialize(assemblyContext); + target.getConfiguredServices().add(cTargetService); + target.initialize(assemblyContext); + + // create the source component + AtomicComponent source = factory.createSimpleComponent(); + ComponentType componentType = factory.createComponentType(); + source.setName("source"); + JavaImplementation impl = factory.createJavaImplementation(); + impl.setComponentType(componentType); + impl.setImplementationClass(SourceImpl.class); + source.setImplementation(impl); + Service s = systemFactory.createService(); + JavaServiceContract contract = systemFactory.createJavaServiceContract(); + contract.setInterface(Source.class); + s.setServiceContract(contract); + contract.setScope(sourceScope); + impl.getComponentType().getServices().add(s); + source.setImplementation(impl); + + // wire source to target + JavaServiceContract refContract = systemFactory.createJavaServiceContract(); + refContract.setInterface(Target.class); + Reference reference = systemFactory.createReference(); + reference.setName("setTarget"); + reference.setServiceContract(refContract); + componentType.getReferences().add(reference); + ConfiguredReference cReference = systemFactory.createConfiguredReference(reference.getName(), "target"); + cReference.initialize(assemblyContext); + source.getConfiguredReferences().add(cReference); + + // wire multiplicity using a setter + JavaServiceContract refContract2 = systemFactory.createJavaServiceContract(); + refContract2.setInterface(Target.class); + Reference reference2 = systemFactory.createReference(); + reference2.setName("setTargets"); + reference2.setServiceContract(refContract2); + reference2.setMultiplicity(Multiplicity.ONE_N); + componentType.getReferences().add(reference2); + ConfiguredReference cReference2 = systemFactory.createConfiguredReference(reference2.getName(), "target"); + cReference2.initialize(assemblyContext); + source.getConfiguredReferences().add(cReference2); + + // wire multiplicity using a field + JavaServiceContract refContract3 = systemFactory.createJavaServiceContract(); + refContract3.setInterface(Target.class); + Reference reference3 = systemFactory.createReference(); + reference3.setName("targetsThroughField"); + reference3.setServiceContract(refContract3); + reference3.setMultiplicity(Multiplicity.ONE_N); + componentType.getReferences().add(reference3); + ConfiguredReference cReference3 = systemFactory.createConfiguredReference(reference3.getName(), "target"); + cReference3.initialize(assemblyContext); + source.getConfiguredReferences().add(cReference3); + + // wire multiplicity using a array + JavaServiceContract refContract4 = systemFactory.createJavaServiceContract(); + refContract4.setInterface(Target.class); + Reference reference4 = systemFactory.createReference(); + reference4.setName("setArrayOfTargets"); + reference4.setServiceContract(refContract4); + reference4.setMultiplicity(Multiplicity.ONE_N); + componentType.getReferences().add(reference4); + ConfiguredReference cReference4 = systemFactory.createConfiguredReference(reference4.getName(), "target"); + cReference4.initialize(assemblyContext); + source.getConfiguredReferences().add(cReference4); + + source.initialize(assemblyContext); + + Module module = systemFactory.createModule(); + module.setName("system.module"); + + module.getComponents().add(source); + module.getComponents().add(target); + module.initialize(assemblyContext); + return module; + } + + + /** + * Returns a collection of bootstrap configuration builders + */ + public static List createSystemBuilders() { + List builders = new ArrayList(); + builders.add((new SystemContextFactoryBuilder(null))); + builders.add(new SystemEntryPointBuilder()); + builders.add(new SystemExternalServiceBuilder()); + return builders; + } + + /** + * Creates an composite context faxtory + * + * @param name the name of the component + * @throws BuilderException + * @see ContextFactory + */ + public static ContextFactory createCompositeConfiguration(String name + ) throws BuilderException, ConfigurationLoadException { + + Component sc = createCompositeComponent(name); + SystemContextFactoryBuilder builder = new SystemContextFactoryBuilder(null); + builder.build(sc); + return (ContextFactory) sc.getContextFactory(); + } + + /** + * Creates a Java POJO component context + * + * @param name the name of the context + * @param implType the POJO class + * @param scope the component scope + * @param moduleComponentContext the containing composite context + * @throws NoSuchMethodException if the POJO does not have a default noi-args constructor + */ + public static JavaAtomicContext createPojoContext(String name, Class implType, Scope scope, + CompositeContext moduleComponentContext) throws NoSuchMethodException, ConfigurationLoadException { + AtomicComponent component = createComponent(name, implType, scope); + + Set fields = JavaIntrospectionHelper.getAllFields(implType); + Set methods = JavaIntrospectionHelper.getAllUniqueMethods(implType); + List injectors = new ArrayList(); + + EventInvoker initInvoker = null; + boolean eagerInit = false; + EventInvoker destroyInvoker = null; + for (Field field : fields) { + ComponentName compName = field.getAnnotation(ComponentName.class); + if (compName != null) { + Injector injector = new FieldInjector(field, new SingletonObjectFactory(name)); + injectors.add(injector); + } + org.osoa.sca.annotations.Context context = field.getAnnotation(org.osoa.sca.annotations.Context.class); + if (context != null) { + Injector injector = new FieldInjector(field, new SingletonObjectFactory(moduleComponentContext)); + injectors.add(injector); + } + } + for (Method method : methods) { + // FIXME Java5 + Init init = method.getAnnotation(Init.class); + if (init != null && initInvoker == null) { + initInvoker = new MethodEventInvoker(method); + eagerInit = init.eager(); + continue; + } + Destroy destroy = method.getAnnotation(Destroy.class); + if (destroy != null && destroyInvoker == null) { + destroyInvoker = new MethodEventInvoker(method); + continue; + } + ComponentName compName = method.getAnnotation(ComponentName.class); + if (compName != null) { + Injector injector = new MethodInjector(method, new SingletonObjectFactory(name)); + injectors.add(injector); + } + org.osoa.sca.annotations.Context context = method.getAnnotation(org.osoa.sca.annotations.Context.class); + if (context != null) { + Injector injector = new MethodInjector(method, new SingletonObjectFactory(moduleComponentContext)); + injectors.add(injector); + } + } + boolean stateless = (scope == Scope.INSTANCE); + return new JavaAtomicContext("foo", new PojoObjectFactory(JavaIntrospectionHelper + .getDefaultConstructor(implType), null, injectors), eagerInit, initInvoker, destroyInvoker, stateless); + } + + /** + * Creates a default {@link RuntimeContext} configured with support for Java component implementations + * + * @throws ConfigurationException + */ + public static RuntimeContext createJavaRuntime() throws ConfigurationException { + MonitorFactory monitorFactory = new NullMonitorFactory(); + ContextFactoryBuilderRegistry builderRegistry = BootstrapHelper.bootstrapContextFactoryBuilders(monitorFactory); + DefaultWireBuilder wireBuilder = new DefaultWireBuilder(); + RuntimeContext runtime = new RuntimeContextImpl(monitorFactory, builderRegistry, wireBuilder); + runtime.start(); + runtime.getSystemContext().registerModelObject(createSystemCompositeComponent(SYSTEM_CHILD)); + SystemCompositeContext ctx = (SystemCompositeContext) runtime.getSystemContext().getContext(SYSTEM_CHILD); + Component comp = systemFactory.createSystemComponent(POLICY_BUILDER_REGISTRY, PolicyBuilderRegistry.class, DefaultPolicyBuilderRegistry.class, Scope.MODULE); + comp.getImplementation().setComponentType(getIntrospector().introspect(DefaultPolicyBuilderRegistry.class)); + ctx.registerModelObject(comp); + comp = systemFactory.createSystemComponent(MESSAGE_FACTORY, MessageFactory.class, MessageFactoryImpl.class, Scope.MODULE); + comp.getImplementation().setComponentType(getIntrospector().introspect(MessageFactoryImpl.class)); + ctx.registerModelObject(comp); + comp = systemFactory.createSystemComponent(PROXY_FACTORY_FACTORY, WireFactoryFactory.class, JDKWireFactoryFactory.class, Scope.MODULE); + comp.getImplementation().setComponentType(getIntrospector().introspect(JDKWireFactoryFactory.class)); + ctx.registerModelObject(comp); + comp = systemFactory.createSystemComponent(WIRE_FACTORY_SERVICE, org.apache.tuscany.core.wire.service.WireFactoryService.class, DefaultWireFactoryService.class, Scope.MODULE); + comp.getImplementation().setComponentType(getIntrospector().introspect(DefaultWireFactoryService.class)); + ctx.registerModelObject(comp); + comp = systemFactory.createSystemComponent(JAVA_BUILDER, ContextFactoryBuilder.class, JavaContextFactoryBuilder.class, Scope.MODULE); + comp.getImplementation().setComponentType(getIntrospector().introspect(JavaContextFactoryBuilder.class)); + ctx.registerModelObject(comp); + comp = systemFactory.createSystemComponent(JAVA_WIRE_BUILDER, WireBuilder.class, JavaTargetWireBuilder.class, Scope.MODULE); + comp.getImplementation().setComponentType(getIntrospector().introspect(JavaTargetWireBuilder.class)); + ctx.registerModelObject(comp); + ctx.publish(new ModuleStart(new Object())); + return runtime; + } + + /** + * Registers the {@link FooBinding} builders with a given runtime + * + * @throws ConfigurationException + */ + public static RuntimeContext registerFooBinding(RuntimeContext runtime) throws ConfigurationException { + CompositeContext child = (CompositeContext) runtime.getSystemContext().getContext(MockFactory.SYSTEM_CHILD); + child.getContext(MockFactory.JAVA_BUILDER).getInstance(null); + Component comp = systemFactory.createSystemComponent(FOO_BUILDER, ContextFactoryBuilder.class, FooBindingBuilder.class, Scope.MODULE); + comp.getImplementation().setComponentType(getIntrospector().introspect(FooBindingBuilder.class)); + child.registerModelObject(comp); + comp = systemFactory.createSystemComponent(FOO_WIRE_BUILDER, WireBuilder.class, FooBindingWireBuilder.class, Scope.MODULE); + comp.getImplementation().setComponentType(getIntrospector().introspect(FooBindingWireBuilder.class)); + child.registerModelObject(comp); + // since the child context is already started, we need to manually retrieve the components to init them + Assert.assertNotNull(child.getContext(FOO_BUILDER).getInstance(null)); + Assert.assertNotNull(child.getContext(FOO_WIRE_BUILDER).getInstance(null)); + return runtime; + } + + +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/MockScopeContext.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/MockScopeContext.java new file mode 100644 index 0000000000..fe128f19a7 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/MockScopeContext.java @@ -0,0 +1,131 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.mock; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.tuscany.container.java.invocation.mock.SimpleTargetImpl; +import org.apache.tuscany.core.builder.ContextFactory; +import org.apache.tuscany.core.context.AtomicContext; +import org.apache.tuscany.core.context.Context; +import org.apache.tuscany.core.context.ContextRuntimeException; +import org.apache.tuscany.core.context.EventFilter; +import org.apache.tuscany.core.context.QualifiedName; +import org.apache.tuscany.core.context.RuntimeEventListener; +import org.apache.tuscany.core.context.ScopeContext; +import org.apache.tuscany.core.context.ScopeRuntimeException; +import org.apache.tuscany.core.context.event.Event; +import org.apache.tuscany.model.assembly.AtomicComponent; + +public class MockScopeContext implements ScopeContext { + + Map components; + + public MockScopeContext() { + components = new HashMap(); + components.put("foo", new SimpleTargetImpl()); + components.put("bar", new SimpleTargetImpl()); + } + + public MockScopeContext(Map instances) { + components = instances; + } + + + public void start() { + } + + public void stop() { + } + + public void publish(Event object) { + //To change body of implemented methods use File | Settings | File Templates. + } + + public void addListener(RuntimeEventListener listener) throws ContextRuntimeException { + } + + public void addListener(EventFilter filter, RuntimeEventListener listener) { + //To change body of implemented methods use File | Settings | File Templates. + } + + public void removeListener(RuntimeEventListener listener) throws ContextRuntimeException { + } + + public String getName() { + return "Mock Scope Container"; + } + + public boolean isCacheable() { + return false; + } + + public int[] getEventTypes() { + return null; + } + + public AtomicContext getContext(String name) { + return null; + } + + public Object getInstance(QualifiedName name) throws ScopeRuntimeException { + return components.get(name.getPartName()); + } + + public AtomicContext getContextByKey(String name, Object key) { + return null; + } + + public void setComponent(AtomicComponent component) throws ScopeRuntimeException { + } + + public void removeContext(String name) throws ScopeRuntimeException { + } + + public void removeContextByKey(String name, Object key) throws ScopeRuntimeException { + } + + public AtomicComponent[] getComponents() { + return null; + } + + public void registerFactories(List> configurations) { + } + + public void registerFactory(ContextFactory configuration) { + } + + public int getLifecycleState(){ + return RUNNING; + } + + + public void setLifecycleState(int state) { + } + + + public void setName(String name) { + } + + + public void onEvent(Event event) { + //To change body of implemented methods use File | Settings | File Templates. + } +} + diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/binding/foo/FooBinding.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/binding/foo/FooBinding.java new file mode 100644 index 0000000000..49c59bc718 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/binding/foo/FooBinding.java @@ -0,0 +1,58 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package org.apache.tuscany.container.java.mock.binding.foo; + +import org.apache.tuscany.model.assembly.AssemblyContext; +import org.apache.tuscany.model.assembly.AssemblyVisitor; +import org.apache.tuscany.model.assembly.Binding; + +/** + * Represents a mock binding that echoes back a single parameter + * + * @version $Rev$ $Date$ + */ +public class FooBinding implements Binding { + + public FooBinding() { + } + + public String getURI() { + return null; + } + + public void setURI(String value) { + } + + public void initialize(AssemblyContext modelContext) { + } + + public void freeze() { + } + + public boolean accept(AssemblyVisitor visitor) { + return true; + } + + private Object contextFactory; + + public void setContextFactory(Object factory) { + contextFactory = factory; + } + + public Object getContextFactory() { + System.out.println("retting"); + return contextFactory; + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/binding/foo/FooBindingBuilder.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/binding/foo/FooBindingBuilder.java new file mode 100644 index 0000000000..558a8ce2cf --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/binding/foo/FooBindingBuilder.java @@ -0,0 +1,114 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package org.apache.tuscany.container.java.mock.binding.foo; + +import org.apache.tuscany.core.builder.BuilderException; +import org.apache.tuscany.core.builder.ContextFactoryBuilder; +import org.apache.tuscany.core.builder.ContextFactoryBuilderRegistry; +import org.apache.tuscany.core.builder.ObjectFactory; +import org.apache.tuscany.core.extension.EntryPointContextFactory; +import org.apache.tuscany.core.injection.ObjectCreationException; +import org.apache.tuscany.core.message.MessageFactory; +import org.apache.tuscany.core.system.annotation.Autowire; +import org.apache.tuscany.core.wire.SourceWireFactory; +import org.apache.tuscany.core.wire.TargetWireFactory; +import org.apache.tuscany.core.wire.service.WireFactoryService; +import org.apache.tuscany.model.assembly.AssemblyObject; +import org.apache.tuscany.model.assembly.ConfiguredService; +import org.apache.tuscany.model.assembly.EntryPoint; +import org.apache.tuscany.model.assembly.ExternalService; +import org.apache.tuscany.model.assembly.Service; +import org.osoa.sca.annotations.Init; +import org.osoa.sca.annotations.Scope; + +/** + * Creates a ContextFactoryBuilder for an entry point or external service configured with the {@link FooBinding} + * + * @version $Rev$ $Date$ + */ +@Scope("MODULE") +public class FooBindingBuilder implements ContextFactoryBuilder { + private ContextFactoryBuilderRegistry builderRegistry; + + private MessageFactory messageFactory; + + private WireFactoryService wireFactoryService; + + public FooBindingBuilder(WireFactoryService wireFactoryService) { + this.wireFactoryService = wireFactoryService; + } + + public FooBindingBuilder() { + } + + @Init(eager = true) + public void init() { + builderRegistry.register(this); + } + + @Autowire + public void setBuilderRegistry(ContextFactoryBuilderRegistry builderRegistry) { + this.builderRegistry = builderRegistry; + } + + @Autowire + public void setWireFactoryService(WireFactoryService wireFactoryService) { + this.wireFactoryService = wireFactoryService; + } + + + /** + * Sets the factory used to construct wire messages + * + * @param msgFactory + */ + @Autowire + public void setMessageFactory(MessageFactory msgFactory) { + this.messageFactory = msgFactory; + } + + public void build(AssemblyObject object) throws BuilderException { + if (object instanceof EntryPoint) { + EntryPoint ep = (EntryPoint) object; + if (ep.getBindings().size() < 1 || !(ep.getBindings().get(0) instanceof FooBinding)) { + return; + } + EntryPointContextFactory contextFactory = new FooEntryPointContextFactory(ep.getName(), messageFactory); + ConfiguredService configuredService = ep.getConfiguredService(); + Service service = configuredService.getPort(); + SourceWireFactory wireFactory = wireFactoryService.createSourceFactory(ep.getConfiguredReference()).get(0); + contextFactory.addSourceWireFactory(service.getName(), wireFactory); + ep.setContextFactory(contextFactory); + } else if (object instanceof ExternalService) { + ExternalService es = (ExternalService) object; + if (es.getBindings().size() < 1 || !(es.getBindings().get(0) instanceof FooBinding)) { + return; + } + FooExternalServiceContextFactory contextFactory = new FooExternalServiceContextFactory(es.getName(), + new FooClientFactory()); + ConfiguredService configuredService = es.getConfiguredService(); + Service service = configuredService.getPort(); + TargetWireFactory wireFactory = wireFactoryService.createTargetFactory(configuredService); + contextFactory.addTargetWireFactory(service.getName(), wireFactory); + es.setContextFactory(contextFactory); + } + } + + private static class FooClientFactory implements ObjectFactory { + + public Object getInstance() throws ObjectCreationException { + return new FooClient(); + } + } +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/binding/foo/FooBindingWireBuilder.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/binding/foo/FooBindingWireBuilder.java new file mode 100644 index 0000000000..e2592024f8 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/binding/foo/FooBindingWireBuilder.java @@ -0,0 +1,76 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.mock.binding.foo; + +import org.apache.tuscany.core.builder.BuilderConfigException; +import org.apache.tuscany.core.builder.WireBuilder; +import org.apache.tuscany.core.context.ScopeContext; +import org.apache.tuscany.core.runtime.RuntimeContext; +import org.apache.tuscany.core.system.annotation.Autowire; +import org.apache.tuscany.core.wire.SourceInvocationConfiguration; +import org.apache.tuscany.core.wire.SourceWireFactory; +import org.apache.tuscany.core.wire.TargetInvocationConfiguration; +import org.apache.tuscany.core.wire.TargetInvoker; +import org.apache.tuscany.core.wire.TargetWireFactory; +import org.osoa.sca.annotations.Init; + +public class FooBindingWireBuilder implements WireBuilder { + + public FooBindingWireBuilder() { + super(); + } + + private RuntimeContext runtimeContext; + + @Autowire + public void setRuntimeContext(RuntimeContext context) { + runtimeContext = context; + } + + @Init(eager = true) + public void init() { + runtimeContext.addBuilder(this); + } + + + public void connect(SourceWireFactory sourceFactory, TargetWireFactory targetFactory, Class targetType, boolean downScope, + ScopeContext targetScopeContext) throws BuilderConfigException { + if (!FooExternalServiceContextFactory.class.isAssignableFrom(targetType)) { + return; + } + for (SourceInvocationConfiguration sourceInvocationConfig : sourceFactory.getConfiguration().getInvocationConfigurations() + .values()) { + FooExternalServiceTargetInvoker invoker = new FooExternalServiceTargetInvoker(sourceFactory.getConfiguration().getTargetName() + .getPartName()); + sourceInvocationConfig.setTargetInvoker(invoker); + } + + } + + public void completeTargetChain(TargetWireFactory targetFactory, Class targetType, ScopeContext targetScopeContext) + throws BuilderConfigException { + if (FooExternalServiceContextFactory.class.isAssignableFrom(targetType)) { + for (TargetInvocationConfiguration targetInvocationConfig : targetFactory.getConfiguration().getInvocationConfigurations() + .values()) { + TargetInvoker invoker = new FooExternalServiceTargetInvoker(targetFactory.getConfiguration().getTargetName().getQualifiedName()); + targetInvocationConfig.setTargetInvoker(invoker); + } + + } + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/binding/foo/FooClient.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/binding/foo/FooClient.java new file mode 100644 index 0000000000..9f67eb7786 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/binding/foo/FooClient.java @@ -0,0 +1,37 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package org.apache.tuscany.container.java.mock.binding.foo; + +import java.lang.reflect.Array; + +import org.apache.tuscany.core.context.TargetException; + +/** + * A mock client for a transport binding + * + * @version $Rev$ $Date$ + */ +public class FooClient { + + public FooClient() { + } + + public Object invoke(Object msg) { + if (msg!=null && msg.getClass().isArray() && Array.getLength(msg) == 1){ + return Array.get(msg,0); + }else{ + throw new TargetException("This binding only understands operations with a single parameter"); + } + } +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/binding/foo/FooEntryPointContextFactory.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/binding/foo/FooEntryPointContextFactory.java new file mode 100644 index 0000000000..69d81f66be --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/binding/foo/FooEntryPointContextFactory.java @@ -0,0 +1,31 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package org.apache.tuscany.container.java.mock.binding.foo; + +import org.apache.tuscany.core.extension.EntryPointContextFactory; +import org.apache.tuscany.core.message.MessageFactory; + +/** + * + * + * @version $Rev$ $Date$ + */ +public class FooEntryPointContextFactory extends EntryPointContextFactory { + + public FooEntryPointContextFactory(String name, MessageFactory msgFactory) { + super(name, msgFactory); + } + +} + diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/binding/foo/FooExternalServiceContextFactory.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/binding/foo/FooExternalServiceContextFactory.java new file mode 100644 index 0000000000..c7f67e2ff2 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/binding/foo/FooExternalServiceContextFactory.java @@ -0,0 +1,32 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package org.apache.tuscany.container.java.mock.binding.foo; + +import org.apache.tuscany.core.builder.ObjectFactory; +import org.apache.tuscany.core.extension.ExternalServiceContextFactory; + +/** + * Creates instances of {@link org.apache.tuscany.core.context.ExternalServiceContext} configured with the appropriate + * wire chains and bindings. This implementation serves as a marker for + * {@link org.apache.tuscany.container.java.mock.binding.foo.FooBindingWireBuilder} + * + * @version $Rev$ $Date$ + */ +public class FooExternalServiceContextFactory extends ExternalServiceContextFactory { + + public FooExternalServiceContextFactory(String name, ObjectFactory objectFactory) { + super(name, objectFactory); + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/binding/foo/FooExternalServiceTargetInvoker.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/binding/foo/FooExternalServiceTargetInvoker.java new file mode 100644 index 0000000000..ecc9655a10 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/binding/foo/FooExternalServiceTargetInvoker.java @@ -0,0 +1,78 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package org.apache.tuscany.container.java.mock.binding.foo; + +import org.apache.tuscany.core.context.ExternalServiceContext; +import org.apache.tuscany.core.message.Message; +import org.apache.tuscany.core.wire.Interceptor; +import org.apache.tuscany.core.wire.TargetInvoker; + +import java.lang.reflect.InvocationTargetException; + +/** + * Responsible for invoking a mock transport binding client configured for an external service over a wire + * + * @version $Rev$ $Date$ + */ +public class FooExternalServiceTargetInvoker implements TargetInvoker { + + private String name; + private ExternalServiceContext context; + + public FooExternalServiceTargetInvoker(String esName) { + assert (esName != null) : "No external service name specified"; + name = esName; // name is not used; it is included for illustration + } + + public Object invokeTarget(Object payload) throws InvocationTargetException { + FooClient client = new FooClient(); + if (payload != null) { + return client.invoke(payload); + } else { + return client.invoke(null); + } + } + + public boolean isCacheable() { + return false; + } + + public Message invoke(Message msg) { + try { + Object resp = invokeTarget(msg.getBody()); + msg.setBody(resp); + } catch (InvocationTargetException e) { + msg.setBody(e.getCause()); + } catch (Throwable e) { + msg.setBody(e); + } + return msg; + } + + public void setNext(Interceptor next) { + throw new UnsupportedOperationException(); + } + + public Object clone() throws CloneNotSupportedException { + try { + FooExternalServiceTargetInvoker invoker = (FooExternalServiceTargetInvoker) super.clone(); + invoker.context = this.context; + invoker.name = this.name; + return invoker; + } catch (CloneNotSupportedException e) { + return null; // will not happen + } + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/AbstractGenericComponent.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/AbstractGenericComponent.java new file mode 100644 index 0000000000..0c9d8172f8 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/AbstractGenericComponent.java @@ -0,0 +1,296 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.mock.components; + +import java.util.List; +import java.util.Map; + +import org.osoa.sca.ModuleContext; +import org.osoa.sca.annotations.ComponentName; +import org.osoa.sca.annotations.Context; +import org.osoa.sca.annotations.Property; + +/** + * Base test component implementation + * + * @version $Rev$ $Date$ + */ +public class AbstractGenericComponent implements GenericComponent { + + @ComponentName + private String name; + + public String getName() { + return name; + } + + @Context + private ModuleContext context; + + public ModuleContext getModuleContext() { + return context; + } + + //---------------------------------- + // Collections + //---------------------------------- + + Map testMap; + + public Map getTestMap() { + return testMap; + } + + public void setTestMap(Map testMap) { + this.testMap = testMap; + } + + List testList; + + public List getTestList() { + return testList; + } + + public void setTestList(List testList) { + this.testList = testList; + } + + //---------------------------------- + // Arrays + //---------------------------------- + + private int[] arrayInt; + + public int[] getArrayInt() { + return arrayInt; + } + + public void setArrayInt(int[] arrayInt) { + this.arrayInt = arrayInt; + } + + private float[] arrayFloat; + + public float[] getArrayFloat() { + return arrayFloat; + } + + public void setArrayFloat(float[] pArrayFloat) { + arrayFloat = pArrayFloat; + } + + private double[] arrayDouble; + + public double[] getArrayDouble() { + return arrayDouble; + } + + public void setArrayDouble(double[] pArrayDouble) { + arrayDouble = pArrayDouble; + } + + private long[] arrayLong; + + public long[] getArrayLong() { + return arrayLong; + } + + public void setArrayLong(long[] arrayLong) { + this.arrayLong = arrayLong; + } + + private short[] arrayShort; + + public short[] getArrayShort() { + return arrayShort; + } + + public void setArrayShort(short[] arrayShort) { + this.arrayShort = arrayShort; + } + + private boolean[] arrayBoolean; + + public boolean[] getArrayBoolean() { + return arrayBoolean; + } + + public void setArrayBoolean(boolean[] arrayBoolean) { + this.arrayBoolean = arrayBoolean; + } + + private String[] arrayString; + + public String[] getArrayString() { + return arrayString; + } + + public void setArrayString(String[] arrayString) { + this.arrayString = arrayString; + } + + //---------------------------------- + // Primitives + //---------------------------------- + + private boolean mBoolean; + + public boolean getBoolean() { + return mBoolean; + } + + public void setBoolean(boolean pBoolean) { + mBoolean = pBoolean; + } + + private short mShort; + + public short getShort() { + return mShort; + } + + public void setShort(short pShort) { + mShort = pShort; + } + + private int mInt; + + public int getInt() { + return mInt; + } + + public void setInt(int pInt) { + mInt = pInt; + } + + private long mLong; + + public long getLong() { + return mLong; + } + + public void setLong(long pLong) { + mLong = pLong; + } + + private double mDouble; + + public double getDouble() { + return mDouble; + } + + public void setDouble(double pDouble) { + mDouble = pDouble; + } + + private float mFloat; + + public float getFloat() { + return mFloat; + } + + public void setFloat(float pFloat) { + mFloat = pFloat; + } + + private char mChar; + + public char getChar() { + return mChar; + } + + public void setChar(char pChar) { + mChar = pChar; + } + + //---------------------------------- + // Object types + //---------------------------------- + + private String mString; + + public String getString() { + return mString; + } + + public void setString(String pString) { + mString = pString; + } + + private Short mOShort; + + public Short getOShort() { + return mOShort; + } + + public void setOShort(Short pOShort) { + mOShort = pOShort; + } + + private Integer mOInteger; + + public Integer getOInteger() { + return mOInteger; + } + + public void setOInteger(Integer pOInteger) { + mOInteger = pOInteger; + } + + private Long mOLong; + + public Long getOLong() { + return mOLong; + } + + public void setOLong(Long pOLong) { + mOLong = pOLong; + } + + private Float mOFloat; + + public Float getOFloat() { + return mOFloat; + } + + public void setOFloat(Float pOFloat) { + mOFloat = pOFloat; + } + + private Double mODouble; + + public Double getODouble() { + return mODouble; + } + + public void setODouble(Double pODouble) { + mODouble = pODouble; + } + + @Property(name = "genericComponent") + private GenericComponent mGenericComponent; + + public GenericComponent getGenericComponent() { + return mGenericComponent; + } + + public void setGenericComponent(GenericComponent pGenericComponent) { + mGenericComponent = pGenericComponent; + } + + +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/BadContextPojo.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/BadContextPojo.java new file mode 100644 index 0000000000..7840b57dea --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/BadContextPojo.java @@ -0,0 +1,26 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.mock.components; + +import org.osoa.sca.annotations.Context; + +public class BadContextPojo { + + @Context + String moduleContext; + +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/BadNamePojo.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/BadNamePojo.java new file mode 100644 index 0000000000..d9753fa9f0 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/BadNamePojo.java @@ -0,0 +1,24 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.mock.components; + +import org.osoa.sca.annotations.ComponentName; + +public class BadNamePojo { + @ComponentName + private int name; +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/DataObject.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/DataObject.java new file mode 100644 index 0000000000..695cc2a5a1 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/DataObject.java @@ -0,0 +1,38 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.mock.components; + +import java.io.Serializable; + +/** + * A complex type for testing + * + * @version $Rev$ $Date$ + */ +public class DataObject implements Serializable { + + private String stringValue; + + public String getStringValue() { + return stringValue; + } + + public void setStringValue(String stringValue) { + this.stringValue = stringValue; + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/GenericComponent.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/GenericComponent.java new file mode 100644 index 0000000000..44f1c02bfd --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/GenericComponent.java @@ -0,0 +1,142 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.mock.components; + +import java.util.List; +import java.util.Map; + +import org.osoa.sca.ModuleContext; + +/** + * Generic test component + * + * @version $Rev$ $Date$ + */ +public interface GenericComponent { + + public String getName(); + + public ModuleContext getModuleContext(); + + // ---------------------------------- + // Collections + // ---------------------------------- + + public Map getTestMap(); + + public void setTestMap(Map pTestMap); + + public List getTestList(); + + public void setTestList(List pTestList); + + // ---------------------------------- + // Arrays + // ---------------------------------- + + public int[] getArrayInt(); + + public void setArrayInt(int[] pArrayInt); + + public float[] getArrayFloat(); + + public void setArrayFloat(float[] pArrayFloat); + + public double[] getArrayDouble(); + + public void setArrayDouble(double[] pArrayDouble); + + public long[] getArrayLong(); + + public void setArrayLong(long[] pArrayLong); + + public short[] getArrayShort(); + + public void setArrayShort(short[] pArrayShort); + + public boolean[] getArrayBoolean(); + + public void setArrayBoolean(boolean[] pArrayBoolean); + + public String[] getArrayString(); + + public void setArrayString(String[] pArrayString); + + // ---------------------------------- + // Primitives + // ---------------------------------- + + public boolean getBoolean(); + + public void setBoolean(boolean pBoolean); + + public short getShort(); + + public void setShort(short pShort); + + public int getInt(); + + public void setInt(int pInt); + + public long getLong(); + + public void setLong(long pLong); + + public double getDouble(); + + public void setDouble(double pDouble); + + public float getFloat(); + + public void setFloat(float pFloat); + + public char getChar(); + + public void setChar(char pChar); + + // ---------------------------------- + // Object types + // ---------------------------------- + + public String getString(); + + public void setString(String pString); + + public Short getOShort(); + + public void setOShort(Short pOShort); + + public Integer getOInteger(); + + public void setOInteger(Integer pOInteger); + + public Long getOLong(); + + public void setOLong(Long pOLong); + + public Float getOFloat(); + + public void setOFloat(Float pOFloat); + + public Double getODouble(); + + public void setODouble(Double pODouble); + + public GenericComponent getGenericComponent(); + + public void setGenericComponent(GenericComponent pGenericComponent); +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/HelloWorldClient.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/HelloWorldClient.java new file mode 100644 index 0000000000..1e7ca9f36b --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/HelloWorldClient.java @@ -0,0 +1,46 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package org.apache.tuscany.container.java.mock.components; + +import org.apache.tuscany.container.java.assembly.mock.HelloWorldService; + +/** + * + * + * @version $Rev$ $Date$ + */ +public class HelloWorldClient implements HelloWorldService{ + + private int count; + + public HelloWorldClient() { + } + + private HelloWorldService service; + + public void setHelloWorldService(HelloWorldService service){ + this.service = service; + } + + public String hello(String name) { + ++count; + return service.hello(name); + } + + public int count() { + return count; + } + +} + diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/LocalComponentImpl.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/LocalComponentImpl.java new file mode 100644 index 0000000000..4b57c7f301 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/LocalComponentImpl.java @@ -0,0 +1,97 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.mock.components; + +import org.osoa.sca.ModuleContext; +import org.osoa.sca.annotations.ComponentName; +import org.osoa.sca.annotations.Context; +import org.osoa.sca.annotations.Property; +import org.osoa.sca.annotations.Reference; + +/** + * A test local service + * + * @version $Rev$ $Date$ + */ + +public class LocalComponentImpl { + + @ComponentName + protected String name; + + public String getName() { + return name; + } + + @Context + protected ModuleContext moduleCtx; + + public ModuleContext getModuleContext() { + return moduleCtx; + } + + @Property(name = "fieldSetter", required = true) + private String mfieldSetter; + + public String getfieldSetter() { + return mfieldSetter; + } + + public void setfieldSetter(String pfieldSetter) throws Exception { + throw new Exception("Set method instead of field"); + } + + private String mMethodSetter; + boolean mSetByMethod; + + public String getMethodSetter() throws Exception { + if (mSetByMethod) { + return mMethodSetter; + } + throw new Exception("Property method setter failed"); + + } + + @Property(required = true) + public void setMethodSetter(String pMethodSetter) { + mSetByMethod = true; + mMethodSetter = pMethodSetter; + } + + @Reference(name = "requiredDataObject", required = true) + private DataObject mRequiredDataObject; + + public DataObject getRequiredDataObject() { + return mRequiredDataObject; + } + + public void setRequiredDataObject(DataObject pRequiredDataObject) { + mRequiredDataObject = pRequiredDataObject; + } + + @Reference(name = "optionalDataObject") + private DataObject mOptionalDataObject; + + public DataObject getOptionalDataObject() { + return mOptionalDataObject; + } + + public void setOptionalDataObject(DataObject pOptionalDataObject) { + mOptionalDataObject = pOptionalDataObject; + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/ModuleScopeComponent.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/ModuleScopeComponent.java new file mode 100644 index 0000000000..04cbb01de6 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/ModuleScopeComponent.java @@ -0,0 +1,31 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.mock.components; + +import org.osoa.sca.annotations.Scope; + +/** + * @version $Rev$ $Date$ + */ +@Scope("MODULE") +public interface ModuleScopeComponent extends GenericComponent { + public GenericComponent getGenericComponent(); + + public String getString(); + //public boolean isInit(); +} + diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/ModuleScopeComponentImpl.componentType b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/ModuleScopeComponentImpl.componentType new file mode 100644 index 0000000000..ca4c633e59 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/ModuleScopeComponentImpl.componentType @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/ModuleScopeComponentImpl.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/ModuleScopeComponentImpl.java new file mode 100644 index 0000000000..7981208b9e --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/ModuleScopeComponentImpl.java @@ -0,0 +1,38 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.mock.components; + +import org.osoa.sca.annotations.Scope; + + +/** + * @version $Rev$ $Date$ + */ +@Scope("MODULE") +public class ModuleScopeComponentImpl extends AbstractGenericComponent implements + ModuleScopeComponent { + + private String foo; + + public void setFoo(String foo) { + this.foo = foo; + } + + public String getFoo() { + return foo; + } +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/ModuleScopeDestroyOnlyComponent.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/ModuleScopeDestroyOnlyComponent.java new file mode 100644 index 0000000000..76218c2d6c --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/ModuleScopeDestroyOnlyComponent.java @@ -0,0 +1,34 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.mock.components; + +import org.osoa.sca.annotations.Destroy; + +public class ModuleScopeDestroyOnlyComponent extends ModuleScopeComponentImpl { + + boolean destroyed = false; + + public boolean isDestroyed() { + return destroyed; + } + + @Destroy + public void destroy() { + destroyed = true; + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/ModuleScopeEagerInitComponent.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/ModuleScopeEagerInitComponent.java new file mode 100644 index 0000000000..56a0421f24 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/ModuleScopeEagerInitComponent.java @@ -0,0 +1,39 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.mock.components; + +import org.osoa.sca.annotations.Init; + +public class ModuleScopeEagerInitComponent extends ModuleScopeComponentImpl { + + boolean initialized = false; + + public boolean isInitialized() { + return initialized; + } + + // this value tests to ensure introspection can find the init() method even + // if a field is named the same. Ultimately, this should be in the + // introspection tests + private boolean init; + + @Init(eager = true) + public void init() { + initialized = true; + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/ModuleScopeEagerInitDestroyComponent.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/ModuleScopeEagerInitDestroyComponent.java new file mode 100644 index 0000000000..dae156737a --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/ModuleScopeEagerInitDestroyComponent.java @@ -0,0 +1,33 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.mock.components; + +import org.osoa.sca.annotations.Destroy; + +public class ModuleScopeEagerInitDestroyComponent extends ModuleScopeEagerInitComponent { + + boolean destroyed = false; + + public boolean isDestroyed() { + return destroyed; + } + + @Destroy + public void destroy() { + destroyed = true; + } +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/ModuleScopeInitDestroyComponent.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/ModuleScopeInitDestroyComponent.java new file mode 100644 index 0000000000..695157612b --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/ModuleScopeInitDestroyComponent.java @@ -0,0 +1,37 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.mock.components; + +import org.osoa.sca.annotations.Destroy; + +public class ModuleScopeInitDestroyComponent extends ModuleScopeInitOnlyComponent { + + boolean destroyed = false; + + public boolean isDestroyed() { + return destroyed; + } + + @Destroy + public void destroy() { + if (destroyed){ + throw new AssertionError("Destroy called more than once"); + } + destroyed = true; + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/ModuleScopeInitOnlyComponent.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/ModuleScopeInitOnlyComponent.java new file mode 100644 index 0000000000..4945309852 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/ModuleScopeInitOnlyComponent.java @@ -0,0 +1,41 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.mock.components; + +import org.osoa.sca.annotations.Init; + +public class ModuleScopeInitOnlyComponent extends ModuleScopeComponentImpl { + + boolean initialized = false; + + public boolean isInitialized() { + return initialized; + } + + // this value tests to ensure introspection can find the init() method even + // if a field is named the same. Ultimately, this should be in the introspection tests + private boolean init; + + @Init + public void init() { + if (initialized){ + throw new AssertionError("Init called more than once"); + } + initialized = true; + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/OtherTarget.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/OtherTarget.java new file mode 100644 index 0000000000..2edc8246db --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/OtherTarget.java @@ -0,0 +1,27 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package org.apache.tuscany.container.java.mock.components; + +/** + * Implementations are used in wiring tests + * + * @version $Rev$ $Date$ + */ +public interface OtherTarget { + + public String getString(); + + public void setString(String val); +} + diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/OtherTargetImpl.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/OtherTargetImpl.java new file mode 100644 index 0000000000..08d4d9f720 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/OtherTargetImpl.java @@ -0,0 +1,35 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package org.apache.tuscany.container.java.mock.components; + +/** + * A target used for testing wires with a different source and target interface + * + * @version $Rev$ $Date$ + */ +public class OtherTargetImpl implements OtherTarget{ + + private String theString; + + public String getString() { + return theString; + } + + public void setString(String val) { + theString = val; + } + + +} + diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/RemotableService.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/RemotableService.java new file mode 100644 index 0000000000..645fd7f47c --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/RemotableService.java @@ -0,0 +1,40 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.mock.components; + +import org.osoa.sca.annotations.Remotable; + +/** + * Used for testing basic remoting operations + * + * @version $Rev$ $Date$ + */ + +@Remotable +public interface RemotableService { + + public void syncOneWay(String msg); + + public String syncTwoWay(String msg); + + public DataObject syncTwoWayCustomType(DataObject val); + + public String getString(); + + public void setString(String string); + +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/RemotableServiceImpl.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/RemotableServiceImpl.java new file mode 100644 index 0000000000..34a4273323 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/RemotableServiceImpl.java @@ -0,0 +1,61 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.mock.components; + +import junit.framework.Assert; +import org.osoa.sca.annotations.Property; + + +/** + * @version $Rev$ $Date$ + */ +public class RemotableServiceImpl implements RemotableService { + + // ---------------------------------- + // Properties + // ---------------------------------- + + @Property(name = "string", required = true) + private String mString; + + public String getString() { + return mString; + } + + public void setString(String string) { + mString = string; + } + + // ---------------------------------- + // Methods + // ---------------------------------- + + public void syncOneWay(String msg) { + Assert.assertEquals("hello", msg); + } + + public String syncTwoWay(String msg) { + return "response"; + } + + public DataObject syncTwoWayCustomType(DataObject val) { + Assert.assertEquals("hello", val.getStringValue()); + DataObject dto = new DataObject(); + dto.setStringValue("return"); + return dto; + } +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/RequestScopeComponent.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/RequestScopeComponent.java new file mode 100644 index 0000000000..ac7931bd2c --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/RequestScopeComponent.java @@ -0,0 +1,28 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.mock.components; + +import org.osoa.sca.annotations.Scope; + +/** + * @version $Rev$ $Date$ + */ +@Scope("REQUEST") +public interface RequestScopeComponent extends GenericComponent { + +} + diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/RequestScopeComponentImpl.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/RequestScopeComponentImpl.java new file mode 100644 index 0000000000..5b20519d90 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/RequestScopeComponentImpl.java @@ -0,0 +1,25 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.mock.components; + +/** + * @version $Rev$ $Date$ + */ +public class RequestScopeComponentImpl extends AbstractGenericComponent implements + RequestScopeComponent { + +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/RequestScopeDestroyOnlyComponent.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/RequestScopeDestroyOnlyComponent.java new file mode 100644 index 0000000000..ae63f761c3 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/RequestScopeDestroyOnlyComponent.java @@ -0,0 +1,36 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.mock.components; + +import org.osoa.sca.annotations.Destroy; +import org.osoa.sca.annotations.Scope; + +@Scope("REQUEST") +public class RequestScopeDestroyOnlyComponent extends SessionScopeComponentImpl { + + boolean destroyed = false; + + public boolean isDestroyed() { + return destroyed; + } + + @Destroy + public void destroy() { + destroyed = true; + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/RequestScopeInitDestroyComponent.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/RequestScopeInitDestroyComponent.java new file mode 100644 index 0000000000..67f61df36d --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/RequestScopeInitDestroyComponent.java @@ -0,0 +1,36 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.mock.components; + +import org.osoa.sca.annotations.Destroy; +import org.osoa.sca.annotations.Scope; + +@Scope("REQUEST") +public class RequestScopeInitDestroyComponent extends SessionScopeInitOnlyComponent { + + boolean destroyed = false; + + public boolean isDestroyed() { + return destroyed; + } + + @Destroy + public void destroy() { + destroyed = true; + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/RequestScopeInitOnlyComponent.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/RequestScopeInitOnlyComponent.java new file mode 100644 index 0000000000..c6c621f518 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/RequestScopeInitOnlyComponent.java @@ -0,0 +1,37 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.mock.components; + +import org.osoa.sca.annotations.Init; +import org.osoa.sca.annotations.Scope; + +@Scope("REQUEST") +public class RequestScopeInitOnlyComponent extends SessionScopeComponentImpl { + + boolean initialized = false; + + public boolean isInitialized() { + return initialized; + } + + @Init + public void init() { + initialized = true; + } + + +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/SessionScopeComponent.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/SessionScopeComponent.java new file mode 100644 index 0000000000..236e083a2b --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/SessionScopeComponent.java @@ -0,0 +1,28 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.mock.components; + +import org.osoa.sca.annotations.Scope; + +/** + * @version $Rev$ $Date$ + */ +@Scope("SESSION") +public interface SessionScopeComponent extends GenericComponent { + +} + diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/SessionScopeComponentImpl.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/SessionScopeComponentImpl.java new file mode 100644 index 0000000000..265969a450 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/SessionScopeComponentImpl.java @@ -0,0 +1,28 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.mock.components; + +import org.osoa.sca.annotations.Scope; + +/** + * @version $Rev$ $Date$ + */ +@Scope("SESSION") +public class SessionScopeComponentImpl extends AbstractGenericComponent implements + SessionScopeComponent { + +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/SessionScopeDestroyOnlyComponent.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/SessionScopeDestroyOnlyComponent.java new file mode 100644 index 0000000000..be20a23d29 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/SessionScopeDestroyOnlyComponent.java @@ -0,0 +1,34 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.mock.components; + +import org.osoa.sca.annotations.Destroy; + +public class SessionScopeDestroyOnlyComponent extends SessionScopeComponentImpl { + + boolean destroyed = false; + + public boolean isDestroyed() { + return destroyed; + } + + @Destroy + public void destroy() { + destroyed = true; + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/SessionScopeInitDestroyComponent.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/SessionScopeInitDestroyComponent.java new file mode 100644 index 0000000000..32aa0142a4 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/SessionScopeInitDestroyComponent.java @@ -0,0 +1,34 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.mock.components; + +import org.osoa.sca.annotations.Destroy; + +public class SessionScopeInitDestroyComponent extends SessionScopeInitOnlyComponent { + + boolean destroyed = false; + + public boolean isDestroyed() { + return destroyed; + } + + @Destroy + public void destroy() { + destroyed = true; + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/SessionScopeInitOnlyComponent.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/SessionScopeInitOnlyComponent.java new file mode 100644 index 0000000000..a518a9b244 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/SessionScopeInitOnlyComponent.java @@ -0,0 +1,35 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.mock.components; + +import org.osoa.sca.annotations.Init; + +public class SessionScopeInitOnlyComponent extends SessionScopeComponentImpl { + + boolean initialized = false; + + public boolean isInitialized() { + return initialized; + } + + @Init + public void init() { + initialized = true; + } + + +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/Source.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/Source.java new file mode 100644 index 0000000000..1f918590f2 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/Source.java @@ -0,0 +1,32 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package org.apache.tuscany.container.java.mock.components; + +import java.util.List; + +/** + * Implementations are used in wiring tests + * + * @version $Rev$ $Date$ + */ +public interface Source { + + public Target getTarget(); + + public List getTargets(); + + public List getTargetsThroughField(); + +} + diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/SourceImpl.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/SourceImpl.java new file mode 100644 index 0000000000..a2588bae5e --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/SourceImpl.java @@ -0,0 +1,63 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package org.apache.tuscany.container.java.mock.components; + +import java.util.List; + +/** + * Mock system component implementation used in wiring tests + * + * @version $Rev$ $Date$ + */ +public class SourceImpl implements Source { + + private Target target; + + private List targets; + + private List targetsThroughField; + + 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; + } + + + private Target[] targetsArray; + + public Target[] getArrayOfTargets() { + return targetsArray; + } + + public void setArrayOfTargets(Target[] targets) { + targetsArray = targets; + } + + +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/StatelessComponent.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/StatelessComponent.java new file mode 100644 index 0000000000..3fe84dd785 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/StatelessComponent.java @@ -0,0 +1,28 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.mock.components; + +import org.osoa.sca.annotations.Scope; + +/** + * @version $Rev$ $Date$ + */ +@Scope("STATELESS") +public interface StatelessComponent extends GenericComponent { + +} + diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/StatelessComponentImpl.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/StatelessComponentImpl.java new file mode 100644 index 0000000000..8b806d6a2e --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/StatelessComponentImpl.java @@ -0,0 +1,25 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.mock.components; + +/** + * @version $Rev$ $Date$ + */ +public class StatelessComponentImpl extends AbstractGenericComponent implements + StatelessComponent { + +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/Target.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/Target.java new file mode 100644 index 0000000000..a56e52c898 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/Target.java @@ -0,0 +1,27 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package org.apache.tuscany.container.java.mock.components; + +/** + * Implementations are used in wiring tests + * + * @version $Rev$ $Date$ + */ +public interface Target { + + public String getString(); + + public void setString(String val); +} + diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/TargetImpl.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/TargetImpl.java new file mode 100644 index 0000000000..5a10bfdbc1 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/mock/components/TargetImpl.java @@ -0,0 +1,33 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package org.apache.tuscany.container.java.mock.components; + +/** + * Mock system component implementation used in wiring tests + * + * @version $Rev$ $Date$ + */ +public class TargetImpl implements Target { + + private String theString; + + public String getString() { + return theString; + } + + public void setString(String val) { + theString = val; + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/BasicModuleScopeTestCase.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/BasicModuleScopeTestCase.java new file mode 100644 index 0000000000..557f306ad2 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/BasicModuleScopeTestCase.java @@ -0,0 +1,139 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.scopes; + +import java.util.ArrayList; +import java.util.List; + +import junit.framework.Assert; +import junit.framework.TestCase; +import org.apache.tuscany.container.java.builder.JavaContextFactoryBuilder; +import org.apache.tuscany.container.java.mock.MockFactory; +import org.apache.tuscany.container.java.mock.components.ModuleScopeComponentImpl; +import org.apache.tuscany.container.java.mock.components.ModuleScopeInitDestroyComponent; +import org.apache.tuscany.core.builder.BuilderException; +import org.apache.tuscany.core.builder.ContextFactory; +import org.apache.tuscany.core.builder.system.DefaultPolicyBuilderRegistry; +import org.apache.tuscany.core.builder.system.PolicyBuilderRegistry; +import org.apache.tuscany.core.config.ComponentTypeIntrospector; +import org.apache.tuscany.core.config.ConfigurationLoadException; +import org.apache.tuscany.core.context.Context; +import org.apache.tuscany.core.context.EventContext; +import org.apache.tuscany.core.context.event.ModuleStart; +import org.apache.tuscany.core.context.event.ModuleStop; +import org.apache.tuscany.core.context.impl.EventContextImpl; +import org.apache.tuscany.core.context.scope.ModuleScopeContext; +import org.apache.tuscany.core.message.impl.MessageFactoryImpl; +import org.apache.tuscany.core.wire.jdk.JDKWireFactoryFactory; +import org.apache.tuscany.core.wire.service.DefaultWireFactoryService; +import org.apache.tuscany.core.wire.service.WireFactoryService; +import org.apache.tuscany.model.assembly.AtomicComponent; +import org.apache.tuscany.model.assembly.ComponentType; +import org.apache.tuscany.model.assembly.Scope; + +/** + * Unit tests for the module scope container + * + * @version $Rev$ $Date$ + */ +public class BasicModuleScopeTestCase extends TestCase { + + /** + * Tests instance identity is properly maintained + */ + public void testInstanceManagement() throws Exception { + EventContext ctx = new EventContextImpl(); + ModuleScopeContext scope = new ModuleScopeContext(ctx); + scope.registerFactories(createConfigurations()); + scope.start(); + // first request + scope.onEvent(new ModuleStart(this)); + ModuleScopeComponentImpl comp1 = (ModuleScopeComponentImpl) scope.getContext("TestService1").getInstance(null); + Assert.assertNotNull(comp1); + // second request + ModuleScopeComponentImpl comp2 = (ModuleScopeComponentImpl) scope.getContext("TestService1").getInstance(null); + Assert.assertNotNull(comp2); + Assert.assertSame(comp1, comp2); + scope.onEvent(new ModuleStop(this)); + scope.stop(); + } + + public void testSetNullComponents() throws Exception { + EventContext ctx = new EventContextImpl(); + ModuleScopeContext scope = new ModuleScopeContext(ctx); + scope.registerFactories(createConfigurations()); + scope.start(); + scope.onEvent(new ModuleStart(this)); + scope.onEvent(new ModuleStop(this)); + scope.stop(); + } + + public void testRegisterContextBeforeStart() throws Exception { + EventContext ctx = new EventContextImpl(); + ModuleScopeContext scope = new ModuleScopeContext(ctx); + scope.registerFactories(createConfigurations()); + scope.start(); + scope.registerFactory(createConfiguration("NewTestService")); + scope.onEvent(new ModuleStart(this)); + ModuleScopeInitDestroyComponent comp2 = (ModuleScopeInitDestroyComponent) scope.getContext("NewTestService").getInstance(null); + Assert.assertNotNull(comp2); + Assert.assertTrue(comp2.isInitialized()); + scope.onEvent(new ModuleStop(this)); + Assert.assertTrue(comp2.isDestroyed()); + scope.stop(); + } + + public void testRegisterContextAfterStart() throws Exception { + EventContext ctx = new EventContextImpl(); + ModuleScopeContext scope = new ModuleScopeContext(ctx); + scope.start(); + scope.registerFactory(createConfiguration("NewTestService")); + scope.onEvent(new ModuleStart(this)); + scope.registerFactories(createConfigurations()); + ModuleScopeInitDestroyComponent comp2 = (ModuleScopeInitDestroyComponent) scope.getContext("NewTestService").getInstance(null); + Assert.assertNotNull(comp2); + Assert.assertTrue(comp2.isInitialized()); + scope.onEvent(new ModuleStop(this)); + Assert.assertTrue(comp2.isDestroyed()); + scope.stop(); + } + + + private List> createConfigurations() throws BuilderException, ConfigurationLoadException { + PolicyBuilderRegistry policyRegistry = new DefaultPolicyBuilderRegistry(); + WireFactoryService wireService = new DefaultWireFactoryService(new MessageFactoryImpl(), new JDKWireFactoryFactory(), policyRegistry); + JavaContextFactoryBuilder builder = new JavaContextFactoryBuilder(wireService); + AtomicComponent component = MockFactory.createComponent("TestService1", ModuleScopeComponentImpl.class, Scope.MODULE); + builder.build(component); + List> configs = new ArrayList>(); + configs.add((ContextFactory) component.getContextFactory()); + return configs; + } + + private ContextFactory createConfiguration(String name) throws BuilderException, ConfigurationLoadException { + PolicyBuilderRegistry policyRegistry = new DefaultPolicyBuilderRegistry(); + WireFactoryService wireService = new DefaultWireFactoryService(new MessageFactoryImpl(), new JDKWireFactoryFactory(), policyRegistry); + JavaContextFactoryBuilder builder = new JavaContextFactoryBuilder(wireService); + AtomicComponent component = MockFactory.createComponent(name, ModuleScopeInitDestroyComponent.class, + Scope.MODULE); + ComponentTypeIntrospector introspector = MockFactory.getIntrospector(); + ComponentType type = introspector.introspect(ModuleScopeInitDestroyComponent.class); + component.getImplementation().setComponentType(type); + builder.build(component); + return (ContextFactory) component.getContextFactory(); + } +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/BasicRequestScopeTestCase.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/BasicRequestScopeTestCase.java new file mode 100644 index 0000000000..e53b9fc9ac --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/BasicRequestScopeTestCase.java @@ -0,0 +1,158 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.scopes; + +import java.util.ArrayList; +import java.util.List; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.apache.tuscany.container.java.builder.JavaContextFactoryBuilder; +import org.apache.tuscany.container.java.mock.MockFactory; +import org.apache.tuscany.container.java.mock.components.RequestScopeComponent; +import org.apache.tuscany.container.java.mock.components.RequestScopeComponentImpl; +import org.apache.tuscany.core.builder.BuilderException; +import org.apache.tuscany.core.builder.ContextFactory; +import org.apache.tuscany.core.builder.system.DefaultPolicyBuilderRegistry; +import org.apache.tuscany.core.context.EventContext; +import org.apache.tuscany.core.context.Context; +import org.apache.tuscany.core.context.event.RequestEnd; +import org.apache.tuscany.core.context.impl.EventContextImpl; +import org.apache.tuscany.core.context.scope.RequestScopeContext; +import org.apache.tuscany.core.wire.service.WireFactoryService; +import org.apache.tuscany.core.wire.service.DefaultWireFactoryService; +import org.apache.tuscany.core.wire.jdk.JDKWireFactoryFactory; +import org.apache.tuscany.core.message.impl.MessageFactoryImpl; +import org.apache.tuscany.core.config.ConfigurationLoadException; +import org.apache.tuscany.model.assembly.Scope; +import org.apache.tuscany.model.assembly.AtomicComponent; + +/** + * Unit tests for the request scope container + * + * @version $Rev$ $Date$ + */ +public class BasicRequestScopeTestCase extends TestCase { + + /** + * Tests instance identity is properly maintained + */ + public void testInstanceManagement() throws Exception { + EventContext ctx = new EventContextImpl(); + RequestScopeContext scope = new RequestScopeContext(ctx); + scope.registerFactories(createConfigurations()); + scope.start(); + + // first request + RequestScopeComponentImpl comp1 = (RequestScopeComponentImpl) scope.getContext("TestService1").getInstance(null); + Assert.assertNotNull(comp1); + Object id = new Object(); + scope.onEvent(new RequestEnd(this,id)); + + // second request + RequestScopeComponentImpl comp2 = (RequestScopeComponentImpl) scope.getContext("TestService1").getInstance(null); + Assert.assertNotNull(comp2); + Assert.assertNotSame(comp1, comp2); + Object id2 = new Object(); + scope.onEvent(new RequestEnd(this,id2)); + + scope.stop(); + } + + public void testRegisterContextBeforeRequest() throws Exception { + EventContext ctx = new EventContextImpl(); + RequestScopeContext scope = new RequestScopeContext(ctx); + scope.registerFactories(createConfigurations()); + scope.registerFactory(createConfiguration("NewTestService")); + scope.start(); + RequestScopeComponent comp1 = (RequestScopeComponent) scope.getContext("TestService1").getInstance(null); + Assert.assertNotNull(comp1); + RequestScopeComponent comp2 = (RequestScopeComponent) scope.getContext("NewTestService").getInstance(null); + Assert.assertNotNull(comp2); + Object id = new Object(); + scope.onEvent(new RequestEnd(this,id)); + scope.stop(); + } + + public void testRegisterContextAfterRequest() throws Exception { + EventContext ctx = new EventContextImpl(); + RequestScopeContext scope = new RequestScopeContext(ctx); + scope.registerFactories(createConfigurations()); + scope.start(); + RequestScopeComponent comp1 = (RequestScopeComponent) scope.getContext("TestService1").getInstance(null); + Assert.assertNotNull(comp1); + scope.registerFactory(createConfiguration("NewTestService")); + RequestScopeComponent comp2 = (RequestScopeComponent) scope.getContext("NewTestService").getInstance(null); + Assert.assertNotNull(comp2); + Object id = new Object(); + scope.onEvent(new RequestEnd(this,id)); + scope.stop(); + } + + /** + * Tests setting no components in the scope + */ + public void testSetNullComponents() throws Exception { + EventContext ctx = new EventContextImpl(); + RequestScopeContext scope = new RequestScopeContext(ctx); + scope.registerFactories(createConfigurations()); + scope.start(); + scope.stop(); + } + + public void testGetComponentByKey() throws Exception { + EventContext ctx = new EventContextImpl(); + RequestScopeContext scope = new RequestScopeContext(ctx); + scope.registerFactories(createConfigurations()); + scope.start(); + + RequestScopeComponentImpl comp1 = (RequestScopeComponentImpl) scope.getContext("TestService1").getInstance(null); + Assert.assertNotNull(comp1); + Object id = new Object(); + scope.onEvent(new RequestEnd(this,id)); + + // second request + // should be null since the other context (thread) expired w/ onEvent(..) + Assert.assertNull(scope.getContextByKey("TestService1", Thread.currentThread())); + // Note should test better using concurrent threads to pull the instance + + scope.stop(); + } + + + private List> createConfigurations() throws BuilderException, ConfigurationLoadException { + AtomicComponent component = MockFactory.createComponent("TestService1", RequestScopeComponentImpl.class, + Scope.REQUEST); + WireFactoryService wireService = new DefaultWireFactoryService(new MessageFactoryImpl(), new JDKWireFactoryFactory(), new DefaultPolicyBuilderRegistry()); + JavaContextFactoryBuilder builder = new JavaContextFactoryBuilder(wireService); + builder.build(component); + List> configs = new ArrayList>(); + configs.add((ContextFactory) component.getContextFactory()); + return configs; + } + + private ContextFactory createConfiguration(String name) throws BuilderException, ConfigurationLoadException { + AtomicComponent component = MockFactory.createComponent(name, RequestScopeComponentImpl.class, + Scope.REQUEST); + WireFactoryService wireService = new DefaultWireFactoryService(new MessageFactoryImpl(), new JDKWireFactoryFactory(), new DefaultPolicyBuilderRegistry()); + JavaContextFactoryBuilder builder = new JavaContextFactoryBuilder(wireService); + builder.build(component); + return (ContextFactory) component.getContextFactory(); + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/BasicSessionScopeTestCase.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/BasicSessionScopeTestCase.java new file mode 100644 index 0000000000..8bee9a9741 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/BasicSessionScopeTestCase.java @@ -0,0 +1,238 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.scopes; + +import java.util.ArrayList; +import java.util.List; + +import junit.framework.Assert; +import junit.framework.TestCase; +import org.apache.tuscany.container.java.builder.JavaContextFactoryBuilder; +import org.apache.tuscany.container.java.mock.MockFactory; +import org.apache.tuscany.container.java.mock.components.SessionScopeComponent; +import org.apache.tuscany.container.java.mock.components.SessionScopeComponentImpl; +import org.apache.tuscany.container.java.mock.components.SessionScopeInitDestroyComponent; +import org.apache.tuscany.core.builder.BuilderException; +import org.apache.tuscany.core.builder.ContextFactory; +import org.apache.tuscany.core.builder.system.DefaultPolicyBuilderRegistry; +import org.apache.tuscany.core.config.ComponentTypeIntrospector; +import org.apache.tuscany.core.config.ConfigurationLoadException; +import org.apache.tuscany.core.context.Context; +import org.apache.tuscany.core.context.EventContext; +import org.apache.tuscany.core.context.event.HttpSessionEnd; +import org.apache.tuscany.core.context.event.HttpSessionEvent; +import org.apache.tuscany.core.context.event.RequestEnd; +import org.apache.tuscany.core.context.impl.EventContextImpl; +import org.apache.tuscany.core.context.scope.SessionScopeContext; +import org.apache.tuscany.core.message.impl.MessageFactoryImpl; +import org.apache.tuscany.core.wire.jdk.JDKWireFactoryFactory; +import org.apache.tuscany.core.wire.service.DefaultWireFactoryService; +import org.apache.tuscany.core.wire.service.WireFactoryService; +import org.apache.tuscany.model.assembly.AtomicComponent; +import org.apache.tuscany.model.assembly.ComponentType; +import org.apache.tuscany.model.assembly.Scope; + +/** + * Unit tests for the Http session scope container + * + * @version $Rev$ $Date$ + */ +public class BasicSessionScopeTestCase extends TestCase { + + /** + * Tests instance identity is properly maintained + */ + public void testInstanceManagement() throws Exception { + EventContext ctx = new EventContextImpl(); + SessionScopeContext scope = new SessionScopeContext(ctx); + scope.registerFactories(createConfigurations()); + scope.start(); + Object session = new Object(); + Object session2 = new Object(); + // first request + ctx.setIdentifier(HttpSessionEvent.HTTP_IDENTIFIER, session); + SessionScopeComponent comp1 = (SessionScopeComponent) scope.getContext("TestService1").getInstance(null); + Assert.assertNotNull(comp1); + ctx.clearIdentifier(HttpSessionEvent.HTTP_IDENTIFIER); + + // second request + ctx.setIdentifier(HttpSessionEvent.HTTP_IDENTIFIER, session); + SessionScopeComponent comp2 = (SessionScopeComponent) scope.getContext("TestService1").getInstance(null); + Assert.assertNotNull(comp2); + Assert.assertSame(comp1, comp2); + ctx.clearIdentifier(HttpSessionEvent.HTTP_IDENTIFIER); + + // third request, different session + ctx.setIdentifier(HttpSessionEvent.HTTP_IDENTIFIER, session2); + SessionScopeComponent comp3 = (SessionScopeComponent) scope.getContext("TestService1").getInstance(null); + Assert.assertNotNull(comp3); + Assert.assertNotSame(comp1, comp3); // should be different instances + ctx.clearIdentifier(HttpSessionEvent.HTTP_IDENTIFIER); + + scope.onEvent(new HttpSessionEnd(this, session)); + scope.onEvent(new HttpSessionEnd(this, session2)); + scope.stop(); + } + + /** + * Tests setting no components in the scope + */ + public void testSetNullComponents() throws Exception { + EventContext ctx = new EventContextImpl(); + SessionScopeContext scope = new SessionScopeContext(ctx); + scope.registerFactories(new ArrayList>()); + scope.start(); + scope.stop(); + } + + public void testGetContextByKey() throws Exception { + EventContext ctx = new EventContextImpl(); + SessionScopeContext scope = new SessionScopeContext(ctx); + scope.registerFactories(createConfigurations()); + scope.start(); + Object session = new Object(); + Object session2 = new Object(); + + // first request + ctx.setIdentifier(HttpSessionEvent.HTTP_IDENTIFIER, session); + SessionScopeComponent comp1 = (SessionScopeComponent) scope.getContext("TestService1").getInstance(null); + Assert.assertNotNull(comp1); + ctx.clearIdentifier(HttpSessionEvent.HTTP_IDENTIFIER); + + // second request, different session + ctx.setIdentifier(HttpSessionEvent.HTTP_IDENTIFIER, session2); + SessionScopeComponent comp2 = (SessionScopeComponent) scope.getContextByKey("TestService1", session) + .getInstance(null); + SessionScopeComponent comp3 = (SessionScopeComponent) scope.getContextByKey("TestService1", session) + .getInstance(null); + Assert.assertNotNull(comp2); + Object id = new Object(); + scope.onEvent(new RequestEnd(this, id)); + Assert.assertSame(comp1, comp2); // should be same instances + Assert.assertSame(comp2, comp3); // should not be same instances + ctx.clearIdentifier(HttpSessionEvent.HTTP_IDENTIFIER); + + // shutdown sessions + scope.onEvent(new HttpSessionEnd(this, session)); + scope.onEvent(new HttpSessionEnd(this, session2)); + + scope.stop(); + } + + public void testRegisterContextBeforeSession() throws Exception { + EventContext ctx = new EventContextImpl(); + SessionScopeContext scope = new SessionScopeContext(ctx); + scope.registerFactories(createConfigurations()); + scope.start(); + Object session = new Object(); + scope.registerFactory(createConfiguration("NewTestService")); + + // first request + ctx.setIdentifier(HttpSessionEvent.HTTP_IDENTIFIER, session); + + SessionScopeInitDestroyComponent comp2 = (SessionScopeInitDestroyComponent) scope.getContext("NewTestService") + .getInstance(null); + Assert.assertNotNull(comp2); + Assert.assertTrue(comp2.isInitialized()); + ctx.clearIdentifier(HttpSessionEvent.HTTP_IDENTIFIER); + + // second request different session + Object session2 = new Object(); + ctx.setIdentifier(HttpSessionEvent.HTTP_IDENTIFIER, session2); + SessionScopeInitDestroyComponent comp3 = (SessionScopeInitDestroyComponent) scope.getContext("NewTestService") + .getInstance(null); + Assert.assertNotNull(comp3); + Assert.assertNotSame(comp2, comp3); + Assert.assertTrue(comp3.isInitialized()); + ctx.clearIdentifier(HttpSessionEvent.HTTP_IDENTIFIER); + + scope.onEvent(new HttpSessionEnd(this, session)); + Assert.assertTrue(comp2.isDestroyed()); + + scope.onEvent(new HttpSessionEnd(this, session2)); + Assert.assertTrue(comp3.isDestroyed()); + scope.stop(); + } + + /** + * Tests runtime context registration + */ + public void testRegisterContextAfterSession() throws Exception { + EventContext ctx = new EventContextImpl(); + SessionScopeContext scope = new SessionScopeContext(ctx); + scope.registerFactories(createConfigurations()); + scope.start(); + Object session = new Object(); + + // first request + ctx.setIdentifier(HttpSessionEvent.HTTP_IDENTIFIER, session); + SessionScopeComponent comp1 = (SessionScopeComponent) scope.getContext("TestService1").getInstance(null); + Assert.assertNotNull(comp1); + ctx.clearIdentifier(HttpSessionEvent.HTTP_IDENTIFIER); + + scope.registerFactory(createConfiguration("NewTestService")); + + // second request + ctx.setIdentifier(HttpSessionEvent.HTTP_IDENTIFIER, session); + SessionScopeInitDestroyComponent comp2 = (SessionScopeInitDestroyComponent) scope.getContext("NewTestService") + .getInstance(null); + Assert.assertNotNull(comp2); + Assert.assertTrue(comp2.isInitialized()); + ctx.clearIdentifier(HttpSessionEvent.HTTP_IDENTIFIER); + + // third request different session + Object session2 = new Object(); + ctx.setIdentifier(HttpSessionEvent.HTTP_IDENTIFIER, session2); + SessionScopeInitDestroyComponent comp3 = (SessionScopeInitDestroyComponent) scope.getContext("NewTestService") + .getInstance(null); + Assert.assertNotNull(comp3); + Assert.assertNotSame(comp2, comp3); + Assert.assertTrue(comp3.isInitialized()); + ctx.clearIdentifier(HttpSessionEvent.HTTP_IDENTIFIER); + + scope.onEvent(new HttpSessionEnd(this, session)); + Assert.assertTrue(comp2.isDestroyed()); + + scope.onEvent(new HttpSessionEnd(this, session2)); + Assert.assertTrue(comp3.isDestroyed()); + scope.stop(); + } + + private List> createConfigurations() throws BuilderException, ConfigurationLoadException { + WireFactoryService wireService = new DefaultWireFactoryService(new MessageFactoryImpl(), new JDKWireFactoryFactory(), new DefaultPolicyBuilderRegistry()); + JavaContextFactoryBuilder builder = new JavaContextFactoryBuilder(wireService); + AtomicComponent component = MockFactory.createComponent("TestService1", SessionScopeComponentImpl.class, Scope.SESSION); + ComponentTypeIntrospector introspector = MockFactory.getIntrospector(); + ComponentType type = introspector.introspect(SessionScopeComponentImpl.class); + component.getImplementation().setComponentType(type); + builder.build(component); + List> configs = new ArrayList>(); + configs.add((ContextFactory) component.getContextFactory()); + return configs; + } + + private ContextFactory createConfiguration(String name) throws BuilderException, ConfigurationLoadException { + WireFactoryService wireService = new DefaultWireFactoryService(new MessageFactoryImpl(), new JDKWireFactoryFactory(), new DefaultPolicyBuilderRegistry()); + JavaContextFactoryBuilder builder = new JavaContextFactoryBuilder(wireService); + AtomicComponent component = MockFactory.createComponent(name, SessionScopeInitDestroyComponent.class, Scope.SESSION); + ComponentTypeIntrospector introspector = MockFactory.getIntrospector(); + ComponentType type = introspector.introspect(SessionScopeInitDestroyComponent.class); + component.getImplementation().setComponentType(type); + builder.build(component); + return (ContextFactory) component.getContextFactory(); + } +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/BasicStatelessScopeTestCase.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/BasicStatelessScopeTestCase.java new file mode 100644 index 0000000000..3765c8bf27 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/BasicStatelessScopeTestCase.java @@ -0,0 +1,129 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.scopes; + +import java.util.ArrayList; +import java.util.List; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.apache.tuscany.container.java.builder.JavaContextFactoryBuilder; +import org.apache.tuscany.container.java.mock.MockFactory; +import org.apache.tuscany.container.java.mock.components.StatelessComponent; +import org.apache.tuscany.container.java.mock.components.StatelessComponentImpl; +import org.apache.tuscany.core.builder.BuilderException; +import org.apache.tuscany.core.builder.ContextFactory; +import org.apache.tuscany.core.builder.system.DefaultPolicyBuilderRegistry; +import org.apache.tuscany.core.context.EventContext; +import org.apache.tuscany.core.context.Context; +import org.apache.tuscany.core.context.impl.EventContextImpl; +import org.apache.tuscany.core.context.scope.StatelessScopeContext; +import org.apache.tuscany.core.wire.service.WireFactoryService; +import org.apache.tuscany.core.wire.service.DefaultWireFactoryService; +import org.apache.tuscany.core.wire.jdk.JDKWireFactoryFactory; +import org.apache.tuscany.core.message.impl.MessageFactoryImpl; +import org.apache.tuscany.core.config.ConfigurationLoadException; +import org.apache.tuscany.model.assembly.Scope; +import org.apache.tuscany.model.assembly.AtomicComponent; + +/** + * Unit tests for the module scope container + * + * @version $Rev$ $Date$ + */ +public class BasicStatelessScopeTestCase extends TestCase { + + /** + * Tests instance identity is properly maintained + */ + public void testInstanceManagement() throws Exception { + EventContext ctx = new EventContextImpl(); + StatelessScopeContext scope = new StatelessScopeContext(ctx); + scope.registerFactories(createConfigurations()); + scope.start(); + // first request + StatelessComponentImpl comp1 = (StatelessComponentImpl) scope.getContext("TestService1").getInstance(null); + Assert.assertNotNull(comp1); + // second request + StatelessComponentImpl comp2 = (StatelessComponentImpl) scope.getContext("TestService1").getInstance(null); + Assert.assertNotNull(comp2); + Assert.assertNotSame(comp1, comp2); + scope.stop(); + } + + public void testRegisterContextBeforeRequest() throws Exception { + EventContext ctx = new EventContextImpl(); + StatelessScopeContext scope = new StatelessScopeContext(ctx); + scope.registerFactories(createConfigurations()); + scope.registerFactory(createConfiguration("NewTestService")); + scope.start(); + StatelessComponent comp1 = (StatelessComponent) scope.getContext("TestService1").getInstance(null); + Assert.assertNotNull(comp1); + StatelessComponent comp2 = (StatelessComponent) scope.getContext("NewTestService").getInstance(null); + Assert.assertNotNull(comp2); + scope.stop(); + } + + public void testRegisterContextAfterRequest() throws Exception { + EventContext ctx = new EventContextImpl(); + StatelessScopeContext scope = new StatelessScopeContext(ctx); + scope.registerFactories(createConfigurations()); + scope.start(); + StatelessComponent comp1 = (StatelessComponent) scope.getContext("TestService1").getInstance(null); + Assert.assertNotNull(comp1); + scope.registerFactory(createConfiguration("NewTestService")); + StatelessComponent comp2 = (StatelessComponent) scope.getContext("NewTestService").getInstance(null); + Assert.assertNotNull(comp2); + scope.stop(); + } + + + /** + * Tests setting no components in the scope + */ + public void testSetNullComponents() throws Exception { + EventContext ctx = new EventContextImpl(); + StatelessScopeContext scope = new StatelessScopeContext(ctx); + scope.registerFactories(createConfigurations()); + scope.start(); + scope.stop(); + } + + private List> createConfigurations() + throws NoSuchMethodException, BuilderException, ConfigurationLoadException { + AtomicComponent component = MockFactory.createComponent("TestService1", StatelessComponentImpl.class, + Scope.INSTANCE); + WireFactoryService wireService = new DefaultWireFactoryService(new MessageFactoryImpl(), new JDKWireFactoryFactory(), new DefaultPolicyBuilderRegistry()); + JavaContextFactoryBuilder builder = new JavaContextFactoryBuilder(wireService); + builder.build(component); + List> configs = new ArrayList(); + configs.add((ContextFactory) component.getContextFactory()); + return configs; + } + + private ContextFactory createConfiguration(String name) + throws NoSuchMethodException, BuilderException, ConfigurationLoadException { + AtomicComponent component = MockFactory.createComponent(name, StatelessComponentImpl.class, + Scope.INSTANCE); + WireFactoryService wireService = new DefaultWireFactoryService(new MessageFactoryImpl(), new JDKWireFactoryFactory(),new DefaultPolicyBuilderRegistry()); + JavaContextFactoryBuilder builder = new JavaContextFactoryBuilder(wireService); + builder.build(component); + return (ContextFactory) component.getContextFactory(); + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/CompositeScopeTestCase.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/CompositeScopeTestCase.java new file mode 100644 index 0000000000..d5b5a29e9c --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/CompositeScopeTestCase.java @@ -0,0 +1,188 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" + * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ +package org.apache.tuscany.container.java.scopes; + +import java.util.ArrayList; +import java.util.List; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.apache.tuscany.container.java.builder.JavaContextFactoryBuilder; +import org.apache.tuscany.container.java.mock.MockFactory; +import org.apache.tuscany.container.java.mock.components.GenericComponent; +import org.apache.tuscany.container.java.mock.components.ModuleScopeComponentImpl; +import org.apache.tuscany.container.java.mock.components.SessionScopeComponentImpl; +import org.apache.tuscany.core.builder.BuilderException; +import org.apache.tuscany.core.builder.system.DefaultPolicyBuilderRegistry; +import org.apache.tuscany.core.context.CompositeContext; +import org.apache.tuscany.core.context.EventContext; +import org.apache.tuscany.core.context.event.ModuleStart; +import org.apache.tuscany.core.context.event.RequestStart; +import org.apache.tuscany.core.context.event.HttpSessionBound; +import org.apache.tuscany.core.context.event.RequestEnd; +import org.apache.tuscany.core.context.event.HttpSessionEnd; +import org.apache.tuscany.core.context.event.ModuleStop; +import org.apache.tuscany.core.context.impl.CompositeContextImpl; +import org.apache.tuscany.core.context.impl.EventContextImpl; +import org.apache.tuscany.core.context.scope.CompositeScopeContext; +import org.apache.tuscany.core.wire.service.WireFactoryService; +import org.apache.tuscany.core.wire.service.DefaultWireFactoryService; +import org.apache.tuscany.core.wire.jdk.JDKWireFactoryFactory; +import org.apache.tuscany.core.message.impl.MessageFactoryImpl; +import org.apache.tuscany.core.config.ConfigurationLoadException; +import org.apache.tuscany.model.assembly.Extensible; +import org.apache.tuscany.model.assembly.Scope; +import org.apache.tuscany.model.assembly.AtomicComponent; + +/** + * Tests component nesting. This test needs to be in the container.java progject since it relies on Java POJOs for scope + * testing. + * + * @version $Rev$ $Date$ + */ +public class CompositeScopeTestCase extends TestCase { + + /** + * Ensures scope events are propagated in an composite scope + */ + public void testCompositeScopePropagation() throws Exception { + EventContext ctx = new EventContextImpl(); + CompositeContext moduleComponentCtx = new CompositeContextImpl(); + moduleComponentCtx.setName("testMC"); + moduleComponentCtx.start(); + CompositeScopeContext scopeContainer = new CompositeScopeContext(ctx); + scopeContainer.registerFactory(MockFactory.createCompositeConfiguration("CompositeComponent")); + scopeContainer.start(); + CompositeContext child = (CompositeContext) scopeContainer.getContext("CompositeComponent"); + List models = createAssembly(); + for (Extensible model : models) { + child.registerModelObject(model); + } + + scopeContainer.onEvent(new ModuleStart(this)); + Object session = new Object(); + Object id = new Object(); + //ctx.setIdentifier(EventContext.SESSION,session); + scopeContainer.onEvent(new RequestStart(this,id)); + scopeContainer.onEvent(new HttpSessionBound(this,session)); + CompositeContext componentCtx = (CompositeContext) scopeContainer.getContext("CompositeComponent"); + GenericComponent testService1 = (GenericComponent) componentCtx.getContext("TestService1").getInstance(null); + GenericComponent testService2 = (GenericComponent) componentCtx.getContext("TestService2").getInstance(null); + GenericComponent testService3 = (GenericComponent) componentCtx.getContext("TestService3").getInstance(null); + Assert.assertNotNull(testService1); + Assert.assertNotNull(testService2); + Assert.assertNotNull(testService3); + scopeContainer.onEvent(new RequestEnd(this,id)); + scopeContainer.onEvent(new RequestStart(this,id)); + scopeContainer.onEvent(new HttpSessionBound(this,session)); + + GenericComponent testService2a = (GenericComponent) componentCtx.getContext("TestService2").getInstance(null); + Assert.assertNotNull(testService2a); + GenericComponent testService3a = (GenericComponent) componentCtx.getContext("TestService3").getInstance(null); + Assert.assertNotNull(testService3a); + Assert.assertEquals(testService2, testService2a); + Assert.assertNotSame(testService3, testService3a); + scopeContainer.onEvent(new RequestEnd(this,id)); + scopeContainer.onEvent(new HttpSessionEnd(this,session)); + + Object session2 = new Object(); + Object id2 = new Object(); + scopeContainer.onEvent(new RequestStart(this,id2)); + scopeContainer.onEvent(new HttpSessionBound(this,session2)); + GenericComponent testService2b = (GenericComponent) componentCtx.getContext("TestService2").getInstance(null); + Assert.assertNotNull(testService2b); + Assert.assertNotSame(testService2, testService2b); + + scopeContainer.onEvent(new RequestEnd(this,id2)); + scopeContainer.onEvent(new HttpSessionEnd(this,session2)); + + } + + /** + * Ensures only child entry points (and not components) are accessible from parents + */ + public void testCompositeNoEntryPoint() throws Exception { + EventContext ctx = new EventContextImpl(); + CompositeContext moduleComponentCtx = new CompositeContextImpl(); + moduleComponentCtx.setName("testMC"); + CompositeScopeContext scopeContainer = new CompositeScopeContext(ctx); + scopeContainer.registerFactory(MockFactory.createCompositeConfiguration("CompositeComponent")); + scopeContainer.start(); + CompositeContext child = (CompositeContext) scopeContainer.getContext("CompositeComponent"); + List parts = createAssembly(); + for (Extensible part : parts) { + child.registerModelObject(part); + } + scopeContainer.onEvent(new ModuleStart(this)); + scopeContainer.getContext("CompositeComponent"); + } + + /** + * Tests adding a context before its parent has been started + */ + public void testRegisterContextBeforeStart() throws Exception { + EventContext ctx = new EventContextImpl(); + CompositeContext moduleComponentCtx = new CompositeContextImpl(); + moduleComponentCtx.setName("testMC"); + CompositeScopeContext scopeContainer = new CompositeScopeContext(ctx); + scopeContainer.registerFactory(MockFactory.createCompositeConfiguration("CompositeComponent")); + scopeContainer.start(); + scopeContainer.onEvent(new ModuleStart(this)); + scopeContainer.getContext("CompositeComponent"); + scopeContainer.onEvent(new ModuleStop(this)); + scopeContainer.stop(); + } + + /** + * Tests adding a context after its parent has been started + */ + public void testRegisterContextAfterStart() throws Exception { + EventContext ctx = new EventContextImpl(); + CompositeContext moduleComponentCtx = new CompositeContextImpl(); + moduleComponentCtx.setName("testMC"); + CompositeScopeContext scopeContainer = new CompositeScopeContext(ctx); + scopeContainer.start(); + + scopeContainer.onEvent(new ModuleStart(this)); + scopeContainer.registerFactory(MockFactory.createCompositeConfiguration("CompositeComponent")); + scopeContainer.getContext("CompositeComponent"); + scopeContainer.onEvent(new ModuleStop(this)); + scopeContainer.stop(); + } + + /** + * Creats an assembly containing a module-scoped component definition, a session-scoped component definition, and a + * request-scoped component definition + * + */ + private List createAssembly() throws BuilderException, ConfigurationLoadException { + WireFactoryService wireService = new DefaultWireFactoryService(new MessageFactoryImpl(), new JDKWireFactoryFactory(), new DefaultPolicyBuilderRegistry()); + JavaContextFactoryBuilder builder = new JavaContextFactoryBuilder(wireService); + AtomicComponent component = MockFactory.createComponent("TestService1", ModuleScopeComponentImpl.class, Scope.MODULE); + AtomicComponent sessionComponent = MockFactory.createComponent("TestService2", SessionScopeComponentImpl.class, + Scope.SESSION); + AtomicComponent requestComponent = MockFactory.createComponent("TestService3", SessionScopeComponentImpl.class, + Scope.REQUEST); + builder.build(component); + builder.build(sessionComponent); + builder.build(requestComponent); + List configs = new ArrayList(); + configs.add(component); + configs.add(sessionComponent); + configs.add(requestComponent); + return configs; + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/DependencyLifecycleTestCase.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/DependencyLifecycleTestCase.java new file mode 100644 index 0000000000..dc3fe3efcb --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/DependencyLifecycleTestCase.java @@ -0,0 +1,93 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.scopes; + +import junit.framework.TestCase; +import org.apache.tuscany.container.java.mock.MockContextFactory; +import org.apache.tuscany.core.context.EventContext; +import org.apache.tuscany.core.context.event.ModuleStart; +import org.apache.tuscany.core.context.event.ModuleStop; +import org.apache.tuscany.core.context.event.HttpSessionBound; +import org.apache.tuscany.core.context.event.HttpSessionEvent; +import org.apache.tuscany.core.context.event.HttpSessionEnd; +import org.apache.tuscany.core.context.event.RequestStart; +import org.apache.tuscany.core.context.event.RequestEnd; +import org.apache.tuscany.core.context.impl.EventContextImpl; +import org.apache.tuscany.core.context.scope.ModuleScopeContext; +import org.apache.tuscany.core.context.scope.SessionScopeContext; +import org.apache.tuscany.core.context.scope.RequestScopeContext; +import org.apache.tuscany.model.assembly.Scope; + +/** + * Tests that dependencies are initalized and destroyed in the proper order (i.e. LIFO) + * + * @version $Rev: 393992 $ $Date: 2006-04-13 18:01:05 -0700 (Thu, 13 Apr 2006) $ + */ +public class DependencyLifecycleTestCase extends TestCase { + + + + public void testInitDestroyOrderModuleScope() throws Exception { + EventContext ctx = new EventContextImpl(); + ModuleScopeContext scope = new ModuleScopeContext(ctx); + scope.registerFactories(MockContextFactory.createWiredContexts(Scope.MODULE,scope)); + scope.start(); + scope.onEvent(new ModuleStart(this)); + OrderedDependentPojo source = (OrderedDependentPojo) scope.getContext("source").getInstance(null); + assertNotNull(source.getPojo()); + // expire module + assertEquals(2,source.getNumberInstantiated()); + scope.onEvent(new ModuleStop(this)); + assertEquals(0,source.getNumberInstantiated()); + scope.stop(); + } + + public void testInitDestroyOrderSessionScope() throws Exception { + EventContext ctx = new EventContextImpl(); + SessionScopeContext scope = new SessionScopeContext(ctx); + scope.registerFactories(MockContextFactory.createWiredContexts(Scope.SESSION,scope)); + scope.start(); + Object session = new Object(); + ctx.setIdentifier(HttpSessionEvent.HTTP_IDENTIFIER,session); + scope.onEvent(new HttpSessionBound(this,session)); + OrderedDependentPojo source = (OrderedDependentPojo) scope.getContext("source").getInstance(null); + assertNotNull(source.getPojo()); + // expire module + assertEquals(2,source.getNumberInstantiated()); + scope.onEvent(new HttpSessionEnd(this,session)); + assertEquals(0,source.getNumberInstantiated()); + scope.stop(); + } + + + public void testInitDestroyOrderRequestScope() throws Exception { + EventContext ctx = new EventContextImpl(); + RequestScopeContext scope = new RequestScopeContext(ctx); + scope.registerFactories(MockContextFactory.createWiredContexts(Scope.REQUEST,scope)); + scope.start(); + Object request = new Object(); + scope.onEvent(new RequestStart(this,request)); + OrderedDependentPojo source = (OrderedDependentPojo) scope.getContext("source").getInstance(null); + assertNotNull(source.getPojo()); + // expire module + assertEquals(2,source.getNumberInstantiated()); + scope.onEvent(new RequestEnd(this,request)); + assertEquals(0,source.getNumberInstantiated()); + scope.stop(); + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/ModuleScopeLifecycleTestCase.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/ModuleScopeLifecycleTestCase.java new file mode 100644 index 0000000000..904e218c08 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/ModuleScopeLifecycleTestCase.java @@ -0,0 +1,248 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.scopes; + +import java.util.ArrayList; +import java.util.List; + +import junit.framework.Assert; +import junit.framework.TestCase; +import org.apache.tuscany.container.java.builder.JavaContextFactoryBuilder; +import org.apache.tuscany.container.java.mock.MockFactory; +import org.apache.tuscany.container.java.mock.components.ModuleScopeDestroyOnlyComponent; +import org.apache.tuscany.container.java.mock.components.ModuleScopeEagerInitComponent; +import org.apache.tuscany.container.java.mock.components.ModuleScopeEagerInitDestroyComponent; +import org.apache.tuscany.container.java.mock.components.ModuleScopeInitDestroyComponent; +import org.apache.tuscany.container.java.mock.components.ModuleScopeInitOnlyComponent; +import org.apache.tuscany.core.builder.BuilderException; +import org.apache.tuscany.core.builder.ContextFactory; +import org.apache.tuscany.core.builder.system.DefaultPolicyBuilderRegistry; +import org.apache.tuscany.core.config.ComponentTypeIntrospector; +import org.apache.tuscany.core.config.ConfigurationLoadException; +import org.apache.tuscany.core.context.Context; +import org.apache.tuscany.core.context.EventContext; +import org.apache.tuscany.core.context.event.ModuleStart; +import org.apache.tuscany.core.context.event.ModuleStop; +import org.apache.tuscany.core.context.impl.EventContextImpl; +import org.apache.tuscany.core.context.scope.ModuleScopeContext; +import org.apache.tuscany.core.message.impl.MessageFactoryImpl; +import org.apache.tuscany.core.wire.jdk.JDKWireFactoryFactory; +import org.apache.tuscany.core.wire.service.DefaultWireFactoryService; +import org.apache.tuscany.core.wire.service.WireFactoryService; +import org.apache.tuscany.model.assembly.AtomicComponent; +import org.apache.tuscany.model.assembly.ComponentType; +import org.apache.tuscany.model.assembly.Scope; + +/** + * Lifecycle unit tests for the module scope container + * + * @version $Rev$ $Date$ + */ +public class ModuleScopeLifecycleTestCase extends TestCase { + + JavaContextFactoryBuilder builder; + + public void testInitDestroy() throws Exception { + EventContext ctx = new EventContextImpl(); + ModuleScopeContext scope = new ModuleScopeContext(ctx); + scope.registerFactories(createComponents()); + scope.start(); + scope.onEvent(new ModuleStart(this)); + ModuleScopeInitDestroyComponent initDestroy = (ModuleScopeInitDestroyComponent) scope.getContext( + "TestServiceInitDestroy").getInstance(null); + Assert.assertNotNull(initDestroy); + ModuleScopeInitOnlyComponent initOnly = (ModuleScopeInitOnlyComponent) scope.getContext("TestServiceInitOnly") + .getInstance(null); + Assert.assertNotNull(initOnly); + ModuleScopeDestroyOnlyComponent destroyOnly = (ModuleScopeDestroyOnlyComponent) scope.getContext( + "TestServiceDestroyOnly").getInstance(null); + Assert.assertNotNull(destroyOnly); + + Assert.assertTrue(initDestroy.isInitialized()); + Assert.assertTrue(initOnly.isInitialized()); + Assert.assertFalse(initDestroy.isDestroyed()); + Assert.assertFalse(destroyOnly.isDestroyed()); + + // expire module + scope.onEvent(new ModuleStop(this)); + + Assert.assertTrue(initDestroy.isDestroyed()); + Assert.assertTrue(destroyOnly.isDestroyed()); + + scope.stop(); + } + + public void testEagerInit() throws Exception { + EventContext ctx = new EventContextImpl(); + ModuleScopeContext scope = new ModuleScopeContext(ctx); + scope.registerFactories(createEagerInitComponents()); + scope.start(); + scope.onEvent(new ModuleStart(this)); + ModuleScopeEagerInitDestroyComponent initDestroy = (ModuleScopeEagerInitDestroyComponent) scope.getContext( + "TestServiceEagerInitDestroy").getInstance(null); + Assert.assertNotNull(initDestroy); + ModuleScopeEagerInitComponent initOnly = (ModuleScopeEagerInitComponent) scope + .getContext("TestServiceEagerInit").getInstance(null); + Assert.assertNotNull(initOnly); + + Assert.assertTrue(initDestroy.isInitialized()); + Assert.assertTrue(initOnly.isInitialized()); + Assert.assertFalse(initDestroy.isDestroyed()); + + // expire module + scope.onEvent(new ModuleStop(this)); + + Assert.assertTrue(initDestroy.isDestroyed()); + + scope.stop(); + + } + + public void testDestroyOrder() throws Exception { + EventContext ctx = new EventContextImpl(); + ModuleScopeContext scope = new ModuleScopeContext(ctx); + scope.registerFactories(createOrderedInitComponents()); + scope.start(); + scope.onEvent(new ModuleStart(this)); + OrderedInitPojo one = (OrderedInitPojo) scope.getContext("one").getInstance(null); + Assert.assertNotNull(one); + Assert.assertEquals(1, one.getNumberInstantiated()); + Assert.assertEquals(1, one.getInitOrder()); + + OrderedInitPojo two = (OrderedInitPojo) scope.getContext("two").getInstance(null); + Assert.assertNotNull(two); + Assert.assertEquals(2, two.getNumberInstantiated()); + Assert.assertEquals(2, two.getInitOrder()); + + OrderedInitPojo three = (OrderedInitPojo) scope.getContext("three").getInstance(null); + Assert.assertNotNull(three); + Assert.assertEquals(3, three.getNumberInstantiated()); + Assert.assertEquals(3, three.getInitOrder()); + + // expire module + scope.onEvent(new ModuleStop(this)); + Assert.assertEquals(0, one.getNumberInstantiated()); + scope.stop(); + } + + public void testEagerInitDestroyOrder() throws Exception { + EventContext ctx = new EventContextImpl(); + ModuleScopeContext scope = new ModuleScopeContext(ctx); + scope.registerFactories(createOrderedEagerInitComponents()); + scope.start(); + scope.onEvent(new ModuleStart(this)); + OrderedEagerInitPojo one = (OrderedEagerInitPojo) scope.getContext("one").getInstance(null); + Assert.assertNotNull(one); + + OrderedEagerInitPojo two = (OrderedEagerInitPojo) scope.getContext("two").getInstance(null); + Assert.assertNotNull(two); + + OrderedEagerInitPojo three = (OrderedEagerInitPojo) scope.getContext("three").getInstance(null); + Assert.assertNotNull(three); + + // expire module + scope.onEvent(new ModuleStop(this)); + Assert.assertEquals(0, one.getNumberInstantiated()); + scope.stop(); + } + + + private List> createComponents() throws BuilderException, ConfigurationLoadException { + AtomicComponent[] ca = new AtomicComponent[3]; + ca[0] = MockFactory.createComponent("TestServiceInitDestroy", ModuleScopeInitDestroyComponent.class, + Scope.MODULE); + ca[1] = MockFactory.createComponent("TestServiceInitOnly", ModuleScopeInitOnlyComponent.class, + Scope.MODULE); + ca[2] = MockFactory.createComponent("TestServiceDestroyOnly", ModuleScopeDestroyOnlyComponent.class, + Scope.MODULE); + List> configs = new ArrayList>(); + ComponentTypeIntrospector introspector = MockFactory.getIntrospector(); + ca[0].getImplementation().setComponentType(introspector.introspect(ModuleScopeInitDestroyComponent.class)); + ca[1].getImplementation().setComponentType(introspector.introspect(ModuleScopeInitOnlyComponent.class)); + ca[2].getImplementation().setComponentType(introspector.introspect(ModuleScopeDestroyOnlyComponent.class)); + for (AtomicComponent aCa : ca) { + builder.build(aCa); + configs.add((ContextFactory) aCa.getContextFactory()); + + } + return configs; + } + + private List> createEagerInitComponents() throws + BuilderException, ConfigurationLoadException { + AtomicComponent[] ca = new AtomicComponent[2]; + ca[0] = MockFactory.createComponent("TestServiceEagerInitDestroy", ModuleScopeEagerInitDestroyComponent.class, + Scope.MODULE); + ca[1] = MockFactory.createComponent("TestServiceEagerInit", ModuleScopeEagerInitComponent.class, + Scope.MODULE); + List> configs = new ArrayList>(); + ComponentTypeIntrospector introspector = MockFactory.getIntrospector(); + ComponentType type = introspector.introspect(OrderedInitPojo.class); + ca[0].getImplementation().setComponentType(introspector.introspect(ModuleScopeEagerInitDestroyComponent.class)); + ca[1].getImplementation().setComponentType(introspector.introspect(ModuleScopeEagerInitComponent.class)); + for (AtomicComponent aCa : ca) { + builder.build(aCa); + configs.add((ContextFactory) aCa.getContextFactory()); + } + return configs; + } + + private List> createOrderedInitComponents() throws + BuilderException, ConfigurationLoadException { + AtomicComponent[] ca = new AtomicComponent[3]; + ca[0] = MockFactory.createComponent("one", OrderedInitPojo.class, Scope.MODULE); + ca[1] = MockFactory.createComponent("two", OrderedInitPojo.class, Scope.MODULE); + ca[2] = MockFactory.createComponent("three", OrderedInitPojo.class, Scope.MODULE); + List> configs = new ArrayList>(); + ComponentTypeIntrospector introspector = MockFactory.getIntrospector(); + ComponentType type = introspector.introspect(OrderedInitPojo.class); + ca[0].getImplementation().setComponentType(type); + ca[1].getImplementation().setComponentType(type); + ca[2].getImplementation().setComponentType(type); + for (AtomicComponent aCa : ca) { + builder.build(aCa); + configs.add((ContextFactory) aCa.getContextFactory()); + } + return configs; + } + + private List> createOrderedEagerInitComponents() throws + BuilderException, ConfigurationLoadException { + AtomicComponent[] ca = new AtomicComponent[3]; + ca[0] = MockFactory.createComponent("one", OrderedEagerInitPojo.class, Scope.MODULE); + ca[1] = MockFactory.createComponent("two", OrderedEagerInitPojo.class, Scope.MODULE); + ca[2] = MockFactory.createComponent("three", OrderedEagerInitPojo.class, Scope.MODULE); + ComponentTypeIntrospector introspector = MockFactory.getIntrospector(); + ComponentType type = introspector.introspect(OrderedEagerInitPojo.class); + ca[0].getImplementation().setComponentType(type); + ca[1].getImplementation().setComponentType(type); + ca[2].getImplementation().setComponentType(type); + List> configs = new ArrayList>(); + for (AtomicComponent aCa : ca) { + builder.build(aCa); + configs.add((ContextFactory) aCa.getContextFactory()); + + } + return configs; + } + + protected void setUp() throws Exception { + super.setUp(); + WireFactoryService wireService = new DefaultWireFactoryService(new MessageFactoryImpl(), new JDKWireFactoryFactory(), new DefaultPolicyBuilderRegistry()); + builder = new JavaContextFactoryBuilder(wireService); + } +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/OrderException.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/OrderException.java new file mode 100644 index 0000000000..fc5f7c8c58 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/OrderException.java @@ -0,0 +1,38 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.scopes; + +public class OrderException extends Exception { + + public OrderException() { + super(); + } + + public OrderException(String message) { + super(message); + } + + public OrderException(String message, Throwable cause) { + super(message, cause); + } + + public OrderException(Throwable cause) { + super(cause); + } + +} + diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/OrderedDependentPojo.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/OrderedDependentPojo.java new file mode 100644 index 0000000000..f8fe2af7be --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/OrderedDependentPojo.java @@ -0,0 +1,34 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.scopes; + +/** + * @version $$Rev$$ $$Date$$ + */ +public class OrderedDependentPojo extends OrderedInitPojo { + + private OrderedDependentPojo pojo; + + public OrderedDependentPojo getPojo() { + return pojo; + } + + public void setPojo(OrderedDependentPojo pojo) { + this.pojo = pojo; + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/OrderedEagerInitPojo.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/OrderedEagerInitPojo.java new file mode 100644 index 0000000000..f9aeefccbe --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/OrderedEagerInitPojo.java @@ -0,0 +1,56 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.scopes; + +import org.osoa.sca.annotations.Destroy; +import org.osoa.sca.annotations.Init; +import org.osoa.sca.annotations.Scope; + +@Scope("MODULE") +public class OrderedEagerInitPojo { + + private static Object lock = new Object(); + private static int numberInstantied; + private int initOrder; + + @Init(eager = true) + public void init() { + synchronized (lock) { + ++numberInstantied; + initOrder = numberInstantied; + } + } + + @Destroy + public void destroy() throws OrderException { + synchronized (lock) { + if (initOrder != numberInstantied) { + throw new OrderException("Instance shutdown done out of order"); + } + --numberInstantied; + } + } + + public int getNumberInstantiated() { + return numberInstantied; + } + + public int getInitOrder() { + return initOrder; + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/OrderedInitPojo.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/OrderedInitPojo.java new file mode 100644 index 0000000000..b4d4eb03ba --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/OrderedInitPojo.java @@ -0,0 +1,56 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.scopes; + +import org.osoa.sca.annotations.Destroy; +import org.osoa.sca.annotations.Init; +import org.osoa.sca.annotations.Scope; + +@Scope("MODULE") +public class OrderedInitPojo { + + private static Object lock = new Object(); + private static int numberInstantied; + private int initOrder; + + @Init + public void init() { + synchronized (lock) { + ++numberInstantied; + initOrder = numberInstantied; + } + } + + @Destroy + public void destroy() throws OrderException { + synchronized (lock) { + if (initOrder != numberInstantied) { + throw new OrderException("Instance shutdown done out of order"); + } + --numberInstantied; + } + } + + public int getNumberInstantiated() { + return numberInstantied; + } + + public int getInitOrder() { + return initOrder; + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/RequestScopeLifecycleTestCase.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/RequestScopeLifecycleTestCase.java new file mode 100644 index 0000000000..bca1e57cbc --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/RequestScopeLifecycleTestCase.java @@ -0,0 +1,166 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.scopes; + +import java.util.ArrayList; +import java.util.List; + +import junit.framework.Assert; +import junit.framework.TestCase; +import org.apache.tuscany.container.java.builder.JavaContextFactoryBuilder; +import org.apache.tuscany.container.java.mock.MockFactory; +import org.apache.tuscany.container.java.mock.components.RequestScopeDestroyOnlyComponent; +import org.apache.tuscany.container.java.mock.components.RequestScopeInitDestroyComponent; +import org.apache.tuscany.container.java.mock.components.RequestScopeInitOnlyComponent; +import org.apache.tuscany.core.builder.BuilderException; +import org.apache.tuscany.core.builder.ContextFactory; +import org.apache.tuscany.core.builder.system.DefaultPolicyBuilderRegistry; +import org.apache.tuscany.core.config.ComponentTypeIntrospector; +import org.apache.tuscany.core.config.ConfigurationLoadException; +import org.apache.tuscany.core.context.Context; +import org.apache.tuscany.core.context.EventContext; +import org.apache.tuscany.core.context.event.RequestEnd; +import org.apache.tuscany.core.context.impl.EventContextImpl; +import org.apache.tuscany.core.context.scope.RequestScopeContext; +import org.apache.tuscany.core.message.impl.MessageFactoryImpl; +import org.apache.tuscany.core.wire.jdk.JDKWireFactoryFactory; +import org.apache.tuscany.core.wire.service.DefaultWireFactoryService; +import org.apache.tuscany.core.wire.service.WireFactoryService; +import org.apache.tuscany.model.assembly.AtomicComponent; +import org.apache.tuscany.model.assembly.ComponentType; +import org.apache.tuscany.model.assembly.Scope; + +/** + * Lifecycle unit tests for the Http session scope container + * + * @version $Rev$ $Date$ + */ +public class RequestScopeLifecycleTestCase extends TestCase { + + /** + * Tests instance identity is properly maintained + */ + public void testInitDestroy() throws Exception { + EventContext ctx = new EventContextImpl(); + RequestScopeContext scope = new RequestScopeContext(ctx); + scope.registerFactories(createComponents()); + scope.start(); + RequestScopeInitDestroyComponent initDestroy = (RequestScopeInitDestroyComponent) scope.getContext( + "TestServiceInitDestroy").getInstance(null); + Assert.assertNotNull(initDestroy); + RequestScopeInitOnlyComponent initOnly = (RequestScopeInitOnlyComponent) scope.getContext("TestServiceInitOnly") + .getInstance(null); + Assert.assertNotNull(initOnly); + RequestScopeDestroyOnlyComponent destroyOnly = (RequestScopeDestroyOnlyComponent) scope.getContext( + "TestServiceDestroyOnly").getInstance(null); + Assert.assertNotNull(destroyOnly); + + Assert.assertTrue(initDestroy.isInitialized()); + Assert.assertTrue(initOnly.isInitialized()); + Assert.assertFalse(initDestroy.isDestroyed()); + Assert.assertFalse(destroyOnly.isDestroyed()); + + // end request + scope.onEvent(new RequestEnd(this, new Object())); + Assert.assertTrue(initDestroy.isDestroyed()); + Assert.assertTrue(destroyOnly.isDestroyed()); + + scope.stop(); + } + + /** + * Test instances destroyed in proper (i.e. reverse) order + */ + public void testDestroyOrder() throws Exception { + EventContext ctx = new EventContextImpl(); + RequestScopeContext scope = new RequestScopeContext(ctx); + scope.registerFactories(createOrderedInitComponents()); + scope.start(); + // request start + RequestScopedOrderedInitPojo one = (RequestScopedOrderedInitPojo) scope.getContext("one").getInstance(null); + Assert.assertNotNull(one); + Assert.assertEquals(1, one.getNumberInstantiated()); + Assert.assertEquals(1, one.getInitOrder()); + + RequestScopedOrderedInitPojo two = (RequestScopedOrderedInitPojo) scope.getContext("two").getInstance(null); + Assert.assertNotNull(two); + Assert.assertEquals(2, two.getNumberInstantiated()); + Assert.assertEquals(2, two.getInitOrder()); + + RequestScopedOrderedInitPojo three = (RequestScopedOrderedInitPojo) scope.getContext("three").getInstance(null); + Assert.assertNotNull(three); + Assert.assertEquals(3, three.getNumberInstantiated()); + Assert.assertEquals(3, three.getInitOrder()); + + // end request + scope.onEvent(new RequestEnd(this, new Object())); + + Assert.assertEquals(0, one.getNumberInstantiated()); + scope.stop(); + } + + + JavaContextFactoryBuilder builder; + + private List> createComponents() throws BuilderException, ConfigurationLoadException { + AtomicComponent[] ca = new AtomicComponent[3]; + ca[0] = MockFactory.createComponent("TestServiceInitDestroy", RequestScopeInitDestroyComponent.class, + Scope.REQUEST); + ca[1] = MockFactory.createComponent("TestServiceInitOnly", RequestScopeInitOnlyComponent.class, + Scope.REQUEST); + ca[2] = MockFactory.createComponent("TestServiceDestroyOnly", RequestScopeDestroyOnlyComponent.class, + Scope.REQUEST); + ComponentTypeIntrospector introspector = MockFactory.getIntrospector(); + ca[0].getImplementation().setComponentType(introspector.introspect(RequestScopeInitDestroyComponent.class)); + ca[1].getImplementation().setComponentType(introspector.introspect(RequestScopeInitOnlyComponent.class)); + ca[2].getImplementation().setComponentType(introspector.introspect(RequestScopeDestroyOnlyComponent.class)); + List> configs = new ArrayList>(); + for (AtomicComponent aCa : ca) { + builder.build(aCa); + configs.add((ContextFactory) aCa.getContextFactory()); + + } + return configs; + } + + private List> createOrderedInitComponents() throws + BuilderException, ConfigurationLoadException { + AtomicComponent[] ca = new AtomicComponent[3]; + ca[0] = MockFactory.createComponent("one", RequestScopedOrderedInitPojo.class, Scope.REQUEST); + ca[1] = MockFactory.createComponent("two", RequestScopedOrderedInitPojo.class, Scope.REQUEST); + ca[2] = MockFactory.createComponent("three", RequestScopedOrderedInitPojo.class, Scope.REQUEST); + ComponentTypeIntrospector introspector = MockFactory.getIntrospector(); + ComponentType type = introspector.introspect(RequestScopedOrderedInitPojo.class); + ca[0].getImplementation().setComponentType(type); + ca[1].getImplementation().setComponentType(type); + ca[2].getImplementation().setComponentType(type); + List> configs = new ArrayList>(); + for (AtomicComponent aCa : ca) { + builder.build(aCa); + configs.add((ContextFactory) aCa.getContextFactory()); + + } + return configs; + } + + protected void setUp() throws Exception { + super.setUp(); + WireFactoryService wireService = new DefaultWireFactoryService(new MessageFactoryImpl(), new JDKWireFactoryFactory(), new DefaultPolicyBuilderRegistry()); + builder = new JavaContextFactoryBuilder(wireService); + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/RequestScopedOrderedInitPojo.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/RequestScopedOrderedInitPojo.java new file mode 100644 index 0000000000..717c7008c9 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/RequestScopedOrderedInitPojo.java @@ -0,0 +1,56 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.scopes; + +import org.osoa.sca.annotations.Scope; +import org.osoa.sca.annotations.Init; +import org.osoa.sca.annotations.Destroy; + +@Scope("REQUEST") +public class RequestScopedOrderedInitPojo { + + private static Object lock = new Object(); + private static int numberInstantied; + private int initOrder; + + @Init + public void init() { + synchronized (RequestScopedOrderedInitPojo.lock) { + ++RequestScopedOrderedInitPojo.numberInstantied; + initOrder = RequestScopedOrderedInitPojo.numberInstantied; + } + } + + @Destroy + public void destroy() throws OrderException { + synchronized (RequestScopedOrderedInitPojo.lock) { + if (initOrder != RequestScopedOrderedInitPojo.numberInstantied) { + throw new OrderException("Instance shutdown done out of order"); + } + --RequestScopedOrderedInitPojo.numberInstantied; + } + } + + public int getNumberInstantiated() { + return RequestScopedOrderedInitPojo.numberInstantied; + } + + public int getInitOrder() { + return initOrder; + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/SessionScopeLifecycleTestCase.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/SessionScopeLifecycleTestCase.java new file mode 100644 index 0000000000..80d8cb71cb --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/SessionScopeLifecycleTestCase.java @@ -0,0 +1,176 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.scopes; + +import java.util.ArrayList; +import java.util.List; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.apache.tuscany.container.java.builder.JavaContextFactoryBuilder; +import org.apache.tuscany.container.java.mock.MockFactory; +import org.apache.tuscany.container.java.mock.components.SessionScopeDestroyOnlyComponent; +import org.apache.tuscany.container.java.mock.components.SessionScopeInitDestroyComponent; +import org.apache.tuscany.container.java.mock.components.SessionScopeInitOnlyComponent; +import org.apache.tuscany.core.builder.BuilderException; +import org.apache.tuscany.core.builder.ContextFactory; +import org.apache.tuscany.core.builder.system.DefaultPolicyBuilderRegistry; +import org.apache.tuscany.core.context.EventContext; +import org.apache.tuscany.core.context.Context; +import org.apache.tuscany.core.context.event.HttpSessionEnd; +import org.apache.tuscany.core.context.event.HttpSessionEvent; +import org.apache.tuscany.core.context.impl.EventContextImpl; +import org.apache.tuscany.core.context.scope.SessionScopeContext; +import org.apache.tuscany.core.wire.service.WireFactoryService; +import org.apache.tuscany.core.wire.service.DefaultWireFactoryService; +import org.apache.tuscany.core.wire.jdk.JDKWireFactoryFactory; +import org.apache.tuscany.core.message.impl.MessageFactoryImpl; +import org.apache.tuscany.core.config.ComponentTypeIntrospector; +import org.apache.tuscany.core.config.ConfigurationLoadException; +import org.apache.tuscany.model.assembly.Scope; +import org.apache.tuscany.model.assembly.AtomicComponent; +import org.apache.tuscany.model.assembly.ComponentType; + +/** + * Lifecycle unit tests for the Http session scope container + * + * @version $Rev$ $Date$ + */ +public class SessionScopeLifecycleTestCase extends TestCase { + + /** + * Tests instance identity is properly maintained + */ + public void testInitDestroy() throws Exception { + EventContext ctx = new EventContextImpl(); + SessionScopeContext scope = new SessionScopeContext(ctx); + scope.registerFactories(createComponents()); + scope.start(); + Object session = new Object(); + // first request, no need to notify scope container since sessions are + // evaluated lazily + ctx.setIdentifier(HttpSessionEvent.HTTP_IDENTIFIER,session); + SessionScopeInitDestroyComponent initDestroy = (SessionScopeInitDestroyComponent) scope.getContext( + "TestServiceInitDestroy").getInstance(null); + Assert.assertNotNull(initDestroy); + SessionScopeInitOnlyComponent initOnly = (SessionScopeInitOnlyComponent) scope.getContext("TestServiceInitOnly") + .getInstance(null); + Assert.assertNotNull(initOnly); + SessionScopeDestroyOnlyComponent destroyOnly = (SessionScopeDestroyOnlyComponent) scope.getContext( + "TestServiceDestroyOnly").getInstance(null); + Assert.assertNotNull(destroyOnly); + + Assert.assertTrue(initDestroy.isInitialized()); + Assert.assertTrue(initOnly.isInitialized()); + Assert.assertFalse(initDestroy.isDestroyed()); + Assert.assertFalse(destroyOnly.isDestroyed()); + // end request + ctx.clearIdentifier(HttpSessionEvent.HTTP_IDENTIFIER); + // expire session + scope.onEvent(new HttpSessionEnd(this,session)); + Assert.assertTrue(initDestroy.isDestroyed()); + Assert.assertTrue(destroyOnly.isDestroyed()); + + scope.stop(); + } + + /** + * Test instances destroyed in proper (i.e. reverse) order + */ + public void testDestroyOrder() throws Exception { + EventContext ctx = new EventContextImpl(); + SessionScopeContext scope = new SessionScopeContext(ctx); + scope.registerFactories(createOrderedInitComponents()); + scope.start(); + Object session = new Object(); + // request start + ctx.setIdentifier(HttpSessionEvent.HTTP_IDENTIFIER,session); + + SessionScopedOrderedInitPojo one = (SessionScopedOrderedInitPojo) scope.getContext("one").getInstance(null); + Assert.assertNotNull(one); + Assert.assertEquals(1, one.getNumberInstantiated()); + Assert.assertEquals(1, one.getInitOrder()); + + SessionScopedOrderedInitPojo two = (SessionScopedOrderedInitPojo) scope.getContext("two").getInstance(null); + Assert.assertNotNull(two); + Assert.assertEquals(2, two.getNumberInstantiated()); + Assert.assertEquals(2, two.getInitOrder()); + + SessionScopedOrderedInitPojo three = (SessionScopedOrderedInitPojo) scope.getContext("three").getInstance(null); + Assert.assertNotNull(three); + Assert.assertEquals(3, three.getNumberInstantiated()); + Assert.assertEquals(3, three.getInitOrder()); + + // end request + ctx.clearIdentifier(HttpSessionEvent.HTTP_IDENTIFIER); + + // expire session + scope.onEvent(new HttpSessionEnd(this, session)); + Assert.assertEquals(0, one.getNumberInstantiated()); + scope.stop(); + } + + JavaContextFactoryBuilder builder; + + private List> createComponents() throws BuilderException, ConfigurationLoadException { + AtomicComponent[] ca = new AtomicComponent[3]; + ca[0] = MockFactory.createComponent("TestServiceInitDestroy", SessionScopeInitDestroyComponent.class, + Scope.SESSION); + ca[1] = MockFactory.createComponent("TestServiceInitOnly", SessionScopeInitOnlyComponent.class, Scope.SESSION); + ca[2] = MockFactory.createComponent("TestServiceDestroyOnly", SessionScopeDestroyOnlyComponent.class, + Scope.SESSION); + ComponentTypeIntrospector introspector = MockFactory.getIntrospector(); + ca[0].getImplementation().setComponentType(introspector.introspect(SessionScopeInitDestroyComponent.class)); + ca[1].getImplementation().setComponentType(introspector.introspect(SessionScopeInitOnlyComponent.class)); + ca[2].getImplementation().setComponentType(introspector.introspect(SessionScopeDestroyOnlyComponent.class)); + List> configs = new ArrayList>(); + for (AtomicComponent aCa : ca) { + builder.build(aCa); + configs.add((ContextFactory) aCa.getContextFactory()); + + } + return configs; + } + + private List> createOrderedInitComponents() throws + BuilderException, ConfigurationLoadException { + AtomicComponent[] ca = new AtomicComponent[3]; + ca[0] = MockFactory.createComponent("one", SessionScopedOrderedInitPojo.class, Scope.SESSION); + ca[1] = MockFactory.createComponent("two", SessionScopedOrderedInitPojo.class, Scope.SESSION); + ca[2] = MockFactory.createComponent("three", SessionScopedOrderedInitPojo.class, Scope.SESSION); + ComponentTypeIntrospector introspector = MockFactory.getIntrospector(); + ComponentType type = introspector.introspect(SessionScopedOrderedInitPojo.class); + ca[0].getImplementation().setComponentType(type); + ca[1].getImplementation().setComponentType(type); + ca[2].getImplementation().setComponentType(type); + List> configs = new ArrayList>(); + for (AtomicComponent aCa : ca) { + builder.build(aCa); + configs.add((ContextFactory) aCa.getContextFactory()); + + } + return configs; + } + + protected void setUp() throws Exception { + super.setUp(); + WireFactoryService wireService = new DefaultWireFactoryService(new MessageFactoryImpl(), new JDKWireFactoryFactory(),new DefaultPolicyBuilderRegistry()); + builder = new JavaContextFactoryBuilder(wireService); + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/SessionScopedOrderedInitPojo.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/SessionScopedOrderedInitPojo.java new file mode 100644 index 0000000000..683247a5c8 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/scopes/SessionScopedOrderedInitPojo.java @@ -0,0 +1,56 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.java.scopes; + +import org.osoa.sca.annotations.Scope; +import org.osoa.sca.annotations.Init; +import org.osoa.sca.annotations.Destroy; + +@Scope("SESSION") +public class SessionScopedOrderedInitPojo { + + private static Object lock = new Object(); + private static int numberInstantied; + private int initOrder; + + @Init + public void init() { + synchronized (SessionScopedOrderedInitPojo.lock) { + ++SessionScopedOrderedInitPojo.numberInstantied; + initOrder = SessionScopedOrderedInitPojo.numberInstantied; + } + } + + @Destroy + public void destroy() throws OrderException { + synchronized (SessionScopedOrderedInitPojo.lock) { + if (initOrder != SessionScopedOrderedInitPojo.numberInstantied) { + throw new OrderException("Instance shutdown done out of order"); + } + --SessionScopedOrderedInitPojo.numberInstantied; + } + } + + public int getNumberInstantiated() { + return SessionScopedOrderedInitPojo.numberInstantied; + } + + public int getInitOrder() { + return initOrder; + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/resources/helloworld/example.wsdl b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/resources/helloworld/example.wsdl new file mode 100644 index 0000000000..3a23e7b717 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/resources/helloworld/example.wsdl @@ -0,0 +1,23 @@ + + + + + + + diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/resources/helloworld/sca.module b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/resources/helloworld/sca.module new file mode 100644 index 0000000000..d5bc2cd5f9 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/resources/helloworld/sca.module @@ -0,0 +1,32 @@ + + + + + + + + + + + diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/resources/helloworldmc/sca.module b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/resources/helloworldmc/sca.module new file mode 100644 index 0000000000..8c590976de --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/resources/helloworldmc/sca.module @@ -0,0 +1,40 @@ + + + + + + + + + + + bar + en + + + + HelloWorld/greetingProvider + GreetingProvider + + + + + Hello + + + diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/resources/org/apache/tuscany/container/java/assembly/tests/sca.module b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/resources/org/apache/tuscany/container/java/assembly/tests/sca.module new file mode 100644 index 0000000000..d0f0856225 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/resources/org/apache/tuscany/container/java/assembly/tests/sca.module @@ -0,0 +1,54 @@ + + + + + + + + AccountServiceComponent + + + + + + EURO + + + AccountDataServiceComponent + StockQuoteService + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/resources/org/apache/tuscany/container/java/config/ModuleComponentLoaderTest1.module b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/resources/org/apache/tuscany/container/java/config/ModuleComponentLoaderTest1.module new file mode 100644 index 0000000000..46169aa304 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.java/src/test/resources/org/apache/tuscany/container/java/config/ModuleComponentLoaderTest1.module @@ -0,0 +1,24 @@ + + + + + + + + diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/LICENSE.txt b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/LICENSE.txt new file mode 100644 index 0000000000..d645695673 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/LICENSE.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/README.txt b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/README.txt new file mode 100644 index 0000000000..9b26d1690a --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/README.txt @@ -0,0 +1,35 @@ +Apache Tuscany M1 build (May, 2006) +=================================== + +http://incubator.apache.org/tuscany/ + +Tuscany is an effort undergoing incubation at the Apache Software Foundation +(ASF), sponsored by the Web Services PMC. + +Incubation is required of all newly accepted projects until a further review +indicates that the infrastructure, communications, and decision making process +have stabilized in a manner consistent with other successful ASF projects. + +While incubation status is not necessarily a reflection of the completeness or +stability of the code, it does indicate that the project has yet to be fully +endorsed by the ASF. + + +Support +------- + +Any problem with this release can be reported to the Tuscany mailing list +or in the JIRA issue tracker. + +Mailing list subscription: + tuscany-dev-subscribe@ws.apache.org + +Jira: + http://issues.apache.org/jira/browse/Tuscany + + +Thank you for using Tuscany! + + +The Tuscany Team. + diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/pom.xml b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/pom.xml new file mode 100644 index 0000000000..3f8d8fe9cd --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/pom.xml @@ -0,0 +1,68 @@ + + + + + + org.apache.tuscany.sca.containers + tuscany-sca-containers + incubating-M1 + + + 4.0.0 + tuscany-container-rhino + Tuscany Rhino JavaScript Container + Tuscany Rhino JavaScript Container + incubating-M1 + + + + org.apache.tuscany + tuscany-core + ${pom.version} + compile + + + + rhino + js + 1.6R2 + compile + + + + org.apache.tuscany.databinding + tuscany-databinding-sdo + ${pom.version} + compile + + + + xmlbeans + xbean + 2.1.0 + compile + + + + junit + junit + 3.8.1 + test + + + + diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/main/java/org/apache/tuscany/container/rhino/assembly/JavaScriptImplementation.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/main/java/org/apache/tuscany/container/rhino/assembly/JavaScriptImplementation.java new file mode 100644 index 0000000000..c68bf239a3 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/main/java/org/apache/tuscany/container/rhino/assembly/JavaScriptImplementation.java @@ -0,0 +1,74 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.rhino.assembly; + +import org.apache.tuscany.common.resource.ResourceLoader; +import org.apache.tuscany.model.assembly.impl.AtomicImplementationImpl; + +import commonj.sdo.helper.TypeHelper; + +/** + * Default implementation of a JavScript component implementation type + * + * @version $Rev$ $Date$ + */ +public class JavaScriptImplementation extends AtomicImplementationImpl { + + private String scriptFile; + + private String script; + + private ResourceLoader resourceLoader; + + private TypeHelper typeHelper; + + public JavaScriptImplementation() { + super(); + } + + public void setResourceLoader(ResourceLoader resourceLoader) { + this.resourceLoader = resourceLoader; + } + + public ResourceLoader getResourceLoader() { + return resourceLoader; + } + + public TypeHelper getTypeHelper() { + return typeHelper; + } + + public void setTypeHelper(TypeHelper typeHelper) { + this.typeHelper = typeHelper; + } + + public String getScriptFile() { + return scriptFile; + } + + public void setScriptFile(String fn) { + scriptFile = fn; + } + + public String getScript() { + return script; + } + + public void setScript(String script) { + this.script = script; + } +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/main/java/org/apache/tuscany/container/rhino/builder/JavaScriptContextFactoryBuilder.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/main/java/org/apache/tuscany/container/rhino/builder/JavaScriptContextFactoryBuilder.java new file mode 100644 index 0000000000..2012971014 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/main/java/org/apache/tuscany/container/rhino/builder/JavaScriptContextFactoryBuilder.java @@ -0,0 +1,132 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.rhino.builder; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.wsdl.Input; +import javax.wsdl.Message; +import javax.wsdl.Operation; +import javax.wsdl.Part; +import javax.wsdl.PortType; + +import org.apache.tuscany.container.rhino.assembly.JavaScriptImplementation; +import org.apache.tuscany.container.rhino.config.JavaScriptContextFactory; +import org.apache.tuscany.container.rhino.rhino.E4XDataBinding; +import org.apache.tuscany.container.rhino.rhino.RhinoE4XScript; +import org.apache.tuscany.container.rhino.rhino.RhinoScript; +import org.apache.tuscany.core.builder.BuilderConfigException; +import org.apache.tuscany.core.builder.ContextFactory; +import org.apache.tuscany.core.extension.ContextFactoryBuilderSupport; +import org.apache.tuscany.model.assembly.Scope; +import org.apache.tuscany.model.assembly.Service; +import org.apache.tuscany.model.assembly.ServiceContract; +import org.apache.tuscany.model.types.wsdl.WSDLServiceContract; + +import commonj.sdo.helper.TypeHelper; + +/** + * Builds {@link org.apache.tuscany.container.rhino.config.JavaScriptContextFactory}s from a JavaScript component type + * + * @version $Rev$ $Date$ + */ +@org.osoa.sca.annotations.Scope("MODULE") +public class JavaScriptContextFactoryBuilder extends ContextFactoryBuilderSupport { + + @Override + protected ContextFactory createContextFactory(String componentName, JavaScriptImplementation jsImplementation, Scope scope) { + + Map services = new HashMap(); + for (Service service : jsImplementation.getComponentType().getServices()) { + services.put(service.getName(), service.getServiceContract().getInterface()); + } + + Map defaultProperties = new HashMap(); + for (org.apache.tuscany.model.assembly.Property property : jsImplementation.getComponentType().getProperties()) { + defaultProperties.put(property.getName(), property.getDefaultValue()); + } + + String script = jsImplementation.getScript(); + ClassLoader cl = jsImplementation.getResourceLoader().getClassLoader(); + + RhinoScript invoker; + if (isE4XStyle(componentName, jsImplementation.getComponentType().getServices())) { + E4XDataBinding dataBinding = createDataBinding(jsImplementation); + invoker = new RhinoE4XScript(componentName, script, defaultProperties, cl, dataBinding); + } else { + invoker = new RhinoScript(componentName, script, defaultProperties, cl); + } + + Map properties = new HashMap(); + JavaScriptContextFactory contextFactory = new JavaScriptContextFactory(componentName, scope, services, properties, invoker); + + return contextFactory; + } + + /** + * Tests if this should be an E4X style service + * Its E4X if the JavaScript component uses WSDL to define its interface + */ + protected boolean isE4XStyle(String componentName, List services) { + Boolean isE4XStyle = null; + for (Service service : services) { + ServiceContract sc = service.getServiceContract(); + if (sc instanceof WSDLServiceContract) { + if (isE4XStyle != null && !isE4XStyle.booleanValue()) { + throw new BuilderConfigException("mixed service interface types not supportted"); + } + isE4XStyle = Boolean.TRUE; + } else { + isE4XStyle = Boolean.FALSE; + } + } + return isE4XStyle.booleanValue(); + } + + /** + * Create the data binding for the component initialized for each operation in the service + */ + protected E4XDataBinding createDataBinding(JavaScriptImplementation jsImplementation) { + ClassLoader classLoader = jsImplementation.getResourceLoader().getClassLoader(); + TypeHelper typeHelper = jsImplementation.getTypeHelper(); + E4XDataBinding dataBinding = new E4XDataBinding(classLoader, typeHelper); + for (Service service : jsImplementation.getComponentType().getServices()) { + ServiceContract sc = service.getServiceContract(); + if (sc instanceof WSDLServiceContract) { + PortType pt = ((WSDLServiceContract) sc).getPortType(); + for (Object o : pt.getOperations()) { + Operation operation = (Operation) o; + Input input = operation.getInput(); + if (input != null) { + Message message = input.getMessage(); + if (message != null) { + List parts = message.getOrderedParts(null); + if (parts != null && parts.size() > 0) { + Part part = (Part) parts.get(0); + dataBinding.addElementQName(operation.getName(), part.getElementName()); + } + } + } + } + } + } + return dataBinding; + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/main/java/org/apache/tuscany/container/rhino/builder/JavaScriptTargetWireBuilder.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/main/java/org/apache/tuscany/container/rhino/builder/JavaScriptTargetWireBuilder.java new file mode 100644 index 0000000000..0c45aee35e --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/main/java/org/apache/tuscany/container/rhino/builder/JavaScriptTargetWireBuilder.java @@ -0,0 +1,40 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.rhino.builder; + +import java.lang.reflect.Method; + +import org.apache.tuscany.container.rhino.config.JavaScriptContextFactory; +import org.apache.tuscany.core.context.QualifiedName; +import org.apache.tuscany.core.context.ScopeContext; +import org.apache.tuscany.core.extension.ComponentTargetInvoker; +import org.apache.tuscany.core.extension.WireBuilderSupport; +import org.apache.tuscany.core.wire.TargetInvoker; +import org.osoa.sca.annotations.Scope; + +/** + * Responsible for bridging source- and target-side invocations chains when the target type is a JavaScript implementation + * + * @version $Rev$ $Date$ + */ +@Scope("MODULE") +public class JavaScriptTargetWireBuilder extends WireBuilderSupport { + + protected TargetInvoker createInvoker(QualifiedName targetName, Method operation, ScopeContext context, boolean downScope) { + return new ComponentTargetInvoker(targetName, operation, context); + } +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/main/java/org/apache/tuscany/container/rhino/config/JavaScriptContextFactory.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/main/java/org/apache/tuscany/container/rhino/config/JavaScriptContextFactory.java new file mode 100644 index 0000000000..28a0302a4f --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/main/java/org/apache/tuscany/container/rhino/config/JavaScriptContextFactory.java @@ -0,0 +1,114 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.rhino.config; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.tuscany.container.rhino.context.JavaScriptComponentContext; +import org.apache.tuscany.container.rhino.rhino.RhinoScript; +import org.apache.tuscany.core.builder.ContextCreationException; +import org.apache.tuscany.core.builder.ContextFactory; +import org.apache.tuscany.core.builder.ContextResolver; +import org.apache.tuscany.core.context.AtomicContext; +import org.apache.tuscany.core.context.CompositeContext; +import org.apache.tuscany.core.wire.SourceWireFactory; +import org.apache.tuscany.core.wire.TargetWireFactory; +import org.apache.tuscany.model.assembly.Scope; + +/** + * Creates instance contexts for JavaScript component types + * + * @version $Rev$ $Date$ + */ +public class JavaScriptContextFactory implements ContextFactory, ContextResolver { + + private Scope scope; + + private String name; + + private Map targetProxyFactories = new HashMap(); + + private List sourceProxyFactories = new ArrayList(); + + private Map services; + + private Map properties; + + private RhinoScript invoker; + + private CompositeContext parentContext; + + public JavaScriptContextFactory(String name, Scope scope, Map services, Map properties, RhinoScript invoker) { + this.name = name; + this.scope = scope; + this.services = services; + this.properties = properties; + this.invoker = invoker; + } + + public AtomicContext createContext() throws ContextCreationException { + return new JavaScriptComponentContext(name, services, properties, sourceProxyFactories, targetProxyFactories, invoker.copy()); + } + + public Scope getScope() { + return scope; + } + + public String getName() { + return name; + } + + public void addProperty(String propertyName, Object value) { + properties.put(propertyName, value); + } + + public void addTargetWireFactory(String serviceName, TargetWireFactory factory) { + targetProxyFactories.put(serviceName, factory); + } + + public TargetWireFactory getTargetWireFactory(String serviceName) { + return targetProxyFactories.get(serviceName); + } + + public Map getTargetWireFactories() { + return targetProxyFactories; + } + + public void addSourceWireFactory(String referenceName, SourceWireFactory factory) { + sourceProxyFactories.add(factory); + } + + public void addSourceWireFactories(String referenceName, Class referenceInterface, List factories, boolean multiplicity) { + sourceProxyFactories.addAll(factories); + } + + public List getSourceWireFactories() { + return sourceProxyFactories; + } + + public void prepare(CompositeContext parent) { + parentContext = parent; + } + + public CompositeContext getCurrentContext() { + return parentContext; + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/main/java/org/apache/tuscany/container/rhino/context/JavaScriptComponentContext.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/main/java/org/apache/tuscany/container/rhino/context/JavaScriptComponentContext.java new file mode 100644 index 0000000000..bfa4eeaffb --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/main/java/org/apache/tuscany/container/rhino/context/JavaScriptComponentContext.java @@ -0,0 +1,140 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.rhino.context; + +import org.apache.tuscany.container.rhino.rhino.RhinoScript; +import org.apache.tuscany.core.context.AtomicContext; +import org.apache.tuscany.core.context.CoreRuntimeException; +import org.apache.tuscany.core.context.QualifiedName; +import org.apache.tuscany.core.context.TargetException; +import org.apache.tuscany.core.context.event.InstanceCreated; +import org.apache.tuscany.core.context.impl.AbstractContext; +import org.apache.tuscany.core.wire.ProxyCreationException; +import org.apache.tuscany.core.wire.WireFactory; +import org.apache.tuscany.core.wire.SourceWireFactory; +import org.apache.tuscany.core.wire.TargetWireFactory; +import org.osoa.sca.ServiceRuntimeException; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class JavaScriptComponentContext extends AbstractContext implements AtomicContext { + + private Map services; + + private RhinoScript rhinoInvoker; + + private Map properties; + + private List sourceProxyFactories; + + private Map targetProxyFactories; + + private Object instance; + + public JavaScriptComponentContext(String name, Map services, Map properties, + List sourceProxyFactories, Map targetProxyFactories, RhinoScript invoker) { + super(name); + assert (services != null) : "No service interface mapping specified"; + assert (properties != null) : "No properties specified"; + this.services = services; + this.properties = properties; + this.rhinoInvoker = invoker; + this.sourceProxyFactories = sourceProxyFactories; + this.targetProxyFactories = targetProxyFactories; + } + + public Object getInstance(QualifiedName qName) throws TargetException { + return getInstance(qName, true); + } + + public void init() throws TargetException { + getInstance(null, false); + } + + public void destroy() throws TargetException { + + } + + private synchronized Object getInstance(QualifiedName qName, boolean notify) throws TargetException { + String portName = qName.getPortName(); + WireFactory targetFactory; + if (portName != null) { + targetFactory = targetProxyFactories.get(portName); + } else { + //FIXME The port name is null here, either locateService needs more information (the expected interface) to + // select the correct port, or we need to return a factory that matches the whole set of services exposed by + // the component. + targetFactory = targetProxyFactories.values().iterator().next(); + } + if (targetFactory == null) { + TargetException e = new TargetException("Target service not found"); + e.setIdentifier(qName.getPortName()); + e.addContextName(getName()); + throw e; + } + try { + Object proxy = targetFactory.createProxy(); //createProxy(new Class[] { iface }); + if (notify) { + publish(new InstanceCreated(this)); + } + return proxy; + } catch (ProxyCreationException e) { + TargetException te = new TargetException("Error returning target", e); + e.setIdentifier(qName.getPortName()); + e.addContextName(getName()); + throw te; + } + } + + public Object getTargetInstance() throws TargetException { + rhinoInvoker.updateScriptScope(createServiceReferences()); // create references + rhinoInvoker.updateScriptScope(properties); // create prop values + return rhinoInvoker; + } + + /** + * Creates a map containing any ServiceReferences + */ + private Map createServiceReferences() { + try { + Map context = new HashMap(); + for (SourceWireFactory proxyFactory : sourceProxyFactories) { + context.put(proxyFactory.getConfiguration().getReferenceName(), proxyFactory.createProxy()); + } + return context; + } catch (ProxyCreationException e) { + throw new ServiceRuntimeException(e); + } + } + + public boolean isEagerInit() { + return false; + } + + public boolean isDestroyable() { + return false; + } + + public void start() throws CoreRuntimeException { + } + + public void stop() throws CoreRuntimeException { + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/main/java/org/apache/tuscany/container/rhino/loader/JavaScriptImplementationLoader.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/main/java/org/apache/tuscany/container/rhino/loader/JavaScriptImplementationLoader.java new file mode 100644 index 0000000000..e28776049c --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/main/java/org/apache/tuscany/container/rhino/loader/JavaScriptImplementationLoader.java @@ -0,0 +1,168 @@ +/** + * + * Copyright 2005 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.rhino.loader; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.common.resource.ResourceLoader; +import org.apache.tuscany.container.rhino.assembly.JavaScriptImplementation; +import org.apache.tuscany.core.config.ConfigurationLoadException; +import org.apache.tuscany.core.config.InvalidRootElementException; +import org.apache.tuscany.core.config.MissingResourceException; +import org.apache.tuscany.core.config.SidefileLoadException; +import org.apache.tuscany.core.loader.LoaderContext; +import org.apache.tuscany.core.loader.StAXElementLoader; +import org.apache.tuscany.core.loader.StAXLoaderRegistry; +import org.apache.tuscany.core.loader.assembly.AssemblyConstants; +import org.apache.tuscany.core.system.annotation.Autowire; +import org.apache.tuscany.model.assembly.ComponentType; +import org.osoa.sca.annotations.Destroy; +import org.osoa.sca.annotations.Init; +import org.osoa.sca.annotations.Scope; + +/** + * @version $Rev$ $Date$ + */ +@Scope("MODULE") +public class JavaScriptImplementationLoader implements StAXElementLoader { + + public static final QName IMPLEMENTATION_JS = new QName("http://org.apache.tuscany/xmlns/js/0.9", "implementation.js"); + + protected StAXLoaderRegistry registry; + + private XMLInputFactory xmlFactory; + + public JavaScriptImplementationLoader() { + // todo make this a reference to a system service + xmlFactory = XMLInputFactory.newInstance(); + } + + @Autowire + public void setRegistry(StAXLoaderRegistry registry) { + this.registry = registry; + } + + @Init(eager = true) + public void start() { + registry.registerLoader(IMPLEMENTATION_JS, this); + } + + @Destroy + public void stop() { + registry.unregisterLoader(IMPLEMENTATION_JS, this); + } + + public JavaScriptImplementation load(XMLStreamReader reader, LoaderContext loaderContext) throws XMLStreamException, ConfigurationLoadException { + String scriptFile = reader.getAttributeValue(null, "scriptFile"); + String script = loadScript(scriptFile, loaderContext.getResourceLoader()); + ComponentType componentType = loadComponentType(scriptFile, loaderContext); + + JavaScriptImplementation jsImpl = new JavaScriptImplementation(); + jsImpl.setComponentType(componentType); + jsImpl.setScriptFile(scriptFile); + jsImpl.setScript(script); + jsImpl.setResourceLoader(loaderContext.getResourceLoader()); + jsImpl.setTypeHelper(registry.getContext().getTypeHelper()); + return jsImpl; + } + + protected String loadScript(String scriptFile, ResourceLoader resourceLoader) throws ConfigurationLoadException { + URL url = resourceLoader.getResource(scriptFile); + if (url == null) { + throw new ConfigurationLoadException(scriptFile); + } + InputStream inputStream; + try { + inputStream = url.openStream(); + } catch (IOException e) { + throw new ConfigurationLoadException(scriptFile, e); + } + try { + StringBuilder sb = new StringBuilder(1024); + int n; + while ((n = inputStream.read()) != -1) { + sb.append((char) n); + } + return sb.toString(); + } catch (IOException e) { + throw new ConfigurationLoadException(scriptFile, e); + } finally { + try { + inputStream.close(); + } catch (IOException e) { + // ignore + } + } + } + + protected ComponentType loadComponentType(String scriptFile, LoaderContext loaderContext) throws SidefileLoadException, MissingResourceException{ + String sidefile = scriptFile.substring(0, scriptFile.lastIndexOf('.')) + ".componentType"; + URL componentTypeFile = loaderContext.getResourceLoader().getResource(sidefile); + if (componentTypeFile == null) { + throw new MissingResourceException(sidefile); + } + + try { + XMLStreamReader reader; + InputStream is; + is = componentTypeFile.openStream(); + try { + reader = xmlFactory.createXMLStreamReader(is); + try { + reader.nextTag(); + if (!AssemblyConstants.COMPONENT_TYPE.equals(reader.getName())) { + InvalidRootElementException e = new InvalidRootElementException(AssemblyConstants.COMPONENT_TYPE, reader.getName()); + e.setResourceURI(componentTypeFile.toString()); + throw e; + } + return (ComponentType) registry.load(reader, loaderContext); + } finally { + try { + reader.close(); + } catch (XMLStreamException e) { + // ignore + } + } + } finally { + try { + is.close(); + } catch (IOException e) { + // ignore + } + } + } catch (IOException e) { + SidefileLoadException sfe = new SidefileLoadException(e.getMessage()); + sfe.setResourceURI(componentTypeFile.toString()); + throw sfe; + } catch (XMLStreamException e) { + SidefileLoadException sfe = new SidefileLoadException(e.getMessage()); + sfe.setResourceURI(componentTypeFile.toString()); + throw sfe; + } catch (ConfigurationLoadException e) { + SidefileLoadException sfe = new SidefileLoadException(e.getMessage()); + sfe.setResourceURI(componentTypeFile.toString()); + throw sfe; + } + } +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/main/java/org/apache/tuscany/container/rhino/rhino/E4XDataBinding.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/main/java/org/apache/tuscany/container/rhino/rhino/E4XDataBinding.java new file mode 100644 index 0000000000..3969735b23 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/main/java/org/apache/tuscany/container/rhino/rhino/E4XDataBinding.java @@ -0,0 +1,108 @@ +/** + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.rhino.rhino; + +import java.io.ByteArrayInputStream; +import java.util.HashMap; +import java.util.Map; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.core.wire.InvocationRuntimeException; +import org.apache.tuscany.databinding.sdo.SDOXMLHelper; +import org.apache.xmlbeans.XmlObject; +import org.mozilla.javascript.Context; +import org.mozilla.javascript.Scriptable; + +import commonj.sdo.helper.TypeHelper; + +/** + * DataBinding to convert between Java objects and JavaScript E4X XML objects. This uses SDO to do the conversion between XML and Java so WSDL/XSDs + * need to have be registered with the SDO runtime. + * + * TODO: suport non-wrapped WSDL + */ +public class E4XDataBinding { + + private ClassLoader classLoader; + + private TypeHelper typeHelper; + + private Map function2ElementMap; + + private static final boolean IS_WRAPPED = true; + + public E4XDataBinding(ClassLoader classLoader, TypeHelper typeHelper) { + this.classLoader = classLoader; + this.typeHelper = typeHelper; + this.function2ElementMap = new HashMap(); + } + + /** + * Convert E4X XML to Java objects + * + * @param e4xXML + * @return the array of Objects + */ + public Object[] toObjects(Scriptable e4xXML) { + byte[] xmlBytes = e4xXML.toString().getBytes(); + Object[] os = SDOXMLHelper.toObjects(classLoader, typeHelper, xmlBytes, IS_WRAPPED); + return os; + } + + /** + * Convert request Java objects to XML + * + * @param functionName + * @param os + * @param scope + * @return a JavaScript E4X XML object + */ + public Scriptable toE4X(String functionName, Object[] os, Scriptable scope) { + QName elementQN = function2ElementMap.get(functionName); + byte[] xmlBytes = SDOXMLHelper.toXMLBytes(classLoader, typeHelper, os, elementQN, IS_WRAPPED); + + XmlObject xmlObject; + try { + xmlObject = XmlObject.Factory.parse(new ByteArrayInputStream(xmlBytes)); + } catch (Exception e) { + throw new InvocationRuntimeException(e); + } + + Context cx = Context.enter(); + try { + + Object xml = cx.getWrapFactory().wrap(cx, scope, xmlObject, XmlObject.class); + Scriptable jsXML = cx.newObject(scope, "XML", new Object[] { xml }); + + return jsXML; + + } finally { + Context.exit(); + } + } + + /** + * Add the XML element name to use for an operation when converting from + * Java objects to XML. + * + * @param functionName + * @param elementQN + */ + public void addElementQName(String functionName, QName elementQN) { + function2ElementMap.put(functionName, elementQN); + } +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/main/java/org/apache/tuscany/container/rhino/rhino/RhinoE4XScript.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/main/java/org/apache/tuscany/container/rhino/rhino/RhinoE4XScript.java new file mode 100644 index 0000000000..5f42f6d164 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/main/java/org/apache/tuscany/container/rhino/rhino/RhinoE4XScript.java @@ -0,0 +1,76 @@ +/** + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.rhino.rhino; + +import java.util.Map; + +import org.mozilla.javascript.Function; +import org.mozilla.javascript.Scriptable; +import org.mozilla.javascript.xml.XMLObject; + +/** + * Invokes a JavaScript/E4X function with argument and return values that may be E4X XML objects. + */ +public class RhinoE4XScript extends RhinoScript { + + private E4XDataBinding dataBinding; + + public RhinoE4XScript(String scriptName, String script, Map context, ClassLoader cl, E4XDataBinding dataBinding) { + super(scriptName, script, context, cl); + this.dataBinding = dataBinding; + } + + protected RhinoE4XScript(String scriptName, String script, Scriptable scriptScope, E4XDataBinding dataBinding) { + super(scriptName, script, scriptScope); + this.dataBinding = dataBinding; + } + + /** + * Turn args to JS objects and convert any OMElement to E4X XML + */ + @Override + protected Object[] processArgs(String functionName, Object[] args, Scriptable scope) { + return new Object[] { dataBinding.toE4X(functionName, args, scope) }; + } + + /** + * Unwrap and convert response converting any E4X XML into Java objects + */ + @Override + protected Object processResponse(String functionName, Object response, Class responseClass) { + if (response instanceof XMLObject) { + Object[] os = dataBinding.toObjects((XMLObject) response); + if (os == null || os.length < 1) { + return null; + } else { + return os[0]; + } + } else { + return super.processResponse(functionName, response, responseClass); + } + } + + @Override + protected Function getFunction(Scriptable scope, String functionName) { + return super.getFunction(scope, "process"); + } + + @Override + public RhinoE4XScript copy() { + return new RhinoE4XScript(scriptName, script, scriptScope, dataBinding); + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/main/java/org/apache/tuscany/container/rhino/rhino/RhinoScript.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/main/java/org/apache/tuscany/container/rhino/rhino/RhinoScript.java new file mode 100644 index 0000000000..5518159f69 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/main/java/org/apache/tuscany/container/rhino/rhino/RhinoScript.java @@ -0,0 +1,290 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.rhino.rhino; + +import java.util.Iterator; +import java.util.Map; + +import org.apache.tuscany.core.extension.ExternalServiceInvoker; +import org.mozilla.javascript.Context; +import org.mozilla.javascript.ContextFactory; +import org.mozilla.javascript.Function; +import org.mozilla.javascript.ImporterTopLevel; +import org.mozilla.javascript.Script; +import org.mozilla.javascript.Scriptable; +import org.mozilla.javascript.Wrapper; + +/** + * Represents, and is responsible for dispatching to, a JavaScript artifact in Rhino + */ +public class RhinoScript implements ExternalServiceInvoker { + + protected String scriptName; + + protected String script; + + protected Scriptable scriptScope; + + private Scriptable sharedScope; + + /* + * Enable dynamic scopes so a script can be used concurrently with a global shared scope and individual execution + * scopes. See http://www.mozilla.org/rhino/scopes.html TODO: need to review how ths fits in with Tuscany scopes + */ + private static class MyFactory extends ContextFactory { + protected boolean hasFeature(Context cx, int featureIndex) { + if (featureIndex == Context.FEATURE_DYNAMIC_SCOPE) { + return true; + } + return super.hasFeature(cx, featureIndex); + } + } + + static { + ContextFactory.initGlobal(new MyFactory()); + } + + /** + * Create a new RhinoInvoker. + * + * @param scriptName the name of the script. Can be anything, only used in messages to identify the script + * @param script the complete script + */ + public RhinoScript(String scriptName, String script) { + this(scriptName, script, (Map) null, null); + } + + /** + * Create a new RhinoInvoker. + * + * @param scriptName the name of the script. Can be anything, only used in messages to identify the script + * @param script the complete script + * @param context name-value pairs that are added in to the scope where the script is compiled. May be null. The + * value objects are made available to the script by using a variable with the name. + */ + public RhinoScript(String scriptName, String script, Map context, ClassLoader cl) { + this.scriptName = scriptName; + this.script = script; + initScriptScope(scriptName, script, context, cl); + initSharedScope(); + } + + /** + * Construct a RhinoInvoker from another RhinoInvoker object. This uses the original script scope so the script + * doesn't need to be recompiled. + */ + protected RhinoScript(String scriptName, String script, Scriptable scriptScope) { + this.scriptName = scriptName; + this.script = script; + this.scriptScope = scriptScope; + initSharedScope(); + } + + /** + * Invoke a script function + * + * @param functionName the name of the function to invoke. + * @param arg arguments to the function, may be a single object or an array of objects. + * @return the function return value. + */ + public Object invoke(String functionName, Object[] args) { + return invoke(functionName, args, null, null); + } + + /** + * Invoke a script function + * + * @param functionName the name of the function to invoke. + * @param arg arguments to the function, may be a single object or an array of objects. + * @param contexts a Map of name-value pairs which are added to the wire Scope to enable the script to access + * the values by using the variable in name. + * @return the function return value. + */ + public Object invoke(String functionName, Object[] args, Map contexts) { + return invoke(functionName, args, null, contexts); + } + + /** + * Invoke a script function + * + * @param functionName the name of the function to invoke. + * @param arg arguments to the function, may be a single object or an array of objects. + * @param responseClass the desired class of the response object. + * @param contexts a Map of name-value pairs which are added to the wire Scope to enable the script to access + * the values by using the variable in name. + * @return the function return value. + */ + public Object invoke(String functionName, Object[] args, Class responseClass, Map contexts) { + Context cx = Context.enter(); + try { + Function function = getFunction(scriptScope, functionName); + Scriptable invocationScope = getInvocationScope(cx, contexts); + Object[] jsArgs = processArgs(functionName, args, invocationScope); + Object jsResponse = function.call(cx, invocationScope, invocationScope, jsArgs); + Object response = processResponse(functionName, jsResponse, responseClass); + return response; + } finally { + Context.exit(); + } + } + + /** + * Turn args to JS objects and convert any OMElement to E4X XML + */ + protected Object[] processArgs(String functionName, Object[] arg, Scriptable scope) { + Object[] args; + if (arg == null) { + args = new Object[] { null }; + } else if (arg.getClass().isArray()) { + args = (Object[]) arg; + for (int i = 0; i < args.length; i++) { + args[i] = Context.toObject(args[i], scope); + } + } else { + args = new Object[] { Context.toObject(arg, scope) }; + } + return args; + } + + /** + * Unwrap and convert response + */ + protected Object processResponse(String functionName, Object response, Class responseClass) { + if (Context.getUndefinedValue().equals(response)) { + response = null; + } else if (response instanceof Wrapper) { + response = ((Wrapper) response).unwrap(); + } else { + if (responseClass != null) { + response = Context.jsToJava(response, responseClass); + } else { + response = Context.jsToJava(response, String.class); + } + } + return response; + } + + /** + * Create a Rhino scope and compile the script into it + */ + protected void initScriptScope(String fileName, String scriptCode, Map context, ClassLoader cl) { + Context cx = Context.enter(); + try { + + if (cl != null) { + cx.setApplicationClassLoader(cl); + } + this.scriptScope = new ImporterTopLevel( cx, true ); + Script compiledScript = cx.compileString(scriptCode, fileName, 1, null); + compiledScript.exec(cx, scriptScope); + addContexts(scriptScope, context); + + } finally { + Context.exit(); + } + } + + /** + * Initializes the shared scope + */ + protected void initSharedScope() { + Context cx = Context.enter(); + try { + + this.sharedScope = cx.newObject(scriptScope); + sharedScope.setPrototype(scriptScope); + sharedScope.setParentScope(null); + + } finally { + Context.exit(); + } + } + + /** + * Get a Rhino scope for the function wire. If the wire has no context objects then this will use the + * shared scope otherwise a new scope is created to hold the context objects. Any new variables the executing script + * might define will go in the sharedScope. This new scope is just to hold the wire specific context objects. + */ + protected Scriptable getInvocationScope(Context cx, Map contexts) { + + Scriptable scope; + if (contexts == null || contexts.size() == 0) { + scope = sharedScope; + } else { + scope = cx.newObject(sharedScope); + scope.setPrototype(sharedScope); + scope.setParentScope(null); + addContexts(scope, contexts); + } + + return scope; + } + + /** + * Add the context to the scope. This will make the objects available to a script by using the name it was added + * with. + */ + protected void addContexts(Scriptable scope, Map contexts) { + if (contexts != null) { + for (Iterator i = contexts.keySet().iterator(); i.hasNext();) { + String name = (String) i.next(); + Object value = contexts.get(name); + if (value != null) { + scope.put(name, scope, Context.toObject(value, scope)); + } + } + } + } + + /** + * Get the Rhino Function object for the named script function + */ + protected Function getFunction(Scriptable scope, String functionName) { + + Object handleObj = scope.get(functionName, scope); + + if (!(handleObj instanceof Function)) { + throw new RuntimeException("script function '" + functionName + "' is undefined or not a function in script " + + scriptName); + } + + return (Function) handleObj; + } + + /** + * Make a copy of this RhinoScript object. This shares the script scope to avoid the overhead of recompiling the + * script, and to allow any initialization done by the script to be shared. + */ + public RhinoScript copy() { + return new RhinoScript(scriptName, script, scriptScope); + } + + /** + * Update the scope where the script is complied with new context values + * + * @param properties + */ + public void updateScriptScope(Map context) { + Context.enter(); + try { + addContexts(scriptScope, context); + } finally { + Context.exit(); + } + } + +} \ No newline at end of file diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/main/resources/system.fragment b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/main/resources/system.fragment new file mode 100644 index 0000000000..840efd10bc --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/main/resources/system.fragment @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/java/org/apache/tuscany/container/rhino/integration/AbstractJavaScriptTestCase.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/java/org/apache/tuscany/container/rhino/integration/AbstractJavaScriptTestCase.java new file mode 100644 index 0000000000..ee6b533ddf --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/java/org/apache/tuscany/container/rhino/integration/AbstractJavaScriptTestCase.java @@ -0,0 +1,46 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package org.apache.tuscany.container.rhino.integration; + +import junit.framework.TestCase; + +import org.apache.tuscany.core.client.TuscanyRuntime; +import org.osoa.sca.CurrentModuleContext; +import org.osoa.sca.ModuleContext; + +/** + * Integration tests for JavaScript components + */ +public abstract class AbstractJavaScriptTestCase extends TestCase { + + protected TuscanyRuntime tuscany; + + protected ModuleContext moduleContext; + + @Override + protected void setUp() throws Exception { + super.setUp(); + + tuscany = new TuscanyRuntime("tests", null); + tuscany.start(); + moduleContext = CurrentModuleContext.getContext(); + + } + + @Override + protected void tearDown() throws Exception { + super.tearDown(); + tuscany.stop(); + } +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/java/org/apache/tuscany/container/rhino/integration/BasicTestCase.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/java/org/apache/tuscany/container/rhino/integration/BasicTestCase.java new file mode 100644 index 0000000000..f66f2e1079 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/java/org/apache/tuscany/container/rhino/integration/BasicTestCase.java @@ -0,0 +1,27 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package org.apache.tuscany.container.rhino.integration; + +/** + * Integration tests for JavaScript components + */ +public class BasicTestCase extends AbstractJavaScriptTestCase { + + public void testBasicInvocation() throws Exception { + HelloWorld helloworldService = (HelloWorld) moduleContext.locateService("HelloWorldComponent1"); + String response = helloworldService.getGreetings("petra"); + assertEquals("jsHello petra", response); + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/java/org/apache/tuscany/container/rhino/integration/E4XTestCase.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/java/org/apache/tuscany/container/rhino/integration/E4XTestCase.java new file mode 100644 index 0000000000..d6060aea90 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/java/org/apache/tuscany/container/rhino/integration/E4XTestCase.java @@ -0,0 +1,29 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package org.apache.tuscany.container.rhino.integration; + +/** + * Integration tests for JavaScript components and composite contexts + * + * @version $Rev$ $Date$ + */ +public class E4XTestCase extends AbstractJavaScriptTestCase { + + public void testE4X() throws Exception { + HelloWorld helloworldService = (HelloWorld) moduleContext.locateService("HelloWorldComponentE4X"); + String response = helloworldService.getGreetings("petra"); + assertEquals("e4xHello petra", response); + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/java/org/apache/tuscany/container/rhino/integration/HelloWorld.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/java/org/apache/tuscany/container/rhino/integration/HelloWorld.java new file mode 100644 index 0000000000..3a90be0102 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/java/org/apache/tuscany/container/rhino/integration/HelloWorld.java @@ -0,0 +1,26 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.rhino.integration; + +/** + * This is the business interface of the HelloWorld service component. + */ +public interface HelloWorld { + + public String getGreetings(String name); + +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/java/org/apache/tuscany/container/rhino/integration/InitializationTestCase.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/java/org/apache/tuscany/container/rhino/integration/InitializationTestCase.java new file mode 100644 index 0000000000..138d9a8452 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/java/org/apache/tuscany/container/rhino/integration/InitializationTestCase.java @@ -0,0 +1,33 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package org.apache.tuscany.container.rhino.integration; + +/** + * Integration tests for JavaScript components + */ +public class InitializationTestCase extends AbstractJavaScriptTestCase { + + public void testInitialization() throws Exception { + HelloWorld helloworldService = (HelloWorld) moduleContext.locateService("HelloWorldComponent4"); + String response = helloworldService.getGreetings("petra"); + assertEquals("Bonjour petra", response); + } + + public void testImports1() throws Exception { + HelloWorld helloworldService = (HelloWorld) moduleContext.locateService("HelloWorldComponent5"); + String response = helloworldService.getGreetings("petra"); + assertEquals("Kia ora petra", response); + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/java/org/apache/tuscany/container/rhino/integration/PropertiesTestCase.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/java/org/apache/tuscany/container/rhino/integration/PropertiesTestCase.java new file mode 100644 index 0000000000..7b14376dbe --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/java/org/apache/tuscany/container/rhino/integration/PropertiesTestCase.java @@ -0,0 +1,33 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package org.apache.tuscany.container.rhino.integration; + +/** + * Integration tests for JavaScript components + */ +public class PropertiesTestCase extends AbstractJavaScriptTestCase { + + public void testDefaultProperty() throws Exception { + HelloWorld helloworldService = (HelloWorld) moduleContext.locateService("HelloWorldComponent2a"); + String response = helloworldService.getGreetings("petra"); + assertEquals("Hi petra", response); + } + + public void testOverrideProperty() throws Exception { + HelloWorld helloworldService = (HelloWorld) moduleContext.locateService("HelloWorldComponent2b"); + String response = helloworldService.getGreetings("petra"); + assertEquals("Guten Tag petra", response); + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/java/org/apache/tuscany/container/rhino/integration/Salutation.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/java/org/apache/tuscany/container/rhino/integration/Salutation.java new file mode 100644 index 0000000000..42d46c16d1 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/java/org/apache/tuscany/container/rhino/integration/Salutation.java @@ -0,0 +1,25 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.rhino.integration; + +/** + */ +public interface Salutation { + + public String getSalutation(); + +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/java/org/apache/tuscany/container/rhino/integration/ServiceRefsTestCase.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/java/org/apache/tuscany/container/rhino/integration/ServiceRefsTestCase.java new file mode 100644 index 0000000000..27993c2b99 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/java/org/apache/tuscany/container/rhino/integration/ServiceRefsTestCase.java @@ -0,0 +1,27 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package org.apache.tuscany.container.rhino.integration; + +/** + * Integration tests for JavaScript components + */ +public class ServiceRefsTestCase extends AbstractJavaScriptTestCase { + + public void testServiceReference() throws Exception { + HelloWorld helloworldService = (HelloWorld) moduleContext.locateService("HelloWorldComponent3a"); + String response = helloworldService.getGreetings("petra"); + assertEquals("Guten Tag petra", response); + } + +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/java/org/apache/tuscany/container/rhino/integration/TestMethods.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/java/org/apache/tuscany/container/rhino/integration/TestMethods.java new file mode 100644 index 0000000000..327edd1cbb --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/java/org/apache/tuscany/container/rhino/integration/TestMethods.java @@ -0,0 +1,30 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.rhino.integration; + +public class TestMethods { + + private String salutation = "Kia ora"; + + public String getSalutation() { + return salutation; + } + + public void getSalutation(String s) { + salutation = s; + } +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/java/org/apache/tuscany/container/rhino/rhino/RhinoE4XScriptTestCase.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/java/org/apache/tuscany/container/rhino/rhino/RhinoE4XScriptTestCase.java new file mode 100644 index 0000000000..714814f2cf --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/java/org/apache/tuscany/container/rhino/rhino/RhinoE4XScriptTestCase.java @@ -0,0 +1,89 @@ +/* + * Copyright 2004,2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.rhino.rhino; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; + +import javax.xml.namespace.QName; + +import junit.framework.TestCase; + +import org.apache.tuscany.sdo.helper.XSDHelperImpl; +import org.apache.tuscany.sdo.util.SDOUtil; + +import commonj.sdo.helper.TypeHelper; +import commonj.sdo.helper.XSDHelper; + +/** + * Tests for the RhinoE4XScript + */ +public class RhinoE4XScriptTestCase extends TestCase { + + private static final String scriptName = "RhinoE4XScriptTestCase.js"; + + private String script; + + private E4XDataBinding dataBinding; + + protected void setUp() throws Exception { + super.setUp(); + this.script = readResource(scriptName); + TypeHelper th = SDOUtil.createTypeHelper(); + XSDHelper xsdHelper = new XSDHelperImpl(th); + URL url = getClass().getResource("helloworld.wsdl"); + xsdHelper.define(url.openStream(), null); + + dataBinding = new E4XDataBinding(getClass().getClassLoader(),th); + dataBinding.addElementQName("getGreetings", new QName("http://helloworld.samples.tuscany.apache.org", "getGreetings")); + } + + public void testSimpleInvocation() throws IOException { + RhinoE4XScript ri = new RhinoE4XScript(scriptName, script, null, null, dataBinding); + Object x = ri.invoke("getGreetings", new Object[] { "petra" }, null); + assertEquals(x, "hello petra"); + } + + /** + * Read a resource into a String + */ + private String readResource(String name) { + try { + URL url = getClass().getResource(name); + if (url == null) { + throw new RuntimeException("resource not found: " + name); + } + InputStream inputStream = url.openStream(); + + StringBuffer resource = new StringBuffer(); + int n = 0; + + while ((n = inputStream.read()) != -1) { + resource.append((char) n); + } + + inputStream.close(); + + String s = resource.toString(); + return s; + + } catch (IOException e) { + throw new RuntimeException("IOException reading resource " + name, e); + } + } + +} \ No newline at end of file diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/java/org/apache/tuscany/container/rhino/rhino/RhinoScriptTestCase.java b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/java/org/apache/tuscany/container/rhino/rhino/RhinoScriptTestCase.java new file mode 100644 index 0000000000..19c0d9bcf6 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/java/org/apache/tuscany/container/rhino/rhino/RhinoScriptTestCase.java @@ -0,0 +1,186 @@ +/* + * Copyright 2004,2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.container.rhino.rhino; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.util.HashMap; +import java.util.Map; + +import junit.framework.TestCase; + +import org.apache.tuscany.container.rhino.rhino.RhinoScript; +import org.mozilla.javascript.EcmaError; + +/** + * Tests for the RhinoScript + */ +public class RhinoScriptTestCase extends TestCase { + + private static final String scriptName = "RhinoScriptTestCase.js"; + + private String script; + + protected void setUp() throws Exception { + super.setUp(); + this.script = readResource(scriptName); + } + + public void testSimpleInvocation() { + RhinoScript ri = new RhinoScript(scriptName, script); + Object x = ri.invoke("echo", new Object[] { "petra" }, null); + assertEquals("petra", x); + } + + public void testCopy() { + RhinoScript ri = new RhinoScript(scriptName, script); + Object x = ri.invoke("echo", new Object[] { "petra" }, null); + assertEquals("petra", x); + + ri = ri.copy(); + x = ri.invoke("echo", new Object[] { "sue" }, null); + assertEquals("sue", x); + + } + + public void testContexts1() { + RhinoScript ri = new RhinoScript(scriptName, script); + Map contexts = new HashMap(); + contexts.put("a", "petra"); + Object x = ri.invoke("getA", null, contexts); + assertEquals("petra", x); + } + + /** + * Tests context not accessable across invocations + */ + public void testContexts2() { + RhinoScript ri = new RhinoScript(scriptName, script); + Map contexts = new HashMap(); + contexts.put("a", "petra"); + Object x = ri.invoke("getA", null, contexts); + assertEquals("petra", x); + + try { + x = ri.invoke("getA", null, null); + assertTrue("expected ReferenceError", false); + } catch (EcmaError e) { + assertEquals("ReferenceError", e.getName()); + } + } + + /** + * Tests shared scope is accessable across invocations + */ + public void testScopes1() { + RhinoScript ri = new RhinoScript(scriptName, script); + ri.invoke("setGlobalVarY", new Object[] { "petra" }, null); + + Object x = ri.invoke("getGlobalVarY", null, null); + assertEquals("petra", x); + } + + /** + * Tests local vars are NOT accessable across invocations + */ + public void testScopes2() { + RhinoScript ri = new RhinoScript(scriptName, script); + ri.invoke("setLocalVarY", new Object[] { "petra" }, null); + + try { + ri.invoke("getGlobalVarY", null, null); + assertTrue("expected ReferenceError", false); + } catch (EcmaError e) { + assertEquals("ReferenceError", e.getName()); + } + } + + /** + * Tests shared scope is accessable when using contexts (ie an wire scope) + */ + public void testScopes3() { + RhinoScript ri = new RhinoScript(scriptName, script); + ri.invoke("setGlobalVarY", new Object[] { "petra" }, null); + + Map contexts = new HashMap(); + contexts.put("a", "sue"); + Object x = ri.invoke("getGlobalVarY", null, contexts); + assertEquals("petra", x); + + x = ri.invoke("getA", null, contexts); + assertEquals("sue", x); + + } + + /** + * Tests a copy only retains the script scope not the shared scope + */ + public void testScopes4() { + RhinoScript ri = new RhinoScript(scriptName, script); + ri.invoke("setGlobalVarY", new Object[] { "petra" }, null); + + ri = ri.copy(); + try { + ri.invoke("getGlobalVarY", null, null); + assertTrue("expected ReferenceError", false); + } catch (EcmaError e) { + assertEquals("ReferenceError", e.getName()); + } + try { + ri.invoke("getA", null, null); + assertTrue("expected ReferenceError", false); + } catch (EcmaError e) { + assertEquals("ReferenceError", e.getName()); + } + + } + + public void testGetInt() { + RhinoScript ri = new RhinoScript(scriptName, script); + Object x = ri.invoke("getInt", null, Integer.TYPE, null); + assertEquals(Integer.class, x.getClass()); + } + + /** + * Read a resource into a String + */ + private String readResource(String name) { + try { + URL url = getClass().getResource(name); + if (url == null) { + throw new RuntimeException("resource not found: " + name); + } + InputStream inputStream = url.openStream(); + + StringBuffer resource = new StringBuffer(); + int n = 0; + + while ((n = inputStream.read()) != -1) { + resource.append((char) n); + } + + inputStream.close(); + + String s = resource.toString(); + return s; + + } catch (IOException e) { + throw new RuntimeException("IOException reading resource " + name, e); + } + } + +} \ No newline at end of file diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/resources/org/apache/tuscany/container/rhino/rhino/RhinoE4XScriptTestCase.js b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/resources/org/apache/tuscany/container/rhino/rhino/RhinoE4XScriptTestCase.js new file mode 100644 index 0000000000..20dc2245f9 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/resources/org/apache/tuscany/container/rhino/rhino/RhinoE4XScriptTestCase.js @@ -0,0 +1,11 @@ + +function process(inXML) { + + var greeting = "hello " + inXML..*::in0; + var outXML = + + { greeting } + ; + + return outXML; +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/resources/org/apache/tuscany/container/rhino/rhino/RhinoScriptTestCase.js b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/resources/org/apache/tuscany/container/rhino/rhino/RhinoScriptTestCase.js new file mode 100644 index 0000000000..2de740d5f8 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/resources/org/apache/tuscany/container/rhino/rhino/RhinoScriptTestCase.js @@ -0,0 +1,22 @@ + +function echo(x) { + return x; +} + +function getA(x) { + return a; +} + +function setGlobalVarY(x) { + y = x; +} +function setLocalVarY(x) { + var y = x; +} +function getGlobalVarY(x) { + return y; +} + +function getInt(x) { + return 42; +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/resources/org/apache/tuscany/container/rhino/rhino/helloworld.wsdl b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/resources/org/apache/tuscany/container/rhino/rhino/helloworld.wsdl new file mode 100644 index 0000000000..a402cc4d7c --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/resources/org/apache/tuscany/container/rhino/rhino/helloworld.wsdl @@ -0,0 +1,97 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/resources/sca.module b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/resources/sca.module new file mode 100644 index 0000000000..f78a41381a --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/resources/sca.module @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + Guten Tag + + + + + + + SalutationComponent3b + + + + + + + Guten Tag + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/resources/tests/HelloWorldImpl1.componentType b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/resources/tests/HelloWorldImpl1.componentType new file mode 100644 index 0000000000..90b6c09015 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/resources/tests/HelloWorldImpl1.componentType @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/resources/tests/HelloWorldImpl1.js b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/resources/tests/HelloWorldImpl1.js new file mode 100644 index 0000000000..b3104f78a5 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/resources/tests/HelloWorldImpl1.js @@ -0,0 +1,20 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +function getGreetings(name) { + return "jsHello " + name; +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/resources/tests/HelloWorldImpl2.componentType b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/resources/tests/HelloWorldImpl2.componentType new file mode 100644 index 0000000000..33208811bf --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/resources/tests/HelloWorldImpl2.componentType @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/resources/tests/HelloWorldImpl2.js b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/resources/tests/HelloWorldImpl2.js new file mode 100644 index 0000000000..4f91dba40e --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/resources/tests/HelloWorldImpl2.js @@ -0,0 +1,20 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +function getGreetings(name) { + return salutation + " " + name; +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/resources/tests/HelloWorldImpl3a.componentType b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/resources/tests/HelloWorldImpl3a.componentType new file mode 100644 index 0000000000..1bc6922e6d --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/resources/tests/HelloWorldImpl3a.componentType @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/resources/tests/HelloWorldImpl3a.js b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/resources/tests/HelloWorldImpl3a.js new file mode 100644 index 0000000000..f3160f6f65 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/resources/tests/HelloWorldImpl3a.js @@ -0,0 +1,20 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +function getGreetings(name) { + return SalutationService.getSalutation() + " " + name; +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/resources/tests/HelloWorldImpl4.componentType b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/resources/tests/HelloWorldImpl4.componentType new file mode 100644 index 0000000000..90b6c09015 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/resources/tests/HelloWorldImpl4.componentType @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/resources/tests/HelloWorldImpl4.js b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/resources/tests/HelloWorldImpl4.js new file mode 100644 index 0000000000..338c3ac3cd --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/resources/tests/HelloWorldImpl4.js @@ -0,0 +1,26 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +initSalutation(); + +function getGreetings(name) { + return SALUTATION + name; +} + +function initSalutation() { + SALUTATION = "Bonjour "; +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/resources/tests/HelloWorldImpl5.componentType b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/resources/tests/HelloWorldImpl5.componentType new file mode 100644 index 0000000000..90b6c09015 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/resources/tests/HelloWorldImpl5.componentType @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/resources/tests/HelloWorldImpl5.js b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/resources/tests/HelloWorldImpl5.js new file mode 100644 index 0000000000..f01cd1727f --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/resources/tests/HelloWorldImpl5.js @@ -0,0 +1,29 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +//importPackage(Packages.sample.utils); +importClass(Packages.org.apache.tuscany.container.rhino.integration.TestMethods); + +initSalutation(); + +function getGreetings(name) { + return SALUTATION.getSalutation() + " " + name; +} + +function initSalutation() { + SALUTATION = new TestMethods(); +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/resources/tests/SalutationImpl.componentType b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/resources/tests/SalutationImpl.componentType new file mode 100644 index 0000000000..1c819bff32 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/resources/tests/SalutationImpl.componentType @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/resources/tests/SalutationImpl.js b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/resources/tests/SalutationImpl.js new file mode 100644 index 0000000000..2116e40ae3 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/resources/tests/SalutationImpl.js @@ -0,0 +1,20 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +function getSalutation() { + return GREETING; +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/resources/tests/e4x.componentType b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/resources/tests/e4x.componentType new file mode 100644 index 0000000000..6bf89d2ef8 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/resources/tests/e4x.componentType @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/resources/tests/e4x.js b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/resources/tests/e4x.js new file mode 100644 index 0000000000..7fe882df55 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/resources/tests/e4x.js @@ -0,0 +1,28 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +function process(xmlIn) { + + var greeting = "e4xHello " + xmlIn..*::in0; + + var xmlOut = + + { greeting } + ; + + return xmlOut; +} diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/resources/wsdl/helloworld.wsdl b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/resources/wsdl/helloworld.wsdl new file mode 100644 index 0000000000..7bcb48dcf2 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/container.rhino/src/test/resources/wsdl/helloworld.wsdl @@ -0,0 +1,97 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/pom.xml b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/pom.xml new file mode 100644 index 0000000000..e3a992c3a3 --- /dev/null +++ b/sca-java-1.x/tags/java-M1-20060518/java/sca/containers/pom.xml @@ -0,0 +1,37 @@ + + + + + + org.apache.tuscany + tuscany-sca + incubating-M1 + + + 4.0.0 + org.apache.tuscany.sca.containers + tuscany-sca-containers + pom + Tuscany SCA Containers + incubating-M1 + + + container.java + container.rhino + + + -- cgit v1.2.3