コード例 #1
0
  @Test
  public void testPopulateAll() {
    final CustomerData customerData = mock(CustomerData.class);
    final CustomerModel customerModel = new CustomerModel();

    final CurrencyData currencyData = mock(CurrencyData.class);
    final LanguageData languageData = mock(LanguageData.class);
    final CurrencyModel currencyModel = mock(CurrencyModel.class);
    final LanguageModel languageModel = mock(LanguageModel.class);

    given(customerData.getFirstName()).willReturn("firstName");
    given(customerData.getLastName()).willReturn("lastName");
    given(customerData.getTitleCode()).willReturn(null);
    given(customerNameStrategy.getName("firstName", "lastName")).willReturn("firstName lastName");

    given(customerData.getCurrency()).willReturn(currencyData);
    given(currencyData.getIsocode()).willReturn("USD");
    given(currencyModel.getIsocode()).willReturn("USD");
    given(commonI18NService.getCurrency("USD")).willReturn(currencyModel);

    given(customerData.getLanguage()).willReturn(languageData);
    given(languageData.getIsocode()).willReturn("en");
    given(languageModel.getIsocode()).willReturn("en");
    given(commonI18NService.getLanguage("en")).willReturn(languageModel);

    customerReversePopulator.populate(customerData, customerModel);
    Assert.assertEquals("firstName lastName", customerModel.getName());
    Assert.assertNull(customerModel.getTitle());
    Assert.assertEquals("USD", customerModel.getSessionCurrency().getIsocode());
    Assert.assertEquals("en", customerModel.getSessionLanguage().getIsocode());
  }
コード例 #2
0
 @Test
 public void searchRestrictionTest() {
   final UserGroupModel group = new UserGroupModel();
   group.setUid("customergroup");
   modelService.save(group);
   // create test user
   final UserModel user = new UserModel();
   user.setUid(TEST_USER);
   // assign user to customergroup
   user.setGroups(Collections.singleton((PrincipalGroupModel) group));
   modelService.save(user);
   // create test catalog
   final CatalogModel catalog = new CatalogModel();
   catalog.setId(TEST_CATALOG);
   modelService.save(catalog);
   // create test catalog version
   final CatalogVersionModel catalogVersion = new CatalogVersionModel();
   catalogVersion.setCatalog(catalog);
   catalogVersion.setVersion(TEST_VERSION);
   modelService.save(catalogVersion);
   // create test product
   final ProductModel product = new ProductModel();
   product.setCode(TEST_PRODUCT);
   product.setCatalogVersion(catalogVersion);
   modelService.save(product);
   // set current user
   userService.setCurrentUser(user);
   // create search restriction
   commonI18NService.setCurrentLanguage(commonI18NService.getLanguage(LANG_EN));
   final Map<String, String[]> params = new HashMap<String, String[]>();
   params.put("customerreview.searchrestrictions.create", new String[] {"true"});
   final SystemSetupContext ctx =
       new SystemSetupContext(params, Type.ESSENTIAL, Process.ALL, "customerreview");
   customerReviewSystemSetup.createSearchRestrictions(ctx);
   // enable search restrictions
   searchRestrictionService.enableSearchRestrictions();
   // make sure that number of customer reviews is 0
   assertEquals(
       INVALID_NUMBER_OF_CUSTOMER_REVIEWS,
       Integer.valueOf(0),
       customerReviewService.getNumberOfReviews(product));
   // create restricted customer review
   createCustomerReview(null, user, product, CustomerReviewApprovalType.PENDING);
   // create valid customer review
   createCustomerReview("headline", user, product, CustomerReviewApprovalType.APPROVED);
   // make sure that number of customer reviews is 1
   assertEquals(
       INVALID_NUMBER_OF_CUSTOMER_REVIEWS,
       Integer.valueOf(1),
       customerReviewService.getNumberOfReviews(product));
   // disable search restrictions
   searchRestrictionService.disableSearchRestrictions();
   // make sure that number of customer reviews is 2
   assertEquals(
       INVALID_NUMBER_OF_CUSTOMER_REVIEWS,
       Integer.valueOf(2),
       customerReviewService.getNumberOfReviews(product));
 }
