@Test public void toRestAttachment() { com.xpn.xwiki.api.Attachment xwikiAttachment = mock(com.xpn.xwiki.api.Attachment.class); when(xwikiAttachment.getLongSize()).thenReturn(123L); when(xwikiAttachment.getVersion()).thenReturn("2.1"); when(xwikiAttachment.getMimeType()).thenReturn("image/png"); when(xwikiAttachment.getAuthor()).thenReturn("XWiki.Admin"); when(xwikiAttachment.getDate()).thenReturn(new Date(1559347200000L)); AttachmentReference attachmentReference = new AttachmentReference("logo.png", new DocumentReference("test", "Space", "Page")); when(xwikiAttachment.getReference()).thenReturn(attachmentReference); when(xwikiAttachment.getFilename()).thenReturn(attachmentReference.getName()); Document document = mock(Document.class); when(xwikiAttachment.getDocument()).thenReturn(document); when(document.getFullName()).thenReturn("Space.Page"); when(document.getVersion()).thenReturn("5.2"); when(this.xwiki.getURL(attachmentReference, this.xcontext)).thenReturn("attachment URL"); when(this.xwiki.getExternalAttachmentURL("Space.Page", "logo.png", this.xcontext)) .thenReturn("attachment external URL"); when(this.defaultEntityReferenceSerializer.serialize(attachmentReference.getParent())) .thenReturn("test:Space.Page"); when(this.defaultEntityReferenceSerializer.serialize(attachmentReference)) .thenReturn("test:Space.Page@logo.png"); Attachment restAttachment = this.modelFactory.toRestAttachment(this.baseURI, xwikiAttachment, false, false); assertEquals(xwikiAttachment.getAuthor(), restAttachment.getAuthor()); assertEquals(xwikiAttachment.getDate(), restAttachment.getDate().getTime()); assertEquals(4, restAttachment.getHierarchy().getItems().size()); assertEquals("test:Space.Page@logo.png", restAttachment.getId()); assertEquals(3, restAttachment.getLinks().size()); assertEquals(xwikiAttachment.getLongSize(), restAttachment.getLongSize()); assertEquals(xwikiAttachment.getMimeType(), restAttachment.getMimeType()); assertEquals(xwikiAttachment.getFilename(), restAttachment.getName()); assertEquals("test:Space.Page", restAttachment.getPageId()); assertEquals(document.getVersion(), restAttachment.getPageVersion()); assertEquals(123, restAttachment.getSize()); assertEquals(xwikiAttachment.getVersion(), restAttachment.getVersion()); assertEquals("attachment external URL", restAttachment.getXwikiAbsoluteUrl()); assertEquals("attachment URL", restAttachment.getXwikiRelativeUrl()); }
public Attachment toRestAttachment(URI baseUri, com.xpn.xwiki.api.Attachment xwikiAttachment, Boolean withPrettyNames, boolean versionURL) { XWikiContext xcontext = this.xcontextProvider.get(); String relativeURL = xcontext.getWiki().getURL(xwikiAttachment.getReference(), xcontext); String absoluteURL = xcontext.getWiki().getExternalAttachmentURL(xwikiAttachment.getDocument().getFullName(), xwikiAttachment.getFilename(), xcontext); return toRestAttachment(baseUri, xwikiAttachment, relativeURL, absoluteURL, withPrettyNames, versionURL); }
ModelFactory { public Attachment toRestAttachment(URI baseUri, com.xpn.xwiki.api.Attachment xwikiAttachment, Boolean withPrettyNames, boolean versionURL) { XWikiContext xcontext = this.xcontextProvider.get(); String relativeURL = xcontext.getWiki().getURL(xwikiAttachment.getReference(), xcontext); String absoluteURL = xcontext.getWiki().getExternalAttachmentURL(xwikiAttachment.getDocument().getFullName(), xwikiAttachment.getFilename(), xcontext); return toRestAttachment(baseUri, xwikiAttachment, relativeURL, absoluteURL, withPrettyNames, versionURL); } }
ModelFactory { public Attachment toRestAttachment(URI baseUri, com.xpn.xwiki.api.Attachment xwikiAttachment, Boolean withPrettyNames, boolean versionURL) { XWikiContext xcontext = this.xcontextProvider.get(); String relativeURL = xcontext.getWiki().getURL(xwikiAttachment.getReference(), xcontext); String absoluteURL = xcontext.getWiki().getExternalAttachmentURL(xwikiAttachment.getDocument().getFullName(), xwikiAttachment.getFilename(), xcontext); return toRestAttachment(baseUri, xwikiAttachment, relativeURL, absoluteURL, withPrettyNames, versionURL); } ModelFactory(); }
ModelFactory { public Attachment toRestAttachment(URI baseUri, com.xpn.xwiki.api.Attachment xwikiAttachment, Boolean withPrettyNames, boolean versionURL) { XWikiContext xcontext = this.xcontextProvider.get(); String relativeURL = xcontext.getWiki().getURL(xwikiAttachment.getReference(), xcontext); String absoluteURL = xcontext.getWiki().getExternalAttachmentURL(xwikiAttachment.getDocument().getFullName(), xwikiAttachment.getFilename(), xcontext); return toRestAttachment(baseUri, xwikiAttachment, relativeURL, absoluteURL, withPrettyNames, versionURL); } ModelFactory(); boolean toDocument(Document doc, org.xwiki.rest.model.jaxb.Page restPage); ObjectSummary toRestObjectSummary(URI baseUri, Document doc, BaseObject xwikiObject, boolean useVersion,
        Boolean withPrettyNames); void toObject(com.xpn.xwiki.api.Object xwikiObject, org.xwiki.rest.model.jaxb.Object restObject); Object toRestObject(URI baseUri, Document doc, BaseObject xwikiObject, boolean useVersion,
        Boolean withPrettyNames); Wiki toRestWiki(URI baseUri, String wikiName); Space toRestSpace(URI baseUri, String wikiName, List<String> spaces, Document home); Translations toRestTranslations(URI baseUri, Document doc); PageSummary toRestPageSummary(URI baseUri, Document doc, Boolean withPrettyNames); Page toRestPage(URI baseUri, URI self, Document doc, boolean useVersion, Boolean withPrettyNames,
        Boolean withObjects, Boolean withXClass, Boolean withAttachments); Class toRestClass(URI baseUri, com.xpn.xwiki.api.Class xwikiClass); Attachment toRestAttachment(URI baseUri, com.xpn.xwiki.api.Attachment xwikiAttachment,
        Boolean withPrettyNames, boolean versionURL); Attachment toRestAttachment(URI baseUri, com.xpn.xwiki.api.Attachment xwikiAttachment,
        String xwikiRelativeUrl, String xwikiAbsoluteUrl, Boolean withPrettyNames, boolean versionURL); Hierarchy toRestHierarchy(EntityReference targetEntityReference, Boolean withPrettyNames); JobRequest toRestJobRequest(Request request); JobId toRestJobId(List<String> id); MapEntry toRestMapEntry(String key, java.lang.Object value); DefaultRequest toJobRequest(JobRequest restJobRequest); JobStatus toRestJobStatus(org.xwiki.job.event.status.JobStatus jobStatus, URI self, boolean request,
        boolean progress, boolean log, String logFromLevel); JobProgress toRestJobProgress(org.xwiki.job.event.status.JobProgress progress); JobLog toRestJobLog(LogTail logQueue, URI self, String level, String fromLevel); JobLog toRestJobLog(Iterable<LogEvent> logs, URI self); }
