@Test
  public void updateCreditCardFromTransparentRedirect() {
    Customer customer = gateway.customer().create(new CustomerRequest()).getTarget();
    CreditCardRequest request =
        new CreditCardRequest()
            .customerId(customer.getId())
            .number("5105105105105100")
            .expirationDate("05/12");
    CreditCard card = gateway.creditCard().create(request).getTarget();

    CreditCardRequest updateRequest = new CreditCardRequest();
    CreditCardRequest trParams =
        new CreditCardRequest()
            .paymentMethodToken(card.getToken())
            .number("4111111111111111")
            .expirationDate("10/10");
    String queryString =
        TestHelper.simulateFormPostForTR(
            gateway, trParams, updateRequest, gateway.transparentRedirect().url());

    Result<CreditCard> result = gateway.transparentRedirect().confirmCreditCard(queryString);

    assertTrue(result.isSuccess());
    CreditCard updatedCreditCard = gateway.creditCard().find(card.getToken());
    assertEquals("411111", updatedCreditCard.getBin());
    assertEquals("1111", updatedCreditCard.getLast4());
    assertEquals("10/2010", updatedCreditCard.getExpirationDate());
  }
예제 #2
0
  @Test
  public void onCustomer() {
    Result<Customer> customerResult =
        gateway.customer().create(new CustomerRequest().paymentMethodNonce(Nonce.Coinbase));
    assertTrue(customerResult.isSuccess());
    Customer customer = customerResult.getTarget();

    List<CoinbaseAccount> accounts =
        gateway.customer().find(customer.getId()).getCoinbaseAccounts();
    assertEquals(1, accounts.size());

    CoinbaseAccount account = accounts.get(0);
    assertNotNull(account);
    assertNotNull(account.getToken());
    assertNotNull(account.getUserId());
    assertThat(account.getUserId(), not(equalTo("")));
    assertNotNull(account.getUserName());
    assertThat(account.getUserName(), not(equalTo("")));
    assertNotNull(account.getUserEmail());
    assertThat(account.getUserEmail(), not(equalTo("")));

    String token = account.getToken();

    gateway.paymentMethod().delete(token);

    exception.expect(NotFoundException.class);
    gateway.paymentMethod().find(token);
  }
 private Customer getNewCustomerWithUniqueName() {
   Customer c1 = getCustomerComponent().createNew();
   c1.setName("A" + System.currentTimeMillis());
   c1.setPhoneNumber("808-555-1212");
   getCustomerComponent().persist(c1);
   return c1;
 }
예제 #4
0
  @Theory
  public void test(Fixture fixture1, Fixture fixture2) {
    // 【テスト条件のセットアップ】
    if (fixture1 != null) {
      sut.addRental(fixture1.rental);
    }
    if (fixture2 != null) {
      sut.addRental(fixture2.rental);
    }

    // 【テスト実施】
    String result = sut.statement();

    // 【テスト結果の検証】
    // 期待値作成
    String expected = "Rental Record for " + CUSTOMER_NAME + "\n";
    expected += buildAmountPartString(fixture1);
    expected += buildAmountPartString(fixture2);
    double totalAmount = calcTotalAmount(fixture1, fixture2);
    expected += "Amount owed is " + String.valueOf(totalAmount) + "\n";
    int frequentREnterPoints = calcPoint(fixture1, fixture2);
    expected += "You earned " + String.valueOf(frequentREnterPoints) + " frequent renter points";

    assertThat(result, is(expected));
  }
