1 package org.jbpm.bpel.tutorial.atm; 2 3 import java.util.Properties ; 4 5 import javax.naming.Context ; 6 import javax.naming.InitialContext ; 7 import javax.naming.NamingException ; 8 9 import junit.framework.TestCase; 10 11 import org.jbpm.bpel.tutorial.atm.types.OperationRequestType; 12 13 17 public class AtmTest extends TestCase { 18 19 private Atm atm; 20 21 public AtmTest(String name) { 22 super(name); 23 } 24 25 protected void setUp() throws Exception { 26 Context initialContext = getInitialContext(); 27 AtmService service = (AtmService) initialContext.lookup("java:comp/env/service/ATM"); 29 atm = service.getAtmPort(); 31 } 32 33 public void testAtmSimpleScenario() throws Exception { 34 int sessionId = atm.connect(); 36 assertTrue(sessionId > 0); 37 38 String status = atm.status(sessionId); 40 assertEquals("connected", status); 41 42 atm.logon(sessionId, "Pete"); 44 45 48 Thread.sleep(500); 49 status = atm.status(sessionId); 50 assertEquals("loggedon", status); 51 52 double balance = atm.getBalance("Pete"); 54 55 OperationRequestType operation = new OperationRequestType(); 57 operation.setCustomerName("Pete"); 58 operation.setAmount(300); 59 double oldBalance = balance; 60 balance = atm.deposit(operation); 61 assertEquals(oldBalance + 300, balance, 0); 63 64 operation.setAmount(100); 66 oldBalance = balance; 67 balance = atm.withdraw(operation); 68 assertEquals(oldBalance - 100, balance, 0); 70 71 atm.logoff("Pete"); 73 74 77 Thread.sleep(500); 78 status = atm.status(sessionId); 79 assertEquals("connected", status); 80 81 atm.disconnect(sessionId); 83 } 84 85 protected InitialContext getInitialContext() throws NamingException { 86 Properties env = new Properties (); 88 env.setProperty("j2ee.clientName", "atm-client"); 90 return new InitialContext (env); 92 } 93 } | Popular Tags |