summaryrefslogtreecommitdiffstats
path: root/sca-java-1.x/branches/sca-java-1.2.1/itest/callback-set-callback
diff options
context:
space:
mode:
authorlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2009-11-11 23:07:45 +0000
committerlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2009-11-11 23:07:45 +0000
commit6a3ca6736c808c1647854e405ef379b609f276db (patch)
tree67670193d3511b227100419589d0f2ec0bb02cc0 /sca-java-1.x/branches/sca-java-1.2.1/itest/callback-set-callback
parent9f395ebf3ec27f89c8dc63137bc99c8d6b0cff6d (diff)
Moving 1.x branches
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@835126 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-1.x/branches/sca-java-1.2.1/itest/callback-set-callback')
-rw-r--r--sca-java-1.x/branches/sca-java-1.2.1/itest/callback-set-callback/pom.xml45
-rw-r--r--sca-java-1.x/branches/sca-java-1.2.1/itest/callback-set-callback/src/main/java/org/apache/tuscany/sca/test/CallBackSetCalbackService.java34
-rw-r--r--sca-java-1.x/branches/sca-java-1.2.1/itest/callback-set-callback/src/main/java/org/apache/tuscany/sca/test/CallBackSetCallbackBadCallback.java38
-rw-r--r--sca-java-1.x/branches/sca-java-1.2.1/itest/callback-set-callback/src/main/java/org/apache/tuscany/sca/test/CallBackSetCallbackCallback.java31
-rw-r--r--sca-java-1.x/branches/sca-java-1.2.1/itest/callback-set-callback/src/main/java/org/apache/tuscany/sca/test/CallBackSetCallbackCallbackImpl.java66
-rw-r--r--sca-java-1.x/branches/sca-java-1.2.1/itest/callback-set-callback/src/main/java/org/apache/tuscany/sca/test/CallBackSetCallbackClient.java28
-rw-r--r--sca-java-1.x/branches/sca-java-1.2.1/itest/callback-set-callback/src/main/java/org/apache/tuscany/sca/test/CallBackSetCallbackClientImpl.java190
-rw-r--r--sca-java-1.x/branches/sca-java-1.2.1/itest/callback-set-callback/src/main/java/org/apache/tuscany/sca/test/CallBackSetCallbackObjectCallback.java44
-rw-r--r--sca-java-1.x/branches/sca-java-1.2.1/itest/callback-set-callback/src/main/java/org/apache/tuscany/sca/test/CallBackSetCallbackServiceImpl.java75
-rw-r--r--sca-java-1.x/branches/sca-java-1.2.1/itest/callback-set-callback/src/main/resources/CallBackSetCallbackTest.composite37
-rw-r--r--sca-java-1.x/branches/sca-java-1.2.1/itest/callback-set-callback/src/test/java/org/apache/tuscany/sca/test/CallBackSetCallbackTestCase.java49
11 files changed, 637 insertions, 0 deletions
diff --git a/sca-java-1.x/branches/sca-java-1.2.1/itest/callback-set-callback/pom.xml b/sca-java-1.x/branches/sca-java-1.2.1/itest/callback-set-callback/pom.xml
new file mode 100644
index 0000000000..0513f68393
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-1.2.1/itest/callback-set-callback/pom.xml
@@ -0,0 +1,45 @@
+<?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.
+-->
+<project>
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-itest</artifactId>
+ <version>1.2.1-incubating-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <artifactId>itest-callback-set-callback</artifactId>
+ <name>Apache Tuscany SCA Set Callback Integration Tests</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-host-embedded</artifactId>
+ <version>1.2.1-incubating-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-implementation-java-runtime</artifactId>
+ <version>1.2.1-incubating-SNAPSHOT</version>
+ <scope>runtime</scope>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/sca-java-1.x/branches/sca-java-1.2.1/itest/callback-set-callback/src/main/java/org/apache/tuscany/sca/test/CallBackSetCalbackService.java b/sca-java-1.x/branches/sca-java-1.2.1/itest/callback-set-callback/src/main/java/org/apache/tuscany/sca/test/CallBackSetCalbackService.java
new file mode 100644
index 0000000000..3b9599f53f
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-1.2.1/itest/callback-set-callback/src/main/java/org/apache/tuscany/sca/test/CallBackSetCalbackService.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.test;
+
+import org.osoa.sca.annotations.Callback;
+
+// @Remotable
+@Callback(CallBackSetCallbackCallback.class)
+/**
+ *
+ */
+public interface CallBackSetCalbackService {
+
+ public void knockKnock(String aString);
+
+ public boolean setCallbackIllegally(String aString);
+
+}
diff --git a/sca-java-1.x/branches/sca-java-1.2.1/itest/callback-set-callback/src/main/java/org/apache/tuscany/sca/test/CallBackSetCallbackBadCallback.java b/sca-java-1.x/branches/sca-java-1.2.1/itest/callback-set-callback/src/main/java/org/apache/tuscany/sca/test/CallBackSetCallbackBadCallback.java
new file mode 100644
index 0000000000..48752f2ea1
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-1.2.1/itest/callback-set-callback/src/main/java/org/apache/tuscany/sca/test/CallBackSetCallbackBadCallback.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.test;
+
+import junit.framework.Assert;
+
+public class CallBackSetCallbackBadCallback {
+
+ public CallBackSetCallbackBadCallback() {
+ super();
+ }
+
+ public void callback(String aString) {
+ //
+ // This callback method should never be called.
+ //
+ System.out.println("CallBackSetCallbackBadCallback: callback called");
+ Assert.fail("CallBackSetCallbackBadCallback: callback called");
+ return;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-java-1.2.1/itest/callback-set-callback/src/main/java/org/apache/tuscany/sca/test/CallBackSetCallbackCallback.java b/sca-java-1.x/branches/sca-java-1.2.1/itest/callback-set-callback/src/main/java/org/apache/tuscany/sca/test/CallBackSetCallbackCallback.java
new file mode 100644
index 0000000000..ad0e0603a3
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-1.2.1/itest/callback-set-callback/src/main/java/org/apache/tuscany/sca/test/CallBackSetCallbackCallback.java
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.test;
+
+// @Remotable
+/**
+ *
+ */
+public interface CallBackSetCallbackCallback {
+
+ public void callBackMessage(String aString);
+
+ public void callBackIncrement(String aString);
+
+}
diff --git a/sca-java-1.x/branches/sca-java-1.2.1/itest/callback-set-callback/src/main/java/org/apache/tuscany/sca/test/CallBackSetCallbackCallbackImpl.java b/sca-java-1.x/branches/sca-java-1.2.1/itest/callback-set-callback/src/main/java/org/apache/tuscany/sca/test/CallBackSetCallbackCallbackImpl.java
new file mode 100644
index 0000000000..0a22b0e01f
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-1.2.1/itest/callback-set-callback/src/main/java/org/apache/tuscany/sca/test/CallBackSetCallbackCallbackImpl.java
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.test;
+
+import java.io.File;
+
+import org.osoa.sca.annotations.Service;
+
+@Service(CallBackSetCallbackCallback.class)
+public class CallBackSetCallbackCallbackImpl implements CallBackSetCallbackCallback {
+
+ private static String returnMessage = null;
+ private static int callBackCount = 0;
+
+ public String getReturnMessage() {
+ return returnMessage;
+ }
+
+ public void setReturnMessage(String aReturnMessage) {
+ returnMessage = aReturnMessage;
+ }
+
+ public int getCallBackCount() {
+ return callBackCount;
+ }
+
+ public void incrementCallBackCount() {
+ callBackCount++;
+ }
+
+ public void callBackMessage(String aString) {
+
+ System.out.println("Entering CallBackSetCallbackCallbackImpl callBackMessage: " + aString);
+
+ File aFile = new File("target/test4_marker");
+ try {
+ aFile.createNewFile();
+ } catch (Exception ex) {
+ System.out.println("Error Creating target/test4_marker marker file");
+ ex.printStackTrace();
+ }
+
+ }
+
+ public void callBackIncrement(String aString) {
+ System.out.println("Entering callback increment: " + aString);
+ this.incrementCallBackCount();
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-java-1.2.1/itest/callback-set-callback/src/main/java/org/apache/tuscany/sca/test/CallBackSetCallbackClient.java b/sca-java-1.x/branches/sca-java-1.2.1/itest/callback-set-callback/src/main/java/org/apache/tuscany/sca/test/CallBackSetCallbackClient.java
new file mode 100644
index 0000000000..94cb6aa73b
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-1.2.1/itest/callback-set-callback/src/main/java/org/apache/tuscany/sca/test/CallBackSetCallbackClient.java
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.test;
+
+import org.osoa.sca.annotations.Remotable;
+
+@Remotable
+public interface CallBackSetCallbackClient {
+
+ public void run();
+
+}
diff --git a/sca-java-1.x/branches/sca-java-1.2.1/itest/callback-set-callback/src/main/java/org/apache/tuscany/sca/test/CallBackSetCallbackClientImpl.java b/sca-java-1.x/branches/sca-java-1.2.1/itest/callback-set-callback/src/main/java/org/apache/tuscany/sca/test/CallBackSetCallbackClientImpl.java
new file mode 100644
index 0000000000..ee14467de0
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-1.2.1/itest/callback-set-callback/src/main/java/org/apache/tuscany/sca/test/CallBackSetCallbackClientImpl.java
@@ -0,0 +1,190 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.test;
+
+import java.io.File;
+
+import junit.framework.Assert;
+
+import org.osoa.sca.NoRegisteredCallbackException;
+import org.osoa.sca.ServiceReference;
+import org.osoa.sca.annotations.Reference;
+import org.osoa.sca.annotations.Service;
+
+@Service(CallBackSetCallbackClient.class)
+public class CallBackSetCallbackClientImpl implements CallBackSetCallbackClient {
+
+ @Reference
+ protected ServiceReference<CallBackSetCalbackService> aCallBackService;
+ @Reference
+ protected ServiceReference<CallBackSetCallbackCallback> callBack;
+
+ public void run() {
+
+ // This test various aspects of the setCallback() API in a stateless
+ // scope.
+
+ /*
+ * test4 Client does not implement the callback interface but calls
+ * setCallback with a service reference before invoking the target,
+ * Verify successful executon.
+ */
+
+ test4();
+
+ /*
+ * test5 The client does not implement the callback interface and does
+ * not call setCallback() before invoking the target. Verify a
+ * NoRegisteredCallbackException is thrown.
+ */
+
+ test5();
+
+ /*
+ * test6() The client calls setCallback() with an object that is not a
+ * service reference and the callback interface is stateless. Verify
+ * that an appropriate exception is thrown. When calling setCallback
+ * with an object the interface must be stateful. Stateless interfaces
+ * require a service Reference.
+ */
+
+ test6();
+
+ /*
+ * test10 The target calls setCallback() on its own service reference,
+ * e.g. getRequestContext().getServiceReference().getCallback(). Verify
+ * an appropriate exeception occurs.
+ */
+
+ test10();
+
+ return;
+ }
+
+ private void test4() {
+
+ //
+ // Since callbacks do not synchronously return and this test results in
+ // a callback to a component other
+ // than this client I am using a marker file to determine the outcome.
+ // The presence of the marker
+ // file will be used for the Assertion test. If it exists then the
+ // callback occurred and all is good.
+ //
+
+ // Make sure the marker file is not present before starting the test.
+ File aFile = new File("target/test4_marker");
+ if (aFile.exists())
+ aFile.delete();
+
+ aCallBackService.setCallback(callBack);
+
+ aCallBackService.getService().knockKnock("Knock Knock");
+
+ // Lets give the callback a little time to complete....
+
+ int count = 0;
+ long timeout = 1000;
+
+ while (count++ < 30 && (aFile.exists() == false)) {
+ try {
+ Thread.sleep(timeout);
+ } catch (InterruptedException ie) {
+ }
+ }
+
+ Assert.assertEquals("CallBackSetCallback - Test4", true, aFile.exists());
+
+ aCallBackService.setCallback(null); // leave this in the default state for next test
+
+ }
+
+ private void test5() {
+
+ boolean correctException = false;
+
+ //
+ // The backend service is expecting a callback reference to be set. This
+ // test will not
+ // set one so an exception is expected. According to the spec if a
+ // client calls a method on
+ // a service reference prior to calling setCallback() then a
+ // NoRegisteredCallbackException
+ // will be thrown on the client.
+ //
+
+ try {
+ aCallBackService.getService().knockKnock("Knock Knock");
+ } catch (NoRegisteredCallbackException NotRegEx) {
+ correctException = true;
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+
+ Assert.assertEquals("CallBackSetCallback - Test5", true, correctException);
+
+ }
+
+ private void test6() {
+
+ boolean correctException = false;
+
+ //
+ // This test is to specify an Object that is not a service reference
+ // that does implement
+ // the callback interface. However because this callback service is
+ // stateless the expected
+ // result is an appropriate exception.
+ //
+
+ try {
+ aCallBackService.setCallback(new CallBackSetCallbackObjectCallback());
+ aCallBackService.getService().knockKnock("Knock Knock");
+ }
+ //
+ // This should catch an appropriate exception.
+ //
+ catch (IllegalArgumentException goodEx) {
+ correctException = true;
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+
+ Assert.assertEquals("CallBackSetCallback - Test6", true, correctException);
+
+ }
+
+ private void test10() {
+
+ //
+ // The appropriate exception should be thrown and caught on the service side.
+ // If this happens, the setCallbackIllegally() method will return true.
+ // If not, this method will return false.
+ //
+
+ aCallBackService.setCallback(callBack); // ensure no client-side exception
+
+ boolean result = aCallBackService.getService().setCallbackIllegally
+ ("Try to set callback on your own service reference");
+
+ Assert.assertEquals("CallBackSetCallback - Test10", true, result);
+
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-java-1.2.1/itest/callback-set-callback/src/main/java/org/apache/tuscany/sca/test/CallBackSetCallbackObjectCallback.java b/sca-java-1.x/branches/sca-java-1.2.1/itest/callback-set-callback/src/main/java/org/apache/tuscany/sca/test/CallBackSetCallbackObjectCallback.java
new file mode 100644
index 0000000000..afedcdf7f1
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-1.2.1/itest/callback-set-callback/src/main/java/org/apache/tuscany/sca/test/CallBackSetCallbackObjectCallback.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.test;
+
+public class CallBackSetCallbackObjectCallback implements CallBackSetCallbackCallback {
+
+ private int callBackCount = 0;
+
+ public CallBackSetCallbackObjectCallback() {
+ super();
+ }
+
+ public void incrementCallBackCount() {
+ callBackCount++;
+ }
+
+ public void callBackMessage(String aString) {
+
+ System.out.println("Entering CallBackSetCallbackObjectCallback callBackMessage: " + aString);
+
+ }
+
+ public void callBackIncrement(String aString) {
+ System.out.println("Entering callback increment: " + aString);
+ this.incrementCallBackCount();
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-java-1.2.1/itest/callback-set-callback/src/main/java/org/apache/tuscany/sca/test/CallBackSetCallbackServiceImpl.java b/sca-java-1.x/branches/sca-java-1.2.1/itest/callback-set-callback/src/main/java/org/apache/tuscany/sca/test/CallBackSetCallbackServiceImpl.java
new file mode 100644
index 0000000000..8093093968
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-1.2.1/itest/callback-set-callback/src/main/java/org/apache/tuscany/sca/test/CallBackSetCallbackServiceImpl.java
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.test;
+
+import java.io.File;
+
+import org.osoa.sca.ComponentContext;
+import org.osoa.sca.RequestContext;
+import org.osoa.sca.ServiceReference;
+import org.osoa.sca.annotations.Callback;
+import org.osoa.sca.annotations.Context;
+import org.osoa.sca.annotations.Service;
+
+@Service(CallBackSetCalbackService.class)
+public class CallBackSetCallbackServiceImpl implements CallBackSetCalbackService {
+
+ @Callback
+ protected CallBackSetCallbackCallback callback;
+ @Context
+ protected ComponentContext context;
+
+ public void knockKnock(String aString) {
+
+ try {
+ System.out.println("CallBackBasicServiceImpl message received: " + aString);
+ callback.callBackMessage("Who's There");
+ System.out.println("CallBackBasicServiceImpl response sent");
+ return;
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+
+ }
+
+ public boolean setCallbackIllegally(String aString) {
+
+ System.out.println("CallBackBasicServiceImpl.setCallbackIllegally() message received: " + aString);
+
+ boolean exceptionProduced = false;
+ RequestContext requestContext = null;
+ ServiceReference serviceRef = null;
+
+ try {
+ requestContext = context.getRequestContext();
+ serviceRef = (ServiceReference) requestContext.getServiceReference();
+ serviceRef.setCallback(serviceRef);
+ } catch (ClassCastException goodEx) {
+ exceptionProduced = true;
+ System.out.println("Test10 appropriate exception caught during setCallback to own service reference");
+ } catch (Exception badEx) {
+ System.out.println("CallBackBasicServiceImpl.setCallbackIllegally() " + badEx.toString());
+ badEx.printStackTrace();
+ }
+
+ // Return a flag indicating whether we got the exception we are looking for
+ return exceptionProduced;
+
+ }
+}
diff --git a/sca-java-1.x/branches/sca-java-1.2.1/itest/callback-set-callback/src/main/resources/CallBackSetCallbackTest.composite b/sca-java-1.x/branches/sca-java-1.2.1/itest/callback-set-callback/src/main/resources/CallBackSetCallbackTest.composite
new file mode 100644
index 0000000000..3552ddecab
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-1.2.1/itest/callback-set-callback/src/main/resources/CallBackSetCallbackTest.composite
@@ -0,0 +1,37 @@
+<?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"
+ targetNamespace="http://callback"
+ name="CallBackSetCallbackTest">
+
+ <component name="CallBackSetCallbackClient">
+ <implementation.java class="org.apache.tuscany.sca.test.CallBackSetCallbackClientImpl"/>
+ <reference name="aCallBackService" target="CallBackSetCallbackService"/>
+ <reference name="callBack" target="CallBackSetCallbackCallback"/>
+ </component>
+
+ <component name="CallBackSetCallbackCallback">
+ <implementation.java class="org.apache.tuscany.sca.test.CallBackSetCallbackCallbackImpl"/>
+ </component>
+
+ <component name="CallBackSetCallbackService">
+ <implementation.java class="org.apache.tuscany.sca.test.CallBackSetCallbackServiceImpl"/>
+ </component>
+</composite>
diff --git a/sca-java-1.x/branches/sca-java-1.2.1/itest/callback-set-callback/src/test/java/org/apache/tuscany/sca/test/CallBackSetCallbackTestCase.java b/sca-java-1.x/branches/sca-java-1.2.1/itest/callback-set-callback/src/test/java/org/apache/tuscany/sca/test/CallBackSetCallbackTestCase.java
new file mode 100644
index 0000000000..496ae0b1a5
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-1.2.1/itest/callback-set-callback/src/test/java/org/apache/tuscany/sca/test/CallBackSetCallbackTestCase.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.test;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.host.embedded.SCADomain;
+
+//FIXME Fix this test case
+public class CallBackSetCallbackTestCase extends TestCase {
+
+ private SCADomain domain;
+ private CallBackSetCallbackClient aCallBackClient;
+
+ public void testCallBackSetCallback() {
+ aCallBackClient.run();
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ domain = SCADomain.newInstance("CallBackSetCallbackTest.composite");
+
+ aCallBackClient =
+ domain.getService(CallBackSetCallbackClient.class,
+ "CallBackSetCallbackClient");
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ domain.close();
+ }
+
+}