예제 #5
0
  @Test
  public void getAllCustomerCars() {
    assertFalse(customer1.getActive());
    assertFalse(customer2.getActive());
    assertFalse(customer3.getActive());

    manager.rentCarToCustomer(
        car2, customer1, Date.valueOf("2012-03-21"), Date.valueOf("2012-03-31"));
    manager.rentCarToCustomer(
        car3, customer1, Date.valueOf("2012-03-25"), Date.valueOf("2012-04-02"));
    manager.rentCarToCustomer(
        car1, customer2, Date.valueOf("2012-03-15"), Date.valueOf("2012-03-27"));

    List<Car> carsRetnedtoCustomer1 = Arrays.asList(car2, car3);
    List<Car> carsRetnedtoCustomer2 = Arrays.asList(car1);

    assertCarDeepEquals(carsRetnedtoCustomer1, manager.getAllCustomerCars(customer1));
    assertCarDeepEquals(carsRetnedtoCustomer2, manager.getAllCustomerCars(customer2));
    assertFalse(customer3.getActive());

    try {
      manager.getAllCustomerCars(null);
      fail();
    } catch (IllegalArgumentException e) {
    }

    try {
      manager.getAllCustomerCars(customerWithoutID);
      fail();
    } catch (IllegalArgumentException e) {
    }
  }
  /**
   * Test case to show the usage of the geo-spatial APIs to lookup people within a given distance of
   * a reference point.
   */
  @Test
  public void exposesGeoSpatialFunctionality() {

    GeospatialIndex indexDefinition = new GeospatialIndex("address.location");
    indexDefinition.getIndexOptions().put("min", -180);
    indexDefinition.getIndexOptions().put("max", 180);

    operations.indexOps(Customer.class).ensureIndex(indexDefinition);

    Customer ollie = new Customer("Oliver", "Gierke");
    ollie.setAddress(new Address(new Point(52.52548, 13.41477)));
    ollie = repository.save(ollie);

    Point referenceLocation = new Point(52.51790, 13.41239);
    Distance oneKilometer = new Distance(1, Metrics.KILOMETERS);

    GeoResults<Customer> result =
        repository.findByAddressLocationNear(referenceLocation, oneKilometer);

    assertThat(result.getContent(), hasSize(1));

    Distance distanceToFirstStore = result.getContent().get(0).getDistance();
    assertThat(distanceToFirstStore.getMetric(), is(Metrics.KILOMETERS));
    assertThat(distanceToFirstStore.getValue(), closeTo(0.862, 0.001));
  }
예제 #7
0
  private void prepareTestData() {

    car1 = newCar("Black", "0B6 6835", "Škoda", 200.0);
    car2 = newCar("Red", "7B4 0044", "BMW", 500.0);
    car3 = newCar("White", "8B5 0983", "Volkwagen", 300.0);

    customer1 = newCustomer("Vitalii", "Chepeliuk", "Komarov", "5-20-86", "AK 373979");
    customer2 = newCustomer("Juraj", "Kolchak", "Komarov", "5-34-86", "AK 372548");
    customer3 = newCustomer("Martin", "Jirman", "Lazhot", "5-25-87", "AK 251245");

    carManager.addCar(car1);
    carManager.addCar(car2);
    carManager.addCar(car3);

    customerManager.addCustomer(customer1);
    customerManager.addCustomer(customer2);
    customerManager.addCustomer(customer3);

    carWithoutID = newCar("Green", "8B3 9763", "Audi", 400.0);
    carNotInDB = newCar("Blue", "3B6 8463", "Peugeot", 0.0);
    carNotInDB.setID(car3.getID() + 100);

    customerWithoutID = newCustomer("Martin", "Pulec", "Brno", "5-11-24", "AK 897589");
    customerNotInDB = newCustomer("Lukas", "Rucka", "Brno", "5-21-06", "AK 256354");
    customerNotInDB.setID(customer3.getID() + 100);
    customerNotInDB.setActive(true);
  }
예제 #8
0
  @Test
  public void testDoAdapterWithRewardCustomer() throws Exception {
    Customer customer = getCustomerByFile(super.FILE_CUSTOMER_REWARDS);

    assertNotNull(customer);
    assertNotNull(customer.getType());
    assertEquals(CustomerTypeEnum.REWARDS, customer.getType());
  }
 @Test
 public void testDeleteCustomer() {
   Customer c1 = getNewCustomerWithUniqueName();
   Customer c1FromDb = getCustomerComponent().getById(c1.getId());
   getCustomerComponent().delete(c1FromDb);
   Customer c1FromDbAgain = getCustomerComponent().getById(c1.getId());
   assertNull(c1FromDbAgain);
 }
