GCSNotebookRepo implements NotebookRepo { @Override public Map<String, NoteInfo> list(AuthenticationInfo subject) throws IOException { try { Map<String, NoteInfo> infos = new HashMap<>(); Iterable<Blob> blobsUnderDir; if (basePath.isPresent()) { blobsUnderDir = storage .list(bucketName, BlobListOption.prefix(this.basePath.get() + "/")) .iterateAll(); } else { blobsUnderDir = storage .list(bucketName) .iterateAll(); } for (Blob b : blobsUnderDir) { Matcher matcher = notePathPattern.matcher(b.getName()); if (matcher.matches()) { String noteFileName = matcher.group(1); try { String noteId = getNoteId(noteFileName); String notePath = getNotePath("", noteFileName); infos.put(noteId, new NoteInfo(noteId, notePath)); } catch (IOException e) { LOGGER.warn(e.getMessage()); } } } return infos; } catch (StorageException se) { throw new IOException("Could not list GCS directory: " + se.getMessage(), se); } } GCSNotebookRepo(); @VisibleForTesting  GCSNotebookRepo(ZeppelinConfiguration zConf, Storage storage); @Override void init(ZeppelinConfiguration zConf); @Override Map<String, NoteInfo> list(AuthenticationInfo subject); @Override Note get(String noteId, String notePath, AuthenticationInfo subject); @Override void save(Note note, AuthenticationInfo subject); @Override void move(String noteId, String notePath, String newNotePath, AuthenticationInfo subject); @Override void move(String folderPath, String newFolderPath, AuthenticationInfo subject); @Override void remove(String noteId, String notePath, AuthenticationInfo subject); @Override void remove(String folderPath, AuthenticationInfo subject); @Override void close(); @Override List<NotebookRepoSettingsInfo> getSettings(AuthenticationInfo subject); @Override void updateSettings(Map<String, String> settings, AuthenticationInfo subject);  }
@Test public void testList_nonexistent() throws Exception { assertThat(notebookRepo.list(AUTH_INFO)).isEmpty(); }
@Test public void testList() throws Exception { createAt(runningNote, "note.zpln"); createAt(runningNote, "/note.zpln"); createAt(runningNote, "validid/my_12.zpln"); createAt(runningNote, "validid-2/my_123.zpln"); createAt(runningNote, "cannot-be-dir/note.json/foo"); createAt(runningNote, "cannot/be/nested/note.json"); Map<String, NoteInfo> infos = notebookRepo.list(AUTH_INFO); List<String> noteIds = new ArrayList<>(); for (NoteInfo info : infos.values()) { noteIds.add(info.getId()); } assertThat(noteIds).containsExactlyElementsIn(ImmutableList.of("12", "123")); }