コード例 #3
0
  private void prepareData() {
    catVersion = catalogVersionService.getCatalogVersion("hwcatalog", "Online");
    catalogVersionService.addSessionCatalogVersion(catVersion);

    user = userService.getUserForUID("ariel");
    userService.setCurrentUser(user);
    cart = cartService.getSessionCart();
    commonI18NService.setCurrentCurrency(commonI18NService.getCurrency("EUR"));
    product1 = productService.getProductForCode(catVersion, "HW2110-0012");
  }
コード例 #4
0
  @Before
  public void before() throws Exception {
    de.hybris.platform.servicelayer.ServicelayerTest.createCoreData();
    de.hybris.platform.servicelayer.ServicelayerTest.createDefaultCatalog();
    de.hybris.platform.catalog.jalo.CatalogManager.getInstance()
        .createEssentialData(java.util.Collections.EMPTY_MAP, null);
    importCsv("/impex/essentialdata_1_usergroups.impex", "UTF-8");
    importCsv("/impex/essentialdata_2_b2bcommerce.impex", "UTF-8");
    importCsv("/b2bapprovalprocess/test/b2borganizations.csv", "UTF-8");

    i18nService.setCurrentLocale(Locale.ENGLISH);
    commonI18NService.setCurrentLanguage(commonI18NService.getLanguage("en"));
    commonI18NService.setCurrentCurrency(commonI18NService.getCurrency("USD"));
  }
コード例 #5
0
  @Before
  public void beforeTest() throws Exception {
    B2BIntegrationTest.loadTestData();
    importCsv("/b2bapprovalprocess/test/b2borganizations.csv", "UTF-8");
    importCsv("/b2bapprovalprocess/test/creditlimit.impex", "UTF-8");

    sessionService
        .getCurrentSession()
        .setAttribute(
            "user", this.modelService.<Object>toPersistenceLayer(userService.getAdminUser()));
    i18nService.setCurrentLocale(Locale.ENGLISH);
    commonI18NService.setCurrentLanguage(commonI18NService.getLanguage("en"));
    commonI18NService.setCurrentCurrency(commonI18NService.getCurrency("EUR"));
  }
  @Override
  @Before
  public void setUp() throws Exception {
    super.setUp();

    final CatalogVersionModel version =
        catalogVersionService.getCatalogVersion("hwcatalog", "Online");
    catalogVersionService.addSessionCatalogVersion(version);
    baseProduct = productService.getProductForCode(version, "HW2110-0019");
    partnerProduct = productService.getProductForCode(version, "HW2200-0561");
    user = userService.getUserForUID("demo");
    userService.setCurrentUser(user);
    currency = commonI18NService.getCurrency("EUR");
    commonI18NService.setCurrentCurrency(currency);
  }
コード例 #7
0
  @Before
  public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    searchResult = new SolrSearchResult(0, null, null, null, null, 0, 0, null, searchQuery, null);
    lang.setIsocode("de");

    when(commonI18NService.getCurrentLanguage()).thenReturn(lang);
    when(searchQuery.getFacetSearchConfig()).thenReturn(facetSearchConfig);

    final HashMap<KeywordRedirectMatchType, KeywordRedirectHandler> map =
        new HashMap<KeywordRedirectMatchType, KeywordRedirectHandler>();
    map.put(KeywordRedirectMatchType.CONTAINS, new DefaultContainsKeywordRedirectHandler());
    map.put(KeywordRedirectMatchType.ENDS_WITH, new DefaultEndsWithKeywordRedirectHandler());
    map.put(KeywordRedirectMatchType.EXACT, new DefaultExactKeywordRedirectHandler());
    map.put(KeywordRedirectMatchType.REGEX, new DefaultRegexKeywordRedirectHandler());
    map.put(KeywordRedirectMatchType.STARTS_WITH, new DefaultStartsWithKeywordRedirectHandler());

    solrKeywordRedirectService.setRedirectHandlers(map);
    when(keywordRedirectSorter.sort(Mockito.<List<SolrFacetSearchKeywordRedirectModel>>any()))
        .thenAnswer(
            new Answer() {
              @Override
              public List<KeywordRedirectValue> answer(final InvocationOnMock invocation) {
                final Object[] args = invocation.getArguments();
                return (List<KeywordRedirectValue>) args[0];
              }
            });
  }
