コード例 #1
0
  @Test
  public void testPopulate() {
    // create search result values
    final SearchResultValueData searchResultValueData = new SearchResultValueData();
    final Map<String, Object> searchValueMap = new HashMap<String, Object>();
    searchValueMap.put(BillingPlanModel.BILLINGFREQUENCY, "monthly");
    searchValueMap.put(ProductModel.SOLDINDIVIDUALLY, Boolean.TRUE);
    searchValueMap.put(SubscriptionTermModel.TERMOFSERVICERENEWAL, "yearly");
    searchValueMap.put("termLimit", "18 months");
    searchValueMap.put("lowestBundlePriceValue", Double.valueOf(1.99));
    searchResultValueData.setValues(searchValueMap);

    final CurrencyModel currency = new CurrencyModel();
    currency.setIsocode("USD");
    final PriceData priceData = new PriceData();
    priceData.setValue(BigDecimal.valueOf(1.99));
    priceData.setCurrencyIso(currency.getIsocode());
    given(commonI18NService.getCurrentCurrency()).willReturn(currency);
    given(
            priceDataFactory.create(
                PriceDataType.BUY, BigDecimal.valueOf(1.99), currency.getIsocode()))
        .willReturn(priceData);

    final ProductData productData = new ProductData();
    searchProductTelcoPopulator.populate(searchResultValueData, productData);

    assertNotNull("", productData.getSubscriptionTerm());
    assertNotNull("", productData.getSubscriptionTerm().getBillingPlan());
    assertNotNull("", productData.getSubscriptionTerm().getBillingPlan().getBillingTime());
    assertEquals(
        "",
        searchProductTelcoPopulator.getValue(searchResultValueData, "billingTime"),
        productData.getSubscriptionTerm().getBillingPlan().getBillingTime().getName());
    assertEquals(
        "",
        searchProductTelcoPopulator.getValue(searchResultValueData, ProductModel.SOLDINDIVIDUALLY),
        Boolean.valueOf(productData.isSoldIndividually()));
    assertNotNull("", productData.getSubscriptionTerm().getTermOfServiceFrequency());
    assertEquals(
        "",
        searchProductTelcoPopulator.getValue(searchResultValueData, "termLimit"),
        productData.getSubscriptionTerm().getTermOfServiceFrequency().getName());
    assertNotNull("", productData.getLowestBundlePrice());
    assertEquals(
        "",
        BigDecimal.valueOf(
            ((Double)
                    searchProductTelcoPopulator.getValue(
                        searchResultValueData, "lowestBundlePriceValue"))
                .doubleValue()),
        productData.getLowestBundlePrice().getValue());
  }