@DataProvider(name = "setupCustomers") public static Object[][] createCustomers() { Customer customer1 = new CustomerImpl(); customer1.setPassword("customer1Password"); customer1.setUsername("customer1"); Customer customer2 = new CustomerImpl(); customer2.setPassword("customer2Password"); customer2.setUsername("customer2"); return new Object[][] { new Object[] { customer1 }, new Object[] { customer2 } }; } }
cloned.setReceiveEmail(receiveEmail); cloned.setPasswordChangeRequired(passwordChangeRequired); cloned.setPassword(password); cloned.setLastName(lastName); cloned.setFirstName(firstName);
@Test(groups = { "changeCustomerPassword" }, dependsOnGroups = { "readCustomer" }) @Transactional @Commit public void changeCustomerPasswords() { for (String userName : userNames) { Customer customer = customerService.readCustomerByUsername(userName); customer.setPassword(customer.getPassword() + "-Changed"); customerService.saveCustomer(customer); } }
@Override public Entity update(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException { Entity entity = persistencePackage.getEntity(); try { PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective(); Map<String, FieldMetadata> adminProperties = helper.getSimpleMergedProperties(Customer.class.getName(), persistencePerspective); Object primaryKey = helper.getPrimaryKey(entity, adminProperties); Customer adminInstance = (Customer) dynamicEntityDao.retrieve(Class.forName(entity.getType()[0]), primaryKey); Entity errorEntity = validateUniqueUsername(entity, adminInstance, false); if (errorEntity != null) { return errorEntity; } String passwordBefore = adminInstance.getPassword(); adminInstance.setPassword(null); adminInstance = (Customer) helper.createPopulatedInstance(adminInstance, entity, adminProperties, false); adminInstance.setPassword(passwordBefore); if (useEmailForLogin) { adminInstance.setUsername(adminInstance.getEmailAddress()); } adminInstance = customerService.saveCustomer(adminInstance); Entity adminEntity = helper.getRecord(adminProperties, adminInstance, null, null); return adminEntity; } catch (Exception e) { throw new ServiceException("Unable to update entity for " + entity.getType()[0], e); } }
@Override @Transactional(TransactionUtils.DEFAULT_TRANSACTION_MANAGER) public Customer saveCustomer(Customer customer, boolean register) { if (register && !customer.isRegistered()) { customer.setRegistered(true); } if (customer.getUnencodedPassword() != null) { customer.setPassword(encodePassword(customer.getUnencodedPassword(), customer)); } // let's make sure they entered a new challenge answer (we will populate // the password field with hashed values so check that they have changed // id if (customer.getUnencodedChallengeAnswer() != null && !customer.getUnencodedChallengeAnswer().equals(customer.getChallengeAnswer())) { customer.setChallengeAnswer(encodePassword(customer.getUnencodedChallengeAnswer(), customer)); } return customerDao.save(customer); }
@Test(groups = "createCustomers", dependsOnGroups="createCustomerIdGeneration", dataProvider = "setupCustomers", dataProviderClass = CustomerDataProvider.class) @Rollback(false) public void createCustomer(Customer customerInfo) { Customer customer = customerService.createCustomerFromId(null); customer.setPassword(customerInfo.getPassword()); customer.setUsername(customerInfo.getUsername()); Long customerId = customer.getId(); assert customerId != null; customer = customerService.saveCustomer(customer); assert customer.getId() == customerId; userIds.add(customer.getId()); userNames.add(customer.getUsername()); }
public Customer createAnonymousCustomer() throws DataAccessException { Customer customer = customerService.createNewCustomer(); customer.setUsername(String.valueOf(customer.getId())); customer.setPassword(RandomStringUtils.randomAscii(8)); return customerService.saveCustomer(customer); }