public VehicleDTO createVehicleDTO(VehicleDTO vehicleDTO, Long shopId) { vehicleDTO.setShopId(shopId); vehicleDTO.setLicenceNo("苏A00098"); vehicleDTO.setBrand("奥迪"); vehicleDTO.setModel("A6"); vehicleDTO.setYear("2012"); return vehicleDTO; }
@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()); }