package com.javaeye.jert.service.test;
import java.util.List;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.javaeye.jert.domain.bookmark.Bookmark;
import com.javaeye.jert.domain.bookmark.BookmarkFolder;
import com.javaeye.jert.service.BookmarkFolderService;
import com.javaeye.jert.service.BookmarkService;
/**
* @author firebody
* @since 2005-1-5
* @version $Revision: 1.3 $
*/
public class BookmarkServiceTest extends TestService {
private BookmarkService bookmarkService;
private BookmarkFolderService bookmarkFolderService;
protected void setUp() throws Exception {
super.setUp();
bookmarkFolderService = (BookmarkFolderService) context.getBean("bookmarkFolderService");
bookmarkService = (BookmarkService)context.getBean("bookmarkService");
}
/* (non-Javadoc)
* @see com.javaeye.jert.service.test.TestService#getContext()
*/
protected ApplicationContext getContext() {
return new ClassPathXmlApplicationContext("com/javaeye/jert/service/test/BookmarkServiceTest.xml");
}
public void testCRUDBookmarkFolder() throws Exception{
BookmarkFolder folder=new BookmarkFolder();
folder.setName("test for folder");
folder.setUserName("user");
bookmarkFolderService.createBookmarkFolder(folder);
BookmarkFolder storedFolder=bookmarkFolderService.getBookmarkFolder(folder.getId());
assertNotNull(storedFolder);
assertEquals(storedFolder.getName(),folder.getName());
assertEquals(storedFolder.getUserName(),folder.getUserName());
storedFolder.setName("changed");
bookmarkFolderService.updateBookmarkFolder(storedFolder);
BookmarkFolder changedFolder=bookmarkFolderService.getBookmarkFolder(storedFolder.getId());
assertEquals(changedFolder.getName(),"changed");
bookmarkFolderService.deleteBookmarkFolder(changedFolder);
assertNull(bookmarkFolderService.getBookmarkFolder(changedFolder.getId()));
}
public void testCRUDBookmark() throws Exception{
BookmarkFolder folder=new BookmarkFolder();
folder.setName("test for folder");
folder.setUserName("user");
bookmarkFolderService.createBookmarkFolder(folder);
Bookmark bm=new Bookmark();
bm.setName("test for bookmark");
bm.setQueryString("http://test/");
bm.setBookmarkFolder(folder);
bookmarkService.createBookmark(bm);
Bookmark storedbm=bookmarkService.getBookmark(bm.getId());
assertNotNull(storedbm);
assertEquals(storedbm.getName(),bm.getName());
assertEquals(storedbm.getQueryString(),bm.getQueryString());
storedbm.setName("changed");
bookmarkService.updateBookmark(storedbm);
Bookmark changedbm=bookmarkService.getBookmark(storedbm.getId());
assertEquals(changedbm.getName(),"changed");
bookmarkService.deleteBookmark(changedbm);
bookmarkFolderService.deleteBookmarkFolder(folder);
assertNull(bookmarkService.getBookmark(changedbm.getId()));
}
public void testForTest() throws Exception{
BookmarkFolder folder=new BookmarkFolder();
folder.setName("test for folder");
folder.setUserName("user");
bookmarkFolderService.createBookmarkFolder(folder);
Bookmark bm=new Bookmark();
bm.setName("test for bookmark");
bm.setQueryString("http://test/");
bm.setBookmarkFolder(folder);
bookmarkService.createBookmark(bm);
Bookmark storedbm=bookmarkService.getBookmark(bm.getId());
assertNotNull(storedbm);
assertEquals(storedbm.getName(),bm.getName());
assertEquals(storedbm.getQueryString(),bm.getQueryString());
assertEquals(storedbm.hashCode(),bm.hashCode());
}
public void testGetBookmarkFoldersByUser() throws Exception{
String userName="user";
BookmarkFolder folder1=new BookmarkFolder();
folder1.setName("test for folder1");
folder1.setUserName(userName);
BookmarkFolder folder2=new BookmarkFolder();
folder2.setName("test for folder2");
folder2.setUserName(userName);
BookmarkFolder folder3=new BookmarkFolder();
folder3.setName("test for folder3");
folder3.setUserName(userName);
bookmarkFolderService.createBookmarkFolder(folder1);
bookmarkFolderService.createBookmarkFolder(folder2);
bookmarkFolderService.createBookmarkFolder(folder3);
List folders=bookmarkFolderService.getBookmarkFoldersByUserName(userName);
assertEquals(folders.size(),3);
bookmarkFolderService.deleteBookmarkFolder(folder1);
bookmarkFolderService.deleteBookmarkFolder(folder2);
bookmarkFolderService.deleteBookmarkFolder(folder3);
}
}