@Test public void testUpdateCustomerMobile() throws Exception { ModelMap model = new ModelMap(); Long shopId = createShop(); CustomerDTO customer = new CustomerDTO(); customer = createCustomerDTO(customer, shopId); customer.setId(123456L); customer = userService.createCustomer(customer); request.getSession().setAttribute("shopId", shopId); request.setParameter("customerId", customer.getId().toString()); request.setParameter("mobile", "15851654173"); customerController.updateMobile(request, response); CustomerDTO customerNew = customerService.getCustomerById(customer.getId()); Assert.assertEquals("15851654173", customerNew.getMobile()); CustomerRecordDTO customerRecordDTO = new CustomerRecordDTO(); customerRecordDTO = createCustomerRecordDTO(customerRecordDTO, shopId); customerRecordDTO.setCustomerId(customer.getId()); customerRecordDTO = userService.createCustomerRecord(customerRecordDTO); request.getSession().setAttribute("shopId", shopId); request.setParameter("customerId", customer.getId().toString()); request.setParameter("mobile", "15851654173"); customerController.updateMobile(request, response); CustomerDTO customerDTO = userService.getCustomerDTOByCustomerId(customer.getId(), shopId); Assert.assertEquals("15851654173", customerDTO.getMobile()); }
@Test public void testClientInfo() throws Exception { ModelMap model = new ModelMap(); Long shopId = createShop(); request.getSession().setAttribute("shopId", shopId); CustomerRecordDTO customerRecordDTO = new CustomerRecordDTO(); CustomerDTO customer = new CustomerDTO(); CustomerVehicleDTO customerVehicleDTO = new CustomerVehicleDTO(); VehicleDTO vehicleDTO = new VehicleDTO(); createCustomerDTO(customer, shopId); createCustomerRecordDTO(customerRecordDTO, shopId); createVehicleDTO(vehicleDTO, shopId); IUserService userService = ServiceManager.getService(IUserService.class); userService.createCustomerRecord(customerRecordDTO); CustomerDTO customerDTO = userService.createCustomer(customer); VehicleDTO vehicleDTO1 = userService.createVehicle(vehicleDTO); userService.addVehicleToCustomer(vehicleDTO1.getId(), customerDTO.getId()); txnController.clientInfo(model, request, "MRS.SHAO", "15151774444", "phone", "2343545", "", ""); CustomerRecordDTO customerRecordDTO2 = (CustomerRecordDTO) model.get("customerRecordDTO"); Assert.assertEquals("MRS.SHAO", customerRecordDTO2.getName()); Assert.assertEquals("", customerRecordDTO2.getContact()); Assert.assertEquals("15151774444", customerRecordDTO2.getMobile()); txnController.clientInfo(model, request, "邵磊", "15151774443", "", "", "小邵", ""); CustomerRecordDTO customerRecordDTO3 = (CustomerRecordDTO) model.get("customerRecordDTO"); Assert.assertEquals("邵磊", customerRecordDTO3.getName()); Assert.assertEquals("15151774443", customerRecordDTO3.getMobile()); }
public CustomerRecordDTO createCustomerRecordDTO( CustomerRecordDTO customerRecordDTO, Long shopId) { customerRecordDTO.setShopId(shopId); customerRecordDTO.setName("MRS.SHAO"); customerRecordDTO.setCustomerId(2343545L); customerRecordDTO.setArea("苏州"); customerRecordDTO.setBankAccountName("test"); customerRecordDTO.setShortName("test"); customerRecordDTO.setCustomerKind("s"); customerRecordDTO.setMobile("15151774444"); customerRecordDTO.setAddress("shanghai"); customerRecordDTO.setContact("MR.SHAO"); customerRecordDTO.setPhone("0512-0808"); customerRecordDTO.setFax("test"); customerRecordDTO.setBank("test"); customerRecordDTO.setQq("test"); customerRecordDTO.setAccount("test"); customerRecordDTO.setMemberNumber("test"); customerRecordDTO.setEmail("test"); return customerRecordDTO; }
@Test public void testDeleteCustomer() throws Exception { Long shopId = createShop(); CustomerRecordDTO customerRecordDTO = new CustomerRecordDTO(); CustomerDTO customerDTO = new CustomerDTO(); customerDTO.setName("cfl"); customerDTO.setShopId(shopId); customerDTO.setArea("苏州"); customerDTO.setBankAccountName("test"); customerDTO.setShortName("test"); customerDTO.setCustomerKind("s"); customerDTO.setMobile("15151774444"); customerDTO.setAddress("shanghai"); customerDTO.setContact("MR.SHAO"); customerDTO.setFax("test"); customerDTO.setBank("test"); customerDTO.setQq("test"); customerDTO.setAccount("test"); customerDTO.setEmail("test"); customerDTO.setBirthday(222L); customerDTO.setLandLine("44444444"); ContactDTO[] contactDTOs = new ContactDTO[3]; ContactDTO contactDTO = new ContactDTO(); contactDTO.setCustomerId(customerDTO.getId()); contactDTO.setMobile("15151774444"); contactDTO.setIsMainContact(1); contactDTO.setShopId(shopId); contactDTO.setLevel(0); contactDTOs[0] = contactDTO; customerDTO.setContacts(contactDTOs); customerDTO = userService.createCustomer(customerDTO); customerRecordDTO.setShopId(shopId); customerRecordDTO.setName(customerDTO.getName()); customerRecordDTO.setCustomerId(customerDTO.getId()); customerRecordDTO.setArea(customerDTO.getArea()); customerRecordDTO.setBankAccountName(customerDTO.getBankAccountName()); customerRecordDTO.setShortName(customerDTO.getShortName()); customerRecordDTO.setCustomerKind(customerDTO.getCustomerKind()); customerRecordDTO.setMobile(customerDTO.getMobile()); customerRecordDTO.setAddress(customerDTO.getAddress()); customerRecordDTO.setContact(customerDTO.getContact()); customerRecordDTO.setPhone(customerDTO.getMobile()); customerRecordDTO.setFax(customerDTO.getFax()); customerRecordDTO.setBank(customerDTO.getBank()); customerRecordDTO.setQq(customerDTO.getQq()); customerRecordDTO.setAccount(customerDTO.getAccount()); customerRecordDTO.setMemberNumber(customerDTO.getMemberNumber()); customerRecordDTO.setEmail(customerDTO.getEmail()); customerRecordDTO = userService.createCustomerRecord(customerRecordDTO); VehicleDTO vehicleDTO = new VehicleDTO(); vehicleDTO.setLicenceNo("苏U66666"); vehicleDTO.setShopId(shopId); vehicleDTO = userService.createVehicle(vehicleDTO); CustomerVehicle customerVehicle = new CustomerVehicle(); customerVehicle.setCustomerId(customerDTO.getId()); customerVehicle.setVehicleId(vehicleDTO.getId()); UserWriter writer = userDaoManager.getWriter(); Object status = writer.begin(); try { writer.save(customerVehicle); writer.commit(status); } finally { writer.rollback(status); } Customer customer = userService.getCustomerByCustomerId(customerDTO.getId(), shopId); Assert.assertNotNull(customer); List<CustomerDTO> customerDTOList = userService.getCustomerByBirth(customerDTO.getBirthday()); Assert.assertEquals(1, customerDTOList.size()); customerDTOList = userService.getCustomerByLicenceNo(shopId, vehicleDTO.getLicenceNo()); Assert.assertEquals(1, customerDTOList.size()); customerDTOList = userService.getCustomerByMobile(shopId, customerDTO.getMobile()); Assert.assertEquals(1, customerDTOList.size()); customerDTOList = userService.getCustomerByName(shopId, customerDTO.getName()); Assert.assertEquals(1, customerDTOList.size()); customerDTOList = userService.getCustomerByTelephone(shopId, customerDTO.getLandLine()); Assert.assertEquals(1, customerDTOList.size()); List<CustomerRecordDTO> customerRecordDTOList = userService.getCustomerRecordByName(customerDTO.getName()); Assert.assertEquals(1, customerRecordDTOList.size()); List<VehicleDTO> vehicleDTOList = userService.getVehicleByLicenceNo(shopId, vehicleDTO.getLicenceNo()); Assert.assertEquals(1, vehicleDTOList.size()); vehicleDTOList = userService.getVehicleByMobile(shopId, customerDTO.getMobile()); Assert.assertEquals(1, vehicleDTOList.size()); request.setParameter("customerId", customerDTO.getId().toString()); customerController.deleteCustomer(modelMap, request, response); customer = userService.getCustomerByCustomerId(customerDTO.getId(), shopId); Assert.assertNotNull(customer); customerDTOList = userService.getCustomerByBirth(customerDTO.getBirthday()); Assert.assertEquals(0, customerDTOList.size()); customerDTOList = userService.getCustomerByLicenceNo(shopId, vehicleDTO.getLicenceNo()); Assert.assertEquals(0, customerDTOList.size()); customerDTOList = userService.getCustomerByMobile(shopId, customerDTO.getMobile()); Assert.assertEquals(0, customerDTOList.size()); customerDTOList = userService.getCustomerByName(shopId, customerDTO.getName()); Assert.assertNull(customerDTOList); customerDTOList = userService.getCustomerByTelephone(shopId, customerDTO.getLandLine()); Assert.assertEquals(0, customerDTOList.size()); customerRecordDTOList = userService.getCustomerRecordByName(customerDTO.getName()); Assert.assertEquals(0, customerRecordDTOList.size()); vehicleDTOList = userService.getVehicleByLicenceNo(shopId, vehicleDTO.getLicenceNo()); Assert.assertEquals(0, vehicleDTOList.size()); vehicleDTOList = userService.getVehicleByMobile(shopId, customerDTO.getMobile()); Assert.assertEquals(0, vehicleDTOList.size()); }
/** * 创建100个客户,客户记录 用于测试 * * @param shopId * @throws BcgogoException */ private void createCustomerAndCustomerRecordDTO(Long shopId) throws BcgogoException { for (int i = 0; i < 100; i++) { CustomerRecordDTO customerRecordDTO = new CustomerRecordDTO(); CustomerDTO customerDTO = new CustomerDTO(); customerDTO.setName("MRS.SHAO" + i); customerDTO.setShopId(shopId); customerDTO.setArea("苏州" + i); customerDTO.setBankAccountName("test" + i); customerDTO.setShortName("test" + i); customerDTO.setCustomerKind("s" + i); customerDTO.setMobile("15151774444" + i); customerDTO.setAddress("shanghai" + i); customerDTO.setContact("MR.SHAO" + i); customerDTO.setFax("test" + i); customerDTO.setBank("test" + i); customerDTO.setQq("test" + i); customerDTO.setAccount("test" + i); customerDTO.setEmail("test" + i); customerRecordDTO.setShopId(shopId); customerRecordDTO.setName(customerDTO.getName()); customerRecordDTO.setCustomerId(customerDTO.getId()); customerRecordDTO.setArea(customerDTO.getArea()); customerRecordDTO.setBankAccountName(customerDTO.getBankAccountName()); customerRecordDTO.setShortName(customerDTO.getShortName()); customerRecordDTO.setCustomerKind(customerDTO.getCustomerKind()); customerRecordDTO.setMobile(customerDTO.getMobile()); customerRecordDTO.setAddress(customerDTO.getAddress()); customerRecordDTO.setContact(customerDTO.getContact()); customerRecordDTO.setPhone(customerDTO.getMobile()); customerRecordDTO.setFax(customerDTO.getFax()); customerRecordDTO.setBank(customerDTO.getBank()); customerRecordDTO.setQq(customerDTO.getQq()); customerRecordDTO.setAccount(customerDTO.getAccount()); customerRecordDTO.setMemberNumber(customerDTO.getMemberNumber()); customerRecordDTO.setEmail(customerDTO.getEmail()); userService.createCustomerRecord(customerRecordDTO); userService.createCustomer(customerDTO); } }