コード例 #1
0
 @Test
 public void testDelete() {
   when(jdoTemplate.getObjectById(User.class, user.getId())).thenReturn(user);
   Response result = userService.delete(user.getId());
   verify(jdoTemplate).getObjectById(User.class, user.getId());
   verify(jdoTemplate).deletePersistent(user);
   assertEquals(200, result.getStatus());
 }
コード例 #2
0
 @Test
 public void testUpdate() {
   when(jdoTemplate.getObjectById(User.class, user.getId())).thenReturn(user);
   when(jdoTemplate.makePersistent(user)).thenReturn(user);
   User result = userService.update(user);
   verify(jdoTemplate).getObjectById(User.class, user.getId());
   verify(jdoTemplate).makePersistent(user);
   assertEquals("bill", result.getName());
 }
コード例 #3
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());
   }
 }
コード例 #4
0
 @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;
 }