예제 #10
0
 public void orderTest3() {
   Customer customer = customerDAO.getCustomerById(2);
   List list = orderService.getOrdersByUsername(customer.getUsername());
   System.out.println("List size :" + list.size());
   for (Object obj : list) {
     System.out.println(obj);
   }
 }
예제 #11
0
  @Test
  public void testAutowireCandidateTrue() {

    Customer customer = applicationContext.getBean("customer", Customer.class);
    assertNotNull(customer);
    assertNotNull(customer.getOrder());
    assertNull(customer.getOrder().getItem());
    assertNotNull(customer.getCart());
  }
예제 #12
0
 @Test
 public void testWithOneChildrensMovie_ShouldGenerateSimpleStatement() {
   Movie irongiant = new Movie("Iron Giant", Movie.CHILDRENS);
   Rental sunday = new Rental(irongiant, 2);
   customer.addRental(sunday);
   assertEquals(
       "Rental Record for Ryan\n"
           + "\tIron Giant\t1.5\n"
           + "Amount owed is 1.5\n"
           + "You earned 1 frequent renters points",
       customer.statement());
 }
예제 #13
0
 @Test
 public void testWithOneNewReleaseMovie_ShouldGenerateSimpleStatement() {
   Movie ironman = new Movie("Iron Man 2", Movie.NEW_RELEASE);
   Rental sunday = new Rental(ironman, 2);
   customer.addRental(sunday);
   assertEquals(
       "Rental Record for Ryan\n"
           + "\tIron Man 2\t6.0\n"
           + "Amount owed is 6.0\n"
           + "You earned 2 frequent renters points",
       customer.statement());
 }
예제 #14
0
 @Test
 public void testWithOneRegularMovie_ShouldGenerateSimpleStatement() {
   Movie ironman = new Movie("Iron Man", Movie.REGULAR);
   Rental sunday = new Rental(ironman, 2);
   customer.addRental(sunday);
   assertEquals(
       "Rental Record for Ryan\n"
           + "\tIron Man\t2.0\n"
           + "Amount owed is 2.0\n"
           + "You earned 1 frequent renters points",
       customer.statement());
 }
예제 #15
0
  /** This method tests the requirement that the address can not null */
  @Test(expected = IllegalArgumentException.class)
  public void addressShouldNotBeNull() {
    // Customer customer = new Customer();
    instance.setAddress(null);

    // assertNotNull(instance.getAddress());
  }
예제 #16
0
 @Test
 public void testCustomerList() throws HTTPError {
   ArrayList<Customer> customers = Customer.query().all();
   // Customer.Collection customers = mp.customers;
   // assertTrue(customers.getClass().equals(Customer.Collection.class));
   assertTrue(customers.size() > 0);
 }
예제 #17
0
 @Test
 public void testWithNoMovie_ShouldGenerateEmptyStatement() {
   assertEquals(
       "Rental Record for Ryan\n"
           + "Amount owed is 0.0\n"
           + "You earned 0 frequent renters points",
       customer.statement());
 }
예제 #18
0
  @Test
  public void testDoAdapterWithAllMonths() throws Exception {
    Customer customer = getCustomerByFile(super.FILE_INPUT_MONTHS);

    assertEquals(MonthEnum.values().length, customer.getReservations().size());

    // The order of MonthEnum must bem the same that of the file.
    Iterator<DateReservation> iterator = customer.getReservations().iterator();
    for (MonthEnum month : MonthEnum.values()) {
      if (iterator.hasNext()) {
        MonthEnum monthEnum = iterator.next().getMoth();
        assertEquals(month, monthEnum);
      } else {
        fail();
      }
    }
  }
