WikibaseDataFetcher { public MediaInfoIdValue getMediaInfoIdByFileName(String fileName) throws IOException, MediaWikiApiErrorException { return getMediaInfoIdsByFileName(fileName).get(fileName); } WikibaseDataFetcher(ApiConnection connection, String siteUri); static WikibaseDataFetcher getWikidataDataFetcher(); static WikibaseDataFetcher getWikimediaCommonsDataFetcher(); DocumentDataFilter getFilter(); EntityDocument getEntityDocument(String entityId); Map<String, EntityDocument> getEntityDocuments(String... entityIds); Map<String, EntityDocument> getEntityDocuments(List<String> entityIds); EntityDocument getEntityDocumentByTitle(String siteKey, String title); Map<String, EntityDocument> getEntityDocumentsByTitle(
			String siteKey, String... titles); Map<String, EntityDocument> getEntityDocumentsByTitle(
			String siteKey, List<String> titles); MediaInfoIdValue getMediaInfoIdByFileName(String fileName); Map<String, MediaInfoIdValue> getMediaInfoIdsByFileName(String... fileNames); Map<String, MediaInfoIdValue> getMediaInfoIdsByFileName(List<String> fileNames); List<WbSearchEntitiesResult> searchEntities(String search); List<WbSearchEntitiesResult> searchEntities(String search, String language); List<WbSearchEntitiesResult> searchEntities(String search, Long limit); List<WbSearchEntitiesResult> searchEntities(String search, String language, Long limit); List<WbSearchEntitiesResult> searchEntities(WbGetEntitiesSearchData properties);  }
@Test public void testGetMediaInfoId() throws IOException, MediaWikiApiErrorException { Map<String, String> parameters = new HashMap<>(); parameters.put("action", "query"); parameters.put("format", "json"); parameters.put("titles", "File:Albert Einstein Head.jpg"); con.setWebResourceFromPath(parameters, getClass(), "/query-Albert Einstein Head.jpg.json", CompressionType.NONE); MediaInfoIdValue result = wdf.getMediaInfoIdByFileName("File:Albert Einstein Head.jpg"); assertEquals("M925243", result.getId()); }
@Test public void testGetMediaInfoIdWithoutPrefix() throws IOException, MediaWikiApiErrorException { Map<String, String> parameters = new HashMap<>(); parameters.put("action", "query"); parameters.put("format", "json"); parameters.put("titles", "File:Albert Einstein Head.jpg"); con.setWebResourceFromPath(parameters, getClass(), "/query-Albert Einstein Head.jpg.json", CompressionType.NONE); MediaInfoIdValue result = wdf.getMediaInfoIdByFileName("Albert Einstein Head.jpg"); assertEquals("M925243", result.getId()); }
@Test public void testGetMediaInfoIdNormalized() throws IOException, MediaWikiApiErrorException { Map<String, String> parameters = new HashMap<>(); parameters.put("action", "query"); parameters.put("format", "json"); parameters.put("titles", "File:Albert_Einstein_Head.jpg"); con.setWebResourceFromPath(parameters, getClass(), "/query-Albert Einstein Head normalized.jpg.json", CompressionType.NONE); MediaInfoIdValue result = wdf.getMediaInfoIdByFileName("File:Albert_Einstein_Head.jpg"); assertEquals("M925243", result.getId()); }
@Test public void testGetMediaInfoIdNormalizedWithoutPrefix() throws IOException, MediaWikiApiErrorException { Map<String, String> parameters = new HashMap<>(); parameters.put("action", "query"); parameters.put("format", "json"); parameters.put("titles", "File:Albert_Einstein_Head.jpg"); con.setWebResourceFromPath(parameters, getClass(), "/query-Albert Einstein Head normalized.jpg.json", CompressionType.NONE); MediaInfoIdValue result = wdf.getMediaInfoIdByFileName("Albert_Einstein_Head.jpg"); assertEquals("M925243", result.getId()); }
@Test public void testGetMediaInfoIdNotFound() throws IOException, MediaWikiApiErrorException { Map<String, String> parameters = new HashMap<>(); parameters.put("action", "query"); parameters.put("format", "json"); parameters.put("titles", "File:Not Found"); con.setWebResourceFromPath(parameters, getClass(), "/query-Not Found.json", CompressionType.NONE); MediaInfoIdValue result = wdf.getMediaInfoIdByFileName("Not Found"); assertNull(result); }