@Test public void getAttachments() throws Exception { this.xcontext.setWikiId("other"); Query query = mock(Query.class); when(this.queryManager.createQuery("select doc.space, doc.name, doc.version, attachment " + "from XWikiDocument as doc, XWikiAttachment as attachment " + "where attachment.docId = doc.id and doc.fullName = :localDocumentReference and" + " upper(attachment.author) like :author and upper(attachment.filename) like :name and" + " (attachment.mimeType is null or attachment.mimeType = '' or upper(attachment.mimeType) like :mediaType0" + " or upper(attachment.filename) like :extension0)", Query.HQL)).thenReturn(query); mockContainsQueryParam(query, "author", "MFLOREA"); mockContainsQueryParam(query, "name", "LOGO"); mockContainsQueryParam(query, "mediaType0", "VIDEO/"); mockSuffixQueryParam(query, "extension0", ".PNG"); when(query.setOffset(10)).thenReturn(query); when(query.setLimit(5)).thenReturn(query); XWikiAttachment imageAttachment = mock(XWikiAttachment.class, "image"); when(imageAttachment.getFilename()).thenReturn("logo.pNg"); XWikiAttachment videoAttachment = mock(XWikiAttachment.class, "video"); when(videoAttachment.getFilename()).thenReturn("video.mp4"); when(videoAttachment.getMimeType(this.xcontext)).thenReturn("video/mp4"); XWikiAttachment textAttachment = mock(XWikiAttachment.class, "text"); when(textAttachment.getFilename()).thenReturn("plain.txt"); when(textAttachment.getMimeType(this.xcontext)).thenReturn("text/plain"); List<Object> results = Arrays.asList(new Object[] {"Path.To", "Page", "1.3", videoAttachment}, new Object[] {"Path.To", "Page", "1.3", textAttachment}, new Object[] {"Path.To", "Page", "1.3", imageAttachment}); when(query.execute()).thenReturn(results); DocumentReference documentReference = new DocumentReference("test", Arrays.asList("Path", "To"), "Page"); when(this.defaultSpaceReferenceResover.resolve(eq("Path.To"), any())) .thenReturn(documentReference.getLastSpaceReference()); when(this.localEntityReferenceSerializer.serialize(documentReference)).thenReturn("Path.To.Page"); Attachment videoRestAttachment = mock(Attachment.class, "video"); Attachment imageRestAttachment = mock(Attachment.class, "image"); when(this.modelFactory.toRestAttachment(eq(this.uriInfo.getBaseUri()), any(), eq(true), eq(false))) .thenReturn(videoRestAttachment, imageRestAttachment); Attachments attachments = this.attachmentsResource.getAttachments("test", "Path/spaces/To", "Page", 10, 5, true, "logo", "mflorea", ".png,video/"); verify(query).bindValue("localDocumentReference", "Path.To.Page"); verify(this.modelFactory, times(2)).toRestAttachment(eq(this.uriInfo.getBaseUri()), any(), eq(true), eq(false)); assertEquals(Arrays.asList(videoRestAttachment, imageRestAttachment), attachments.getAttachments()); assertEquals("other", this.xcontext.getWikiId()); }
@Override public Attachments getAttachments(String wiki, String spaces, String page, Integer offset, Integer limit, Boolean withPrettyNames, String name, String author, String fileTypes) throws XWikiRestException { Map<String, String> filters = new HashMap<>(); filters.put(NAME, name); filters.put("author", author); filters.put("fileTypes", fileTypes); return super.getAttachments(new DocumentReference(wiki, parseSpaceSegments(spaces), page), filters, offset, limit, withPrettyNames); }
AttachmentsResourceImpl extends BaseAttachmentsResource implements AttachmentsResource { @Override public Attachments getAttachments(String wiki, String spaces, String page, Integer offset, Integer limit, Boolean withPrettyNames, String name, String author, String fileTypes) throws XWikiRestException { Map<String, String> filters = new HashMap<>(); filters.put(NAME, name); filters.put("author", author); filters.put("fileTypes", fileTypes); return super.getAttachments(new DocumentReference(wiki, parseSpaceSegments(spaces), page), filters, offset, limit, withPrettyNames); } }
AttachmentsResourceImpl extends BaseAttachmentsResource implements AttachmentsResource { @Override public Attachments getAttachments(String wiki, String spaces, String page, Integer offset, Integer limit, Boolean withPrettyNames, String name, String author, String fileTypes) throws XWikiRestException { Map<String, String> filters = new HashMap<>(); filters.put(NAME, name); filters.put("author", author); filters.put("fileTypes", fileTypes); return super.getAttachments(new DocumentReference(wiki, parseSpaceSegments(spaces), page), filters, offset, limit, withPrettyNames); }  }
AttachmentsResourceImpl extends BaseAttachmentsResource implements AttachmentsResource { @Override public Attachments getAttachments(String wiki, String spaces, String page, Integer offset, Integer limit, Boolean withPrettyNames, String name, String author, String fileTypes) throws XWikiRestException { Map<String, String> filters = new HashMap<>(); filters.put(NAME, name); filters.put("author", author); filters.put("fileTypes", fileTypes); return super.getAttachments(new DocumentReference(wiki, parseSpaceSegments(spaces), page), filters, offset, limit, withPrettyNames); }  @Override Attachments getAttachments(String wiki, String spaces, String page, Integer offset, Integer limit,
        Boolean withPrettyNames, String name, String author, String fileTypes); @Override Response addAttachment(String wikiName, String spaceName, String pageName, Multipart multipart,
        Boolean withPrettyNames, Boolean createPage); }
AttachmentsResourceImpl extends BaseAttachmentsResource implements AttachmentsResource { @Override public Attachments getAttachments(String wiki, String spaces, String page, Integer offset, Integer limit, Boolean withPrettyNames, String name, String author, String fileTypes) throws XWikiRestException { Map<String, String> filters = new HashMap<>(); filters.put(NAME, name); filters.put("author", author); filters.put("fileTypes", fileTypes); return super.getAttachments(new DocumentReference(wiki, parseSpaceSegments(spaces), page), filters, offset, limit, withPrettyNames); }  @Override Attachments getAttachments(String wiki, String spaces, String page, Integer offset, Integer limit,
        Boolean withPrettyNames, String name, String author, String fileTypes); @Override Response addAttachment(String wikiName, String spaceName, String pageName, Multipart multipart,
        Boolean withPrettyNames, Boolean createPage);  }