예제 #19
0
 @Test
 public void testWithOneOfEachTypeOfMovieFor3Days_ShouldGenerateComplexStatement() {
   Movie ironman = new Movie("Iron Man", Movie.REGULAR);
   customer.addRental(new Rental(ironman, 3));
   Movie irongiant = new Movie("Iron Giant", Movie.CHILDRENS);
   customer.addRental(new Rental(irongiant, 3));
   Movie ironman2 = new Movie("Iron Man 2", Movie.NEW_RELEASE);
   customer.addRental(new Rental(ironman2, 3));
   assertEquals(
       "Rental Record for Ryan\n"
           + "\tIron Man\t3.5\n"
           + "\tIron Giant\t1.5\n"
           + "\tIron Man 2\t9.0\n"
           + "Amount owed is 14.0\n"
           + "You earned 4 frequent renters points",
       customer.statement());
 }
예제 #20
0
  @Test
  public void testCustomerInsertAndGet() {
    Customer c1 = getNewCustomerWithUniqueName();
    Customer c2 = getNewCustomerWithUniqueName();

    assertEquals(c1.getId() + 1, c2.getId());

    Customer c1FromDb = getCustomerComponent().getById(c1.getId());
    assertEquals(c1.getName(), c1FromDb.getName());
  }
예제 #21
0
 /** Tests the functionality of the get methods for the customer class */
 @Test
 public void CustomerGetMethods() {
   assertEquals(1, testCustomer.getCustomerID());
   assertEquals("01782566491", testCustomer.getCustomerPhone());
   assertEquals(10000f, testCustomer.getAvailableCredit(), 0.001f);
   assertEquals("George Freshwater", testCustomer.getCustomerName());
   assertEquals("*****@*****.**", testCustomer.getCustomerEmail());
   assertEquals("fresh", testCustomer.getCustomerUsername());
   assertEquals("water123", testCustomer.getCustomerPassword());
   assertEquals("EMAIL", testCustomer.getCustomerContactMethod());
 }
예제 #22
0
 /** City name should not be empty */
 @Test
 public void validCityNameShouldPass() {
   String[] validCity = {"a", "xxx", "xxxxxx"};
   try {
     for (String vc : validCity) {
       instance.setCity(vc);
     }
   } catch (Exception e) {
     fail("Legal value was rejected, not good!");
   }
 }
예제 #23
0
 @Test
 public void testCustomerUpdateAndGet() {
   Customer c1 = getNewCustomerWithUniqueName();
   Customer c1FromDb = getCustomerComponent().getById(c1.getId());
   String NEW_PHONE = "415-555-1212";
   c1FromDb.setPhoneNumber(NEW_PHONE);
   getCustomerComponent().persist(c1FromDb);
   Customer c1FromDbAgain = getCustomerComponent().getById(c1.getId());
   assertEquals(NEW_PHONE, c1FromDbAgain.getPhoneNumber());
 }
예제 #24
0
  @Test
  public void testMerchantStatusNoMatch() throws HTTPError {
    Map<String, Object> payload = new HashMap<String, Object>();

    payload.put("name", "John Lee Hooker");
    payload.put("phone", "(904) 555-1796");

    Map<String, String> address = new HashMap<String, String>();
    address.put("city", "San Francisco");
    address.put("state", "CA");
    address.put("postal_code", "94103");
    address.put("line1", "965 Mission St");
    address.put("country_code", "US");
    payload.put("address", address);

    payload.put("ssn_last4", "3209");

    Customer merchant = new Customer(payload);
    merchant.save();
    assertEquals("no-match", merchant.merchant_status);
  }
