TreeActivatePageAction implements Action { @Override public String doAction(Resource resource) throws PersistenceException, AecuException { Page page = context.getPageManager().getContainingPage(resource); if (page == null) { return "Unable to find a page for resource " + resource.getPath(); } String skip = skipDeactivated ? "skipping" : "not skipping"; try { performActivation(page); } catch (ReplicationException e) { throw new PersistenceException("Unable to replicate tree " + page.getPath(), e); } return "Replicated page tree " + page.getPath() + " " + skip + " deactivated pages (" + count + " pages)"; } TreeActivatePageAction(boolean skipDeactivated, BindingContext context); @Override String doAction(Resource resource);  }
@Test public void doAction_pageNotFound() throws PersistenceException, AecuException { 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_replicatorException() throws PersistenceException, ReplicationException, AecuException { doThrow(ReplicationException.class).when(replicator).replicate(session, ReplicationActionType.ACTIVATE, PATH); action.doAction(resource); }
@Test public void doAction_success() throws PersistenceException, ReplicationException, AecuException { String result = action.doAction(resource); assertTrue(result.contains("Replicated page tree")); assertTrue(result.contains("2 pages")); verify(replicator, times(1)).replicate(session, ReplicationActionType.ACTIVATE, PATH); verify(replicator, times(1)).replicate(session, ReplicationActionType.ACTIVATE, SUBPATH); }
@Test public void doAction_successDeactivatedSubpage() throws PersistenceException, ReplicationException, AecuException { ReplicationStatus replicationStatus = mock(ReplicationStatus.class); when(replicationStatus.isDeactivated()).thenReturn(true); when(subPage.adaptTo(ReplicationStatus.class)).thenReturn(replicationStatus); this.action = new TreeActivatePageAction(true, context); String result = action.doAction(resource); assertTrue(result.contains("Replicated page tree")); assertTrue(result.contains("1 pages")); verify(replicator, times(1)).replicate(session, ReplicationActionType.ACTIVATE, PATH); verify(replicator, never()).replicate(session, ReplicationActionType.ACTIVATE, SUBPATH); }