@Test
public void testMovePage() throws Exception {

	Page page1 = pageService.createPage(new Page("p1"));
	Page page2 = pageService.createPage(new Page("p2"));
	Page page3 = pageService.createPage(new Page("p3"));
	Playlist playlist = new Playlist("d1");
	playlist.addPageReference(new PageReference(page1));
	playlist.addPageReference(new PageReference(page2));
	playlist.addPageReference(new PageReference(page3));
	playlist = playlistService.createPlaylist(playlist);
	long id = playlist.getId();
	assertEquals("p1", getPlaylist(id).getPageReferences().get(0).getPage().getName());
	assertEquals("p2", getPlaylist(id).getPageReferences().get(1).getPage().getName());
	// swap
	playlistService.movePage(id, getPlaylist(id).getPageReferences().get(1).getId(), 0);
	assertEquals(3, getPlaylist(id).getPageReferences().size());
	assertEquals("p2", getPlaylist(id).getPageReferences().get(0).getPage().getName());
	assertEquals("p1", getPlaylist(id).getPageReferences().get(1).getPage().getName());
	// switch back
	playlistService.movePage(id, getPlaylist(id).getPageReferences().get(0).getId(), 1);
	assertEquals(3, getPlaylist(id).getPageReferences().size());
	assertEquals("p1", getPlaylist(id).getPageReferences().get(0).getPage().getName());
	assertEquals("p2", getPlaylist(id).getPageReferences().get(1).getPage().getName());
	// switch to same position
	playlistService.movePage(id, getPlaylist(id).getPageReferences().get(0).getId(), 0);
	assertEquals(3, getPlaylist(id).getPageReferences().size());
	assertEquals("p1", getPlaylist(id).getPageReferences().get(0).getPage().getName());
	assertEquals("p2", getPlaylist(id).getPageReferences().get(1).getPage().getName());
	assertEquals("p3", getPlaylist(id).getPageReferences().get(2).getPage().getName());
	// add some more pages
	Page page4 = pageService.createPage(new Page("p4"));
	Page page5 = pageService.createPage(new Page("p5"));
	playlistService.addPage(id, page4);
	playlistService.addPage(id, page5);
	assertEquals(5, getPlaylist(id).getPageReferences().size());
	assertEquals("p1", getPlaylist(id).getPageReferences().get(0).getPage().getName());
	assertEquals("p2", getPlaylist(id).getPageReferences().get(1).getPage().getName());
	assertEquals("p3", getPlaylist(id).getPageReferences().get(2).getPage().getName());
	assertEquals("p4", getPlaylist(id).getPageReferences().get(3).getPage().getName());
	assertEquals("p5", getPlaylist(id).getPageReferences().get(4).getPage().getName());
	playlistService.movePage(id, getPlaylist(id).getPageReferences().get(3).getId(), 2);
	assertEquals(5, getPlaylist(id).getPageReferences().size());
	assertEquals("p1", getPlaylist(id).getPageReferences().get(0).getPage().getName());
	assertEquals("p2", getPlaylist(id).getPageReferences().get(1).getPage().getName());
	assertEquals("p4", getPlaylist(id).getPageReferences().get(2).getPage().getName());
	assertEquals("p3", getPlaylist(id).getPageReferences().get(3).getPage().getName());
	assertEquals("p5", getPlaylist(id).getPageReferences().get(4).getPage().getName());
}