コード例 #1
0
 @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);
 }
コード例 #2
0
 @Test
 @SuppressWarnings("unchecked")
 public void testCRUD() throws Exception {
   APIResponse response = mailAPI.create(mail);
   if (response.isDone()) {
     mail = (Mail) response.getMessage();
     assertEquals(false, mail.isRead());
     assertEquals("aa", mail.getTitle());
     assertEquals("bb", mail.getContent());
     assertEquals("jack", mail.getReceiver().getName());
     assertEquals("bill", mail.getSender().getName());
   } else {
     logger.log(Level.SEVERE, response.getMessage().toString());
   }
   mail.setRead(true);
   mail.setTitle("cc");
   mail.setContent("dd");
   response = mailAPI.update(mail);
   if (response.isDone()) {
     mail = (Mail) response.getMessage();
     assertEquals(true, mail.isRead());
     assertEquals("cc", mail.getTitle());
     assertEquals("dd", mail.getContent());
   } else {
     logger.log(Level.SEVERE, response.getMessage().toString());
   }
   response = mailAPI.show("id=='" + mail.getId() + "'");
   if (response.isDone()) {
     assertEquals(1, ((Collection<Mail>) response.getMessage()).size());
   } else {
     logger.log(Level.SEVERE, response.getMessage().toString());
   }
   response = mailAPI.delete(mail.getId());
   if (response.isDone()) {
     assertEquals("Mail Deleted!", response.getMessage().toString());
   } else {
     logger.log(Level.SEVERE, response.getMessage().toString());
   }
   response = mailAPI.showByReceiver("id=='" + receiver.getId() + "'");
   if (response.isDone()) {
     assertEquals(0, ((Collection<Mail>) response.getMessage()).size());
   } else {
     logger.log(Level.SEVERE, response.getMessage().toString());
   }
   response = mailAPI.showBySender("id=='" + sender.getId() + "'");
   if (response.isDone()) {
     assertEquals(0, ((Collection<Mail>) response.getMessage()).size());
   } else {
     logger.log(Level.SEVERE, response.getMessage().toString());
   }
 }