@Test public void testPublish() throws PublicationException { PublicationManagerFactory publicationManagerFactory = Mockito.mock(PublicationManagerFactory.class); PublicationManager publicationManager = Mockito.mock(PublicationManager.class); Mockito.when(publicationManagerFactory.getPublicationManager()).thenReturn(publicationManager); context.registerService(PublicationManagerFactory.class, publicationManagerFactory); PublishPostOperation publishPostOperation = context.registerInjectActivateService(new PublishPostOperation()); PostResponse response = Mockito.mock(PostResponse.class); publishPostOperation.run(context.request(), response, null); Mockito.verify(publicationManager).publish(Mockito.any()); Mockito.verify(response, Mockito.never()).setError(Mockito.any()); Mockito.verify(response).setPath(context.currentResource().getPath()); }
@Override public void run(SlingHttpServletRequest request, PostResponse response, SlingPostProcessor[] processors) { final List<Modification> changes = new ArrayList<>(); try { response.setPath(request.getResource().getPath()); publicationManagerFactory.getPublicationManager() .publish(request.getResource().adaptTo(PublishableResource.class)); if (processors != null) { for (SlingPostProcessor processor : processors) { processor.process(request, changes); } } request.getResourceResolver().commit(); response.onModified(request.getResource().getPath()); } catch (Exception e) { log.error("Failed to publish", e); response.setError(e); } }
PublishPostOperation implements PostOperation { @Override public void run(SlingHttpServletRequest request, PostResponse response, SlingPostProcessor[] processors) { final List<Modification> changes = new ArrayList<>(); try { response.setPath(request.getResource().getPath()); publicationManagerFactory.getPublicationManager() .publish(request.getResource().adaptTo(PublishableResource.class)); if (processors != null) { for (SlingPostProcessor processor : processors) { processor.process(request, changes); } } request.getResourceResolver().commit(); response.onModified(request.getResource().getPath()); } catch (Exception e) { log.error("Failed to publish", e); response.setError(e); } } }
PublishPostOperation implements PostOperation { @Override public void run(SlingHttpServletRequest request, PostResponse response, SlingPostProcessor[] processors) { final List<Modification> changes = new ArrayList<>(); try { response.setPath(request.getResource().getPath()); publicationManagerFactory.getPublicationManager() .publish(request.getResource().adaptTo(PublishableResource.class)); if (processors != null) { for (SlingPostProcessor processor : processors) { processor.process(request, changes); } } request.getResourceResolver().commit(); response.onModified(request.getResource().getPath()); } catch (Exception e) { log.error("Failed to publish", e); response.setError(e); } }  }
PublishPostOperation implements PostOperation { @Override public void run(SlingHttpServletRequest request, PostResponse response, SlingPostProcessor[] processors) { final List<Modification> changes = new ArrayList<>(); try { response.setPath(request.getResource().getPath()); publicationManagerFactory.getPublicationManager() .publish(request.getResource().adaptTo(PublishableResource.class)); if (processors != null) { for (SlingPostProcessor processor : processors) { processor.process(request, changes); } } request.getResourceResolver().commit(); response.onModified(request.getResource().getPath()); } catch (Exception e) { log.error("Failed to publish", e); response.setError(e); } }  @Override void run(SlingHttpServletRequest request, PostResponse response, SlingPostProcessor[] processors); }
PublishPostOperation implements PostOperation { @Override public void run(SlingHttpServletRequest request, PostResponse response, SlingPostProcessor[] processors) { final List<Modification> changes = new ArrayList<>(); try { response.setPath(request.getResource().getPath()); publicationManagerFactory.getPublicationManager() .publish(request.getResource().adaptTo(PublishableResource.class)); if (processors != null) { for (SlingPostProcessor processor : processors) { processor.process(request, changes); } } request.getResourceResolver().commit(); response.onModified(request.getResource().getPath()); } catch (Exception e) { log.error("Failed to publish", e); response.setError(e); } }  @Override void run(SlingHttpServletRequest request, PostResponse response, SlingPostProcessor[] processors);  }