@Test public void testPublish() throws PublicationException { EventAdmin eventAdmin = Mockito.mock(EventAdmin.class); PublicationManager pman = new StandalonePublicationManager(eventAdmin); context.currentResource("/content/apache/sling-apache-org/index"); pman.publish(context.currentResource().adaptTo(Page.class)); Mockito.verify(eventAdmin).postEvent(Mockito.any()); ValueMap properties = context.currentResource().getChild("jcr:content").getValueMap(); assertEquals(true, properties.get(CMSConstants.PN_PUBLISHED, Boolean.class)); assertEquals("ADD", properties.get(CMSConstants.PN_LAST_PUBLICATION_TYPE, String.class)); }
@Override public void publish(PublishableResource resource) throws PublicationException { try { ModifiableValueMap properties = Optional .ofNullable(resource.getContentResource().adaptTo(ModifiableValueMap.class)) .orElseThrow(() -> new PublicationException("Cannot modify resource")); properties.put(CMSConstants.PN_PUBLISHED, true); properties.put(CMSConstants.PN_LAST_PUBLICATION, Calendar.getInstance()); properties.put(CMSConstants.PN_LAST_PUBLICATION_TYPE, PublicationType.ADD.toString()); resource.getResource().getResourceResolver().commit(); eventAdmin.postEvent(PublicationEvent.publish(resource, false)); } catch (PersistenceException e) { throw new PublicationException("Cannot save publication status", e); } }
StandalonePublicationManager implements PublicationManager { @Override public void publish(PublishableResource resource) throws PublicationException { try { ModifiableValueMap properties = Optional .ofNullable(resource.getContentResource().adaptTo(ModifiableValueMap.class)) .orElseThrow(() -> new PublicationException("Cannot modify resource")); properties.put(CMSConstants.PN_PUBLISHED, true); properties.put(CMSConstants.PN_LAST_PUBLICATION, Calendar.getInstance()); properties.put(CMSConstants.PN_LAST_PUBLICATION_TYPE, PublicationType.ADD.toString()); resource.getResource().getResourceResolver().commit(); eventAdmin.postEvent(PublicationEvent.publish(resource, false)); } catch (PersistenceException e) { throw new PublicationException("Cannot save publication status", e); } } }
StandalonePublicationManager implements PublicationManager { @Override public void publish(PublishableResource resource) throws PublicationException { try { ModifiableValueMap properties = Optional .ofNullable(resource.getContentResource().adaptTo(ModifiableValueMap.class)) .orElseThrow(() -> new PublicationException("Cannot modify resource")); properties.put(CMSConstants.PN_PUBLISHED, true); properties.put(CMSConstants.PN_LAST_PUBLICATION, Calendar.getInstance()); properties.put(CMSConstants.PN_LAST_PUBLICATION_TYPE, PublicationType.ADD.toString()); resource.getResource().getResourceResolver().commit(); eventAdmin.postEvent(PublicationEvent.publish(resource, false)); } catch (PersistenceException e) { throw new PublicationException("Cannot save publication status", e); } } StandalonePublicationManager(EventAdmin eventAdmin); }
StandalonePublicationManager implements PublicationManager { @Override public void publish(PublishableResource resource) throws PublicationException { try { ModifiableValueMap properties = Optional .ofNullable(resource.getContentResource().adaptTo(ModifiableValueMap.class)) .orElseThrow(() -> new PublicationException("Cannot modify resource")); properties.put(CMSConstants.PN_PUBLISHED, true); properties.put(CMSConstants.PN_LAST_PUBLICATION, Calendar.getInstance()); properties.put(CMSConstants.PN_LAST_PUBLICATION_TYPE, PublicationType.ADD.toString()); resource.getResource().getResourceResolver().commit(); eventAdmin.postEvent(PublicationEvent.publish(resource, false)); } catch (PersistenceException e) { throw new PublicationException("Cannot save publication status", e); } } StandalonePublicationManager(EventAdmin eventAdmin); @Override void publish(PublishableResource resource); @Override void unpublish(PublishableResource resource); @Override PUBLICATION_MODE getPublicationMode(); }
StandalonePublicationManager implements PublicationManager { @Override public void publish(PublishableResource resource) throws PublicationException { try { ModifiableValueMap properties = Optional .ofNullable(resource.getContentResource().adaptTo(ModifiableValueMap.class)) .orElseThrow(() -> new PublicationException("Cannot modify resource")); properties.put(CMSConstants.PN_PUBLISHED, true); properties.put(CMSConstants.PN_LAST_PUBLICATION, Calendar.getInstance()); properties.put(CMSConstants.PN_LAST_PUBLICATION_TYPE, PublicationType.ADD.toString()); resource.getResource().getResourceResolver().commit(); eventAdmin.postEvent(PublicationEvent.publish(resource, false)); } catch (PersistenceException e) { throw new PublicationException("Cannot save publication status", e); } } StandalonePublicationManager(EventAdmin eventAdmin); @Override void publish(PublishableResource resource); @Override void unpublish(PublishableResource resource); @Override PUBLICATION_MODE getPublicationMode();  }