From bdd0a41aed7edf21ec2a65cfa17a86af2ef8c48a Mon Sep 17 00:00:00 2001 From: dims Date: Tue, 17 Jun 2008 00:23:01 +0000 Subject: Move Tuscany from Incubator to top level. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@668359 13f79535-47bb-0310-9956-ffa450edef68 --- .../sca-java-0.90/samples/loanapplication/pom.xml | 65 +++++++++++++++++ .../main/java/loanapplication/LoanApplication.java | 35 ++++++++++ .../loanapplication/LoanApplicationClient.java | 37 ++++++++++ .../src/main/java/loanapplication/LoanClient.java | 29 ++++++++ .../main/java/loanapplication/LoanClientImpl.java | 64 +++++++++++++++++ .../src/main/java/loanapplication/LoanService.java | 37 ++++++++++ .../main/java/loanapplication/LoanServiceImpl.java | 63 +++++++++++++++++ .../src/main/resources/loanapplication.composite | 34 +++++++++ .../loanapplication/LoanApplicationTestCase.java | 81 ++++++++++++++++++++++ 9 files changed, 445 insertions(+) create mode 100644 branches/sca-java-0.90/samples/loanapplication/pom.xml create mode 100644 branches/sca-java-0.90/samples/loanapplication/src/main/java/loanapplication/LoanApplication.java create mode 100644 branches/sca-java-0.90/samples/loanapplication/src/main/java/loanapplication/LoanApplicationClient.java create mode 100644 branches/sca-java-0.90/samples/loanapplication/src/main/java/loanapplication/LoanClient.java create mode 100644 branches/sca-java-0.90/samples/loanapplication/src/main/java/loanapplication/LoanClientImpl.java create mode 100644 branches/sca-java-0.90/samples/loanapplication/src/main/java/loanapplication/LoanService.java create mode 100644 branches/sca-java-0.90/samples/loanapplication/src/main/java/loanapplication/LoanServiceImpl.java create mode 100644 branches/sca-java-0.90/samples/loanapplication/src/main/resources/loanapplication.composite create mode 100644 branches/sca-java-0.90/samples/loanapplication/src/test/java/loanapplication/LoanApplicationTestCase.java (limited to 'branches/sca-java-0.90/samples/loanapplication') diff --git a/branches/sca-java-0.90/samples/loanapplication/pom.xml b/branches/sca-java-0.90/samples/loanapplication/pom.xml new file mode 100644 index 0000000000..1e58d99e1b --- /dev/null +++ b/branches/sca-java-0.90/samples/loanapplication/pom.xml @@ -0,0 +1,65 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-sca + 1.0-incubating-SNAPSHOT + ../../pom.xml + + sample-loanapplication + Apache Tuscany Loan Application Conversation Sample + + + + apache.incubator + http://people.apache.org/repo/m2-incubating-repository + + + + + + org.apache.tuscany.sca + tuscany-host-embedded + 1.0-incubating-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 1.0-incubating-SNAPSHOT + runtime + + + + junit + junit + 4.2 + test + + + + + + ${artifactId} + + + diff --git a/branches/sca-java-0.90/samples/loanapplication/src/main/java/loanapplication/LoanApplication.java b/branches/sca-java-0.90/samples/loanapplication/src/main/java/loanapplication/LoanApplication.java new file mode 100644 index 0000000000..441f68ebf0 --- /dev/null +++ b/branches/sca-java-0.90/samples/loanapplication/src/main/java/loanapplication/LoanApplication.java @@ -0,0 +1,35 @@ +/* + * 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 loanapplication; + +public class LoanApplication { + + private String customerName; + private float loanAmount; + + public LoanApplication(String customerName, float loanAmount) { + this.customerName = customerName; + this.loanAmount = loanAmount; + } + + public String toString() { + return "[Customer: " + customerName + ", loan amount: " + + loanAmount + "]"; + } +} diff --git a/branches/sca-java-0.90/samples/loanapplication/src/main/java/loanapplication/LoanApplicationClient.java b/branches/sca-java-0.90/samples/loanapplication/src/main/java/loanapplication/LoanApplicationClient.java new file mode 100644 index 0000000000..5183ece867 --- /dev/null +++ b/branches/sca-java-0.90/samples/loanapplication/src/main/java/loanapplication/LoanApplicationClient.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 loanapplication; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + + +public class LoanApplicationClient { + + public static void main(String[] args) throws Exception { + SCADomain domain = SCADomain.newInstance("loanapplication.composite"); + + // Locate the MyClient component and invoke it + LoanClient loanClient = domain.getService(LoanClient.class, "LoanClientComponent"); + loanClient.applyForLoan("John Doe", 1000.0f); + System.out.println(loanClient.displayLoan()); + System.out.println("Loan approved: " + loanClient.isApproved()); + + domain.close(); + } +} diff --git a/branches/sca-java-0.90/samples/loanapplication/src/main/java/loanapplication/LoanClient.java b/branches/sca-java-0.90/samples/loanapplication/src/main/java/loanapplication/LoanClient.java new file mode 100644 index 0000000000..7e4438bbff --- /dev/null +++ b/branches/sca-java-0.90/samples/loanapplication/src/main/java/loanapplication/LoanClient.java @@ -0,0 +1,29 @@ +/* + * 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 loanapplication; + +public interface LoanClient { + + void applyForLoan(String customerName, float amount); + boolean isApproved(); + boolean isCancelled(); + String displayLoan(); + void cancelLoan(); + void closeLoan(); +} diff --git a/branches/sca-java-0.90/samples/loanapplication/src/main/java/loanapplication/LoanClientImpl.java b/branches/sca-java-0.90/samples/loanapplication/src/main/java/loanapplication/LoanClientImpl.java new file mode 100644 index 0000000000..b06d9465a2 --- /dev/null +++ b/branches/sca-java-0.90/samples/loanapplication/src/main/java/loanapplication/LoanClientImpl.java @@ -0,0 +1,64 @@ +/* + * 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 loanapplication; + + +import org.osoa.sca.annotations.Reference; +import org.osoa.sca.annotations.Scope; + +@Scope("COMPOSITE") +public class LoanClientImpl implements LoanClient { + + private LoanService loanService; + + @Reference + public void setLoanService(LoanService loanService) { + this.loanService = loanService; + } + + public void applyForLoan(String customerName, float amount) { + loanService.apply(new LoanApplication(customerName, amount)); + } + + public boolean isApproved() { + if (loanService.getLoanStatus() == null) { + return false; + } + return loanService.getLoanStatus().equals("approved"); + } + + public boolean isCancelled() { + if (loanService.getLoanStatus() == null) { + return false; + } + return loanService.getLoanStatus().equals("cancelled"); + } + + public String displayLoan() { + return loanService.display(); + } + + public void cancelLoan() { + loanService.cancelApplication(); + } + + public void closeLoan() { + loanService.close(); + } +} diff --git a/branches/sca-java-0.90/samples/loanapplication/src/main/java/loanapplication/LoanService.java b/branches/sca-java-0.90/samples/loanapplication/src/main/java/loanapplication/LoanService.java new file mode 100644 index 0000000000..d09864ea55 --- /dev/null +++ b/branches/sca-java-0.90/samples/loanapplication/src/main/java/loanapplication/LoanService.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 loanapplication; + +import org.osoa.sca.annotations.EndsConversation; +import org.osoa.sca.annotations.OneWay; +import org.osoa.sca.annotations.Remotable; +import org.osoa.sca.annotations.Scope; + +@Scope("CONVERSATION") +@Remotable +public interface LoanService { + void apply(LoanApplication application); + void lockCurrentRate(int termInYears); + @OneWay + void cancelApplication(); + String getLoanStatus(); + String display(); + @EndsConversation + void close(); +} diff --git a/branches/sca-java-0.90/samples/loanapplication/src/main/java/loanapplication/LoanServiceImpl.java b/branches/sca-java-0.90/samples/loanapplication/src/main/java/loanapplication/LoanServiceImpl.java new file mode 100644 index 0000000000..76a53323bd --- /dev/null +++ b/branches/sca-java-0.90/samples/loanapplication/src/main/java/loanapplication/LoanServiceImpl.java @@ -0,0 +1,63 @@ +/* + * 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 loanapplication; + +import org.osoa.sca.annotations.AllowsPassByReference; +import org.osoa.sca.annotations.ConversationID; +import org.osoa.sca.annotations.Scope; + +@Scope("CONVERSATION") +@AllowsPassByReference +public class LoanServiceImpl implements LoanService { + + private LoanApplication application; + private String status; + private int termLocked = 0; + @ConversationID + protected String conversationID; + + public void apply(LoanApplication application) { + this.application = application; + status = "open"; + } + + public void lockCurrentRate(int termInYears) { + termLocked = termInYears; + status = "locked"; + } + + public void cancelApplication() { + status = "cancelled"; + } + + public String getLoanStatus() { + return status; + } + + public String display() { + return "Loan application: " + application + ", term: " + + termLocked + ", status: " + status + + ", conversationID: " + conversationID; + } + + public void close() { + this.application = null; + this.status = "closed"; + } +} diff --git a/branches/sca-java-0.90/samples/loanapplication/src/main/resources/loanapplication.composite b/branches/sca-java-0.90/samples/loanapplication/src/main/resources/loanapplication.composite new file mode 100644 index 0000000000..3aa8d030b7 --- /dev/null +++ b/branches/sca-java-0.90/samples/loanapplication/src/main/resources/loanapplication.composite @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + diff --git a/branches/sca-java-0.90/samples/loanapplication/src/test/java/loanapplication/LoanApplicationTestCase.java b/branches/sca-java-0.90/samples/loanapplication/src/test/java/loanapplication/LoanApplicationTestCase.java new file mode 100644 index 0000000000..f97dfc9875 --- /dev/null +++ b/branches/sca-java-0.90/samples/loanapplication/src/test/java/loanapplication/LoanApplicationTestCase.java @@ -0,0 +1,81 @@ +/* + * 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 loanapplication; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +public class LoanApplicationTestCase extends TestCase { + + private LoanClient loanClient; + private SCADomain domain; + + protected void setUp() throws Exception { + domain = SCADomain.newInstance("loanapplication.composite"); + + loanClient = domain.getService(LoanClient.class, "LoanClientComponent"); + } + + protected void tearDown() throws Exception { + domain.close(); + } + + public void test() throws Exception { + try { + loanClient.applyForLoan("John Doe", 1000.0f); + System.out.println("Applied: " + loanClient.displayLoan()); + System.out.println("Loan approved: " + loanClient.isApproved()); + loanClient.cancelLoan(); + System.out.println("Sleeping to let cancel complete ..."); + Thread.sleep(500); + if (!loanClient.isCancelled()) { + fail("Loan should be cancelled"); + } + System.out.println("Cancelled: " + loanClient.displayLoan()); + loanClient.closeLoan(); + + /* This is a mistake, after @EndsConversation, a new conversation is + * started automatically, so we should not get TargetNotFoundException. + * Keep this for the timeout case, where we should get the exception + try { + System.out.println("Trying to use the closed loan in the ended conversation ..."); + System.out.println("Closed: " + loanClient.displayLoan()); + fail("Target should not be found"); + } catch(TargetNotFoundException e) { + System.out.println("Target not found as expected"); + } + */ + + // Now check that a new conversation's loan is not cancelled + + if (loanClient.isCancelled()) { + fail("Loan should not be cancelled"); + } + } catch(Throwable e) { + e.printStackTrace(); + if (e instanceof Exception) { + throw (Exception)e; + } + if (e instanceof Error) { + throw (Error)e; + } + } + } +} -- cgit v1.2.3