@Override @Transactional("blTransactionManager") public Customer deleteCustomerPaymentFromCustomer(Customer customer, CustomerPayment payment) { List<CustomerPayment> payments = customer.getCustomerPayments(); for (CustomerPayment customerPayment : payments) { if (customerPayment.getId().equals(payment.getId())) { customer.getCustomerPayments().remove(customerPayment); break; } } return customerService.saveCustomer(customer); }
@Override public void addCustomerAttributeToCustomer(Long customerId, String customerAttributeKey, String customerAttributeValue) throws PaymentException { Customer currentCustomer = CustomerState.getCustomer(); Long currentCustomerId = currentCustomer.getId(); if (customerId != null && !currentCustomerId.equals(customerId)) { logWarningIfCustomerMismatch(currentCustomerId, customerId); currentCustomer = customerService.readCustomerById(customerId); } CustomerAttribute customerAttribute = new CustomerAttributeImpl(); customerAttribute.setName(customerAttributeKey); customerAttribute.setValue(customerAttributeValue); customerAttribute.setCustomer(currentCustomer); currentCustomer.getCustomerAttributes().put(customerAttributeKey, customerAttribute); customerService.saveCustomer(currentCustomer); }
@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); } }
customer = customerService.saveCustomer(customer); return;
customer = customerService.saveCustomer(customer);
@Test(groups = { "testNamedOrderForCustomer" }, dependsOnGroups = { "testOrderProperties" }) public void testNamedOrderForCustomer() throws PricingException { Customer customer = customerService.createCustomerFromId(null); customer = customerService.saveCustomer(customer); Order order = orderService.createNamedOrderForCustomer("Birthday Order", customer); Long orderId = order.getId(); assert order != null; assert order.getName().equals("Birthday Order"); assert order.getCustomer().equals(customer); orderService.cancelOrder(order); assert orderService.findOrderById(orderId) == null; }
@Transactional @Test(groups = { "testMergeCart" }) public void testMergeWithNoCustomerCart() throws PricingException, RemoveFromCartException, AddToCartException { Order anonymousCart = setUpCartWithActiveSku(); Order customerCart = null; Customer customer = customerService.saveCustomer(createNamedCustomer()); MergeCartResponse response = mergeCartService.mergeCart(customer, anonymousCart); assert response.getOrder().getOrderItems().size() == 1; assert response.getOrder().getId().equals(anonymousCart.getId()); assert response.isMerged() == false; }
@Test(groups = { "testOrderPaymentInfos" }, dataProvider = "basicPaymentInfo", dataProviderClass = PaymentInfoDataProvider.class) @Transactional public void testOrderPaymentInfos(OrderPayment info) throws PricingException { Customer customer = customerService.saveCustomer(createNamedCustomer()); Order order = orderService.createNewCartForCustomer(customer); info = orderService.addPaymentToOrder(order, info, null); boolean foundInfo = false; assert order.getPayments() != null; for (OrderPayment testInfo : order.getPayments()) { if (testInfo.equals(info)) { foundInfo = true; } } assert foundInfo == true; assert orderService.findPaymentsForOrder(order) != null; }
return customerService.saveCustomer(resultHolder.getResult());
@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()); }
@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); } }
@Test(groups = {"testOfferDelete"}, dependsOnGroups = { "testFulfillmentGroupOffers"}) @Transactional public void testOfferDelete() throws Exception { CustomerOffer customerOffer = customerOfferDao.create(); Customer customer = createCustomer(); Long customerId = customer.getId(); customerOffer.setCustomer(customerService.saveCustomer(customer)); Offer offer = createOfferUtility.createOffer("1.20 Dollars Off Order Offer", OfferType.ORDER, OfferDiscountType.AMOUNT_OFF, 1.20, null, true, true, 10, null); offer = offerService.save(offer); Long offerId = offer.getId(); offerDao.delete(offer); Offer deletedOffer = offerDao.readOfferById(offerId); assert ((OfferImpl) deletedOffer).getArchived() == 'Y'; offer = createOfferUtility.createOffer("1.20 Dollars Off Order Offer", OfferType.ORDER, OfferDiscountType.AMOUNT_OFF, 1.20, null, true, true, 10, null); offer = offerService.save(offer); customerOffer.setOffer(offer); customerOffer = customerOfferDao.save(customerOffer); Long customerOfferId = customerOffer.getId(); customerOffer = customerOfferDao.readCustomerOfferById(customerOfferId); assert(customerOffer != null); Customer customer2 = createCustomer(); customerOffer.setCustomer(customerService.saveCustomer(customer2)); customerOffer = customerOfferDao.save(customerOffer); assert !customerOffer.getCustomer().getId().equals(customerId); customerOfferDao.delete(customerOffer); customerOffer = customerOfferDao.readCustomerOfferById(customerOfferId); assert customerOffer == null || ((OfferImpl) customerOffer).getArchived() == 'Y'; }
public Order setUpNamedOrder() throws AddToCartException { Customer customer = customerService.saveCustomer(createNamedCustomer()); Order order = orderService.createNamedOrderForCustomer("Boxes Named Order", customer); Product newProduct = addTestProduct("Cube Box", "Boxes"); Category newCategory = newProduct.getDefaultCategory(); order = orderService.addItem(order.getId(), new OrderItemRequestDTO(newProduct.getId(), newProduct.getDefaultSku().getId(), newCategory.getId(), 2), true); return order; }
public Order setUpCartWithActiveSku() throws AddToCartException { Customer customer = customerService.saveCustomer(createNamedCustomer()); Order order = orderService.createNewCartForCustomer(customer); Product newProduct = addTestProduct("Plastic Crate Active", "Crates"); Category newCategory = newProduct.getDefaultCategory(); order = orderService.addItem(order.getId(), new OrderItemRequestDTO(newProduct.getId(), newProduct.getDefaultSku().getId(), newCategory.getId(), 1), true); return order; }
public Order setUpCartWithInactiveSku() throws AddToCartException { Customer customer = customerService.saveCustomer(createNamedCustomer()); Order order = orderService.createNewCartForCustomer(customer); Product newProduct = addTestProduct("Plastic Crate Should Be Inactive", "Crates"); Category newCategory = newProduct.getDefaultCategory(); order = orderService.addItem(order.getId(), new OrderItemRequestDTO(newProduct.getId(), newProduct.getDefaultSku().getId(), newCategory.getId(), 1), true); // Make the SKU inactive newProduct.getDefaultSku().setActiveEndDate(DateUtils.addDays(new Date(), -1)); catalogService.saveSku(newProduct.getDefaultSku()); return order; }
Order order = orderService.createNewCartForCustomer(createCustomer()); customerService.saveCustomer(order.getCustomer());
Order order = orderService.createNewCartForCustomer(createCustomer()); customerService.saveCustomer(order.getCustomer());
@Controller public class DojoSpringMvcController { @Autowired(required =true) private CustomerService customerService; @RequestMapping(method = RequestMethod.POST , value = "/hello", produces = {MediaType.APPLICATION_JSON_VALUE}) @ResponseBody public List<Customer> sampleController(@RequestBody List<Customer> customers) { for (Customer current : customers) { customerService.saveCustomer(current); } return customers; } }
Order order = orderService.createNewCartForCustomer(customer); customerService.saveCustomer(order.getCustomer());
public Customer createAnonymousCustomer() throws DataAccessException { Customer customer = customerService.createNewCustomer(); customer.setUsername(String.valueOf(customer.getId())); customer.setPassword(RandomStringUtils.randomAscii(8)); return customerService.saveCustomer(customer); }