ModelFactory { public Attachment toRestAttachment(URI baseUri, com.xpn.xwiki.api.Attachment xwikiAttachment, Boolean withPrettyNames, boolean versionURL) { XWikiContext xcontext = this.xcontextProvider.get(); String relativeURL = xcontext.getWiki().getURL(xwikiAttachment.getReference(), xcontext); String absoluteURL = xcontext.getWiki().getExternalAttachmentURL(xwikiAttachment.getDocument().getFullName(), xwikiAttachment.getFilename(), xcontext); return toRestAttachment(baseUri, xwikiAttachment, relativeURL, absoluteURL, withPrettyNames, versionURL); } ModelFactory(); boolean toDocument(Document doc, org.xwiki.rest.model.jaxb.Page restPage); ObjectSummary toRestObjectSummary(URI baseUri, Document doc, BaseObject xwikiObject, boolean useVersion,
        Boolean withPrettyNames); void toObject(com.xpn.xwiki.api.Object xwikiObject, org.xwiki.rest.model.jaxb.Object restObject); Object toRestObject(URI baseUri, Document doc, BaseObject xwikiObject, boolean useVersion,
        Boolean withPrettyNames); Wiki toRestWiki(URI baseUri, String wikiName); Space toRestSpace(URI baseUri, String wikiName, List<String> spaces, Document home); Translations toRestTranslations(URI baseUri, Document doc); PageSummary toRestPageSummary(URI baseUri, Document doc, Boolean withPrettyNames); Page toRestPage(URI baseUri, URI self, Document doc, boolean useVersion, Boolean withPrettyNames,
        Boolean withObjects, Boolean withXClass, Boolean withAttachments); Class toRestClass(URI baseUri, com.xpn.xwiki.api.Class xwikiClass); Attachment toRestAttachment(URI baseUri, com.xpn.xwiki.api.Attachment xwikiAttachment,
        Boolean withPrettyNames, boolean versionURL); Attachment toRestAttachment(URI baseUri, com.xpn.xwiki.api.Attachment xwikiAttachment,
        String xwikiRelativeUrl, String xwikiAbsoluteUrl, Boolean withPrettyNames, boolean versionURL); Hierarchy toRestHierarchy(EntityReference targetEntityReference, Boolean withPrettyNames); JobRequest toRestJobRequest(Request request); JobId toRestJobId(List<String> id); MapEntry toRestMapEntry(String key, java.lang.Object value); DefaultRequest toJobRequest(JobRequest restJobRequest); JobStatus toRestJobStatus(org.xwiki.job.event.status.JobStatus jobStatus, URI self, boolean request,
        boolean progress, boolean log, String logFromLevel); JobProgress toRestJobProgress(org.xwiki.job.event.status.JobProgress progress); JobLog toRestJobLog(LogTail logQueue, URI self, String level, String fromLevel); JobLog toRestJobLog(Iterable<LogEvent> logs, URI self);  }