예제 #25
0
  @Test
  public void testDoAdapterWithAllWeekDays() throws Exception {
    Customer customer = getCustomerByFile(super.FILE_INPUT_WEEK_DAYS);

    // The order of WeekDayEnum must bem the same that of the file.
    Iterator<DateReservation> iterator = customer.getReservations().iterator();

    for (WeekDayEnum weekDay : WeekDayEnum.values()) {
      // ignore days not present on file
      if (weekDay.equals(WeekDayEnum.WEEKDAY) || weekDay.equals(WeekDayEnum.WEEKEND)) {
        continue;
      }

      if (iterator.hasNext()) {
        WeekDayEnum weekDay1 = iterator.next().getWeekDay();
        assertEquals(weekDay, weekDay1);
      } else {
        fail();
      }
    }
  }
예제 #26
0
  public void paymentTest() {
    Payment payment = new Payment();
    // 取出订单
    Order order = orderDAO.getOrderById(8);
    // 取出订单顾客
    Customer customer = order.getCustomer();
    // 取出操作员
    Worker worker = workerDAO.getWorkerById(7);
    // 取出银行卡
    Bankcard bankcard = customer.getBankcardList().get(0);

    payment.setPayCustomer(customer);
    System.out.println("OrderId:" + order.getOrderId());
    payment.setPayOrder(order);
    System.out.println(bankcard);
    payment.setPayCard(bankcard);
    payment.setPayPrice(order.getOrderPrice());
    payment.setPayType(1);
    payment.setWorker(worker);

    paymentDAO.createPayment(payment);
  }
예제 #27
0
  public static String generateEuropeBankAccountNonce(BraintreeGateway gateway, Customer customer) {
    SEPAClientTokenRequest request = new SEPAClientTokenRequest();
    request.customerId(customer.getId());
    request.mandateType(EuropeBankAccount.MandateType.BUSINESS);
    request.mandateAcceptanceLocation("Rostock, Germany");

    String encodedClientToken = gateway.clientToken().generate(request);
    String clientToken = TestHelper.decodeClientToken(encodedClientToken);

    String authorizationFingerprint = extractParamFromJson("authorizationFingerprint", clientToken);
    Configuration configuration = gateway.getConfiguration();
    String url =
        configuration.getBaseURL()
            + configuration.getMerchantPath()
            + "/client_api/v1/sepa_mandates";
    QueryString payload = new QueryString();
    payload
        .append("authorization_fingerprint", authorizationFingerprint)
        .append("sepa_mandate[locale]", "de-DE")
        .append("sepa_mandate[bic]", "DEUTDEFF")
        .append("sepa_mandate[iban]", "DE89370400440532013000")
        .append("sepa_mandate[accountHolderName]", "Bob Holder")
        .append("sepa_mandate[billingAddress][streetAddress]", "123 Currywurst Way")
        .append("sepa_mandate[billingAddress][extendedAddress]", "Lager Suite")
        .append("sepa_mandate[billingAddress][firstName]", "Wilhelm")
        .append("sepa_mandate[billingAddress][lastName]", "Dix")
        .append("sepa_mandate[billingAddress][locality]", "Frankfurt")
        .append("sepa_mandate[billingAddress][postalCode]", "60001")
        .append("sepa_mandate[billingAddress][countryCodeAlpha2]", "DE")
        .append("sepa_mandate[billingAddress][region]", "Hesse");

    String responseBody;
    String nonce = "";
    try {
      responseBody = HttpHelper.post(url, payload.toString());
      nonce = extractParamFromJson("nonce", responseBody);
    } catch (Exception e) {
      throw new RuntimeException(e);
    }

    return nonce;
  }
  @Test
  public void updateCustomerFromTransparentRedirect() {
    CustomerRequest request = new CustomerRequest().firstName("John").lastName("Doe");
    Customer customer = gateway.customer().create(request).getTarget();

    CustomerRequest updateRequest = new CustomerRequest().firstName("Jane");
    CustomerRequest trParams = new CustomerRequest().customerId(customer.getId()).lastName("Dough");
    String queryString =
        TestHelper.simulateFormPostForTR(
            gateway, trParams, updateRequest, gateway.transparentRedirect().url());

    Result<Customer> result = gateway.transparentRedirect().confirmCustomer(queryString);

    assertTrue(result.isSuccess());
    Customer updatedCustomer = gateway.customer().find(customer.getId());
    assertEquals("Jane", updatedCustomer.getFirstName());
    assertEquals("Dough", updatedCustomer.getLastName());
  }
