@Test public void testDeterminePricingPolicyCustomer() throws Exception { final CustomerService customerService = context.mock(CustomerService.class, "customerService"); final ShopService shopService = context.mock(ShopService.class, "shopService"); final Shop shop = context.mock(Shop.class, "shop"); final Customer customer = context.mock(Customer.class, "customer"); context.checking(new Expectations() {{ allowing(shopService).getShopByCode("SHOP10"); will(returnValue(shop)); allowing(customerService).getCustomerByEmail("bob@doe.com", shop); will(returnValue(customer)); allowing(customer).getPricingPolicy(); will(returnValue("BOB")); }}); final PricingPolicyProviderCustomerAttributeImpl provider = new PricingPolicyProviderCustomerAttributeImpl(customerService, shopService); PricingPolicyProvider.PricingPolicy policy; policy = provider.determinePricingPolicy("SHOP10", "EUR", "bob@doe.com", "GB", "GB-CAM"); assertEquals(PricingPolicyProvider.PricingPolicy.Type.CUSTOMER, policy.getType()); assertEquals("BOB", policy.getID()); context.assertIsSatisfied(); }
@Override @Cacheable(value = "priceService-determinePricingPolicy") public PricingPolicy determinePricingPolicy(final String shopCode, final String currency, final String customerEmail, String countryCode, String stateCode) { final Shop shop = shopService.getShopByCode(shopCode); if (shop != null) { if (StringUtils.isNotBlank(customerEmail)) { final Customer customer = customerService.getCustomerByEmail(customerEmail, shop); if (customer != null && StringUtils.isNotBlank(customer.getPricingPolicy())) { return new PricingPolicyImpl(customer.getPricingPolicy(), PricingPolicy.Type.CUSTOMER); } } if (StringUtils.isNotBlank(countryCode)) { if (StringUtils.isNotBlank(stateCode)) { final String statePolicy = shop.getAttributeValueByCode(AttributeNamesKeys.Shop.SHOP_REGIONAL_PRICING_PREFIX + countryCode + "_" + stateCode); if (StringUtils.isNotBlank(statePolicy)) { return new PricingPolicyImpl(statePolicy, PricingPolicy.Type.STATE); } } final String countryPolicy = shop.getAttributeValueByCode(AttributeNamesKeys.Shop.SHOP_REGIONAL_PRICING_PREFIX + countryCode); if (StringUtils.isNotBlank(countryPolicy)) { return new PricingPolicyImpl(countryPolicy, PricingPolicy.Type.COUNTRY); } } } return DEFAULT; }
PricingPolicyProviderCustomerAttributeImpl implements PricingPolicyProvider, Configuration { @Override @Cacheable(value = "priceService-determinePricingPolicy") public PricingPolicy determinePricingPolicy(final String shopCode, final String currency, final String customerEmail, String countryCode, String stateCode) { final Shop shop = shopService.getShopByCode(shopCode); if (shop != null) { if (StringUtils.isNotBlank(customerEmail)) { final Customer customer = customerService.getCustomerByEmail(customerEmail, shop); if (customer != null && StringUtils.isNotBlank(customer.getPricingPolicy())) { return new PricingPolicyImpl(customer.getPricingPolicy(), PricingPolicy.Type.CUSTOMER); } } if (StringUtils.isNotBlank(countryCode)) { if (StringUtils.isNotBlank(stateCode)) { final String statePolicy = shop.getAttributeValueByCode(AttributeNamesKeys.Shop.SHOP_REGIONAL_PRICING_PREFIX + countryCode + "_" + stateCode); if (StringUtils.isNotBlank(statePolicy)) { return new PricingPolicyImpl(statePolicy, PricingPolicy.Type.STATE); } } final String countryPolicy = shop.getAttributeValueByCode(AttributeNamesKeys.Shop.SHOP_REGIONAL_PRICING_PREFIX + countryCode); if (StringUtils.isNotBlank(countryPolicy)) { return new PricingPolicyImpl(countryPolicy, PricingPolicy.Type.COUNTRY); } } } return DEFAULT; } }
PricingPolicyProviderCustomerAttributeImpl implements PricingPolicyProvider, Configuration { @Override @Cacheable(value = "priceService-determinePricingPolicy") public PricingPolicy determinePricingPolicy(final String shopCode, final String currency, final String customerEmail, String countryCode, String stateCode) { final Shop shop = shopService.getShopByCode(shopCode); if (shop != null) { if (StringUtils.isNotBlank(customerEmail)) { final Customer customer = customerService.getCustomerByEmail(customerEmail, shop); if (customer != null && StringUtils.isNotBlank(customer.getPricingPolicy())) { return new PricingPolicyImpl(customer.getPricingPolicy(), PricingPolicy.Type.CUSTOMER); } } if (StringUtils.isNotBlank(countryCode)) { if (StringUtils.isNotBlank(stateCode)) { final String statePolicy = shop.getAttributeValueByCode(AttributeNamesKeys.Shop.SHOP_REGIONAL_PRICING_PREFIX + countryCode + "_" + stateCode); if (StringUtils.isNotBlank(statePolicy)) { return new PricingPolicyImpl(statePolicy, PricingPolicy.Type.STATE); } } final String countryPolicy = shop.getAttributeValueByCode(AttributeNamesKeys.Shop.SHOP_REGIONAL_PRICING_PREFIX + countryCode); if (StringUtils.isNotBlank(countryPolicy)) { return new PricingPolicyImpl(countryPolicy, PricingPolicy.Type.COUNTRY); } } } return DEFAULT; } PricingPolicyProviderCustomerAttributeImpl(final CustomerService customerService,
                                                      final ShopService shopService); }
