From a40e527938d76ba71f211da7e327adb50384ba69 Mon Sep 17 00:00:00 2001 From: lresende Date: Wed, 11 Nov 2009 23:26:33 +0000 Subject: Moving 1.x tags git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@835157 13f79535-47bb-0310-9956-ffa450edef68 --- .../test/CallBackSetCallbackConvBadCallback.java | 38 +++++ .../sca/test/CallBackSetCallbackConvCallback.java | 31 ++++ .../sca/test/CallBackSetCallbackConvClient.java | 28 ++++ .../test/CallBackSetCallbackConvClientImpl.java | 173 +++++++++++++++++++++ .../CallBackSetCallbackConvNonSerCallback.java | 58 +++++++ .../CallBackSetCallbackConvObjectCallback.java | 59 +++++++ .../sca/test/CallBackSetCallbackConvService.java | 34 ++++ .../test/CallBackSetCallbackConvServiceImpl.java | 102 ++++++++++++ 8 files changed, 523 insertions(+) create mode 100644 sca-java-1.x/tags/0.99-incubating/itest/callback-set-conversation/src/main/java/org/apache/tuscany/sca/test/CallBackSetCallbackConvBadCallback.java create mode 100644 sca-java-1.x/tags/0.99-incubating/itest/callback-set-conversation/src/main/java/org/apache/tuscany/sca/test/CallBackSetCallbackConvCallback.java create mode 100644 sca-java-1.x/tags/0.99-incubating/itest/callback-set-conversation/src/main/java/org/apache/tuscany/sca/test/CallBackSetCallbackConvClient.java create mode 100644 sca-java-1.x/tags/0.99-incubating/itest/callback-set-conversation/src/main/java/org/apache/tuscany/sca/test/CallBackSetCallbackConvClientImpl.java create mode 100644 sca-java-1.x/tags/0.99-incubating/itest/callback-set-conversation/src/main/java/org/apache/tuscany/sca/test/CallBackSetCallbackConvNonSerCallback.java create mode 100644 sca-java-1.x/tags/0.99-incubating/itest/callback-set-conversation/src/main/java/org/apache/tuscany/sca/test/CallBackSetCallbackConvObjectCallback.java create mode 100644 sca-java-1.x/tags/0.99-incubating/itest/callback-set-conversation/src/main/java/org/apache/tuscany/sca/test/CallBackSetCallbackConvService.java create mode 100644 sca-java-1.x/tags/0.99-incubating/itest/callback-set-conversation/src/main/java/org/apache/tuscany/sca/test/CallBackSetCallbackConvServiceImpl.java (limited to 'sca-java-1.x/tags/0.99-incubating/itest/callback-set-conversation/src/main/java/org/apache/tuscany/sca') diff --git a/sca-java-1.x/tags/0.99-incubating/itest/callback-set-conversation/src/main/java/org/apache/tuscany/sca/test/CallBackSetCallbackConvBadCallback.java b/sca-java-1.x/tags/0.99-incubating/itest/callback-set-conversation/src/main/java/org/apache/tuscany/sca/test/CallBackSetCallbackConvBadCallback.java new file mode 100644 index 0000000000..eb840a006d --- /dev/null +++ b/sca-java-1.x/tags/0.99-incubating/itest/callback-set-conversation/src/main/java/org/apache/tuscany/sca/test/CallBackSetCallbackConvBadCallback.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 CallBackSetCallbackConvBadCallback { + + public CallBackSetCallbackConvBadCallback() { + super(); + } + + public void callback(String aString) { + // + // This callback method should never be called. + // + System.out.println("CallBackSetCallbackBadCallback: callback called"); + Assert.fail("CallBackSetCallbackConvBadCallback: callback called"); + return; + } + +} diff --git a/sca-java-1.x/tags/0.99-incubating/itest/callback-set-conversation/src/main/java/org/apache/tuscany/sca/test/CallBackSetCallbackConvCallback.java b/sca-java-1.x/tags/0.99-incubating/itest/callback-set-conversation/src/main/java/org/apache/tuscany/sca/test/CallBackSetCallbackConvCallback.java new file mode 100644 index 0000000000..eb7adffc7c --- /dev/null +++ b/sca-java-1.x/tags/0.99-incubating/itest/callback-set-conversation/src/main/java/org/apache/tuscany/sca/test/CallBackSetCallbackConvCallback.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 CallBackSetCallbackConvCallback { + + public void callBackMessage(String aString); + + public void callBackIncrement(String aString); + +} diff --git a/sca-java-1.x/tags/0.99-incubating/itest/callback-set-conversation/src/main/java/org/apache/tuscany/sca/test/CallBackSetCallbackConvClient.java b/sca-java-1.x/tags/0.99-incubating/itest/callback-set-conversation/src/main/java/org/apache/tuscany/sca/test/CallBackSetCallbackConvClient.java new file mode 100644 index 0000000000..013424bf5e --- /dev/null +++ b/sca-java-1.x/tags/0.99-incubating/itest/callback-set-conversation/src/main/java/org/apache/tuscany/sca/test/CallBackSetCallbackConvClient.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 CallBackSetCallbackConvClient { + + public void run(); + +} diff --git a/sca-java-1.x/tags/0.99-incubating/itest/callback-set-conversation/src/main/java/org/apache/tuscany/sca/test/CallBackSetCallbackConvClientImpl.java b/sca-java-1.x/tags/0.99-incubating/itest/callback-set-conversation/src/main/java/org/apache/tuscany/sca/test/CallBackSetCallbackConvClientImpl.java new file mode 100644 index 0000000000..ef9d858126 --- /dev/null +++ b/sca-java-1.x/tags/0.99-incubating/itest/callback-set-conversation/src/main/java/org/apache/tuscany/sca/test/CallBackSetCallbackConvClientImpl.java @@ -0,0 +1,173 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 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; + +import org.osoa.sca.NoRegisteredCallbackException; +import org.osoa.sca.ServiceReference; +import org.osoa.sca.annotations.Reference; +import org.osoa.sca.annotations.Scope; +import org.osoa.sca.annotations.Service; + +@Service(CallBackSetCallbackConvClient.class) +@Scope("CONVERSATION") +public class CallBackSetCallbackConvClientImpl implements CallBackSetCallbackConvClient { + + @Reference + protected CallBackSetCallbackConvService aCallBackService; + private CallBackSetCallbackConvObjectCallback aCallbackObject = null; + private Object monitor = new Object(); + + public void run() { + + // This tests aspects of the setCallback() API within a conversational + // scope. + + /* + * test7 The client calls setCallback() with an object that is not a + * service reference and the callback interface is stateful. Verify + * successful execution. + */ + test7(); + + /* + * test8() The client calls setCallback() with an object that does not + * implement the callback interface. Verify an appropriate exception is + * thrown. This requires a STATEFUL interface. + */ + test8(); + + /* + * test9 The client calls setCallback() with an object that is not + * serializable. Verify an appropriate exception is thrown. This + * requires a STATEFUL callback interface. Move from the stateless test + * case. + */ + test9(); + + return; + } + + private void test7() { + + // + // This test is to specify an Object that is not a service reference + // that does implement + // the callback interface and is Serializeable. Verify successful + // execution. + // + + aCallbackObject = new CallBackSetCallbackConvObjectCallback(); + aCallbackObject.incrementCallBackCount(); + aCallbackObject.setMonitor(monitor); + + ((ServiceReference)aCallBackService).setCallback(aCallbackObject); + aCallBackService.knockKnock("Knock Knock"); + + // Lets give the callback a little time to complete.... + + int count = 0; + + synchronized (monitor) { + while (aCallbackObject.getCount() != 2 && count++ < 30) { + try { + monitor.wait(1000L); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + + Assert.assertEquals("CallBackSetCallbackConv - Test7", 2, aCallbackObject.getCount()); + + } + + private void test8() { + + boolean correctException = false; + + // + // This test is to specify an Object that is not a service reference + // that does not impliment + // the callback interface. The expected result is an appropriate + // exception. + // + + try { + ((ServiceReference)aCallBackService).setCallback(new CallBackSetCallbackConvBadCallback()); + aCallBackService.knockKnock("Knock Knock"); + } + + // + // This should catch an appropriate exception. + // + + catch (NoRegisteredCallbackException NotRegEx) // This needs to be + // changed to proper + // exception once we + // know what it is ;-) + { + correctException = true; + } + + catch (Exception ex) { + // This means an inappropriate exception occurred + ex.printStackTrace(); + } + + Assert.assertEquals("CallBackSetCallbackConv - Test8", true, correctException); + + } + + private void test9() { + + boolean correctException = false; + + // + // This test is to specify an Object that is not a service reference + // that does impliment + // the callback interface but does not implement Serializeable. Verify + // an appropriate exception + // is thrown. + // + + try { + ((ServiceReference)aCallBackService).setCallback(new CallBackSetCallbackConvNonSerCallback()); + aCallBackService.knockKnock("Knock Knock"); + } + // + // This should catch an appropriate exception. + // + catch (NoRegisteredCallbackException NotRegEx) // This needs to be + // changed to + // appropriate exception + // when we know what it + // is ;-) + { + correctException = true; + } catch (Exception ex) { + ex.printStackTrace(); + } + + Assert.assertEquals("CallBackSetCallbackConv - Test9", true, correctException); + + } + +} diff --git a/sca-java-1.x/tags/0.99-incubating/itest/callback-set-conversation/src/main/java/org/apache/tuscany/sca/test/CallBackSetCallbackConvNonSerCallback.java b/sca-java-1.x/tags/0.99-incubating/itest/callback-set-conversation/src/main/java/org/apache/tuscany/sca/test/CallBackSetCallbackConvNonSerCallback.java new file mode 100644 index 0000000000..789e04e907 --- /dev/null +++ b/sca-java-1.x/tags/0.99-incubating/itest/callback-set-conversation/src/main/java/org/apache/tuscany/sca/test/CallBackSetCallbackConvNonSerCallback.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 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 CallBackSetCallbackConvNonSerCallback implements CallBackSetCallbackConvCallback { + + private int callBackCount = 0; + private Object monitor; + + public CallBackSetCallbackConvNonSerCallback() { + super(); + } + + public synchronized void incrementCallBackCount() { + callBackCount++; + } + + public synchronized int getCount() { + return callBackCount; + } + + public void setMonitor(Object anObject) { + monitor = anObject; + } + + public void callBackMessage(String aString) { + + System.out.println("Entering CallBackSetCallbackConvNonSerCallback callBackMessage: " + aString); + + } + + public void callBackIncrement(String aString) { + + System.out.println("Entering callback increment: " + aString); + + synchronized (monitor) { + this.incrementCallBackCount(); + monitor.notify(); + } + } + +} diff --git a/sca-java-1.x/tags/0.99-incubating/itest/callback-set-conversation/src/main/java/org/apache/tuscany/sca/test/CallBackSetCallbackConvObjectCallback.java b/sca-java-1.x/tags/0.99-incubating/itest/callback-set-conversation/src/main/java/org/apache/tuscany/sca/test/CallBackSetCallbackConvObjectCallback.java new file mode 100644 index 0000000000..643aa00a9d --- /dev/null +++ b/sca-java-1.x/tags/0.99-incubating/itest/callback-set-conversation/src/main/java/org/apache/tuscany/sca/test/CallBackSetCallbackConvObjectCallback.java @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 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 CallBackSetCallbackConvObjectCallback implements CallBackSetCallbackConvCallback { + + private int callBackCount = 0; + private Object monitor; + + public CallBackSetCallbackConvObjectCallback() { + super(); + } + + public synchronized void incrementCallBackCount() { + callBackCount++; + } + + public synchronized int getCount() { + return callBackCount; + } + + public void setMonitor(Object anObject) { + monitor = anObject; + } + + public void callBackMessage(String aString) { + + System.out.println("Entering CallBackSetCallbackObjectCallback callBackMessage: " + aString); + + } + + public void callBackIncrement(String aString) { + + System.out.println("Entering callback increment: " + aString); + + synchronized (monitor) { + this.incrementCallBackCount(); + monitor.notify(); + } + } + +} diff --git a/sca-java-1.x/tags/0.99-incubating/itest/callback-set-conversation/src/main/java/org/apache/tuscany/sca/test/CallBackSetCallbackConvService.java b/sca-java-1.x/tags/0.99-incubating/itest/callback-set-conversation/src/main/java/org/apache/tuscany/sca/test/CallBackSetCallbackConvService.java new file mode 100644 index 0000000000..4b0dccefdc --- /dev/null +++ b/sca-java-1.x/tags/0.99-incubating/itest/callback-set-conversation/src/main/java/org/apache/tuscany/sca/test/CallBackSetCallbackConvService.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(CallBackSetCallbackConvCallback.class) +/** + * + */ +public interface CallBackSetCallbackConvService { + + public void knockKnock(String aString); + + public void setCallbackIllegally(String aString); + +} diff --git a/sca-java-1.x/tags/0.99-incubating/itest/callback-set-conversation/src/main/java/org/apache/tuscany/sca/test/CallBackSetCallbackConvServiceImpl.java b/sca-java-1.x/tags/0.99-incubating/itest/callback-set-conversation/src/main/java/org/apache/tuscany/sca/test/CallBackSetCallbackConvServiceImpl.java new file mode 100644 index 0000000000..5b685e695b --- /dev/null +++ b/sca-java-1.x/tags/0.99-incubating/itest/callback-set-conversation/src/main/java/org/apache/tuscany/sca/test/CallBackSetCallbackConvServiceImpl.java @@ -0,0 +1,102 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 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.Scope; +import org.osoa.sca.annotations.Service; + +@Service(CallBackSetCallbackConvService.class) +@Scope("CONVERSATION") +public class CallBackSetCallbackConvServiceImpl implements CallBackSetCallbackConvService { + + @Callback + private CallBackSetCallbackConvCallback 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 void setCallbackIllegally(String aString) { + + System.out.println("CallBackBasicServiceImpl.setCallbackIllegally() message received: " + aString); + + boolean exceptionProduced = false; + RequestContext requestContext = null; + ServiceReference serviceRef = null; + + // Context is not working properly so we can't trust that this is + // working..... + try { + requestContext = context.getRequestContext(); + serviceRef = (ServiceReference) requestContext.getServiceReference(); + } catch (Exception ex) { + System.out.println("CallBackBasicServiceImpl.setCallbackIllegally() " + ex.toString()); + ex.printStackTrace(); + return; + } + + // Ok, call setCallback with my own service reference. + try { + serviceRef.setCallback(serviceRef); + } catch (NullPointerException npe) { + // This is not an appropriate exception. + System.out.println("Test10 NPE exception during setCallback to own service reference"); + npe.printStackTrace(); + return; + } + // This needs to catch the appropriate exception, once we figure out + // what is needs to be! + catch (Exception ex) { + exceptionProduced = true; + System.out.println("Test10 appropriate exception caught during setCallback to own service reference"); + } + ; + + // If we get the exception we are looking for then create the marker + // file. + if (exceptionProduced == true) { + File aFile = new File("target/test10_marker"); + try { + aFile.createNewFile(); + } catch (Exception ex) { + System.out.println("Error Creating target/test10_marker marker file"); + ex.printStackTrace(); + } + } + + } +} -- cgit v1.2.3