diff options
Diffstat (limited to 'sandbox/jboynes/sca-client/src/test/java')
6 files changed, 207 insertions, 0 deletions
diff --git a/sandbox/jboynes/sca-client/src/test/java/org/osoa/sca/annotations/CallbackTestCase.java b/sandbox/jboynes/sca-client/src/test/java/org/osoa/sca/annotations/CallbackTestCase.java new file mode 100644 index 0000000000..c4506713f6 --- /dev/null +++ b/sandbox/jboynes/sca-client/src/test/java/org/osoa/sca/annotations/CallbackTestCase.java @@ -0,0 +1,70 @@ +/* + * 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.osoa.sca.annotations; + +import java.lang.reflect.Field; +import java.lang.reflect.Method; + +import junit.framework.TestCase; +import org.osoa.sca.annotations.usage.CallbackType; + +/** + * Test case for callback annotation. + * + * @version $Rev$ $Date$ + */ +public class CallbackTestCase extends TestCase { + private Class<?> type; + private Field field; + private Method method; + + /** + * Test annotation of a callback interface. + */ + public void testTypeDeclaration() { + assertTrue(type.isAnnotationPresent(Callback.class)); + Callback callback = type.getAnnotation(Callback.class); + assertEquals(Object.class, callback.value()); + } + + /** + * Test annotation of a private field. + */ + public void testField() { + assertTrue(field.isAnnotationPresent(Callback.class)); + Callback callback = field.getAnnotation(Callback.class); + assertEquals(Void.class, callback.value()); + } + + /** + * Test annotation of a method. + */ + public void testMethod() { + assertTrue(method.isAnnotationPresent(Callback.class)); + Callback callback = method.getAnnotation(Callback.class); + assertEquals(Void.class, callback.value()); + } + + protected void setUp() throws Exception { + super.setUp(); + type = CallbackType.class; + field = type.getDeclaredField("cbField"); + method = type.getMethod("cbMethod"); + } +} diff --git a/sandbox/jboynes/sca-client/src/test/java/org/osoa/sca/annotations/usage/CallbackType.java b/sandbox/jboynes/sca-client/src/test/java/org/osoa/sca/annotations/usage/CallbackType.java new file mode 100644 index 0000000000..962c7bef51 --- /dev/null +++ b/sandbox/jboynes/sca-client/src/test/java/org/osoa/sca/annotations/usage/CallbackType.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.osoa.sca.annotations.usage; + +import org.osoa.sca.annotations.Callback; + +/** + * Mock object for callback annotation tests. + * + * @version $Rev$ $Date$ + */ +@Callback(Object.class) +public class CallbackType { + @Callback + private Object cbField; + + /** + * Site for testing annotation of a public method. + */ + @Callback + public void cbMethod() { + cbField = new Object(); + } + + /** + * Mock method to make IDEs stop complaining. + * + * @return nothing + */ + public Object getCbField() { + return cbField; + } +} diff --git a/sandbox/jboynes/sca-client/src/test/java/sample/HelloCallback.java b/sandbox/jboynes/sca-client/src/test/java/sample/HelloCallback.java new file mode 100644 index 0000000000..9efa48d500 --- /dev/null +++ b/sandbox/jboynes/sca-client/src/test/java/sample/HelloCallback.java @@ -0,0 +1,8 @@ +package sample; + +/** + * @version $Rev$ $Date$ + */ +public interface HelloCallback { + String getLocale(); +} diff --git a/sandbox/jboynes/sca-client/src/test/java/sample/HelloService.java b/sandbox/jboynes/sca-client/src/test/java/sample/HelloService.java new file mode 100644 index 0000000000..cea12771a8 --- /dev/null +++ b/sandbox/jboynes/sca-client/src/test/java/sample/HelloService.java @@ -0,0 +1,8 @@ +package sample; + +/** + * @version $Rev$ $Date$ + */ +public interface HelloService { + String hello(String message); +} diff --git a/sandbox/jboynes/sca-client/src/test/java/sample/client/BasicClient.java b/sandbox/jboynes/sca-client/src/test/java/sample/client/BasicClient.java new file mode 100644 index 0000000000..6565a6a5f7 --- /dev/null +++ b/sandbox/jboynes/sca-client/src/test/java/sample/client/BasicClient.java @@ -0,0 +1,38 @@ +package sample.client; + +import org.osoa.sca.ComponentContext; +import org.osoa.sca.ServiceReference; +import sample.HelloService; + +/** + * @version $Rev$ $Date$ + */ +public class BasicClient { + private ComponentContext context; + + public void useComponentDirectly() { + HelloService helloService = context.getService(HelloService.class, "helloService"); + helloService.hello("World"); + } + + public void useComponentViaReference() { + ServiceReference<HelloService> ref = context.getServiceReference(HelloService.class, "helloService"); + HelloService helloService = ref.getService(); + helloService.hello("World"); + + ServiceReference<HelloService> ref2 = context.cast(helloService); + } + + public void useReferenceDirectly() { + HelloService helloService = context.getService(HelloService.class, "helloReference"); + helloService.hello("World"); + } + + public void useReferenceViaReference() { + ServiceReference<HelloService> ref = context.getServiceReference(HelloService.class, "helloReference"); + HelloService helloService = ref.getService(); + helloService.hello("World"); + + ServiceReference<HelloService> ref2 = context.cast(helloService); + } +} diff --git a/sandbox/jboynes/sca-client/src/test/java/sample/client/ReallyBasicClient.java b/sandbox/jboynes/sca-client/src/test/java/sample/client/ReallyBasicClient.java new file mode 100644 index 0000000000..f2ef857166 --- /dev/null +++ b/sandbox/jboynes/sca-client/src/test/java/sample/client/ReallyBasicClient.java @@ -0,0 +1,34 @@ +package sample.client; + +import org.osoa.sca.ComponentContext; +import sample.HelloService; + +/** + * @version $Rev$ $Date$ + */ +public class ReallyBasicClient { + /** + * <composite name="impl2"> + * <component name="comp2a"> + * <implementation.unmanaged/> + * <reference name="helloService" target="hello"/> + * </component> + * + * <component name="hello"> + * <implementation.java class="sample.HelloServiceImpl"/> + * </component> + * </composite> + */ + public static void main(String[] args) { + ComponentContext context = getComponentContext(); + + // access a service through its reference + HelloService helloService = context.getService(HelloService.class, "helloService"); + helloService.hello("World"); + } + + public static ComponentContext getComponentContext() { + // implementation defined mechanism to retrieve appropriate ComponentContext + throw new UnsupportedOperationException(); + } +} |