PricingPolicyProviderCustomerAttributeImpl implements PricingPolicyProvider, Configuration { @Override @Cacheable(value = "priceService-determinePricingPolicy") public PricingPolicy determinePricingPolicy(final String shopCode, final String currency, final String customerEmail, String countryCode, String stateCode) { final Shop shop = shopService.getShopByCode(shopCode); if (shop != null) { if (StringUtils.isNotBlank(customerEmail)) { final Customer customer = customerService.getCustomerByEmail(customerEmail, shop); if (customer != null && StringUtils.isNotBlank(customer.getPricingPolicy())) { return new PricingPolicyImpl(customer.getPricingPolicy(), PricingPolicy.Type.CUSTOMER); } } if (StringUtils.isNotBlank(countryCode)) { if (StringUtils.isNotBlank(stateCode)) { final String statePolicy = shop.getAttributeValueByCode(AttributeNamesKeys.Shop.SHOP_REGIONAL_PRICING_PREFIX + countryCode + "_" + stateCode); if (StringUtils.isNotBlank(statePolicy)) { return new PricingPolicyImpl(statePolicy, PricingPolicy.Type.STATE); } } final String countryPolicy = shop.getAttributeValueByCode(AttributeNamesKeys.Shop.SHOP_REGIONAL_PRICING_PREFIX + countryCode); if (StringUtils.isNotBlank(countryPolicy)) { return new PricingPolicyImpl(countryPolicy, PricingPolicy.Type.COUNTRY); } } } return DEFAULT; } PricingPolicyProviderCustomerAttributeImpl(final CustomerService customerService,
                                                      final ShopService shopService); @Override @Cacheable(value = "priceService-determinePricingPolicy") PricingPolicy determinePricingPolicy(final String shopCode, final String currency, final String customerEmail, String countryCode, String stateCode); @Override ConfigurationContext getCfgContext(); void setCfgContext(final ConfigurationContext cfgContext); }
PricingPolicyProviderCustomerAttributeImpl implements PricingPolicyProvider, Configuration { @Override @Cacheable(value = "priceService-determinePricingPolicy") public PricingPolicy determinePricingPolicy(final String shopCode, final String currency, final String customerEmail, String countryCode, String stateCode) { final Shop shop = shopService.getShopByCode(shopCode); if (shop != null) { if (StringUtils.isNotBlank(customerEmail)) { final Customer customer = customerService.getCustomerByEmail(customerEmail, shop); if (customer != null && StringUtils.isNotBlank(customer.getPricingPolicy())) { return new PricingPolicyImpl(customer.getPricingPolicy(), PricingPolicy.Type.CUSTOMER); } } if (StringUtils.isNotBlank(countryCode)) { if (StringUtils.isNotBlank(stateCode)) { final String statePolicy = shop.getAttributeValueByCode(AttributeNamesKeys.Shop.SHOP_REGIONAL_PRICING_PREFIX + countryCode + "_" + stateCode); if (StringUtils.isNotBlank(statePolicy)) { return new PricingPolicyImpl(statePolicy, PricingPolicy.Type.STATE); } } final String countryPolicy = shop.getAttributeValueByCode(AttributeNamesKeys.Shop.SHOP_REGIONAL_PRICING_PREFIX + countryCode); if (StringUtils.isNotBlank(countryPolicy)) { return new PricingPolicyImpl(countryPolicy, PricingPolicy.Type.COUNTRY); } } } return DEFAULT; } PricingPolicyProviderCustomerAttributeImpl(final CustomerService customerService,
                                                      final ShopService shopService); @Override @Cacheable(value = "priceService-determinePricingPolicy") PricingPolicy determinePricingPolicy(final String shopCode, final String currency, final String customerEmail, String countryCode, String stateCode); @Override ConfigurationContext getCfgContext(); void setCfgContext(final ConfigurationContext cfgContext);  }