Author: edwardsmj
Date: Fri Sep 12 02:51:47 2008
New Revision: 694666

URL: http://svn.apache.org/viewvc?rev=694666&view=rev
Log:
Added a new testcase to cover the functionality fixed by JIRA 2573

Added:
    
tuscany/java/sca/modules/implementation-spring/src/test/java/org/apache/tuscany/sca/implementation/spring/itests/helloworld/SpringContextAccessTestCase.java
    
tuscany/java/sca/modules/implementation-spring/src/test/java/org/apache/tuscany/sca/implementation/spring/itests/mock/TestContextAccessBean.java
    
tuscany/java/sca/modules/implementation-spring/src/test/resources/META-INF/sca/SpringContextAccess-context.xml
    
tuscany/java/sca/modules/implementation-spring/src/test/resources/org/apache/tuscany/sca/implementation/spring/itests/helloworld/SpringContextAccess.composite
Modified:
    
tuscany/java/sca/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringXMLComponentTypeLoader.java
    
tuscany/java/sca/modules/implementation-spring/src/test/java/org/apache/tuscany/sca/implementation/spring/itests/helloworld/AbstractHelloWorldTestCase.java

Modified: 
tuscany/java/sca/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringXMLComponentTypeLoader.java
URL: 
http://svn.apache.org/viewvc/tuscany/java/sca/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringXMLComponentTypeLoader.java?rev=694666&r1=694665&r2=694666&view=diff
==============================================================================
--- 
tuscany/java/sca/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringXMLComponentTypeLoader.java
 (original)
+++ 
tuscany/java/sca/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringXMLComponentTypeLoader.java
 Fri Sep 12 02:51:47 2008
@@ -198,6 +198,7 @@
                         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);

Modified: 
tuscany/java/sca/modules/implementation-spring/src/test/java/org/apache/tuscany/sca/implementation/spring/itests/helloworld/AbstractHelloWorldTestCase.java
URL: 
http://svn.apache.org/viewvc/tuscany/java/sca/modules/implementation-spring/src/test/java/org/apache/tuscany/sca/implementation/spring/itests/helloworld/AbstractHelloWorldTestCase.java?rev=694666&r1=694665&r2=694666&view=diff
==============================================================================
--- 
tuscany/java/sca/modules/implementation-spring/src/test/java/org/apache/tuscany/sca/implementation/spring/itests/helloworld/AbstractHelloWorldTestCase.java
 (original)
+++ 
tuscany/java/sca/modules/implementation-spring/src/test/java/org/apache/tuscany/sca/implementation/spring/itests/helloworld/AbstractHelloWorldTestCase.java
 Fri Sep 12 02:51:47 2008
@@ -33,6 +33,7 @@
      */
     public void testCalculator() throws Exception {
         assertEquals("Hello petra", service.sayHello("petra"));
+        System.out.println("Test " + this.getClass().getSimpleName() + " 
completed successfully");
     }
 
     @Override

Added: 
tuscany/java/sca/modules/implementation-spring/src/test/java/org/apache/tuscany/sca/implementation/spring/itests/helloworld/SpringContextAccessTestCase.java
URL: 
http://svn.apache.org/viewvc/tuscany/java/sca/modules/implementation-spring/src/test/java/org/apache/tuscany/sca/implementation/spring/itests/helloworld/SpringContextAccessTestCase.java?rev=694666&view=auto
==============================================================================
--- 
tuscany/java/sca/modules/implementation-spring/src/test/java/org/apache/tuscany/sca/implementation/spring/itests/helloworld/SpringContextAccessTestCase.java
 (added)
+++ 
tuscany/java/sca/modules/implementation-spring/src/test/java/org/apache/tuscany/sca/implementation/spring/itests/helloworld/SpringContextAccessTestCase.java
 Fri Sep 12 02:51:47 2008
@@ -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
+}

Added: 
tuscany/java/sca/modules/implementation-spring/src/test/java/org/apache/tuscany/sca/implementation/spring/itests/mock/TestContextAccessBean.java
URL: 
http://svn.apache.org/viewvc/tuscany/java/sca/modules/implementation-spring/src/test/java/org/apache/tuscany/sca/implementation/spring/itests/mock/TestContextAccessBean.java?rev=694666&view=auto
==============================================================================
--- 
tuscany/java/sca/modules/implementation-spring/src/test/java/org/apache/tuscany/sca/implementation/spring/itests/mock/TestContextAccessBean.java
 (added)
+++ 
tuscany/java/sca/modules/implementation-spring/src/test/java/org/apache/tuscany/sca/implementation/spring/itests/mock/TestContextAccessBean.java
 Fri Sep 12 02:51:47 2008
@@ -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;       
+    }
+
+}

Added: 
tuscany/java/sca/modules/implementation-spring/src/test/resources/META-INF/sca/SpringContextAccess-context.xml
URL: 
http://svn.apache.org/viewvc/tuscany/java/sca/modules/implementation-spring/src/test/resources/META-INF/sca/SpringContextAccess-context.xml?rev=694666&view=auto
==============================================================================
--- 
tuscany/java/sca/modules/implementation-spring/src/test/resources/META-INF/sca/SpringContextAccess-context.xml
 (added)
+++ 
tuscany/java/sca/modules/implementation-spring/src/test/resources/META-INF/sca/SpringContextAccess-context.xml
 Fri Sep 12 02:51:47 2008
@@ -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>

Added: 
tuscany/java/sca/modules/implementation-spring/src/test/resources/org/apache/tuscany/sca/implementation/spring/itests/helloworld/SpringContextAccess.composite
URL: 
http://svn.apache.org/viewvc/tuscany/java/sca/modules/implementation-spring/src/test/resources/org/apache/tuscany/sca/implementation/spring/itests/helloworld/SpringContextAccess.composite?rev=694666&view=auto
==============================================================================
--- 
tuscany/java/sca/modules/implementation-spring/src/test/resources/org/apache/tuscany/sca/implementation/spring/itests/helloworld/SpringContextAccess.composite
 (added)
+++ 
tuscany/java/sca/modules/implementation-spring/src/test/resources/org/apache/tuscany/sca/implementation/spring/itests/helloworld/SpringContextAccess.composite
 Fri Sep 12 02:51:47 2008
@@ -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>


Reply via email to