tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sl...@apache.org
Subject svn commit: r786960 - in /tuscany/sandbox/travelsample/contributions/payment-java-contribution/src: main/java/payment/PaymentImpl.java test/java/payment/PaymentTestCase.java
Date Sun, 21 Jun 2009 09:24:26 GMT
Author: slaws
Date: Sun Jun 21 09:24:23 2009
New Revision: 786960

URL: http://svn.apache.org/viewvc?rev=786960&view=rev
Log:
Tidy code in Payment component implementation

Modified:
    tuscany/sandbox/travelsample/contributions/payment-java-contribution/src/main/java/payment/PaymentImpl.java
    tuscany/sandbox/travelsample/contributions/payment-java-contribution/src/test/java/payment/PaymentTestCase.java

Modified: tuscany/sandbox/travelsample/contributions/payment-java-contribution/src/main/java/payment/PaymentImpl.java
URL: http://svn.apache.org/viewvc/tuscany/sandbox/travelsample/contributions/payment-java-contribution/src/main/java/payment/PaymentImpl.java?rev=786960&r1=786959&r2=786960&view=diff
==============================================================================
--- tuscany/sandbox/travelsample/contributions/payment-java-contribution/src/main/java/payment/PaymentImpl.java
(original)
+++ tuscany/sandbox/travelsample/contributions/payment-java-contribution/src/main/java/payment/PaymentImpl.java
Sun Jun 21 09:24:23 2009
@@ -57,34 +57,21 @@
     protected float transactionFee = 0.01f;
 
     public String makePaymentMember(String customerId, float amount) {
-        Customer customer = null;
-
         try {
-            customer = customerRegistry.getCustomer(customerId);
+            Customer customer = customerRegistry.getCustomer(customerId);
+            String status = creditCardPayment.authorize(customer.getCreditCard(), 
+                                                        amount + transactionFee);
+            emailGateway.sendEmail("order@tuscanyscatours.com", 
+                                   customer.getEmail(), 
+                                   "Status for your payment", 
+                                   customer + " >>> Status = " + status);
+            return status;
         } catch (CustomerNotFoundException ex) {
             return "Payment failed due to " + ex.getMessage();
+        } catch (AuthorizeFault_Exception e) {
+            return e.getFaultInfo().getErrorCode();
         } catch (Throwable t) {
             return "Payment failed due to system error " + t.getMessage();
-        }
-
-        CreditCardDetailsType ccDetails = customer.getCreditCard();
-        
-        float total = amount + transactionFee;
-
-        String status;
-        try {
-            status = creditCardPayment.authorize(ccDetails, total);
-        } catch (AuthorizeFault_Exception e) {
-            status = e.getFaultInfo().getErrorCode();
-        }
-
-        StringBuffer body = new StringBuffer();
-        body.append(customer);
-        body.append("\n").append("Status: ").append(status).append("\n");
-        emailGateway.sendEmail("order@tuscanyscatours.com", customer.getEmail(), "Status
for your payment", body
-            .toString());
-
-        return status;
+        } 
     }
-
 }

Modified: tuscany/sandbox/travelsample/contributions/payment-java-contribution/src/test/java/payment/PaymentTestCase.java
URL: http://svn.apache.org/viewvc/tuscany/sandbox/travelsample/contributions/payment-java-contribution/src/test/java/payment/PaymentTestCase.java?rev=786960&r1=786959&r2=786960&view=diff
==============================================================================
--- tuscany/sandbox/travelsample/contributions/payment-java-contribution/src/test/java/payment/PaymentTestCase.java
(original)
+++ tuscany/sandbox/travelsample/contributions/payment-java-contribution/src/test/java/payment/PaymentTestCase.java
Sun Jun 21 09:24:23 2009
@@ -25,17 +25,12 @@
 import org.apache.tuscany.sca.node.SCANodeFactory;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
+import org.junit.Ignore;
 import org.junit.Test;
 
-/**
- * 
- */
 public class PaymentTestCase {
     private static SCANode node;
 
-    /**
-     * @throws java.lang.Exception
-     */
     @BeforeClass
     public static void setUpBeforeClass() throws Exception {
     	try {
@@ -53,26 +48,22 @@
     public void testPayment() {
         SCAClient client = (SCAClient) node;
         Payment payment = client.getService(Payment.class, "PaymentComponent");
-        System.out.println(payment.makePaymentMember("c-0", 100.00f));
-        System.out.println(payment.makePaymentMember("c-1", 100.00f));
+        
+        System.out.println("\n\nSuccessful Payment - Status = \n\n" + payment.makePaymentMember("c-0",
100.00f));
+        System.out.println("\n\nFailed Payment - Status = \n\n" + payment.makePaymentMember("c-1",
100.00f));
     }
     
     @Test
-    //@Ignore
+    @Ignore
     public void testWaitForInput() {
-/*
         System.out.println("Press a key to end");
         try {
             System.in.read();
         } catch (Exception ex) {
         }
         System.out.println("Shutting down");
-*/
     }    
 
-    /**
-     * @throws java.lang.Exception
-     */
     @AfterClass
     public static void tearDownAfterClass() throws Exception {
         if (node != null) {



Mime
View raw message