summaryrefslogtreecommitdiffstats
path: root/java/sca/modules/implementation-spring/src
diff options
context:
space:
mode:
authoredwardsmj <edwardsmj@13f79535-47bb-0310-9956-ffa450edef68>2008-09-12 09:51:47 +0000
committeredwardsmj <edwardsmj@13f79535-47bb-0310-9956-ffa450edef68>2008-09-12 09:51:47 +0000
commit34dc5962fca6c85f3751a33abbd249bd37c4c1b9 (patch)
tree0c8bc7e37e25aae47ec393ea35dbbac08b242965 /java/sca/modules/implementation-spring/src
parentcea87e003518f942a98c3a4586461a5e74597f53 (diff)
Added a new testcase to cover the functionality fixed by JIRA 2573
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@694666 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules/implementation-spring/src')
-rw-r--r--java/sca/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringXMLComponentTypeLoader.java1
-rw-r--r--java/sca/modules/implementation-spring/src/test/java/org/apache/tuscany/sca/implementation/spring/itests/helloworld/AbstractHelloWorldTestCase.java1
-rw-r--r--java/sca/modules/implementation-spring/src/test/java/org/apache/tuscany/sca/implementation/spring/itests/helloworld/SpringContextAccessTestCase.java35
-rw-r--r--java/sca/modules/implementation-spring/src/test/java/org/apache/tuscany/sca/implementation/spring/itests/mock/TestContextAccessBean.java77
-rw-r--r--java/sca/modules/implementation-spring/src/test/resources/META-INF/sca/SpringContextAccess-context.xml31
-rw-r--r--java/sca/modules/implementation-spring/src/test/resources/org/apache/tuscany/sca/implementation/spring/itests/helloworld/SpringContextAccess.composite35
6 files changed, 180 insertions, 0 deletions
diff --git a/java/sca/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringXMLComponentTypeLoader.java b/java/sca/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringXMLComponentTypeLoader.java
index a6dfe67a92..9f41fd306f 100644
--- a/java/sca/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringXMLComponentTypeLoader.java
+++ b/java/sca/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringXMLComponentTypeLoader.java
@@ -198,6 +198,7 @@ public class SpringXMLComponentTypeLoader {
QName qname = reader.getName();
//System.out.println("Spring TypeLoader - found element with name: " + qname.toString());
if (Constants.IMPORT_ELEMENT.equals(qname)) {
+ //FIXME - put the sequence of code below which gets the ireader into a subsidiary method
String location = reader.getAttributeValue(null, "resource");
if (location != null) {
XMLStreamReader ireader = getApplicationContextReader(location);
diff --git a/java/sca/modules/implementation-spring/src/test/java/org/apache/tuscany/sca/implementation/spring/itests/helloworld/AbstractHelloWorldTestCase.java b/java/sca/modules/implementation-spring/src/test/java/org/apache/tuscany/sca/implementation/spring/itests/helloworld/AbstractHelloWorldTestCase.java
index f8019cba42..c9b30b1688 100644
--- a/java/sca/modules/implementation-spring/src/test/java/org/apache/tuscany/sca/implementation/spring/itests/helloworld/AbstractHelloWorldTestCase.java
+++ b/java/sca/modules/implementation-spring/src/test/java/org/apache/tuscany/sca/implementation/spring/itests/helloworld/AbstractHelloWorldTestCase.java
@@ -33,6 +33,7 @@ public abstract class AbstractHelloWorldTestCase extends AbstractSCATestCase<Hel
*/
public void testCalculator() throws Exception {
assertEquals("Hello petra", service.sayHello("petra"));
+ System.out.println("Test " + this.getClass().getSimpleName() + " completed successfully");
}
@Override
diff --git a/java/sca/modules/implementation-spring/src/test/java/org/apache/tuscany/sca/implementation/spring/itests/helloworld/SpringContextAccessTestCase.java b/java/sca/modules/implementation-spring/src/test/java/org/apache/tuscany/sca/implementation/spring/itests/helloworld/SpringContextAccessTestCase.java
new file mode 100644
index 0000000000..d77f183a66
--- /dev/null
+++ b/java/sca/modules/implementation-spring/src/test/java/org/apache/tuscany/sca/implementation/spring/itests/helloworld/SpringContextAccessTestCase.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.implementation.spring.itests.helloworld;
+
+/**
+ * A test case to check the ability of Spring Beans used as an SCA implementation
+ * to access the Spring application context without problems:
+ * 1) A composite containing a component with a Spring implementation
+ * 2) The composite has a component with a Java POJO implementation which uses the
+ * Spring implementation to satisfy a reference
+ * 3) The Spring Bean accesses the Spring application context and only returns data
+ * if it is successful
+ *
+ * @version $Rev$ $Date$
+ */
+public class SpringContextAccessTestCase extends AbstractHelloWorldTestCase {
+ // super class does it all getting composite based on this class name
+}
diff --git a/java/sca/modules/implementation-spring/src/test/java/org/apache/tuscany/sca/implementation/spring/itests/mock/TestContextAccessBean.java b/java/sca/modules/implementation-spring/src/test/java/org/apache/tuscany/sca/implementation/spring/itests/mock/TestContextAccessBean.java
new file mode 100644
index 0000000000..79de2b32a0
--- /dev/null
+++ b/java/sca/modules/implementation-spring/src/test/java/org/apache/tuscany/sca/implementation/spring/itests/mock/TestContextAccessBean.java
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.spring.itests.mock;
+
+/**
+ * Spring bean test class for testing the access to the Spring Context from within
+ * a Spring Bean running as part of an SCA Component.
+ *
+ * This class accesses the Spring Context and only returns non-null data if the
+ * Context is successfully accessed.
+ *
+ * The design to receive the application context is as follows:
+ * - the Bean implements the ApplicationContextAware interface
+ * - this interface provides getter and setter methods for the Spring application
+ * context
+ * - when the Bean is created at runtime, the setter method is called, injecting
+ * the context
+ */
+
+import org.apache.tuscany.sca.implementation.spring.itests.helloworld.HelloWorld;
+
+import org.springframework.beans.BeansException;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+
+
+public class TestContextAccessBean implements HelloWorld, ApplicationContextAware {
+
+ private static ApplicationContext ctx;
+ static String hello = "Hello ";
+
+ // Return the hello string only if the application context is successfully accessed
+ public String sayHello(String message) {
+ System.out.println("TestContextAccessBean - sayHello called");
+ ApplicationContext theContext = getApplicationContext();
+
+ if( theContext == null ) return null;
+
+ // A simple check to see if the context contains this bean, which it should...
+ if ( !theContext.containsBean( "testBean" ) ) return null;
+
+ return (hello + message);
+ } // end sayHello()
+
+ /**
+ * Application context setter
+ */
+ public void setApplicationContext(ApplicationContext appContext) throws BeansException {
+ // Wiring the ApplicationContext into a static method
+ ctx = appContext;
+ }
+
+ /**
+ * Application context getter
+ * @return
+ */
+ public static ApplicationContext getApplicationContext() {
+ return ctx;
+ }
+
+}
diff --git a/java/sca/modules/implementation-spring/src/test/resources/META-INF/sca/SpringContextAccess-context.xml b/java/sca/modules/implementation-spring/src/test/resources/META-INF/sca/SpringContextAccess-context.xml
new file mode 100644
index 0000000000..a7d30bf201
--- /dev/null
+++ b/java/sca/modules/implementation-spring/src/test/resources/META-INF/sca/SpringContextAccess-context.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<!-- Application context for the SpringHelloWorld testcase -->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:sca="http://www.springframework.org/schema/sca"
+ xsi:schemaLocation="
+http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+http://www.springframework.org/schema/sca http://www.osoa.org/xmlns/sca/1.0/spring-sca.xsd">
+
+ <bean id="testBean" class="org.apache.tuscany.sca.implementation.spring.itests.mock.TestContextAccessBean" lazy-init="true">
+ </bean>
+
+</beans>
diff --git a/java/sca/modules/implementation-spring/src/test/resources/org/apache/tuscany/sca/implementation/spring/itests/helloworld/SpringContextAccess.composite b/java/sca/modules/implementation-spring/src/test/resources/org/apache/tuscany/sca/implementation/spring/itests/helloworld/SpringContextAccess.composite
new file mode 100644
index 0000000000..0b260b5dcf
--- /dev/null
+++ b/java/sca/modules/implementation-spring/src/test/resources/org/apache/tuscany/sca/implementation/spring/itests/helloworld/SpringContextAccess.composite
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:t="http://tuscany.apache.org/xmlns/sca/1.0"
+ xmlns:c="http://SpringContextAccess"
+ targetNamespace="http://SpringContextAccess"
+ name="SpringContextAccess">
+
+ <component name="ClientComponent">
+ <implementation.java class="org.apache.tuscany.sca.implementation.spring.itests.helloworld.HelloWorldProxy"/>
+ <reference name="delegate" target="HelloWorldComponent"/>
+ </component>
+
+ <component name="HelloWorldComponent">
+ <implementation.spring location="META-INF/sca/SpringContextAccess-context.xml"/>
+ </component>
+
+</composite>