@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()); }
/** ******** */ private B2BCustomerModel createB2BCustomerModel(final CustomerModel customer) { final B2BCustomerModel b2bCustomer = new B2BCustomerModel(); b2bCustomer.setEmail(customer.getUid()); b2bCustomer.setName(customer.getName()); b2bCustomer.setTitle(customer.getTitle()); b2bCustomer.setUid(customer.getUid()); b2bCustomer.setDefaultB2BUnit(createB2BUnit()); return b2bCustomer; }
/** **** */ private CustomerModel createCustomerModel() { final CustomerModel customer = new CustomerModel(); customer.setName(NAME); customer.setUid(DEFAULT_EMAIL); final TitleModel titleModel = new TitleModel(); titleModel.setCode(TITLE); customer.setTitle(titleModel); return customer; }
@Test public void testPopulateEssencial() { final CustomerData customerData = mock(CustomerData.class); final CustomerModel customerModel = new CustomerModel(); given(customerData.getFirstName()).willReturn("firstName"); given(customerData.getLastName()).willReturn("lastName"); given(customerData.getTitleCode()).willReturn(null); given(customerNameStrategy.getName("firstName", "lastName")).willReturn("firstName lastName"); customerReversePopulator.populate(customerData, customerModel); Assert.assertEquals("firstName lastName", customerModel.getName()); Assert.assertNull(customerModel.getTitle()); }
@Override public Boolean get(final CustomerModel model) { if (model == null) { throw new IllegalArgumentException("Item model is required"); } // Accelerator stores the email in the ID (uid) field final String email = model.getUid(); return Boolean.valueOf( email != null && (email.endsWith("hybris.de") || email.endsWith("hybris.com"))); }
/** Test localized validation messages for type based validation. */ @Test public void testTypeConstraintLocalization() { // create a DynamicConstraint which always evaluates a Beanshellscript to 'false' final DynamicConstraintModel constraint = modelService.create(DynamicConstraintModel.class); constraint.setId("typeConstraint"); constraint.setLanguage(ValidatorLanguage.BEANSHELL); final ComposedTypeModel userModel = typeService.getComposedType(UserModel.class); constraint.setType(userModel); constraint.setExpression("return false;"); constraint.setMessage("{type} fails validation", Locale.UK); constraint.setMessage("{type} ist nicht valide", Locale.GERMANY); modelService.save(constraint); validationService.reloadValidationEngine(); // create a CustomerModel which gets validated final CustomerModel model = modelService.create(CustomerModel.class); model.setUid("BeanShellValidatable"); // assert english and german localized messages // both are taken from 'message' attribute // placeholder {type} is processed assertLocalization(Locale.ENGLISH, "CustomerModel fails validation", model); assertLocalization(Locale.GERMAN, "CustomerModel ist nicht valide", model); // nullify localized message for UK // this enabled ResourceBundle fallback constraint.setMessage(null, Locale.UK); // same as above but english localization is now taken from resource bundle assertLocalization( Locale.ENGLISH, "Type \"CustomerModel\" and script \"return false;\" reports an error.", model); assertLocalization(Locale.GERMAN, "CustomerModel ist nicht valide", model); }