/** * Create an instance of {@link NoSuchCustomer } * */ public NoSuchCustomer createNoSuchCustomer() { return new NoSuchCustomer(); }
public Customer getCustomerByName(String name) throws NoSuchCustomerException { Customer customer = customers.get(name); if (customer == null) { NoSuchCustomer noSuchCustomer = new NoSuchCustomer(); noSuchCustomer.setCustomerName(name); throw new NoSuchCustomerException("Did not find any matching customer for name=" + name, noSuchCustomer); } return customer; } }
public void testCustomerService() throws NoSuchCustomerException { List<Customer> customers = null; // First we test the positive case where customers are found and we retreive // a list of customers System.out.println("Sending request for customers named Smith"); customers = customerService.getCustomersByName("Smith"); System.out.println("Response received"); Assert.assertEquals(2, customers.size()); Assert.assertEquals("Smith", customers.get(0).getName()); try { Thread.sleep(1000); } catch (InterruptedException e1) { } // Then we test for an unknown Customer name and expect the NoSuchCustomerException try { customers = customerService.getCustomersByName("None"); Assert.fail("We should get a NoSuchCustomerException here"); } catch (NoSuchCustomerException e) { System.out.println(e.getMessage()); Assert.assertNotNull("FaultInfo must not be null", e.getFaultInfo()); Assert.assertEquals("None", e.getFaultInfo().getCustomerName()); System.out.println("NoSuchCustomer exception was received as expected"); } System.out.println("All calls were successful"); }
public List<Customer> getCustomersByName(String name) throws NoSuchCustomerException { if ("None".equals(name)) { NoSuchCustomer noSuchCustomer = new NoSuchCustomer(); noSuchCustomer.setCustomerName(name); throw new NoSuchCustomerException("Did not find any matching customer for name=" + name, noSuchCustomer); } List<Customer> customers = new ArrayList<Customer>(); for (int c = 0; c < 2; c++) { Customer cust = new Customer(); cust.setName(name); cust.getAddress().add("Pine Street 200"); Date bDate = new GregorianCalendar(2009, 01, 01).getTime(); cust.setBirthDate(bDate); cust.setNumOrders(1); cust.setRevenue(1000); cust.setTest(new BigDecimal(1.5)); cust.setType(CustomerType.BUSINESS); customers.add(cust); } return customers; }
/** * Create an instance of {@link NoSuchCustomer } * */ public NoSuchCustomer createNoSuchCustomer() { return new NoSuchCustomer(); }
/** * Create an instance of {@link NoSuchCustomer } * */ public NoSuchCustomer createNoSuchCustomer() { return new NoSuchCustomer(); }
/** * Create an instance of {@link NoSuchCustomer } * */ public NoSuchCustomer createNoSuchCustomer() { return new NoSuchCustomer(); }