DeletePageAction implements Action { @Override public String doAction(Resource resource) throws PersistenceException { Page page = context.getPageManager().getContainingPage(resource); if (page == null) { return "Unable to find a page for resource " + resource.getPath(); } String successMessage = "Deleted page " + page.getPath(); if (context.isDryRun()) { return successMessage; } try { context.getPageManager().delete(page, false); } catch (WCMException e) { throw new PersistenceException("Unable to delete " + page.getPath()); } return successMessage; } DeletePageAction(BindingContext context); @Override String doAction(Resource resource);  }
@Test public void doAction_pageNotFound() throws PersistenceException { when(pageManager.getContainingPage(resource)).thenReturn(null); String result = action.doAction(resource); assertTrue(result.contains("Unable to find a page")); }
@Test(expected = PersistenceException.class) public void doAction_pagemanagerException() throws PersistenceException, WCMException { doThrow(WCMException.class).when(pageManager).delete(page, false); action.doAction(resource); }
@Test public void doAction_success() throws PersistenceException, WCMException { String result = action.doAction(resource); assertTrue(result.contains("Deleted page")); }
@Test public void doAction_successDryRun() throws PersistenceException, WCMException { when(context.isDryRun()).thenReturn(true); String result = action.doAction(resource); assertTrue(result.contains("Deleted page")); }