diff options
author | dims <dims@13f79535-47bb-0310-9956-ffa450edef68> | 2008-06-17 00:23:01 +0000 |
---|---|---|
committer | dims <dims@13f79535-47bb-0310-9956-ffa450edef68> | 2008-06-17 00:23:01 +0000 |
commit | bdd0a41aed7edf21ec2a65cfa17a86af2ef8c48a (patch) | |
tree | 38a92061c0793434c4be189f1d70c3458b6bc41d /branches/sca-java-1.2.1/samples/implementation-pojo |
Move Tuscany from Incubator to top level.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@668359 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'branches/sca-java-1.2.1/samples/implementation-pojo')
10 files changed, 475 insertions, 0 deletions
diff --git a/branches/sca-java-1.2.1/samples/implementation-pojo/README b/branches/sca-java-1.2.1/samples/implementation-pojo/README new file mode 100644 index 0000000000..e6b285d82d --- /dev/null +++ b/branches/sca-java-1.2.1/samples/implementation-pojo/README @@ -0,0 +1,72 @@ +Implementation POJO Sample +========================== +This sample demonstrates how to use the new implementation type +implementation-pojo. + +The README in the samples directory (the directory above this) provides +general instructions about building and running samples. Take a look there +first. + +Sample Overview +--------------- +This sample contains a POJO implementation type as an example of how to create +new implementation types. + +implementation-pojo-extension/ + src/ + main/ + java/ + helloworld/ - client application artifacts + resources/ + helloworld.composite - the SCA assembly used during unit testing + + test/ + java/ + helloworld/ + HelloWorldTestCase.java - JUnit test case + + build.xml - the Ant build file + pom.xml - the Maven build file + +Building And Running The Sample Using Ant +----------------------------------------- +With the binary distribution the sample extension can be built using Ant as +follows + +cd implementation-pojo +ant compile +ant run + +Building And Running The Sample Using Maven +------------------------------------------- +With either the binary or source distributions the sample can be built +using Maven as follows. + +cd implementation-pojo +mvn + +Maven will also test that the sample extension built properly. You should see +the following output from the test phase. + +------------------------------------------------------- + T E S T S +------------------------------------------------------- +Running helloworld.HelloWorldTestCase +Initializing POJO +Initializing POJO +Executing POJO sayHello +Destroying POJO +Destroying POJO +Initializing POJO +Initializing POJO +Executing POJO sayHello +Destroying POJO +Destroying POJO +Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.463 sec + +Results : + +Tests run: 2, Failures: 0, Errors: 0, Skipped: 0 + + +This shows that the Junit test cases have run successfully. diff --git a/branches/sca-java-1.2.1/samples/implementation-pojo/build.xml b/branches/sca-java-1.2.1/samples/implementation-pojo/build.xml new file mode 100644 index 0000000000..ee61db0467 --- /dev/null +++ b/branches/sca-java-1.2.1/samples/implementation-pojo/build.xml @@ -0,0 +1,74 @@ +<!-- + * 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 name="implementation-pojo-extension" default="compile"> + <property name="test.class" value="helloworld.HelloWorldClient" /> + <property name="test.jar" value="sample-implementation-pojo-extension.jar" /> + + <target name="init"> + <mkdir dir="target/classes"/> + </target> + + <target name="compile" depends="init"> + <javac srcdir="src/main/java" + destdir="target/classes" + debug="on" + source="1.5" + target="1.5"> + <classpath> + <pathelement location="../../lib/tuscany-sca-manifest.jar"/> + </classpath> + </javac> + <copy todir="target/classes"> + <fileset dir="src/main/resources"/> + </copy> + <jar destfile="target/${test.jar}" basedir="target/classes"> + <manifest> + <attribute name="Main-Class" value="${test.class}" /> + </manifest> + </jar> + </target> + + <target name="run-classes"> + <java classname="${test.class}" + fork="true"> + <classpath> + <pathelement path="target/classes"/> + <pathelement location="../implementation-pojo-extension/target/sample-implementation-pojo-extension.jar"/> + <pathelement location="../../lib/tuscany-sca-manifest.jar"/> + </classpath> + </java> + </target> + + <target name="run"> + <java classname="${test.class}" + fork="true"> + <classpath> + <pathelement location="target/${test.jar}"/> + <pathelement location="../implementation-pojo-extension/target/sample-implementation-pojo-extension.jar"/> + <pathelement location="../../lib/tuscany-sca-manifest.jar"/> + </classpath> + </java> + </target> + + <target name="clean"> + <delete quiet="true" includeemptydirs="true"> + <fileset dir="target"/> + </delete> + </target> +</project> diff --git a/branches/sca-java-1.2.1/samples/implementation-pojo/pom.xml b/branches/sca-java-1.2.1/samples/implementation-pojo/pom.xml new file mode 100644 index 0000000000..dbd04b9344 --- /dev/null +++ b/branches/sca-java-1.2.1/samples/implementation-pojo/pom.xml @@ -0,0 +1,82 @@ +<?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-sca</artifactId> + <version>1.2.1-incubating-SNAPSHOT</version> + <relativePath>../../pom.xml</relativePath> + </parent> + <artifactId>sample-implementation-pojo</artifactId> + <name>Apache Tuscany SCA POJO Implementation Extension Sample</name> + + <repositories> + <repository> + <id>apache.incubator</id> + <url>http://people.apache.org/repo/m2-incubating-repository</url> + </repository> + </repositories> + + <dependencies> + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>sample-implementation-pojo-extension</artifactId> + <version>1.2.1-incubating-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-assembly-xml</artifactId> + <version>1.2.1-incubating-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-interface-java-xml</artifactId> + <version>1.2.1-incubating-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-core-spi</artifactId> + <version>1.2.1-incubating-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-host-embedded</artifactId> + <version>1.2.1-incubating-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.2</version> + <scope>test</scope> + </dependency> + + </dependencies> + + <build> + <finalName>${artifactId}</finalName> + </build> + +</project> diff --git a/branches/sca-java-1.2.1/samples/implementation-pojo/src/main/java/helloworld/HelloWorld.java b/branches/sca-java-1.2.1/samples/implementation-pojo/src/main/java/helloworld/HelloWorld.java new file mode 100644 index 0000000000..cc32929f09 --- /dev/null +++ b/branches/sca-java-1.2.1/samples/implementation-pojo/src/main/java/helloworld/HelloWorld.java @@ -0,0 +1,26 @@ +/* + * 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 helloworld; + +public interface HelloWorld { + + String sayHello(String name); + +} diff --git a/branches/sca-java-1.2.1/samples/implementation-pojo/src/main/java/helloworld/HelloWorldClient.java b/branches/sca-java-1.2.1/samples/implementation-pojo/src/main/java/helloworld/HelloWorldClient.java new file mode 100644 index 0000000000..34d9e3a463 --- /dev/null +++ b/branches/sca-java-1.2.1/samples/implementation-pojo/src/main/java/helloworld/HelloWorldClient.java @@ -0,0 +1,37 @@ +/* + * 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 helloworld; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +/** + * Tests the POJO implementation extension. + */ +public class HelloWorldClient { + + public static void main(String[] args) throws Exception { + SCADomain scaDomain = SCADomain.newInstance("helloworld/helloworld.composite"); + HelloWorld helloworld = scaDomain.getService(HelloWorld.class, "HelloWorldComponent"); + helloworld.sayHello("petra"); + + HelloWorld helloworld2 = scaDomain.getService(HelloWorld.class, "HelloWorldComponent2/HelloWorld2"); + helloworld2.sayHello("petra"); + + } +} diff --git a/branches/sca-java-1.2.1/samples/implementation-pojo/src/main/java/helloworld/HelloWorldImpl.java b/branches/sca-java-1.2.1/samples/implementation-pojo/src/main/java/helloworld/HelloWorldImpl.java new file mode 100644 index 0000000000..0580e30aba --- /dev/null +++ b/branches/sca-java-1.2.1/samples/implementation-pojo/src/main/java/helloworld/HelloWorldImpl.java @@ -0,0 +1,37 @@ +/* + * 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 helloworld; + +public class HelloWorldImpl { + + public void init() { + System.out.println("Initializing POJO"); + } + + public void destroy() { + System.out.println("Destroying POJO"); + } + + public String sayHello(String name) { + System.out.println("Executing POJO sayHello"); + return "Hello " + name; + } + +} diff --git a/branches/sca-java-1.2.1/samples/implementation-pojo/src/main/java/helloworld/HelloWorldImpl2.java b/branches/sca-java-1.2.1/samples/implementation-pojo/src/main/java/helloworld/HelloWorldImpl2.java new file mode 100644 index 0000000000..69ab1f567e --- /dev/null +++ b/branches/sca-java-1.2.1/samples/implementation-pojo/src/main/java/helloworld/HelloWorldImpl2.java @@ -0,0 +1,37 @@ +/* + * 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 helloworld; + +public class HelloWorldImpl2 { + + public void init() { + System.out.println("Initializing POJO"); + } + + public void destroy() { + System.out.println("Destroying POJO"); + } + + public String sayHello(String name) { + System.out.println("Executing POJO sayHello"); + return "Hello " + name; + } + +} diff --git a/branches/sca-java-1.2.1/samples/implementation-pojo/src/main/resources/helloworld/HelloWorldImpl2.componentType b/branches/sca-java-1.2.1/samples/implementation-pojo/src/main/resources/helloworld/HelloWorldImpl2.componentType new file mode 100644 index 0000000000..a92c5ab8db --- /dev/null +++ b/branches/sca-java-1.2.1/samples/implementation-pojo/src/main/resources/helloworld/HelloWorldImpl2.componentType @@ -0,0 +1,26 @@ +<?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. +--> +<componentType xmlns="http://www.osoa.org/xmlns/sca/1.0"> + + <service name="HelloWorld2"> + <interface.java interface="helloworld.HelloWorld"/> + </service> + +</componentType>
\ No newline at end of file diff --git a/branches/sca-java-1.2.1/samples/implementation-pojo/src/main/resources/helloworld/helloworld.composite b/branches/sca-java-1.2.1/samples/implementation-pojo/src/main/resources/helloworld/helloworld.composite new file mode 100644 index 0000000000..c38094dfc9 --- /dev/null +++ b/branches/sca-java-1.2.1/samples/implementation-pojo/src/main/resources/helloworld/helloworld.composite @@ -0,0 +1,33 @@ +<?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://test/helloworld" + xmlns:p="http://pojo" + name="helloworld"> + + <component name="HelloWorldComponent"> + <p:implementation.pojo class="helloworld.HelloWorldImpl" /> + </component> + + <component name="HelloWorldComponent2"> + <p:implementation.pojo class="helloworld.HelloWorldImpl2" /> + </component> + +</composite> diff --git a/branches/sca-java-1.2.1/samples/implementation-pojo/src/test/java/helloworld/HelloWorldTestCase.java b/branches/sca-java-1.2.1/samples/implementation-pojo/src/test/java/helloworld/HelloWorldTestCase.java new file mode 100644 index 0000000000..d8b5f41adc --- /dev/null +++ b/branches/sca-java-1.2.1/samples/implementation-pojo/src/test/java/helloworld/HelloWorldTestCase.java @@ -0,0 +1,51 @@ +/* + * 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 helloworld; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +/** + * Tests the POJO implementation extension. + */ +public class HelloWorldTestCase extends TestCase { + + private SCADomain scaDomain; + + @Override + protected void setUp() throws Exception { + scaDomain = SCADomain.newInstance("helloworld/helloworld.composite"); + } + + @Override + protected void tearDown() throws Exception { + scaDomain.close(); + } + + public void testHello() throws Exception { + HelloWorld helloworld = scaDomain.getService(HelloWorld.class, "HelloWorldComponent"); + assertEquals("Hello petra", helloworld.sayHello("petra")); + } + + public void testHello2() throws Exception { + HelloWorld helloworld = scaDomain.getService(HelloWorld.class, "HelloWorldComponent2/HelloWorld2"); + assertEquals("Hello petra", helloworld.sayHello("petra")); + } +} |