コード例 #8
0
 @Test(expected = ConversionException.class)
 public void testPopulateLanguageUnknownIdent() {
   final CustomerData customerData = mock(CustomerData.class);
   final CustomerModel customerModel = new CustomerModel();
   final LanguageData languageData = mock(LanguageData.class);
   given(customerData.getLanguage()).willReturn(languageData);
   given(languageData.getIsocode()).willReturn("languageIso");
   given(commonI18NService.getLanguage("languageIso"))
       .willThrow(new UnknownIdentifierException(""));
   customerReversePopulator.populate(customerData, customerModel);
 }
コード例 #9
0
 private void createCustomerReview(
     final String headline,
     final UserModel user,
     final ProductModel product,
     final CustomerReviewApprovalType approvalStatus) {
   final CustomerReviewModel review =
       customerReviewService.createCustomerReview(
           Double.valueOf(3.0), headline, COMMENT, user, product);
   review.setApprovalStatus(approvalStatus);
   review.setLanguage(commonI18NService.getCurrentLanguage());
   modelService.save(review);
 }
コード例 #10
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());
  }
コード例 #11
0
  private OrderModel createNewOrder() {
    final OrderModel order = modelService.create(OrderModel.class);

    final UserModel user = userService.getCurrentUser();

    order.setUser(user);

    order.setCurrency(commonI18NService.getBaseCurrency());
    order.setDate(new java.util.Date());
    order.setNet(Boolean.FALSE);

    final OrderEntryModel entry1 = modelService.create(OrderEntryModel.class);
    entry1.setOrder(order);
    entry1.setQuantity(Long.valueOf(1));
    entry1.setUnit(productService.getOrderableUnit(product1));
    entry1.setProduct(product1);
    entry1.setEntryNumber(Integer.valueOf(0));

    final OrderEntryModel entry2 = modelService.create(OrderEntryModel.class);
    entry2.setOrder(order);
    entry2.setQuantity(Long.valueOf(1));
    entry2.setUnit(productService.getOrderableUnit(product2));
    entry2.setProduct(product2);
    entry2.setEntryNumber(Integer.valueOf(1));

    final OrderEntryModel entry3 = modelService.create(OrderEntryModel.class);
    entry3.setOrder(order);
    entry3.setQuantity(Long.valueOf(1));
    entry3.setUnit(productService.getOrderableUnit(product3));
    entry3.setProduct(product3);
    entry3.setEntryNumber(Integer.valueOf(2));

    final OrderEntryModel entry4 = modelService.create(OrderEntryModel.class);
    entry4.setOrder(order);
    entry4.setQuantity(Long.valueOf(1));
    entry4.setUnit(productService.getOrderableUnit(product4));
    entry4.setProduct(product4);
    entry4.setEntryNumber(Integer.valueOf(3));

    order.setEntries((List) Arrays.asList(entry1, entry2, entry3, entry4));

    return order;
  }
  @Before
  public void setUp() throws Exception {
    // final Create data for tests
    LOG.info("Creating data for DefaultChangeProductPriceBundleRuleDaoIntegrationTest ..");
    userService.setCurrentUser(userService.getAdminUser());
    final long startTime = System.currentTimeMillis();
    new CoreBasicDataCreator().createEssentialData(Collections.EMPTY_MAP, null);

    // importing test csv
    final String legacyModeBackup = Config.getParameter(ImpExConstants.Params.LEGACY_MODE_KEY);
    LOG.info(
        "Existing value for " + ImpExConstants.Params.LEGACY_MODE_KEY + " :" + legacyModeBackup);
    Config.setParameter(ImpExConstants.Params.LEGACY_MODE_KEY, "true");
    importCsv("/commerceservices/test/testCommerceCart.csv", "utf-8");
    Config.setParameter(ImpExConstants.Params.LEGACY_MODE_KEY, "false");
    importCsv("/subscriptionservices/test/testSubscriptionCommerceCartService.impex", "utf-8");
    importCsv("/configurablebundleservices/test/testBundleCommerceCartService.impex", "utf-8");
    importCsv("/configurablebundleservices/test/testApproveAllBundleTemplates.impex", "utf-8");
    Config.setParameter(ImpExConstants.Params.LEGACY_MODE_KEY, legacyModeBackup);

    LOG.info(
        "Finished data for DefaultChangeProductPriceBundleRuleDaoIntegrationTest "
            + (System.currentTimeMillis() - startTime)
            + "ms");

    baseSiteService.setCurrentBaseSite(baseSiteService.getBaseSiteForUID(TEST_BASESITE_UID), false);
    catalogVersionService.setSessionCatalogVersion("testCatalog", "Online");

    currencyUSD = commonI18NService.getCurrency("USD");
    currencyEUR = commonI18NService.getCurrency("EUR");
    galaxynexus = productService.getProductForCode("GALAXY_NEXUS");
    standardplan1y = productService.getProductForCode("PLAN_STANDARD_1Y");
    standardplan3y = productService.getProductForCode("PLAN_STANDARD_3Y");
    smartPhonePlanBundleTemplate =
        bundleTemplateService.getBundleTemplateForCode("SmartPhonePlanSelection");
    smartPhoneDeviceBundleTemplate =
        bundleTemplateService.getBundleTemplateForCode("SmartPhoneDeviceSelection");

    modelService.detachAll();
  }
