@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()); }
@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()); }