예제 #29
0
  @Test
  public void getCarFromCustomer() {
    assertTrue(car1.getAvailable());
    assertTrue(car2.getAvailable());
    assertTrue(car3.getAvailable());

    manager.rentCarToCustomer(
        car1, customer1, Date.valueOf("2012-03-21"), Date.valueOf("2012-03-31"));
    manager.rentCarToCustomer(
        car2, customer1, Date.valueOf("2012-03-25"), Date.valueOf("2012-04-02"));
    manager.rentCarToCustomer(
        car3, customer2, Date.valueOf("2012-03-15"), Date.valueOf("2012-03-27"));

    assertEquals(customer1, manager.findCustomerWithCar(car1));
    assertCustomerDeepEquals(customer1, manager.findCustomerWithCar(car1));
    assertEquals(customer1, manager.findCustomerWithCar(car2));
    assertCustomerDeepEquals(customer1, manager.findCustomerWithCar(car2));
    assertEquals(customer2, manager.findCustomerWithCar(car3));
    assertCustomerDeepEquals(customer2, manager.findCustomerWithCar(car3));

    manager.getCarFromCustomer(car3, customer2);

    List<Car> carsRetnedtoCustomer1 = Arrays.asList(car1, car2);

    assertCarDeepEquals(carsRetnedtoCustomer1, manager.getAllCustomerCars(customer1));
    assertFalse(customer2.getActive());
    assertFalse(customer3.getActive());

    assertEquals(customer1, manager.findCustomerWithCar(car1));
    assertCustomerDeepEquals(customer1, manager.findCustomerWithCar(car1));
    assertEquals(customer1, manager.findCustomerWithCar(car2));
    assertCustomerDeepEquals(customer1, manager.findCustomerWithCar(car2));
    assertTrue(car3.getAvailable());

    try {
      manager.getCarFromCustomer(car3, customer1);
      fail();
    } catch (TransactionException e) {
    }

    try {
      manager.getCarFromCustomer(car3, customer2);
      fail();
    } catch (IllegalArgumentException e) {
    }

    try {
      manager.getCarFromCustomer(null, customer1);
      fail();
    } catch (IllegalArgumentException e) {
    }

    try {
      manager.getCarFromCustomer(carWithoutID, customer1);
      fail();
    } catch (IllegalArgumentException e) {
    }

    try {
      manager.getCarFromCustomer(carNotInDB, customer1);
      fail();
    } catch (TransactionException e) {
    }

    try {
      manager.getCarFromCustomer(car1, null);
      fail();
    } catch (IllegalArgumentException e) {
    }

    try {
      manager.getCarFromCustomer(car1, customerWithoutID);
      fail();
    } catch (IllegalArgumentException e) {
    }

    try {
      manager.getCarFromCustomer(car1, customerNotInDB);
      fail();
    } catch (TransactionException e) {
    }

    // Check that previous tests didn't affect data in database
    assertCarDeepEquals(carsRetnedtoCustomer1, manager.getAllCustomerCars(customer1));
    assertFalse(customer2.getActive());
    assertFalse(customer3.getActive());

    assertEquals(customer1, manager.findCustomerWithCar(car1));
    assertCustomerDeepEquals(customer1, manager.findCustomerWithCar(car1));
    assertEquals(customer1, manager.findCustomerWithCar(car2));
    assertCustomerDeepEquals(customer1, manager.findCustomerWithCar(car2));
    assertTrue(car3.getAvailable());
  }
예제 #30
0
 @Test
 public void validZipCodeShouldPass() {
   instance.setZip("12345");
 }