@Before public void testSetup() throws Exception { sender = new User(); sender.setName("bill"); receiver = new User(); receiver.setName("jack"); mail = new Mail(); mail.setRead(false); mail.setTitle("aa"); mail.setContent("bb"); userAPI = new UserAPI("localhost", "8888", "service"); mailAPI = new MailAPI("localhost", "8888", "service"); APIResponse response = userAPI.create(sender); if (response.isDone()) { sender = (User) response.getMessage(); assertEquals("bill", sender.getName()); } else { logger.log(Level.SEVERE, response.getMessage().toString()); } response = userAPI.create(receiver); if (response.isDone()) { receiver = (User) response.getMessage(); assertEquals("jack", receiver.getName()); } else { logger.log(Level.SEVERE, response.getMessage().toString()); } mail.setSender(sender); mail.setReceiver(receiver); }
@After @SuppressWarnings("unchecked") public void testShutdown() throws Exception { APIResponse response = userAPI.show("all"); if (response.isDone()) { Collection<User> users = (Collection<User>) response.getMessage(); for (User user : users) { response = userAPI.delete(user.getId()); if (response.isDone()) { assertEquals("User Deleted!", response.getMessage().toString()); } else { logger.log(Level.SEVERE, response.getMessage().toString()); } } } else { logger.log(Level.SEVERE, response.getMessage().toString()); } sender = null; receiver = null; mail = null; userAPI = null; mailAPI = null; }