This is an automated email from the ASF dual-hosted git repository. pdallig pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/zeppelin.git
The following commit(s) were added to refs/heads/master by this push: new d67d834bec [ZEPPELIN-5964] Fix renaming bug (#4658) d67d834bec is described below commit d67d834bec660dfb424bc31f7c77d4adcfdc460b Author: Matthias Koch <23187557+matthias-k...@users.noreply.github.com> AuthorDate: Fri Sep 22 08:37:01 2023 +0200 [ZEPPELIN-5964] Fix renaming bug (#4658) * [ZEPPELIN-5964] Fix renaming bug * [ZEPPELIN-5964] Use StringUtils --------- Co-authored-by: Matthias Koch <matthias-a.k...@rohde-schwarz.com> --- zeppelin-zengine/pom.xml | 5 ++++ .../org/apache/zeppelin/notebook/NoteManager.java | 4 +-- .../org/apache/zeppelin/notebook/NotebookTest.java | 29 ++++++++++++++++------ 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/zeppelin-zengine/pom.xml b/zeppelin-zengine/pom.xml index b974912fb7..9cd879c815 100644 --- a/zeppelin-zengine/pom.xml +++ b/zeppelin-zengine/pom.xml @@ -226,6 +226,11 @@ <scope>test</scope> </dependency> + <dependency> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter-params</artifactId> + </dependency> + <dependency> <groupId>org.mockito</groupId> <artifactId>mockito-core</artifactId> diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/NoteManager.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/NoteManager.java index 69c83030d6..dc8326e6fd 100644 --- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/NoteManager.java +++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/NoteManager.java @@ -247,7 +247,7 @@ public class NoteManager { this.notebookRepo.move(noteId, notePath, newNotePath, subject); // Update path of the note - if (!StringUtils.equalsIgnoreCase(notePath, newNotePath)) { + if (!StringUtils.equals(notePath, newNotePath)) { processNote(noteId, note -> { note.setPath(newNotePath); @@ -258,7 +258,7 @@ public class NoteManager { // save note if note name is changed, because we need to update the note field in note json. String oldNoteName = getNoteName(notePath); String newNoteName = getNoteName(newNotePath); - if (!StringUtils.equalsIgnoreCase(oldNoteName, newNoteName)) { + if (!StringUtils.equals(oldNoteName, newNoteName)) { processNote(noteId, note -> { this.notebookRepo.save(note, subject); diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NotebookTest.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NotebookTest.java index 1ca37e62f6..dd3feb2f22 100644 --- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NotebookTest.java +++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NotebookTest.java @@ -40,9 +40,13 @@ import org.apache.zeppelin.scheduler.Job; import org.apache.zeppelin.scheduler.Job.Status; import org.apache.zeppelin.user.AuthenticationInfo; import org.apache.zeppelin.user.Credentials; +import org.apache.commons.io.FilenameUtils; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; import org.quartz.SchedulerException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -65,6 +69,7 @@ import java.util.Set; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; +import java.util.stream.Stream; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -1858,19 +1863,21 @@ public class NotebookTest extends AbstractInterpreterTest implements ParagraphJo }); } - @Test - public void testMoveNote() throws InterruptedException, IOException { + @ParameterizedTest + @MethodSource("provideMoveTestParameters") + public void testMoveNote(String oldName, String newPath) throws InterruptedException, IOException { String noteId = null; + String newName = FilenameUtils.getBaseName(newPath); try { - noteId = notebook.createNote("note1", anonymous); + noteId = notebook.createNote(oldName, anonymous); notebook.processNote(noteId, note -> { - assertEquals("note1", note.getName()); - assertEquals("/note1", note.getPath()); + assertEquals(oldName, note.getName()); + assertEquals("/" + oldName, note.getPath()); return null; }); - notebook.moveNote(noteId, "/tmp/note2", anonymous); + notebook.moveNote(noteId, newPath, anonymous); // read note json file to check the name field is updated File noteFile = notebook.processNote(noteId, @@ -1878,7 +1885,7 @@ public class NotebookTest extends AbstractInterpreterTest implements ParagraphJo return new File(conf.getNotebookDir() + "/" + notebookRepo.buildNoteFileName(note)); }); String noteJson = IOUtils.toString(new FileInputStream(noteFile), StandardCharsets.UTF_8); - assertTrue(noteJson.contains("note2"), noteJson); + assertTrue(noteJson.contains(newName), noteJson); } finally { if (noteId != null) { notebook.removeNote(noteId, anonymous); @@ -1886,6 +1893,14 @@ public class NotebookTest extends AbstractInterpreterTest implements ParagraphJo } } + private static Stream<Arguments> provideMoveTestParameters() { + return Stream.of( + Arguments.of("note1", "/temp/note2"), + Arguments.of("note1", "/Note1"), + Arguments.of("note1", "/temp/Note1") + ); + } + @Override public void noteRunningStatusChange(String noteId, boolean newStatus) {