@Test public void testPagination() { PaginationConfiguration config = new PaginationConfiguration(0, 2, null, null, null, null); List<Customer> customers = customerService.list(config); Assert.assertEquals(2, customers.size()); Assert.assertEquals(Long.valueOf(1), customers.get(0).getId()); Assert.assertEquals(Long.valueOf(2), customers.get(1).getId()); config = new PaginationConfiguration(2, 2, null, null, null, null); customers = customerService.list(config); Assert.assertEquals(1, customers.size()); Assert.assertEquals(Long.valueOf(3), customers.get(0).getId()); }
@Test public void testCrud() throws Exception { databaseTester.onTearDown(); // crear db before tests // CREATE Assert.assertEquals(0, customerService.count()); Customer customer = new Customer(); customer.setName("Name"); customer.setEmail("*****@*****.**"); customer.setAddress("address"); customer.setPhone("111333444"); customerService.add(customer); Assert.assertEquals(1, customerService.count()); // READ Customer readcustomer = customerService.list().get(0); Assert.assertEquals(readcustomer.getName(), "Name"); Assert.assertEquals(readcustomer.getEmail(), "*****@*****.**"); Assert.assertEquals(readcustomer.getAddress(), "address"); Assert.assertEquals(readcustomer.getPhone(), "111333444"); // UPDATE readcustomer.setName("updatedName"); customerService.update(readcustomer); Customer updatedCustomer = customerService.list().get(0); Assert.assertEquals(updatedCustomer.getName(), "updatedName"); // DELETE customerService.delete(updatedCustomer.getId()); Assert.assertEquals(0, customerService.count()); }
@RequestMapping(value = "/customer/{customerNumber}", method = RequestMethod.GET) public ModelAndView getCustomer(@PathVariable("customerNumber") String customerNumber) { ModelAndView mav = new ModelAndView(); mav.setViewName("marshalview"); mav.addObject(customerService.getCustomer(customerNumber)); return mav; }
@Test public void testListAll() { List<Customer> customers = customerService.list(); Assert.assertEquals(3, customers.size()); for (int i = 0; i < 3; i++) { Assert.assertEquals(Long.valueOf(i + 1), customers.get(i).getId()); } }
@RequestMapping(value = "/customers", method = RequestMethod.GET) public ModelAndView getCustomers() { ModelAndView mav = new ModelAndView(); mav.setViewName("marshalview"); mav.addObject(new Customers(customerService.getCustomers())); return mav; }
@Test public void testFilterByMultipleFilters() { Map<String, Object> filters = new HashMap<String, Object>(); filters.put("name", "tele2"); filters.put("phone", "123456"); filters.put("address", "aaa"); PaginationConfiguration config = new PaginationConfiguration(0, 5, filters, null, null, null); List<Customer> customers = customerService.list(config); Assert.assertEquals(1, customers.size()); Assert.assertEquals(Long.valueOf(1), customers.get(0).getId()); }
@RequestMapping(value = "/customer/{customerNumber}", method = RequestMethod.PUT) public RedirectView updateCustomer(@RequestBody Customer customer) { customerService.updateCustomer(customer); return new RedirectView(customer.getCustomerNumber()); }
@RequestMapping(value = "/customer/{customerNumber}", method = RequestMethod.DELETE) public RedirectView deleteCustomer(@PathVariable("customerNumber") String customerNumber) { customerService.deleteCustomer(customerNumber); return new RedirectView("../customers"); }
@RequestMapping(value = "/customers", method = RequestMethod.POST) public RedirectView addCustomer(@RequestBody Customer customer) { customerService.addCustomer(customer); return new RedirectView("customers"); }
@Test public void testCountAll() { Assert.assertEquals(3, customerService.count()); }
@Test public void testFindById() { Customer customer = customerService.findById(1L); Assert.assertEquals("*****@*****.**", customer.getEmail()); }