コード例 #13
0
  protected OrderModel placeTestOrder(final boolean valid)
      throws InvalidCartException, CalculationException {
    final CartModel cart = cartService.getSessionCart();
    final UserModel user = userService.getCurrentUser();
    cartService.addNewEntry(cart, productService.getProductForCode("testProduct1"), 1, null);
    cartService.addNewEntry(cart, productService.getProductForCode("testProduct2"), 2, null);
    cartService.addNewEntry(cart, productService.getProductForCode("testProduct3"), 3, null);

    final AddressModel deliveryAddress = new AddressModel();
    deliveryAddress.setOwner(user);
    deliveryAddress.setFirstname("Der");
    deliveryAddress.setLastname("Buck");
    deliveryAddress.setTown("Muenchen");
    deliveryAddress.setCountry(commonI18NService.getCountry("DE"));
    modelService.save(deliveryAddress);

    final DebitPaymentInfoModel paymentInfo = new DebitPaymentInfoModel();
    paymentInfo.setOwner(cart);
    paymentInfo.setBank("MeineBank");
    paymentInfo.setUser(user);
    paymentInfo.setAccountNumber("34434");
    paymentInfo.setBankIDNumber("1111112");
    paymentInfo.setBaOwner("Ich");
    paymentInfo.setCode("testPaymentInfo1");
    modelService.save(paymentInfo);

    cart.setDeliveryMode(deliveryService.getDeliveryModeForCode("free"));
    cart.setDeliveryAddress(deliveryAddress);
    cart.setPaymentInfo(paymentInfo);

    final CardInfo card = new CardInfo();
    card.setCardType(CreditCardType.VISA);
    card.setCardNumber("4111111111111111");
    card.setExpirationMonth(Integer.valueOf(12));
    if (valid) {
      card.setExpirationYear(Integer.valueOf(Calendar.getInstance().get(Calendar.YEAR) + 2));
    } else {
      card.setExpirationYear(Integer.valueOf(Calendar.getInstance().get(Calendar.YEAR) - 2));
    }

    final PaymentTransactionModel paymentTransaction =
        paymentService
            .authorize(
                "code4" + codeNo++,
                BigDecimal.ONE,
                Currency.getInstance("EUR"),
                deliveryAddress,
                deliveryAddress,
                card)
            .getPaymentTransaction();

    cart.setPaymentTransactions(Collections.singletonList(paymentTransaction));
    modelService.save(cart);
    calculationService.calculate(cart);

    final CommerceCheckoutParameter parameter = new CommerceCheckoutParameter();
    parameter.setEnableHooks(true);
    parameter.setCart(cart);
    parameter.setSalesApplication(SalesApplication.WEB);

    return commerceCheckoutService.placeOrder(parameter).getOrder();
  }