@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);
 }
Ejemplo n.º 2
0
 @Test
 public void testCreate() {
   when(jdoTemplate.makePersistent(user)).thenReturn(user);
   User result = userService.create(user);
   verify(jdoTemplate).makePersistent(user);
   assertEquals("bill", result.getName());
 }
Ejemplo n.º 3
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());
 }
Ejemplo n.º 4
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());
 }
Ejemplo n.º 5
0
 @Before
 public void testSetup() {
   userService = new UserRestfulService(persistenceManagerFactory);
   userService.setJdoTemplate(jdoTemplate);
   user = new User();
   user.setId("asa");
   user.setName("bill");
   users = new ArrayList();
   users.add(user);
 }
 @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());
   }
 }
 @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;
 }