diff options
Diffstat (limited to 'sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/test')
9 files changed, 489 insertions, 0 deletions
diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/test/java/account/BankManagerFacade.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/test/java/account/BankManagerFacade.java new file mode 100644 index 0000000000..a8100d280b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/test/java/account/BankManagerFacade.java @@ -0,0 +1,33 @@ +/* + * 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 account; + +import org.osoa.sca.annotations.Remotable; + +/** + * + * Compatible EJB interface + * + */ +@Remotable +public interface BankManagerFacade +{ + public java.lang.Double getAccountBalance( java.lang.String accountNo ); + public void changeAccountBalance( java.lang.String accountNo,java.lang.Double balance ); +}
\ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/test/java/account/Customer.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/test/java/account/Customer.java new file mode 100644 index 0000000000..2b5ed04f6a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/test/java/account/Customer.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 account; + +import org.osoa.sca.annotations.Remotable; +import org.osoa.sca.annotations.Service; + +@Remotable +@Service +public interface Customer { + + /** + * This method deposits the amount. method accesses external EJB to get the + * current balance and add the amount to existing balance. + * + * @param String amount to be deposited + * @return total amount in customer accound after deposit + */ + Double depositAmount(java.lang.String accountNo, Double amount); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/test/java/account/CustomerImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/test/java/account/CustomerImpl.java new file mode 100644 index 0000000000..0cbb6d088c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/test/java/account/CustomerImpl.java @@ -0,0 +1,55 @@ +/* + * 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 account; + +import org.osoa.sca.ServiceRuntimeException; +import org.osoa.sca.annotations.Reference; +import org.osoa.sca.annotations.Service; + +@Service(Customer.class) +public class CustomerImpl implements Customer { + + private BankManagerFacade extEJBService = null; + + public BankManagerFacade getExtEJBService() { + return extEJBService; + } + + @Reference + public void setExtEJBService(BankManagerFacade extEJBService) { + this.extEJBService = extEJBService; + } + + // this method invokes external EJB through EJB reference binding + public Double depositAmount(java.lang.String accountNo, Double amount) { + + Double total = null; + + System.out.println("In component implementation. Invoking external EJB through EJB reference binding "); + + try { + Double balance = extEJBService.getAccountBalance(accountNo); //invoke external ejb through ejb reference binding + total = balance + amount; + } catch (Exception e) { + throw new ServiceRuntimeException(e); + } + return total; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/test/java/org/apache/geronimo/samples/bank/ejb/BankManagerFacade.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/test/java/org/apache/geronimo/samples/bank/ejb/BankManagerFacade.java new file mode 100644 index 0000000000..c393d08a25 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/test/java/org/apache/geronimo/samples/bank/ejb/BankManagerFacade.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. + */ + +/* + * Generated by XDoclet - Do not edit! + */ +package org.apache.geronimo.samples.bank.ejb; + +// copied from the Geronimo Bank sample: http://cwiki.apache.org/GMOxDOC11/ejb-sample-application.html#EJBsampleapplication-overview + +/** + * Remote interface for BankManagerFacadeBean. + * @xdoclet-generated at ${TODAY} + * @copyright The XDoclet Team + * @author XDoclet + * @version ${version} + */ +public interface BankManagerFacade + extends javax.ejb.EJBObject +{ + + public void changeAccountBalance( java.lang.String accountNo,java.lang.Double balance ) + throws java.rmi.RemoteException; + + public java.lang.Double getAccountBalance( java.lang.String accountNo ) + throws java.rmi.RemoteException; + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/test/java/org/apache/geronimo/samples/bank/ejb/BankManagerFacadeHome.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/test/java/org/apache/geronimo/samples/bank/ejb/BankManagerFacadeHome.java new file mode 100644 index 0000000000..f5e2f3b2e4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/test/java/org/apache/geronimo/samples/bank/ejb/BankManagerFacadeHome.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. + */ + +/* + * Generated by XDoclet - Do not edit! + */ + +// copied from the Geronimo Bank sample: http://cwiki.apache.org/GMOxDOC11/ejb-sample-application.html#EJBsampleapplication-overview + +package org.apache.geronimo.samples.bank.ejb; + +/** + * Home interface for BankManagerFacadeBean. + * @xdoclet-generated at ${TODAY} + * @copyright The XDoclet Team + * @author XDoclet + * @version ${version} + */ +public interface BankManagerFacadeHome + extends javax.ejb.EJBHome +{ + public static final String COMP_NAME="java:comp/env/ejb/BankManagerFacadeBean"; + public static final String JNDI_NAME="org.apache.geronimo.samples.bank.ejb.BankManagerFacadeBean"; + + public org.apache.geronimo.samples.bank.ejb.BankManagerFacade create() + throws javax.ejb.CreateException,java.rmi.RemoteException; + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/test/java/org/apache/tuscany/sca/binding/ejb/tests/EJBReferenceTestCase.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/test/java/org/apache/tuscany/sca/binding/ejb/tests/EJBReferenceTestCase.java new file mode 100644 index 0000000000..d60468d23c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/test/java/org/apache/tuscany/sca/binding/ejb/tests/EJBReferenceTestCase.java @@ -0,0 +1,56 @@ +/* + * 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.binding.ejb.tests; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +import account.Customer; + +/** + * Invokes the component which calls the reference using the EJB binding + */ +public class EJBReferenceTestCase extends TestCase { + + private SCADomain scaDomain; + + protected void setUp() throws Exception { + System.setProperty("managed", "false"); + System.setProperty("java.naming.factory.initial", "org.openejb.client.RemoteInitialContextFactory"); + System.setProperty("java.naming.provider.url", "localhost:4321"); + scaDomain = SCADomain.newInstance("account/account.composite"); + +// new Thread(new SocketTracer(4321, 4201)).start(); + new Thread(new MockServer(4321)).start(); + } + + protected void tearDown() throws Exception { + scaDomain.close(); + } + + public void testCalculator() throws Exception { + Customer customer = scaDomain.getService(Customer.class, "CustomerComponent"); + // This is one of the customer numbers in bank application running on Geronimo + String accountNo = "1234567890"; + Double balance = customer.depositAmount(accountNo, new Double(100)); + System.out.println("Balance amount for account " + accountNo + " is $" + balance); + assertEquals(1105.35, balance); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/test/java/org/apache/tuscany/sca/binding/ejb/tests/MockServer.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/test/java/org/apache/tuscany/sca/binding/ejb/tests/MockServer.java new file mode 100644 index 0000000000..e81865fb6b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/test/java/org/apache/tuscany/sca/binding/ejb/tests/MockServer.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.binding.ejb.tests; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.ServerSocket; +import java.net.Socket; + +public class MockServer implements Runnable { + + private int listen; + + private int[] r1 = new int[] {79, 69, 74, 80, 47, 50, 46, 48, 172, 237, 0, 5, 119, 1, 1, 116, 0, 5, 71, 85, 69, 83, 84}; + private int[] r2 = new int[] {79, 69, 74, 80, 47, 50, 46, 48, 172, 237, 0, 5, 119, 1, 13, 118, 114, 0, 58, 111, 114, 103, 46, 97, 112, 97, 99, 104, 101, 46, 103, 101, 114, 111, 110, 105, 109, 111, 46, 115, 97, 109, 112, 108, 101, 115, 46, 98, 97, 110, 107, 46, 101, 106, 98, 46, 66, 97, 110, 107, 77, 97, 110, 97, 103, 101, 114, 70, 97, 99, 97, 100, 101, 72, 111, 109, 101, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 120, 112, 118, 114, 0, 54, 111, 114, 103, 46, 97, 112, 97, 99, 104, 101, 46, 103, 101, 114, 111, 110, 105, 109, 111, 46, 115, 97, 109, 112, 108, 101, 115, 46, 98, 97, 110, 107, 46, 101, 106, 98, 46, 66, 97, 110, 107, 77, 97, 110, 97, 103, 101, 114, 70, 97, 99, 97, 100, 101, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 120, 112, 112, 112, 119, 185, 1, 0, 180, 111, 114, 103, 46, 97, 112, 97, 99, 104, 101, 46, 103, 101, 114, 111, 110, 105, 109, 111, 46, 115, 97, 109, 112, 108, 101, 115, 47, 66, 97, 110, 107, 47, 49, 46, 49, 46, 49, 47, 99, 97, 114, 63, 69, 74, 66, 77, 111, 100, 117, 108, 101, 61, 66, 97, 110, 107, 69, 74, 66, 46, 106, 97, 114, 44, 74, 50, 69, 69, 65, 112, 112, 108, 105, 99, 97, 116, 105, 111, 110, 61, 111, 114, 103, 46, 97, 112, 97, 99, 104, 101, 46, 103, 101, 114, 111, 110, 105, 109, 111, 46, 115, 97, 109, 112, 108, 101, 115, 47, 66, 97, 110, 107, 47, 49, 46, 49, 46, 49, 47, 99, 97, 114, 44, 106, 50, 101, 101, 84, 121, 112, 101, 61, 83, 116, 97, 116, 101, 108, 101, 115, 115, 83, 101, 115, 115, 105, 111, 110, 66, 101, 97, 110, 44, 110, 97, 109, 101, 61, 66, 97, 110, 107, 77, 97, 110, 97, 103, 101, 114, 70, 97, 99, 97, 100, 101, 66, 101, 97, 110, 0, 1}; + private int[] r3 = new int[] {79, 69, 74, 80, 47, 50, 46, 48, 172, 237, 0, 5, 119, 1, 4, 112}; + private int[] r4 = new int[] {79, 69, 74, 80, 47, 50, 46, 48, 172, 237, 0, 5, 119, 1, 4, 115, 114, 0, 16, 106, 97, 118, 97, 46, 108, 97, 110, 103, 46, 68, 111, 117, 98, 108, 101, 128, 179, 194, 74, 41, 107, 251, 4, 2, 0, 1, 68, 0, 5, 118, 97, 108, 117, 101, 120, 114, 0, 16, 106, 97, 118, 97, 46, 108, 97, 110, 103, 46, 78, 117, 109, 98, 101, 114, 134, 172, 149, 29, 11, 148, 224, 139, 2, 0, 0, 120, 112, 64, 143, 106, 204, 204, 204, 204, 205}; + + public MockServer(int listen) { + this.listen = listen; + } + + public void run() { + try { + ServerSocket ss = new ServerSocket(listen); + + doExchange(ss.accept(), 15, r1); + doExchange(ss.accept(), 80, r2); + doExchange(ss.accept(), 109, r3); + doExchange(ss.accept(), 163, r4); + + } catch (Exception e) { + e.printStackTrace(); + } + } + + private void doExchange(Socket sin, int readCount, int[] write) throws IOException, InterruptedException { + InputStream is = sin.getInputStream(); + OutputStream os = sin.getOutputStream(); + readBytes(is, readCount); + writeBytes(os, write); + sin.close(); + } + + private void readBytes(InputStream is, int x) throws IOException, InterruptedException { + for (int i = 0; i < x; i++) { + is.read(); + } + } + + private void writeBytes(OutputStream os, int[] bs) throws IOException, InterruptedException { + for (int i = 0; i < bs.length; i++) { + os.write(bs[i]); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/test/java/org/apache/tuscany/sca/binding/ejb/tests/SocketTracer.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/test/java/org/apache/tuscany/sca/binding/ejb/tests/SocketTracer.java new file mode 100644 index 0000000000..3dd153eeef --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/test/java/org/apache/tuscany/sca/binding/ejb/tests/SocketTracer.java @@ -0,0 +1,113 @@ +/* + * 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.binding.ejb.tests; + +import java.io.InputStream; +import java.io.OutputStream; +import java.net.ServerSocket; +import java.net.Socket; + +/** + * Displays the bytes flowing across a Socket connection. + * Used to get the read count and reply data for the MockServer + */ +public class SocketTracer implements Runnable { + + private int listen; + private int send; + + SocketTracer(int listen, int send) { + this.listen = listen; + this.send = send; + } + + public void run() { + try { + ServerSocket ss = new ServerSocket(listen); + while (true) { + Socket sin = ss.accept(); + + Socket sout = new Socket("localhost", send); + + Thread st = new Thread(new Send(sin, sout)); + st.start(); + } + + } catch (Exception e) { + e.printStackTrace(); + } + } + +} + +class Send implements Runnable { + + Socket sin; + Socket sout; + + Send(Socket sin, Socket sout) { + this.sin = sin; + this.sout = sout; + } + + public void run() { + try { + + Reply rr = new Reply(sout.getInputStream(), sin.getOutputStream()); + Thread rt = new Thread(rr); + rt.start(); + + OutputStream outout = sout.getOutputStream(); + + InputStream is = sin.getInputStream(); + int i = 0; + while ((i = is.read()) != -1) { + System.out.println("out: " + i); + outout.write(i); + } + } catch (Exception e) { + e.printStackTrace(); + } + } +} + +class Reply implements Runnable { + + InputStream is; + OutputStream outout; + + Reply(InputStream is, OutputStream outout) { + this.is = is; + this.outout = outout; + } + + public void run() { + try { + int i = 0; + while ((i = is.read()) != -1) { + System.out.println("reply: " + i); + outout.write(i); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/test/resources/account/account.composite b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/test/resources/account/account.composite new file mode 100644 index 0000000000..38aece6a94 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/test/resources/account/account.composite @@ -0,0 +1,32 @@ +<?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"
+ name="account">
+
+ <!-- composite refrence with ejb binding. Modify host and port number in uri attribute based on where you have installed target ResumeBank EJB -->
+
+ <component name="CustomerComponent">
+ <implementation.java class="account.CustomerImpl"/>
+ <reference name="extEJBService"> + <binding.ejb uri="corbaname:iiop:1.2@localhost:4201#org.apache.geronimo.samples.bank.ejb.BankManagerFacadeBean"/>
+ </reference>
+ </component>
+
+</composite>
|